Drop references held by any GUI Lua script after execution
[ardour.git] / gtk2_ardour / transform_dialog.h
1 /*
2  * Copyright (C) 2014-2015 David Robillard <d@drobilla.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18
19 #ifndef __transform_dialog_h__
20 #define __transform_dialog_h__
21
22 #include <list>
23 #include <string>
24
25 #include <gtkmm/combobox.h>
26 #include <gtkmm/liststore.h>
27 #include <gtkmm/treemodel.h>
28 #include <gtkmm/spinbutton.h>
29
30 #include "ardour/midi_model.h"
31 #include "ardour/transform.h"
32 #include "ardour/types.h"
33
34 #include "ardour_dialog.h"
35
36 /** Dialog for building a MIDI note transformation.
37  *
38  * This can build transformations with any number of operations, but is limited
39  * in power and can't build arbitrary transformations since there is no way to do
40  * conceptually parenthetical things (i.e. push things to the stack).
41  *
42  * With this, it is possible to build transformations that process a single
43  * value in a series of steps starting with a seed, like: "value = seed OP
44  * value OP value ..." where OP is +, -, *, or /, left associative with no
45  * precedence.  This is simple and pretty clear to the user what's going to
46  * happen, though a bit limited.  It would be nice if the GUI could build
47  * fancier transformations, but it's not obvious how to do this without making
48  * things more confusing.
49  */
50 class TransformDialog : public ArdourDialog
51 {
52 public:
53         TransformDialog();
54
55         ARDOUR::Transform::Program get();
56
57 private:
58         typedef ARDOUR::MidiModel::NoteDiffCommand::Property Property;
59         typedef ARDOUR::Transform::Value                     Value;
60         typedef ARDOUR::Transform::Value::Source             Source;
61         typedef ARDOUR::Transform::Operation::Operator       Operator;
62         typedef ARDOUR::Transform::Operation                 Operation;
63
64         struct SourceCols : public Gtk::TreeModelColumnRecord {
65                 SourceCols() { add(source); add(label); }
66
67                 Gtk::TreeModelColumn<Source>      source;
68                 Gtk::TreeModelColumn<std::string> label;
69         };
70
71         struct PropertyCols : public Gtk::TreeModelColumnRecord {
72                 PropertyCols() { add(property); add(label); }
73
74                 Gtk::TreeModelColumn<Property>    property;
75                 Gtk::TreeModelColumn<std::string> label;
76         };
77
78         struct OperatorCols : public Gtk::TreeModelColumnRecord {
79                 OperatorCols() { add(op); add(label); }
80
81                 Gtk::TreeModelColumn<Operator>    op;
82                 Gtk::TreeModelColumn<std::string> label;
83         };
84
85         struct Model {
86                 Model();
87
88                 SourceCols                   source_cols;
89                 Glib::RefPtr<Gtk::ListStore> source_list;
90                 PropertyCols                 property_cols;
91                 Glib::RefPtr<Gtk::ListStore> property_list;
92                 OperatorCols                 operator_cols;
93                 Glib::RefPtr<Gtk::ListStore> operator_list;
94         };
95
96         struct ValueChooser : public Gtk::HBox {
97                 ValueChooser(const Model& model);
98
99                 /** Append code to `ops` that pushes value to stack. */
100                 void get(std::list<Operation>& ops);
101
102                 void set_target_property(Property prop);
103                 void source_changed();
104
105                 double get_value () const;
106                 double get_max () const;
107
108                 const Model&    model;            ///< Models for combo boxes
109                 Property        target_property;  ///< Property on source
110                 Gtk::ComboBox   source_combo;     ///< Value source chooser
111                 Gtk::ComboBox   property_combo;   ///< Property chooser
112                 Gtk::SpinButton value_spinner;    ///< Value or minimum for RANDOM
113                 Gtk::Label      to_label;         ///< "to" label for RANDOM
114                 Gtk::SpinButton max_spinner;      ///< Maximum for RANDOM
115         };
116
117         struct OperationChooser : public Gtk::HBox {
118                 OperationChooser(const Model& model);
119
120                 /** Append operations to `ops`. */
121                 void get(std::list<Operation>& ops);
122
123                 void remove_clicked();
124
125                 const Model&  model;
126                 Gtk::ComboBox operator_combo;
127                 ValueChooser  value_chooser;
128                 Gtk::Button   remove_button;
129         };
130
131         void property_changed();
132         void add_clicked();
133
134         Model         _model;
135         Gtk::ComboBox _property_combo;
136         ValueChooser* _seed_chooser;
137         Gtk::VBox     _operations_box;
138         Gtk::Button   _add_button;
139 };
140
141 #endif /* __transform_dialog_h__ */