debug output
[ardour.git] / gtk2_ardour / quantize_dialog.cc
1 /*
2    Copyright (C) 2009 Paul Davis
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
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <gtkmm/stock.h>
21 #include "gtkmm2ext/utils.h"
22
23 #include "quantize_dialog.h"
24 #include "public_editor.h"
25
26 #include "i18n.h"
27
28 using namespace std;
29 using namespace Gtk;
30 using namespace Gtkmm2ext;
31 using namespace ARDOUR;
32
33 static const gchar *_grid_strings[] = {
34         N_("main grid"),
35         N_("Beats/128"),
36         N_("Beats/64"),
37         N_("Beats/32"),
38         N_("Beats/16"),
39         N_("Beats/8"),
40         N_("Beats/4"),
41         N_("Beats/3"),
42         N_("Beats"),
43         0
44 };
45
46 static const gchar *_type_strings[] = {
47         N_("Grid"),
48         N_("Legato"),
49         N_("Groove"),
50         0
51 };
52
53 std::vector<std::string> QuantizeDialog::grid_strings;
54 std::vector<std::string> QuantizeDialog::type_strings;
55
56 QuantizeDialog::QuantizeDialog (PublicEditor& e)
57         : ArdourDialog (_("Quantize"), false, false)
58         , editor (e)
59         , type_label (_("Quantize Type"))
60         , strength_adjustment (100.0, 0.0, 100.0, 1.0, 10.0)
61         , strength_spinner (strength_adjustment)
62         , strength_label (_("Strength"))
63         , swing_adjustment (100.0, -130.0, 130.0, 1.0, 10.0)
64         , swing_spinner (swing_adjustment)
65         , swing_button (_("Swing"))
66         , threshold_adjustment (0.0, -1920.0, 1920.0, 1.0, 10.0) // XXX MAGIC TICK NUMBER FIX ME
67         , threshold_spinner (threshold_adjustment)
68         , threshold_label (_("Threshold (ticks)"))
69         , snap_start_button (_("Snap note start"))
70         , snap_end_button (_("Snap note end"))
71 {
72         if (grid_strings.empty()) {
73                 grid_strings =  I18N (_grid_strings);
74                 type_strings =  I18N (_type_strings);
75         }
76
77         set_popdown_strings (start_grid_combo, grid_strings);
78         start_grid_combo.set_active_text (grid_strings.front());
79         set_popdown_strings (end_grid_combo, grid_strings);
80         end_grid_combo.set_active_text (grid_strings.front());
81
82         set_popdown_strings (type_combo, type_strings);
83         type_combo.set_active_text (type_strings.front());
84
85         get_vbox()->set_border_width (12);
86
87         HBox* hbox;
88
89         hbox = manage (new HBox);
90         hbox->set_spacing (12);
91         hbox->set_border_width (6);
92         hbox->pack_start (type_label);
93         hbox->pack_start (type_combo);
94         hbox->show ();
95         type_label.show ();
96         type_combo.show ();
97         get_vbox()->pack_start (*hbox);
98
99         hbox = manage (new HBox);
100         hbox->set_spacing (12);
101         hbox->set_border_width (6);
102         hbox->pack_start (snap_start_button);
103         hbox->pack_start (start_grid_combo);
104         hbox->show ();
105         snap_start_button.show ();
106         start_grid_combo.show ();
107         get_vbox()->pack_start (*hbox);
108
109         hbox = manage (new HBox);
110         hbox->set_spacing (12);
111         hbox->set_border_width (6);
112         hbox->pack_start (snap_end_button);
113         hbox->pack_start (end_grid_combo);
114         hbox->show ();
115         snap_end_button.show ();
116         end_grid_combo.show ();
117         get_vbox()->pack_start (*hbox);
118
119         hbox = manage (new HBox);
120         hbox->set_spacing (12);
121         hbox->set_border_width (6);
122         hbox->pack_start (threshold_label);
123         hbox->pack_start (threshold_spinner);
124         hbox->show ();
125         threshold_label.show ();
126         threshold_spinner.show ();
127         get_vbox()->pack_start (*hbox);
128
129         hbox = manage (new HBox);
130         hbox->set_spacing (12);
131         hbox->set_border_width (6);
132         hbox->pack_start (strength_label);
133         hbox->pack_start (strength_spinner);
134         hbox->show ();
135         strength_label.show ();
136         strength_spinner.show ();
137         get_vbox()->pack_start (*hbox);
138
139         hbox = manage (new HBox);
140         hbox->set_spacing (12);
141         hbox->set_border_width (6);
142         hbox->pack_start (swing_button);
143         hbox->pack_start (swing_spinner);
144         hbox->show ();
145         swing_button.show ();
146         swing_spinner.show ();
147         get_vbox()->pack_start (*hbox);
148
149         snap_start_button.set_active (true);
150         snap_end_button.set_active (false);
151
152         add_button (Stock::CANCEL, RESPONSE_CANCEL);
153         add_button (Stock::OK, RESPONSE_OK);
154 }
155
156 QuantizeDialog::~QuantizeDialog()
157 {
158 }
159
160 double
161 QuantizeDialog::start_grid_size () const
162 {
163         return grid_size_to_musical_time (start_grid_combo.get_active_text ());
164 }
165
166 double
167 QuantizeDialog::end_grid_size () const
168 {
169         return grid_size_to_musical_time (start_grid_combo.get_active_text ());
170 }
171
172 double
173 QuantizeDialog::grid_size_to_musical_time (const string& txt) const
174 {
175         if (txt == "main_grid") {
176                 bool success;
177
178                 Evoral::MusicalTime b = editor.get_grid_type_as_beats (success, 0);
179                 if (!success) {
180                         return 1.0;
181                 }
182                 return (double) b;
183         }
184
185         if (txt == _("Beats/128")) {
186                 return 1.0/128.0;
187         } else if (txt == _("Beats/64")) {
188                 return 1.0/64.0;
189         } else if (txt == _("Beats/32")) {
190                 return 1.0/32.0;
191         } else if (txt == _("Beats/16")) {
192                 return 1.0/16.0;
193         } if (txt == _("Beats/8")) {
194                 return 1.0/8.0;
195         } else if (txt == _("Beats/4")) {
196                 return 1.0/4.0;
197         } else if (txt == _("Beats/3")) {
198                 return 1.0/3.0;
199         } else if (txt == _("Beats")) {
200                 return 1.0;
201         }
202
203         return 1.0;
204 }
205
206 float
207 QuantizeDialog::swing () const
208 {
209         if (!swing_button.get_active()) {
210                 return 0.0f;
211         }
212
213         return swing_adjustment.get_value ();
214 }
215
216 float
217 QuantizeDialog::strength () const
218 {
219         return strength_adjustment.get_value ();
220 }
221
222 float
223 QuantizeDialog::threshold () const
224 {
225         return threshold_adjustment.get_value ();
226 }