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, framepos_t frame, const string & action)
37 : ArdourDialog (_("New Tempo"))
38 , bpm_adjustment (60.0, 1.0, 999.9, 0.1, 1.0)
39 , bpm_spinner (bpm_adjustment)
40 , when_bar_label (_("bar:"), ALIGN_LEFT, ALIGN_CENTER)
41 , when_beat_label (_("beat:"), ALIGN_LEFT, ALIGN_CENTER)
42 , pulse_selector_label (_("Pulse note"), ALIGN_LEFT, ALIGN_CENTER)
44 Timecode::BBT_Time when;
45 Tempo tempo (map.tempo_at (frame));
46 map.bbt_time (frame, when);
48 init (when, tempo.beats_per_minute(), tempo.note_type(), true);
51 TempoDialog::TempoDialog (TempoSection& section, const string & action)
52 : ArdourDialog ("Edit Tempo")
53 , bpm_adjustment (60.0, 1.0, 999.9, 0.1, 1.0)
54 , bpm_spinner (bpm_adjustment)
55 , when_bar_label (_("bar:"), ALIGN_LEFT, ALIGN_CENTER)
56 , when_beat_label (_("beat:"), ALIGN_LEFT, ALIGN_CENTER)
57 , pulse_selector_label (_("Pulse note"), ALIGN_LEFT, ALIGN_CENTER)
59 init (section.start(), section.beats_per_minute(), section.note_type(), section.movable());
63 TempoDialog::init (const Timecode::BBT_Time& when, double bpm, double note_type, bool movable)
65 vector<string> strings;
66 NoteTypes::iterator x;
68 bpm_spinner.set_numeric (true);
69 bpm_spinner.set_digits (2);
70 bpm_spinner.set_wrap (true);
71 bpm_spinner.set_value (bpm);
73 note_types.insert (make_pair (_("whole"), 1.0));
74 strings.push_back (_("whole"));
75 note_types.insert (make_pair (_("second"), 2.0));
76 strings.push_back (_("second"));
77 note_types.insert (make_pair (_("third"), 3.0));
78 strings.push_back (_("third"));
79 note_types.insert (make_pair (_("quarter"), 4.0));
80 strings.push_back (_("quarter"));
81 note_types.insert (make_pair (_("eighth"), 8.0));
82 strings.push_back (_("eighth"));
83 note_types.insert (make_pair (_("thirty-second"), 32.0));
84 strings.push_back (_("thirty-second"));
85 note_types.insert (make_pair (_("sixty-fourth"), 64.0));
86 strings.push_back (_("sixty-fourth"));
87 note_types.insert (make_pair (_("one-hundred-twenty-eighth"), 128.0));
88 strings.push_back (_("one-hundred-twenty-eighth"));
90 set_popdown_strings (pulse_selector, strings);
92 for (x = note_types.begin(); x != note_types.end(); ++x) {
93 if (x->second == note_type) {
94 pulse_selector.set_active_text (x->first);
98 if (x == note_types.end()) {
99 pulse_selector.set_active_text (strings[3]); // "quarter"
102 Table* table = manage (new Table (5, 5));
103 table->set_spacings (6);
104 table->set_homogeneous (false);
106 Label* bpm_label = manage (new Label(_("Beats per minute:"), ALIGN_LEFT, ALIGN_CENTER));
107 table->attach (*bpm_label, 0, 1, 0, 1);
108 table->attach (bpm_spinner, 1, 5, 0, 1);
110 table->attach (pulse_selector_label, 0, 1, 1, 2);
111 table->attach (pulse_selector, 1, 5, 1, 2);
116 snprintf (buf, sizeof (buf), "%" PRIu32, when.bars);
117 when_bar_entry.set_text (buf);
118 snprintf (buf, sizeof (buf), "%" PRIu32, when.beats);
119 when_beat_entry.set_text (buf);
121 when_bar_entry.set_name ("MetricEntry");
122 when_beat_entry.set_name ("MetricEntry");
124 when_bar_entry.set_width_chars(4);
125 when_beat_entry.set_width_chars (4);
127 when_bar_label.set_name ("MetricLabel");
128 when_beat_label.set_name ("MetricLabel");
130 table->attach (when_bar_label, 1, 2, 2, 3, Gtk::AttachOptions(0), Gtk::AttachOptions(0));
131 table->attach (when_bar_entry, 2, 3, 2, 3, Gtk::AttachOptions(0), Gtk::AttachOptions(0));
133 table->attach (when_beat_label, 3, 4, 2, 3, Gtk::AttachOptions(0), Gtk::AttachOptions(0));
134 table->attach (when_beat_entry, 4, 5, 2, 3, Gtk::AttachOptions(0), Gtk::AttachOptions(0));
136 Label* when_label = manage (new Label(_("Tempo begins at"), ALIGN_LEFT, ALIGN_CENTER));
137 table->attach (*when_label, 0, 1, 2, 3);
140 get_vbox()->set_border_width (12);
141 get_vbox()->pack_end (*table);
144 add_button (Stock::CANCEL, RESPONSE_CANCEL);
145 add_button (Stock::APPLY, RESPONSE_ACCEPT);
146 set_response_sensitive (RESPONSE_ACCEPT, false);
147 set_default_response (RESPONSE_ACCEPT);
151 set_name ("MetricDialog");
153 bpm_spinner.signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &TempoDialog::response), RESPONSE_ACCEPT));
154 bpm_spinner.signal_button_press_event().connect (sigc::mem_fun (*this, &TempoDialog::bpm_button_press), false);
155 bpm_spinner.signal_button_release_event().connect (sigc::mem_fun (*this, &TempoDialog::bpm_button_release), false);
156 bpm_spinner.signal_changed().connect (sigc::mem_fun (*this, &TempoDialog::bpm_changed));
157 when_bar_entry.signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &TempoDialog::response), RESPONSE_ACCEPT));
158 when_bar_entry.signal_key_release_event().connect (sigc::mem_fun (*this, &TempoDialog::entry_key_release), false);
159 when_beat_entry.signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &TempoDialog::response), RESPONSE_ACCEPT));
160 when_beat_entry.signal_key_release_event().connect (sigc::mem_fun (*this, &TempoDialog::entry_key_release), false);
161 pulse_selector.signal_changed().connect (sigc::mem_fun (*this, &TempoDialog::pulse_change));
165 TempoDialog::bpm_changed ()
167 set_response_sensitive (RESPONSE_ACCEPT, true);
171 TempoDialog::bpm_button_press (GdkEventButton*)
177 TempoDialog::bpm_button_release (GdkEventButton*)
179 /* the value has been modified, accept should work now */
181 set_response_sensitive (RESPONSE_ACCEPT, true);
186 TempoDialog::entry_key_release (GdkEventKey*)
188 if (when_beat_entry.get_text() != "" && when_bar_entry.get_text() != "") {
189 set_response_sensitive (RESPONSE_ACCEPT, true);
191 set_response_sensitive (RESPONSE_ACCEPT, false);
197 TempoDialog::get_bpm ()
199 return bpm_spinner.get_value ();
203 TempoDialog::get_bbt_time (Timecode::BBT_Time& requested)
205 if (sscanf (when_bar_entry.get_text().c_str(), "%" PRIu32, &requested.bars) != 1) {
209 if (sscanf (when_beat_entry.get_text().c_str(), "%" PRIu32, &requested.beats) != 1) {
219 TempoDialog::get_note_type ()
221 NoteTypes::iterator x = note_types.find (pulse_selector.get_active_text());
223 if (x == note_types.end()) {
224 error << string_compose(_("incomprehensible pulse note type (%1)"), pulse_selector.get_active_text()) << endmsg;
232 TempoDialog::pulse_change ()
234 set_response_sensitive (RESPONSE_ACCEPT, true);
238 MeterDialog::MeterDialog (TempoMap& map, framepos_t frame, const string & action)
239 : ArdourDialog ("New Meter")
241 Timecode::BBT_Time when;
242 frame = map.round_to_bar(frame,0);
243 Meter meter (map.meter_at(frame));
245 map.bbt_time (frame, when);
246 init (when, meter.divisions_per_bar(), meter.note_divisor(), true);
249 MeterDialog::MeterDialog (MeterSection& section, const string & action)
250 : ArdourDialog ("Edit Meter")
252 init (section.start(), section.divisions_per_bar(), section.note_divisor(), section.movable());
256 MeterDialog::init (const Timecode::BBT_Time& when, double bpb, double note_type, bool movable)
260 snprintf (buf, sizeof (buf), "%.2f", bpb);
261 bpb_entry.set_text (buf);
262 bpb_entry.select_region (0, -1);
264 strings.push_back (_("whole (1)"));
265 strings.push_back (_("second (2)"));
266 strings.push_back (_("third (3)"));
267 strings.push_back (_("quarter (4)"));
268 strings.push_back (_("eighth (8)"));
269 strings.push_back (_("sixteenth (16)"));
270 strings.push_back (_("thirty-second (32)"));
272 set_popdown_strings (note_types, strings);
274 if (note_type == 1.0f) {
275 note_types.set_active_text (_("whole (1)"));
276 } else if (note_type == 2.0f) {
277 note_types.set_active_text (_("second (2)"));
278 } else if (note_type == 3.0f) {
279 note_types.set_active_text (_("third (3)"));
280 } else if (note_type == 4.0f) {
281 note_types.set_active_text (_("quarter (4)"));
282 } else if (note_type == 8.0f) {
283 note_types.set_active_text (_("eighth (8)"));
284 } else if (note_type == 16.0f) {
285 note_types.set_active_text (_("sixteenth (16)"));
286 } else if (note_type == 32.0f) {
287 note_types.set_active_text (_("thirty-second (32)"));
289 note_types.set_active_text (_("quarter (4)"));
292 Label* note_label = manage (new Label (_("Note value:"), ALIGN_LEFT, ALIGN_CENTER));
293 Label* bpb_label = manage (new Label (_("Beats per bar:"), ALIGN_LEFT, ALIGN_CENTER));
294 Table* table = manage (new Table (3, 2));
295 table->set_spacings (6);
297 table->attach (*bpb_label, 0, 1, 0, 1, FILL|EXPAND, FILL|EXPAND);
298 table->attach (bpb_entry, 1, 2, 0, 1, FILL|EXPAND, FILL|EXPAND);
299 table->attach (*note_label, 0, 1, 1, 2, FILL|EXPAND, FILL|EXPAND);
300 table->attach (note_types, 1, 2, 1, 2, FILL|EXPAND, SHRINK);
305 snprintf (buf, sizeof (buf), "%" PRIu32, when.bars);
306 when_bar_entry.set_text (buf);
307 when_bar_entry.set_name ("MetricEntry");
309 Label* when_label = manage (new Label(_("Meter begins at bar:"), ALIGN_LEFT, ALIGN_CENTER));
311 table->attach (*when_label, 0, 1, 2, 3, FILL | EXPAND, FILL | EXPAND);
312 table->attach (when_bar_entry, 1, 2, 2, 3, FILL | EXPAND, FILL | EXPAND);
314 when_bar_entry.set_text ("0");
317 get_vbox()->set_border_width (12);
318 get_vbox()->pack_start (*table, false, false);
320 bpb_entry.set_name ("MetricEntry");
322 add_button (Stock::CANCEL, RESPONSE_CANCEL);
323 add_button (Stock::APPLY, RESPONSE_ACCEPT);
324 set_response_sensitive (RESPONSE_ACCEPT, false);
325 set_default_response (RESPONSE_ACCEPT);
327 get_vbox()->show_all ();
329 set_name ("MetricDialog");
330 bpb_entry.signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &MeterDialog::response), RESPONSE_ACCEPT));
331 bpb_entry.signal_key_press_event().connect (sigc::mem_fun (*this, &MeterDialog::entry_key_press), false);
332 bpb_entry.signal_key_release_event().connect (sigc::mem_fun (*this, &MeterDialog::entry_key_release));
333 when_bar_entry.signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &MeterDialog::response), RESPONSE_ACCEPT));
334 when_bar_entry.signal_key_press_event().connect (sigc::mem_fun (*this, &MeterDialog::entry_key_press), false);
335 when_bar_entry.signal_key_release_event().connect (sigc::mem_fun (*this, &MeterDialog::entry_key_release));
337 note_types.signal_changed().connect (sigc::mem_fun (*this, &MeterDialog::note_types_change));
341 MeterDialog::entry_key_press (GdkEventKey* ev)
344 switch (ev->keyval) {
389 MeterDialog::entry_key_release (GdkEventKey*)
391 if (when_bar_entry.get_text() != "" && bpb_entry.get_text() != "") {
392 set_response_sensitive (RESPONSE_ACCEPT, true);
394 set_response_sensitive (RESPONSE_ACCEPT, false);
400 MeterDialog::note_types_change ()
402 set_response_sensitive (RESPONSE_ACCEPT, true);
406 MeterDialog::get_bpb ()
410 if (sscanf (bpb_entry.get_text().c_str(), "%lf", &bpb) != 1) {
418 MeterDialog::get_note_type ()
420 double note_type = 0;
421 vector<string>::iterator i;
422 string text = note_types.get_active_text();
424 for (i = strings.begin(); i != strings.end(); ++i) {
426 if (sscanf (text.c_str(), "%*[^0-9]%lf", ¬e_type) != 1) {
427 error << string_compose(_("garbaged note type entry (%1)"), text) << endmsg;
435 if (i == strings.end()) {
436 if (sscanf (text.c_str(), "%lf", ¬e_type) != 1) {
437 error << string_compose(_("incomprehensible note type entry (%1)"), text) << endmsg;
446 MeterDialog::get_bbt_time (Timecode::BBT_Time& requested)
448 if (sscanf (when_bar_entry.get_text().c_str(), "%" PRIu32, &requested.bars) != 1) {