Fix thinkos in cubasish theme
[ardour.git] / gtk2_ardour / quantize_dialog.cc
1 /*
2  * Copyright (C) 2009-2015 David Robillard <d@drobilla.net>
3  * Copyright (C) 2009-2017 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2010-2012 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
6  * Copyright (C) 2018 Ben Loftis <ben@harrisonconsoles.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #include <gtkmm/stock.h>
24 #include <gtkmm/table.h>
25 #include "gtkmm2ext/utils.h"
26
27 #include "pbd/convert.h"
28 #include "quantize_dialog.h"
29 #include "public_editor.h"
30
31 #include "pbd/i18n.h"
32
33 using namespace std;
34 using namespace Gtk;
35 using namespace Gtkmm2ext;
36 using namespace ARDOUR;
37
38 static const gchar *_grid_strings[] = {
39         N_("Main Grid"),
40         N_("1/4 Note"),
41         N_("1/8 Note"),
42         N_("1/16 Note"),
43         N_("1/32 Note"),
44         N_("1/64 Note"),
45         N_("1/128 Note"),
46         
47         N_("1/3 (8th triplet)"),
48         N_("1/6 (16th triplet)"),
49         N_("1/12 (32nd triplet)"),
50
51         N_("1/5 (8th quintuplet)"),
52         N_("1/10 (16th quintuplet)"),
53         N_("1/20 (32nd quintuplet)"),
54
55         N_("1/7 (8th septuplet)"),
56         N_("1/14 (16th septuplet)"),
57         N_("1/28 (32nd septuplet)"),
58
59         0
60 };
61
62 static const int _grid_beats[] = {
63         0,
64         1, 2, 4, 8, 16, 32,
65         3, 6, 12,
66         5, 10, 20,
67         7, 14, 28,
68         0
69 };
70
71 std::vector<std::string> QuantizeDialog::grid_strings;
72
73 QuantizeDialog::QuantizeDialog (PublicEditor& e)
74         : ArdourDialog (_("Quantize"), false, false)
75         , editor (e)
76         , strength_adjustment (100.0, 0.0, 100.0, 1.0, 10.0)
77         , strength_spinner (strength_adjustment)
78         , strength_label (_("Strength"))
79         , swing_adjustment (100.0, -130.0, 130.0, 1.0, 10.0)
80         , swing_spinner (swing_adjustment)
81         , swing_button (_("Swing"))
82         , threshold_adjustment (0.0, -Timecode::BBT_Time::ticks_per_beat, Timecode::BBT_Time::ticks_per_beat, 1.0, 10.0)
83         , threshold_spinner (threshold_adjustment)
84         , threshold_label (_("Threshold (ticks)"))
85         , snap_start_button (_("Snap note start"))
86         , snap_end_button (_("Snap note end"))
87 {
88         if (grid_strings.empty()) {
89                 grid_strings =  I18N (_grid_strings);
90         }
91
92         set_popdown_strings (start_grid_combo, grid_strings);
93         start_grid_combo.set_active_text (grid_strings.front());
94         set_popdown_strings (end_grid_combo, grid_strings);
95         end_grid_combo.set_active_text (grid_strings.front());
96
97         Table* table = manage (new Table (6, 2));
98         table->set_spacings (12);
99         table->set_border_width (12);
100
101         int r = 0;
102
103         table->attach (snap_start_button, 0, 1, r, r + 1);
104         table->attach (start_grid_combo, 1, 2, r, r + 1);
105         ++r;
106
107         table->attach (snap_end_button, 0, 1, r, r + 1);
108         table->attach (end_grid_combo, 1, 2, r, r + 1);
109         ++r;
110
111         threshold_label.set_alignment (0, 0.5);
112         table->attach (threshold_label, 0, 1, r, r + 1);
113         table->attach (threshold_spinner, 1, 2, r, r + 1);
114         ++r;
115
116         strength_label.set_alignment (0, 0.5);
117         table->attach (strength_label, 0, 1, r, r + 1);
118         table->attach (strength_spinner, 1, 2, r, r + 1);
119         ++r;
120
121         table->attach (swing_button, 0, 1, r, r + 1);
122         table->attach (swing_spinner, 1, 2, r, r + 1);
123
124         snap_start_button.set_active (true);
125         snap_end_button.set_active (false);
126
127         get_vbox()->pack_start (*table);
128         get_vbox()->show_all ();
129
130         add_button (Stock::CANCEL, RESPONSE_CANCEL);
131         add_button (_("Quantize"), RESPONSE_OK);
132 }
133
134 QuantizeDialog::~QuantizeDialog()
135 {
136 }
137
138 double
139 QuantizeDialog::start_grid_size () const
140 {
141         return grid_size_to_musical_time (start_grid_combo.get_active_text ());
142 }
143
144 double
145 QuantizeDialog::end_grid_size () const
146 {
147         return grid_size_to_musical_time (end_grid_combo.get_active_text ());
148 }
149
150 double
151 QuantizeDialog::grid_size_to_musical_time (const string& txt) const
152 {
153         if ( txt == _grid_strings[0] ) {  //"Main Grid"
154                 bool success;
155
156                 Temporal::Beats b = editor.get_grid_type_as_beats (success, 0);
157                 if (!success) {
158                         return 1.0;
159                 }
160                 return b.to_double();
161         }
162
163
164         double divisor = 1.0;
165         for (size_t i = 1; i < grid_strings.size(); ++i) {
166                 if (txt == grid_strings[i]) {
167                         assert (_grid_beats[i] != 0);
168                         divisor = 1.0 / _grid_beats[i];
169                         break;
170                 }
171         }
172
173         return divisor;
174 }
175
176 float
177 QuantizeDialog::swing () const
178 {
179         if (!swing_button.get_active()) {
180                 return 0.0f;
181         }
182
183         return swing_adjustment.get_value ();
184 }
185
186 float
187 QuantizeDialog::strength () const
188 {
189         return strength_adjustment.get_value ();
190 }
191
192 float
193 QuantizeDialog::threshold () const
194 {
195         return threshold_adjustment.get_value ();
196 }