2 Copyright (C) 2009 Paul Davis
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.
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.
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.
20 #include <gtkmm/stock.h>
21 #include "gtkmm2ext/utils.h"
23 #include "pbd/convert.h"
24 #include "quantize_dialog.h"
25 #include "public_editor.h"
31 using namespace Gtkmm2ext;
32 using namespace ARDOUR;
34 static const gchar *_grid_strings[] = {
48 static const gchar *_type_strings[] = {
55 std::vector<std::string> QuantizeDialog::grid_strings;
56 std::vector<std::string> QuantizeDialog::type_strings;
58 QuantizeDialog::QuantizeDialog (PublicEditor& e)
59 : ArdourDialog (_("Quantize"), false, false)
61 , type_label (_("Quantize Type"))
62 , strength_adjustment (100.0, 0.0, 100.0, 1.0, 10.0)
63 , strength_spinner (strength_adjustment)
64 , strength_label (_("Strength"))
65 , swing_adjustment (100.0, -130.0, 130.0, 1.0, 10.0)
66 , swing_spinner (swing_adjustment)
67 , swing_button (_("Swing"))
68 , threshold_adjustment (0.0, -1920.0, 1920.0, 1.0, 10.0) // XXX MAGIC TICK NUMBER FIX ME
69 , threshold_spinner (threshold_adjustment)
70 , threshold_label (_("Threshold (ticks)"))
71 , snap_start_button (_("Snap note start"))
72 , snap_end_button (_("Snap note end"))
74 if (grid_strings.empty()) {
75 grid_strings = I18N (_grid_strings);
76 type_strings = I18N (_type_strings);
79 set_popdown_strings (start_grid_combo, grid_strings);
80 start_grid_combo.set_active_text (grid_strings.front());
81 set_popdown_strings (end_grid_combo, grid_strings);
82 end_grid_combo.set_active_text (grid_strings.front());
84 set_popdown_strings (type_combo, type_strings);
85 type_combo.set_active_text (type_strings.front());
87 get_vbox()->set_border_width (12);
91 hbox = manage (new HBox);
92 hbox->set_spacing (12);
93 hbox->set_border_width (6);
94 hbox->pack_start (type_label);
95 hbox->pack_start (type_combo);
99 get_vbox()->pack_start (*hbox);
101 hbox = manage (new HBox);
102 hbox->set_spacing (12);
103 hbox->set_border_width (6);
104 hbox->pack_start (snap_start_button);
105 hbox->pack_start (start_grid_combo);
107 snap_start_button.show ();
108 start_grid_combo.show ();
109 get_vbox()->pack_start (*hbox);
111 hbox = manage (new HBox);
112 hbox->set_spacing (12);
113 hbox->set_border_width (6);
114 hbox->pack_start (snap_end_button);
115 hbox->pack_start (end_grid_combo);
117 snap_end_button.show ();
118 end_grid_combo.show ();
119 get_vbox()->pack_start (*hbox);
121 hbox = manage (new HBox);
122 hbox->set_spacing (12);
123 hbox->set_border_width (6);
124 hbox->pack_start (threshold_label);
125 hbox->pack_start (threshold_spinner);
127 threshold_label.show ();
128 threshold_spinner.show ();
129 get_vbox()->pack_start (*hbox);
131 hbox = manage (new HBox);
132 hbox->set_spacing (12);
133 hbox->set_border_width (6);
134 hbox->pack_start (strength_label);
135 hbox->pack_start (strength_spinner);
137 strength_label.show ();
138 strength_spinner.show ();
139 get_vbox()->pack_start (*hbox);
141 hbox = manage (new HBox);
142 hbox->set_spacing (12);
143 hbox->set_border_width (6);
144 hbox->pack_start (swing_button);
145 hbox->pack_start (swing_spinner);
147 swing_button.show ();
148 swing_spinner.show ();
149 get_vbox()->pack_start (*hbox);
151 snap_start_button.set_active (true);
152 snap_end_button.set_active (false);
154 add_button (Stock::CANCEL, RESPONSE_CANCEL);
155 add_button (Stock::OK, RESPONSE_OK);
158 QuantizeDialog::~QuantizeDialog()
163 QuantizeDialog::start_grid_size () const
165 return grid_size_to_musical_time (start_grid_combo.get_active_text ());
169 QuantizeDialog::end_grid_size () const
171 return grid_size_to_musical_time (start_grid_combo.get_active_text ());
175 QuantizeDialog::grid_size_to_musical_time (const string& txt) const
177 if (txt == "main grid") {
180 Evoral::MusicalTime b = editor.get_grid_type_as_beats (success, 0);
187 if (txt == _("Beats/128")) {
189 } else if (txt == _("Beats/64")) {
191 } else if (txt == _("Beats/32")) {
193 } else if (txt == _("Beats/16")) {
195 } if (txt == _("Beats/8")) {
197 } else if (txt == _("Beats/4")) {
199 } else if (txt == _("Beats/3")) {
201 } else if (txt == _("Beats/2")) {
203 } else if (txt == _("Beats")) {
211 QuantizeDialog::swing () const
213 if (!swing_button.get_active()) {
217 return swing_adjustment.get_value ();
221 QuantizeDialog::strength () const
223 return strength_adjustment.get_value ();
227 QuantizeDialog::threshold () const
229 return threshold_adjustment.get_value ();