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