Ardour  9.0-pre0-582-g084a23a80d
transform.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014-2015 David Robillard <d@drobilla.net>
3  * Copyright (C) 2017 Paul Davis <paul@linuxaudiosystems.com>
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 along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #pragma once
21 
22 #include <stack>
23 #include <string>
24 
26 #include "ardour/midi_model.h"
27 #include "ardour/midi_operator.h"
28 #include "ardour/types.h"
29 #include "ardour/variant.h"
30 
31 namespace ARDOUR {
32 
51 public:
55 
57  struct Context {
58  Context() : index(0) {}
59 
61 
62  std::stack<Variant> stack;
63  size_t index;
64  size_t n_notes;
67  };
68 
70  struct Value {
74  enum Source {
81  RANDOM
82  };
83 
84  Value() : source(NOWHERE) {}
85  Value(Source s) : source(s) {}
86  Value(const Variant& v) : source(LITERAL), value(v) {}
87  Value(double v) : source(LITERAL), value(Variant(v)) {}
88 
90  Variant eval(const Context& context) const;
91 
95  };
96 
102  struct Operation {
103  enum Operator {
105  ADD,
106  SUB,
108  DIV,
109  MOD
110  };
111 
112  Operation(Operator o, const Value& a=Value()) : op(o), arg(a) {}
113 
115  void eval(Context& context) const;
116 
119  };
120 
126  struct Program {
128  std::list<Operation> ops;
129  };
130 
131  Transform(const Program& prog);
132 
133  PBD::Command* operator()(std::shared_ptr<ARDOUR::MidiModel> model,
135  std::vector<Notes>& seqs);
136 
137  std::string name() const { return std::string ("transform"); }
138 
139 private:
140  const Program _prog;
141 };
142 
143 } /* namespace */
144 
Evoral::Sequence< Temporal::Beats >::Notes Notes
Definition: transform.h:53
const Program _prog
Definition: transform.h:140
Evoral::Sequence< Temporal::Beats >::NotePtr NotePtr
Definition: transform.h:52
Transform(const Program &prog)
std::string name() const
Definition: transform.h:137
ARDOUR::MidiModel::NoteDiffCommand::Property Property
Definition: transform.h:54
PBD::Command * operator()(std::shared_ptr< ARDOUR::MidiModel > model, Temporal::Beats position, std::vector< Notes > &seqs)
std::multiset< NotePtr, EarlierNoteComparator > Notes
Definition: Sequence.h:157
std::shared_ptr< Evoral::Note< Time > > NotePtr
Definition: Sequence.h:89
#define LIBARDOUR_API
union Value Value
NotePtr this_note
Current note.
Definition: transform.h:66
size_t index
Index of current note.
Definition: transform.h:63
size_t n_notes
Total number of notes to process.
Definition: transform.h:64
NotePtr prev_note
Previous note.
Definition: transform.h:65
std::stack< Variant > stack
The stack of everything.
Definition: transform.h:62
Operation(Operator o, const Value &a=Value())
Definition: transform.h:112
void eval(Context &context) const
@ SUB
Subtract top from second-top.
Definition: transform.h:106
@ ADD
Add top two values.
Definition: transform.h:105
@ MULT
Multiply top two values.
Definition: transform.h:107
@ PUSH
Push argument to the stack.
Definition: transform.h:104
@ DIV
Divide second-top by top.
Definition: transform.h:108
std::list< Operation > ops
List of operations.
Definition: transform.h:128
Property prop
Property to calculate.
Definition: transform.h:127
Variant eval(const Context &context) const
@ LITERAL
Given literal value.
Definition: transform.h:80
@ THIS_NOTE
Value from this note.
Definition: transform.h:76
@ INDEX
Index of the current note.
Definition: transform.h:78
@ N_NOTES
Total number of notes to process.
Definition: transform.h:79
@ PREV_NOTE
Value from the previous note.
Definition: transform.h:77
Property prop
Property for all other sources.
Definition: transform.h:94
Variant value
Value for LITERAL.
Definition: transform.h:93
Source source
Source of value.
Definition: transform.h:92
Value(const Variant &v)
Definition: transform.h:86