2 Copyright (C) 2000-2007 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 <cstdio> // for snprintf, grrr
22 #include <gtkmm/stock.h>
23 #include <gtkmm2ext/utils.h>
25 #include "tempo_dialog.h"
32 using namespace Gtkmm2ext;
33 using namespace ARDOUR;
36 TempoDialog::TempoDialog (TempoMap& map, nframes_t frame, const string & action)
37 : ArdourDialog (_("edit tempo")),
38 bpm_adjustment (60.0, 1.0, 999.9, 0.1, 1.0, 1.0),
39 bpm_spinner (bpm_adjustment),
41 cancel_button (_("Cancel")),
42 when_bar_label (_("bar:"), ALIGN_LEFT, ALIGN_CENTER),
43 when_beat_label (_("beat:"), ALIGN_LEFT, ALIGN_CENTER)
46 Tempo tempo (map.tempo_at (frame));
47 map.bbt_time (frame, when);
49 init (when, tempo.beats_per_minute(), tempo.note_type(), true);
52 TempoDialog::TempoDialog (TempoSection& section, const string & action)
53 : ArdourDialog ("tempo dialog"),
54 bpm_adjustment (60.0, 1.0, 999.9, 0.1, 1.0, 1.0),
55 bpm_spinner (bpm_adjustment),
57 cancel_button (_("Cancel")),
58 when_bar_label (_("bar:"), ALIGN_LEFT, ALIGN_CENTER),
59 when_beat_label (_("beat:"), ALIGN_LEFT, ALIGN_CENTER)
61 init (section.start(), section.beats_per_minute(), section.note_type(), section.movable());
65 TempoDialog::init (const BBT_Time& when, double bpm, double note_type, bool movable)
67 bpm_spinner.set_numeric (true);
68 bpm_spinner.set_digits (2);
69 bpm_spinner.set_wrap (true);
70 bpm_spinner.set_value (bpm);
72 strings.push_back (_("whole (1)"));
73 strings.push_back (_("second (2)"));
74 strings.push_back (_("third (3)"));
75 strings.push_back (_("quarter (4)"));
76 strings.push_back (_("eighth (8)"));
77 strings.push_back (_("sixteenth (16)"));
78 strings.push_back (_("thirty-second (32)"));
80 set_popdown_strings (note_types, strings, true);
82 if (note_type == 1.0f) {
83 note_types.set_active_text (_("whole (1)"));
84 } else if (note_type == 2.0f) {
85 note_types.set_active_text (_("second (2)"));
86 } else if (note_type == 3.0f) {
87 note_types.set_active_text (_("third (3)"));
88 } else if (note_type == 4.0f) {
89 note_types.set_active_text (_("quarter (4)"));
90 } else if (note_type == 8.0f) {
91 note_types.set_active_text (_("eighth (8)"));
92 } else if (note_type == 16.0f) {
93 note_types.set_active_text (_("sixteenth (16)"));
94 } else if (note_type == 32.0f) {
95 note_types.set_active_text (_("thirty-second (32)"));
97 note_types.set_active_text (_("quarter (4)"));
100 Table* table = manage (new Table (3, 3));
101 table->set_spacings (6);
103 Label* bpm_label = manage (new Label(_("Beats per minute:"), ALIGN_LEFT, ALIGN_CENTER));
104 table->attach (*bpm_label, 0, 2, 0, 1);
105 table->attach (bpm_spinner, 2, 3, 0, 1);
108 snprintf (buf, sizeof (buf), "%" PRIu32, when.bars);
109 when_bar_entry.set_text (buf);
110 snprintf (buf, sizeof (buf), "%" PRIu32, when.beats);
111 when_beat_entry.set_text (buf);
113 when_bar_entry.set_name ("MetricEntry");
114 when_beat_entry.set_name ("MetricEntry");
116 when_bar_label.set_name ("MetricLabel");
117 when_beat_label.set_name ("MetricLabel");
119 table->attach (when_bar_label, 1, 2, 2, 3);
120 table->attach (when_bar_entry, 2, 3, 2, 3);
122 table->attach (when_beat_label, 1, 2, 1, 2);
123 table->attach (when_beat_entry, 2, 3, 1, 2);
125 Label* when_label = manage (new Label(_("Tempo begins at"), ALIGN_LEFT, ALIGN_CENTER));
126 table->attach (*when_label, 0, 1, 1, 2);
129 get_vbox()->set_border_width (12);
130 get_vbox()->pack_end (*table);
133 add_button (Stock::CANCEL, RESPONSE_CANCEL);
134 add_button (Stock::APPLY, RESPONSE_ACCEPT);
135 set_response_sensitive (RESPONSE_ACCEPT, false);
136 set_default_response (RESPONSE_ACCEPT);
140 set_name ("MetricDialog");
142 bpm_spinner.signal_activate().connect (bind (mem_fun (*this, &TempoDialog::response), RESPONSE_ACCEPT));
143 bpm_spinner.signal_button_press_event().connect (mem_fun (*this, &TempoDialog::bpm_button_press), false);
144 bpm_spinner.signal_button_release_event().connect (mem_fun (*this, &TempoDialog::bpm_button_release), false);
145 when_bar_entry.signal_activate().connect (bind (mem_fun (*this, &TempoDialog::response), RESPONSE_ACCEPT));
146 when_bar_entry.signal_key_release_event().connect (mem_fun (*this, &TempoDialog::entry_key_release), false);
147 when_beat_entry.signal_activate().connect (bind (mem_fun (*this, &TempoDialog::response), RESPONSE_ACCEPT));
148 when_beat_entry.signal_key_release_event().connect (mem_fun (*this, &TempoDialog::entry_key_release), false);
149 note_types.signal_changed().connect (mem_fun (*this, &TempoDialog::note_types_change));
153 TempoDialog::bpm_button_press (GdkEventButton*)
159 TempoDialog::bpm_button_release (GdkEventButton*)
161 /* the value has been modified, accept should work now */
163 set_response_sensitive (RESPONSE_ACCEPT, true);
168 TempoDialog::entry_key_release (GdkEventKey*)
170 if (when_beat_entry.get_text() != "" && when_bar_entry.get_text() != "") {
171 set_response_sensitive (RESPONSE_ACCEPT, true);
173 set_response_sensitive (RESPONSE_ACCEPT, false);
179 TempoDialog::get_bpm ()
181 return bpm_spinner.get_value ();
185 TempoDialog::get_bbt_time (BBT_Time& requested)
187 if (sscanf (when_bar_entry.get_text().c_str(), "%" PRIu32, &requested.bars) != 1) {
191 if (sscanf (when_beat_entry.get_text().c_str(), "%" PRIu32, &requested.beats) != 1) {
201 TempoDialog::get_note_type ()
203 double note_type = 0;
204 vector<string>::iterator i;
205 string text = note_types.get_active_text();
207 for (i = strings.begin(); i != strings.end(); ++i) {
209 if (sscanf (text.c_str(), "%*[^0-9]%lf", ¬e_type) != 1) {
210 error << string_compose(_("garbaged note type entry (%1)"), text) << endmsg;
218 if (i == strings.end()) {
219 if (sscanf (text.c_str(), "%lf", ¬e_type) != 1) {
220 error << string_compose(_("incomprehensible note type entry (%1)"), text) << endmsg;
229 TempoDialog::note_types_change ()
231 set_response_sensitive (RESPONSE_ACCEPT, true);
235 MeterDialog::MeterDialog (TempoMap& map, nframes_t frame, const string & action)
236 : ArdourDialog ("meter dialog"),
238 cancel_button (_("Cancel"))
241 frame = map.round_to_bar(frame,0);
242 Meter meter (map.meter_at(frame));
244 map.bbt_time (frame, when);
245 init (when, meter.beats_per_bar(), meter.note_divisor(), true);
248 MeterDialog::MeterDialog (MeterSection& section, const string & action)
249 : ArdourDialog ("meter dialog"),
251 cancel_button (_("Cancel"))
253 init (section.start(), section.beats_per_bar(), section.note_divisor(), section.movable());
257 MeterDialog::init (const BBT_Time& when, double bpb, double note_type, bool movable)
259 snprintf (buf, sizeof (buf), "%.2f", bpb);
260 bpb_entry.set_text (buf);
261 bpb_entry.select_region (0, -1);
263 strings.push_back (_("whole (1)"));
264 strings.push_back (_("second (2)"));
265 strings.push_back (_("third (3)"));
266 strings.push_back (_("quarter (4)"));
267 strings.push_back (_("eighth (8)"));
268 strings.push_back (_("sixteenth (16)"));
269 strings.push_back (_("thirty-second (32)"));
271 set_popdown_strings (note_types, strings, true);
273 if (note_type == 1.0f) {
274 note_types.set_active_text (_("whole (1)"));
275 } else if (note_type == 2.0f) {
276 note_types.set_active_text (_("second (2)"));
277 } else if (note_type == 3.0f) {
278 note_types.set_active_text (_("third (3)"));
279 } else if (note_type == 4.0f) {
280 note_types.set_active_text (_("quarter (4)"));
281 } else if (note_type == 8.0f) {
282 note_types.set_active_text (_("eighth (8)"));
283 } else if (note_type == 16.0f) {
284 note_types.set_active_text (_("sixteenth (16)"));
285 } else if (note_type == 32.0f) {
286 note_types.set_active_text (_("thirty-second (32)"));
288 note_types.set_active_text (_("quarter (4)"));
291 Label* note_label = manage (new Label (_("Note value:"), ALIGN_LEFT, ALIGN_CENTER));
292 Label* bpb_label = manage (new Label (_("Beats per bar:"), ALIGN_LEFT, ALIGN_CENTER));
293 Table* table = manage (new Table (3, 2));
294 table->set_spacings (6);
296 table->attach (*bpb_label, 0, 1, 0, 1, FILL|EXPAND, FILL|EXPAND);
297 table->attach (bpb_entry, 1, 2, 0, 1, FILL|EXPAND, FILL|EXPAND);
298 table->attach (*note_label, 0, 1, 1, 2, FILL|EXPAND, FILL|EXPAND);
299 table->attach (note_types, 1, 2, 1, 2, FILL|EXPAND, SHRINK);
302 snprintf (buf, sizeof (buf), "%" PRIu32, when.bars);
303 when_bar_entry.set_text (buf);
304 when_bar_entry.set_name ("MetricEntry");
306 Label* when_label = manage (new Label(_("Meter begins at bar:"), ALIGN_LEFT, ALIGN_CENTER));
308 table->attach (*when_label, 0, 1, 2, 3, FILL | EXPAND, FILL | EXPAND);
309 table->attach (when_bar_entry, 1, 2, 2, 3, FILL | EXPAND, FILL | EXPAND);
311 when_bar_entry.set_text ("0");
314 get_vbox()->set_border_width (12);
315 get_vbox()->pack_start (*table, false, false);
317 bpb_entry.set_name ("MetricEntry");
319 add_button (Stock::CANCEL, RESPONSE_CANCEL);
320 add_button (Stock::APPLY, RESPONSE_ACCEPT);
321 set_response_sensitive (RESPONSE_ACCEPT, false);
322 set_default_response (RESPONSE_ACCEPT);
324 get_vbox()->show_all ();
326 set_name ("MetricDialog");
327 bpb_entry.signal_activate().connect (bind (mem_fun (*this, &MeterDialog::response), RESPONSE_ACCEPT));
328 bpb_entry.signal_key_press_event().connect (mem_fun (*this, &MeterDialog::entry_key_press), false);
329 bpb_entry.signal_key_release_event().connect (mem_fun (*this, &MeterDialog::entry_key_release));
330 when_bar_entry.signal_activate().connect (bind (mem_fun (*this, &MeterDialog::response), RESPONSE_ACCEPT));
331 when_bar_entry.signal_key_press_event().connect (mem_fun (*this, &MeterDialog::entry_key_press), false);
332 when_bar_entry.signal_key_release_event().connect (mem_fun (*this, &MeterDialog::entry_key_release));
334 note_types.signal_changed().connect (mem_fun (*this, &MeterDialog::note_types_change));
338 MeterDialog::entry_key_press (GdkEventKey* ev)
341 switch (ev->keyval) {
386 MeterDialog::entry_key_release (GdkEventKey*)
388 if (when_bar_entry.get_text() != "" && bpb_entry.get_text() != "") {
389 set_response_sensitive (RESPONSE_ACCEPT, true);
391 set_response_sensitive (RESPONSE_ACCEPT, false);
397 MeterDialog::note_types_change ()
399 set_response_sensitive (RESPONSE_ACCEPT, true);
403 MeterDialog::get_bpb ()
407 if (sscanf (bpb_entry.get_text().c_str(), "%lf", &bpb) != 1) {
415 MeterDialog::get_note_type ()
417 double note_type = 0;
418 vector<string>::iterator i;
419 string text = note_types.get_active_text();
421 for (i = strings.begin(); i != strings.end(); ++i) {
423 if (sscanf (text.c_str(), "%*[^0-9]%lf", ¬e_type) != 1) {
424 error << string_compose(_("garbaged note type entry (%1)"), text) << endmsg;
432 if (i == strings.end()) {
433 if (sscanf (text.c_str(), "%lf", ¬e_type) != 1) {
434 error << string_compose(_("incomprehensible note type entry (%1)"), text) << endmsg;
443 MeterDialog::get_bbt_time (BBT_Time& requested)
446 if (sscanf (when_bar_entry.get_text().c_str(), "%" PRIu32, &requested.bars) != 1) {