Only show user-presets in favorite sidebar
[ardour.git] / gtk2_ardour / transform_dialog.h
1 /*
2    Copyright (C) 2009-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 __transform_dialog_h__
21 #define __transform_dialog_h__
22
23 #include <list>
24 #include <string>
25
26 #include <gtkmm/combobox.h>
27 #include <gtkmm/liststore.h>
28 #include <gtkmm/treemodel.h>
29 #include <gtkmm/spinbutton.h>
30
31 #include "ardour/midi_model.h"
32 #include "ardour/transform.h"
33 #include "ardour/types.h"
34
35 #include "ardour_dialog.h"
36
37 /** Dialog for building a MIDI note transformation.
38  *
39  * This can build transformations with any number of operations, but is limited
40  * in power and can't build arbitrary transformations since there is no way to do
41  * conceptually parenthetical things (i.e. push things to the stack).
42  *
43  * With this, it is possible to build transformations that process a single
44  * value in a series of steps starting with a seed, like: "value = seed OP
45  * value OP value ..." where OP is +, -, *, or /, left associative with no
46  * precedence.  This is simple and pretty clear to the user what's going to
47  * happen, though a bit limited.  It would be nice if the GUI could build
48  * fancier transformations, but it's not obvious how to do this without making
49  * things more confusing.
50  */
51 class TransformDialog : public ArdourDialog
52 {
53 public:
54         TransformDialog();
55
56         ARDOUR::Transform::Program get();
57
58 private:
59         typedef ARDOUR::MidiModel::NoteDiffCommand::Property Property;
60         typedef ARDOUR::Transform::Value                     Value;
61         typedef ARDOUR::Transform::Value::Source             Source;
62         typedef ARDOUR::Transform::Operation::Operator       Operator;
63         typedef ARDOUR::Transform::Operation                 Operation;
64
65         struct SourceCols : public Gtk::TreeModelColumnRecord {
66                 SourceCols() { add(source); add(label); }
67
68                 Gtk::TreeModelColumn<Source>      source;
69                 Gtk::TreeModelColumn<std::string> label;
70         };
71
72         struct PropertyCols : public Gtk::TreeModelColumnRecord {
73                 PropertyCols() { add(property); add(label); }
74
75                 Gtk::TreeModelColumn<Property>    property;
76                 Gtk::TreeModelColumn<std::string> label;
77         };
78
79         struct OperatorCols : public Gtk::TreeModelColumnRecord {
80                 OperatorCols() { add(op); add(label); }
81
82                 Gtk::TreeModelColumn<Operator>    op;
83                 Gtk::TreeModelColumn<std::string> label;
84         };
85
86         struct Model {
87                 Model();
88
89                 SourceCols                   source_cols;
90                 Glib::RefPtr<Gtk::ListStore> source_list;
91                 PropertyCols                 property_cols;
92                 Glib::RefPtr<Gtk::ListStore> property_list;
93                 OperatorCols                 operator_cols;
94                 Glib::RefPtr<Gtk::ListStore> operator_list;
95         };
96
97         struct ValueChooser : public Gtk::HBox {
98                 ValueChooser(const Model& model);
99
100                 /** Append code to `ops` that pushes value to stack. */
101                 void get(std::list<Operation>& ops);
102
103                 void set_target_property(Property prop);
104                 void source_changed();
105
106                 double get_value () const;
107                 double get_max () const;
108
109                 const Model&    model;            ///< Models for combo boxes
110                 Property        target_property;  ///< Property on source
111                 Gtk::ComboBox   source_combo;     ///< Value source chooser
112                 Gtk::ComboBox   property_combo;   ///< Property chooser
113                 Gtk::SpinButton value_spinner;    ///< Value or minimum for RANDOM
114                 Gtk::Label      to_label;         ///< "to" label for RANDOM
115                 Gtk::SpinButton max_spinner;      ///< Maximum for RANDOM
116         };
117
118         struct OperationChooser : public Gtk::HBox {
119                 OperationChooser(const Model& model);
120
121                 /** Append operations to `ops`. */
122                 void get(std::list<Operation>& ops);
123
124                 void remove_clicked();
125
126                 const Model&  model;
127                 Gtk::ComboBox operator_combo;
128                 ValueChooser  value_chooser;
129                 Gtk::Button   remove_button;
130         };
131
132         void property_changed();
133         void add_clicked();
134
135         Model         _model;
136         Gtk::ComboBox _property_combo;
137         ValueChooser* _seed_chooser;
138         Gtk::VBox     _operations_box;
139         Gtk::Button   _add_button;
140 };
141
142 #endif /* __transform_dialog_h__ */