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