put the issue of using a monitor section into ~/.config/ardour.rc, not the session...
[ardour2.git] / gtk2_ardour / quantize_dialog.cc
blob727f2b0db9251c2b9bf93ba674eac6bacd7404b2
1 /*
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"
27 #include "i18n.h"
29 using namespace std;
30 using namespace Gtk;
31 using namespace Gtkmm2ext;
32 using namespace ARDOUR;
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"),
47 static const gchar *_type_strings[] = {
48 N_("Grid"),
49 N_("Legato"),
50 N_("Groove"),
54 std::vector<std::string> QuantizeDialog::grid_strings;
55 std::vector<std::string> QuantizeDialog::type_strings;
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"))
73 if (grid_strings.empty()) {
74 grid_strings = I18N (_grid_strings);
75 type_strings = I18N (_type_strings);
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());
83 set_popdown_strings (type_combo, type_strings);
84 type_combo.set_active_text (type_strings.front());
86 get_vbox()->set_border_width (12);
88 HBox* hbox;
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);
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);
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);
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);
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);
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);
150 snap_start_button.set_active (true);
151 snap_end_button.set_active (false);
153 add_button (Stock::CANCEL, RESPONSE_CANCEL);
154 add_button (Stock::OK, RESPONSE_OK);
157 QuantizeDialog::~QuantizeDialog()
161 double
162 QuantizeDialog::start_grid_size () const
164 return grid_size_to_musical_time (start_grid_combo.get_active_text ());
167 double
168 QuantizeDialog::end_grid_size () const
170 return grid_size_to_musical_time (start_grid_combo.get_active_text ());
173 double
174 QuantizeDialog::grid_size_to_musical_time (const string& txt) const
176 if (txt == "main_grid") {
177 bool success;
179 Evoral::MusicalTime b = editor.get_grid_type_as_beats (success, 0);
180 if (!success) {
181 return 1.0;
183 return (double) b;
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;
204 return 1.0;
207 float
208 QuantizeDialog::swing () const
210 if (!swing_button.get_active()) {
211 return 0.0f;
214 return swing_adjustment.get_value ();
217 float
218 QuantizeDialog::strength () const
220 return strength_adjustment.get_value ();
223 float
224 QuantizeDialog::threshold () const
226 return threshold_adjustment.get_value ();