ardour
transform.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 Paul Davis
3  Author: David Robillard
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 
20 #ifndef __ardour_transform_h__
21 #define __ardour_transform_h__
22 
23 #include <stack>
24 #include <string>
25 
27 #include "ardour/midi_model.h"
28 #include "ardour/midi_operator.h"
29 #include "ardour/types.h"
30 #include "ardour/variant.h"
31 
32 namespace ARDOUR {
33 
52 public:
56 
58  struct Context {
59  Context() : index(0) {}
60 
61  Variant pop();
62 
63  std::stack<Variant> stack;
64  size_t index;
65  size_t n_notes;
66  NotePtr prev_note;
67  NotePtr this_note;
68  };
69 
71  struct Value {
75  enum Source {
82  RANDOM
83  };
84 
85  Value() : source(NOWHERE) {}
86  Value(Source s) : source(s) {}
87  Value(const Variant& v) : source(LITERAL), value(v) {}
88  Value(double v) : source(LITERAL), value(Variant(v)) {}
89 
91  Variant eval(const Context& context) const;
92 
95  Property prop;
96  };
97 
103  struct Operation {
104  enum Operator {
106  ADD,
107  SUB,
109  DIV,
110  MOD
111  };
112 
113  Operation(Operator o, const Value& a=Value()) : op(o), arg(a) {}
114 
116  void eval(Context& context) const;
117 
120  };
121 
127  struct Program {
128  Property prop;
129  std::list<Operation> ops;
130  };
131 
132  Transform(const Program& prog);
133 
136  std::vector<Notes>& seqs);
137 
138  std::string name() const { return std::string ("transform"); }
139 
140 private:
141  const Program _prog;
142 };
143 
144 } /* namespace */
145 
146 #endif /* __ardour_transform_h__ */
ARDOUR::MidiModel::NoteDiffCommand::Property Property
Definition: transform.h:55
Value(const Variant &v)
Definition: transform.h:87
std::multiset< NotePtr, EarlierNoteComparator > Notes
Definition: Sequence.hpp:153
const Program _prog
Definition: transform.h:141
Total number of notes to process.
Definition: transform.h:80
Property prop
Property to calculate.
Definition: transform.h:128
Subtract top from second-top.
Definition: transform.h:107
Variant value
Value for LITERAL.
Definition: transform.h:94
Divide second-top by top.
Definition: transform.h:109
Index of the current note.
Definition: transform.h:79
Definition: amp.h:29
Add top two values.
Definition: transform.h:106
Source source
Source of value.
Definition: transform.h:93
Value from the previous note.
Definition: transform.h:78
size_t n_notes
Total number of notes to process.
Definition: transform.h:65
Value from this note.
Definition: transform.h:77
Evoral::Sequence< Evoral::Beats >::Notes Notes
Definition: transform.h:54
std::string name() const
Definition: transform.h:138
std::stack< Variant > stack
The stack of everything.
Definition: transform.h:63
#define LIBARDOUR_API
size_t index
Index of current note.
Definition: transform.h:64
NotePtr prev_note
Previous note.
Definition: transform.h:66
LIBARDOUR_API PBD::PropertyDescriptor< framepos_t > position
Definition: region.cc:65
Given literal value.
Definition: transform.h:81
Push argument to the stack.
Definition: transform.h:105
Operation(Operator o, const Value &a=Value())
Definition: transform.h:113
NotePtr this_note
Current note.
Definition: transform.h:67
std::list< Operation > ops
List of operations.
Definition: transform.h:129
Multiply top two values.
Definition: transform.h:108
Evoral::Sequence< Evoral::Beats >::NotePtr NotePtr
Definition: transform.h:53
Property prop
Property for all other sources.
Definition: transform.h:95