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),
40 bpm_frame (_("Tempo")),
42 cancel_button (_("Cancel")),
43 when_bar_label (_("Bar"), ALIGN_LEFT, ALIGN_CENTER),
44 when_beat_label (_("Beat"), ALIGN_LEFT, ALIGN_CENTER),
46 when_frame (_("Location"))
49 Tempo tempo (map.tempo_at (frame));
50 map.bbt_time (frame, when);
52 init (when, tempo.beats_per_minute(), tempo.note_type(), true);
55 TempoDialog::TempoDialog (TempoSection& section, const string & action)
56 : ArdourDialog ("tempo dialog"),
57 bpm_adjustment (60.0, 1.0, 999.9, 0.1, 1.0, 1.0),
58 bpm_spinner (bpm_adjustment),
59 bpm_frame (_("Tempo")),
61 cancel_button (_("Cancel")),
62 when_bar_label (_("Bar"), ALIGN_LEFT, ALIGN_CENTER),
63 when_beat_label (_("Beat"), ALIGN_LEFT, ALIGN_CENTER),
65 when_frame (_("Location"))
67 init (section.start(), section.beats_per_minute(), section.note_type(), section.movable());
71 TempoDialog::init (const BBT_Time& when, double bpm, double note_type, bool movable)
73 bpm_spinner.set_numeric (true);
74 bpm_spinner.set_digits (2);
75 bpm_spinner.set_wrap (true);
76 bpm_spinner.set_value (bpm);
78 strings.push_back (_("whole (1)"));
79 strings.push_back (_("second (2)"));
80 strings.push_back (_("third (3)"));
81 strings.push_back (_("quarter (4)"));
82 strings.push_back (_("eighth (8)"));
83 strings.push_back (_("sixteenth (16)"));
84 strings.push_back (_("thirty-second (32)"));
86 set_popdown_strings (note_types, strings, true);
89 note_types.set_active_text (_("whole (1)"));
90 else if (note_type==2.0f)
91 note_types.set_active_text (_("second (2)"));
92 else if (note_type==3.0f)
93 note_types.set_active_text (_("third (3)"));
94 else if (note_type==4.0f)
95 note_types.set_active_text (_("quarter (4)"));
96 else if (note_type==8.0f)
97 note_types.set_active_text (_("eighth (8)"));
98 else if (note_type==16.0f)
99 note_types.set_active_text (_("sixteenth (16)"));
100 else if (note_type==32.0f)
101 note_types.set_active_text (_("thirty-second (32)"));
103 note_types.set_active_text (_("quarter (4)"));
105 Label* bpm_label = manage(new Label(_("Beats Per Minute:"), ALIGN_LEFT, ALIGN_CENTER));
107 hspacer1.set_border_width (6);
108 hspacer1.pack_end (bpm_spinner, PACK_EXPAND_PADDING);
109 hspacer1.pack_start (*bpm_label, PACK_EXPAND_PADDING);
110 vspacer1.set_border_width (6);
111 vspacer1.pack_start (hspacer1, PACK_EXPAND_PADDING);
113 hspacer2.set_border_width (6);
114 hspacer2.pack_start (note_types, PACK_EXPAND_PADDING);
116 bpm_frame.add (vspacer1);
119 snprintf (buf, sizeof (buf), "%" PRIu32, when.bars);
120 when_bar_entry.set_text (buf);
121 snprintf (buf, sizeof (buf), "%" PRIu32, when.beats);
122 when_beat_entry.set_text (buf);
124 when_bar_entry.set_name ("MetricEntry");
125 when_beat_entry.set_name ("MetricEntry");
127 when_bar_label.set_name ("MetricLabel");
128 when_beat_label.set_name ("MetricLabel");
130 Gtkmm2ext::set_size_request_to_display_given_text (when_bar_entry, "999g", 5, 7);
131 Gtkmm2ext::set_size_request_to_display_given_text (when_beat_entry, "999g", 5, 7);
133 when_table.set_homogeneous (true);
134 when_table.set_row_spacings (2);
135 when_table.set_col_spacings (2);
136 when_table.set_border_width (0);
138 when_table.attach (when_bar_label, 0, 1, 0, 1, AttachOptions(0), FILL|EXPAND);
139 when_table.attach (when_bar_entry, 1, 2, 0, 1, AttachOptions(0), FILL|EXPAND);
141 when_table.attach (when_beat_label, 0, 1, 1, 2, AttachOptions(0), AttachOptions(0));
142 when_table.attach (when_beat_entry, 1, 2, 1, 2, AttachOptions(0), AttachOptions(0));
144 HBox* when_hbox = manage (new HBox());
145 Label* when_label = manage(new Label(_("Tempo Begins at:"), ALIGN_LEFT, ALIGN_TOP));
146 when_hbox->pack_end(when_table, PACK_EXPAND_PADDING, 6);
147 when_hbox->pack_start(*when_label, PACK_EXPAND_PADDING, 6);
149 when_frame.set_name ("MetricDialogFrame");
150 when_frame.add (*when_hbox);
152 get_vbox()->pack_end (when_frame, false, false);
153 when_frame.show_all();
157 bpm_frame.set_name ("MetricDialogFrame");
158 bpm_spinner.set_name ("MetricEntry");
160 get_vbox()->set_border_width (12);
161 get_vbox()->pack_end (bpm_frame, false, false);
163 add_button (Stock::CANCEL, RESPONSE_CANCEL);
164 add_button (Stock::APPLY, RESPONSE_ACCEPT);
165 set_response_sensitive (RESPONSE_ACCEPT, false);
166 set_default_response (RESPONSE_ACCEPT);
168 bpm_frame.show_all ();
171 set_name ("MetricDialog");
173 bpm_spinner.signal_activate().connect (bind (mem_fun (*this, &TempoDialog::response), RESPONSE_ACCEPT));
174 bpm_spinner.signal_button_press_event().connect (mem_fun (*this, &TempoDialog::bpm_button_press), false);
175 bpm_spinner.signal_button_release_event().connect (mem_fun (*this, &TempoDialog::bpm_button_release), false);
176 when_bar_entry.signal_activate().connect (bind (mem_fun (*this, &TempoDialog::response), RESPONSE_ACCEPT));
177 when_bar_entry.signal_key_release_event().connect (mem_fun (*this, &TempoDialog::entry_key_release), false);
178 when_beat_entry.signal_activate().connect (bind (mem_fun (*this, &TempoDialog::response), RESPONSE_ACCEPT));
179 when_beat_entry.signal_key_release_event().connect (mem_fun (*this, &TempoDialog::entry_key_release), false);
180 note_types.signal_changed().connect (mem_fun (*this, &TempoDialog::note_types_change));
184 TempoDialog::bpm_button_press (GdkEventButton* ev)
190 TempoDialog::bpm_button_release (GdkEventButton* ev)
192 /* the value has been modified, accept should work now */
194 set_response_sensitive (RESPONSE_ACCEPT, true);
199 TempoDialog::entry_key_release (GdkEventKey* ev)
201 if (when_beat_entry.get_text() != "" && when_bar_entry.get_text() != "") {
202 set_response_sensitive (RESPONSE_ACCEPT, true);
204 set_response_sensitive (RESPONSE_ACCEPT, false);
210 TempoDialog::get_bpm ()
212 return bpm_spinner.get_value ();
216 TempoDialog::get_bbt_time (BBT_Time& requested)
218 if (sscanf (when_bar_entry.get_text().c_str(), "%" PRIu32, &requested.bars) != 1) {
222 if (sscanf (when_beat_entry.get_text().c_str(), "%" PRIu32, &requested.beats) != 1) {
232 TempoDialog::get_note_type ()
234 double note_type = 0;
235 vector<string>::iterator i;
236 string text = note_types.get_active_text();
238 for (i = strings.begin(); i != strings.end(); ++i) {
240 if (sscanf (text.c_str(), "%*[^0-9]%lf", ¬e_type) != 1) {
241 error << string_compose(_("garbaged note type entry (%1)"), text) << endmsg;
249 if (i == strings.end()) {
250 if (sscanf (text.c_str(), "%lf", ¬e_type) != 1) {
251 error << string_compose(_("incomprehensible note type entry (%1)"), text) << endmsg;
260 TempoDialog::note_types_change ()
262 set_response_sensitive (RESPONSE_ACCEPT, true);
266 MeterDialog::MeterDialog (TempoMap& map, nframes_t frame, const string & action)
267 : ArdourDialog ("meter dialog"),
268 bpb_frame (_("Meter")),
270 cancel_button (_("Cancel")),
271 when_frame (_("Location"))
274 frame = map.round_to_bar(frame,0);
275 Meter meter (map.meter_at(frame));
277 map.bbt_time (frame, when);
278 init (when, meter.beats_per_bar(), meter.note_divisor(), true);
281 MeterDialog::MeterDialog (MeterSection& section, const string & action)
282 : ArdourDialog ("meter dialog"),
283 bpb_frame (_("Meter")),
285 cancel_button (_("Cancel")),
286 when_frame (_("Location"))
288 init (section.start(), section.beats_per_bar(), section.note_divisor(), section.movable());
292 MeterDialog::init (const BBT_Time& when, double bpb, double note_type, bool movable)
294 snprintf (buf, sizeof (buf), "%.2f", bpb);
295 bpb_entry.set_text (buf);
296 bpb_entry.select_region (0, -1);
297 Gtkmm2ext::set_size_request_to_display_given_text (bpb_entry, "999999g", 5, 5);
299 strings.push_back (_("whole (1)"));
300 strings.push_back (_("second (2)"));
301 strings.push_back (_("third (3)"));
302 strings.push_back (_("quarter (4)"));
303 strings.push_back (_("eighth (8)"));
304 strings.push_back (_("sixteenth (16)"));
305 strings.push_back (_("thirty-second (32)"));
307 set_popdown_strings (note_types, strings, true);
310 note_types.set_active_text (_("whole (1)"));
311 else if (note_type==2.0f)
312 note_types.set_active_text (_("second (2)"));
313 else if (note_type==3.0f)
314 note_types.set_active_text (_("third (3)"));
315 else if (note_type==4.0f)
316 note_types.set_active_text (_("quarter (4)"));
317 else if (note_type==8.0f)
318 note_types.set_active_text (_("eighth (8)"));
319 else if (note_type==16.0f)
320 note_types.set_active_text (_("sixteenth (16)"));
321 else if (note_type==32.0f)
322 note_types.set_active_text (_("thirty-second (32)"));
324 note_types.set_active_text (_("quarter (4)"));
326 Label* note_label = manage(new Label(_("Note Value:"), ALIGN_LEFT, ALIGN_CENTER));
327 Label* bpb_label = manage(new Label(_("Beats Per Bar:"), ALIGN_LEFT, ALIGN_CENTER));
328 Table* bpb_table = manage (new Table(2, 2));
330 bpb_table->attach (*bpb_label, 0, 1, 0, 1, FILL|EXPAND, FILL|EXPAND, 6, 6);
331 bpb_table->attach (bpb_entry, 1, 2, 0, 1, FILL|EXPAND, FILL|EXPAND, 6, 6);
332 bpb_table->attach (*note_label, 0, 1, 1, 2, FILL|EXPAND, FILL|EXPAND, 6, 6);
333 bpb_table->attach (note_types, 1, 2, 1, 2, FILL|EXPAND, SHRINK, 6, 6);
334 bpb_frame.add (*bpb_table);
337 snprintf (buf, sizeof (buf), "%" PRIu32, when.bars);
338 when_bar_entry.set_text (buf);
340 when_bar_entry.set_name ("MetricEntry");
342 Gtkmm2ext::set_size_request_to_display_given_text (when_bar_entry, "999g", 5, 7);
344 HBox* when_hbox = manage (new HBox());
345 Label* when_label = manage(new Label(_("Meter Begins at Bar:"), ALIGN_LEFT, ALIGN_TOP));
346 when_hbox->pack_end(when_bar_entry, PACK_EXPAND_PADDING, 6);
347 when_hbox->pack_start(*when_label, PACK_EXPAND_PADDING, 6);
349 when_frame.set_name ("MetricDialogFrame");
350 when_frame.add (*when_hbox);
352 get_vbox()->pack_end (when_frame, false, false);
355 get_vbox()->set_border_width (12);
356 get_vbox()->pack_start (bpb_frame, false, false);
358 bpb_frame.set_name ("MetricDialogFrame");
359 bpb_entry.set_name ("MetricEntry");
361 add_button (Stock::CANCEL, RESPONSE_CANCEL);
362 add_button (Stock::APPLY, RESPONSE_ACCEPT);
363 set_response_sensitive (RESPONSE_ACCEPT, false);
364 set_default_response (RESPONSE_ACCEPT);
366 get_vbox()->show_all ();
368 set_name ("MetricDialog");
369 bpb_entry.signal_activate().connect (bind (mem_fun (*this, &MeterDialog::response), RESPONSE_ACCEPT));
370 bpb_entry.signal_key_press_event().connect (mem_fun (*this, &MeterDialog::entry_key_press), false);
371 bpb_entry.signal_key_release_event().connect (mem_fun (*this, &MeterDialog::entry_key_release));
372 when_bar_entry.signal_activate().connect (bind (mem_fun (*this, &MeterDialog::response), RESPONSE_ACCEPT));
373 when_bar_entry.signal_key_press_event().connect (mem_fun (*this, &MeterDialog::entry_key_press), false);
374 when_bar_entry.signal_key_release_event().connect (mem_fun (*this, &MeterDialog::entry_key_release));
376 note_types.signal_changed().connect (mem_fun (*this, &MeterDialog::note_types_change));
380 MeterDialog::entry_key_press (GdkEventKey* ev)
383 switch (ev->keyval) {
428 MeterDialog::entry_key_release (GdkEventKey* ev)
430 if (when_bar_entry.get_text() != "" && bpb_entry.get_text() != "") {
431 set_response_sensitive (RESPONSE_ACCEPT, true);
433 set_response_sensitive (RESPONSE_ACCEPT, false);
439 MeterDialog::note_types_change ()
441 set_response_sensitive (RESPONSE_ACCEPT, true);
445 MeterDialog::get_bpb ()
449 if (sscanf (bpb_entry.get_text().c_str(), "%lf", &bpb) != 1) {
457 MeterDialog::get_note_type ()
459 double note_type = 0;
460 vector<string>::iterator i;
461 string text = note_types.get_active_text();
463 for (i = strings.begin(); i != strings.end(); ++i) {
465 if (sscanf (text.c_str(), "%*[^0-9]%lf", ¬e_type) != 1) {
466 error << string_compose(_("garbaged note type entry (%1)"), text) << endmsg;
474 if (i == strings.end()) {
475 if (sscanf (text.c_str(), "%lf", ¬e_type) != 1) {
476 error << string_compose(_("incomprehensible note type entry (%1)"), text) << endmsg;
485 MeterDialog::get_bbt_time (BBT_Time& requested)
488 if (sscanf (when_bar_entry.get_text().c_str(), "%" PRIu32, &requested.bars) != 1) {