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"
31 using namespace Gtkmm2ext;
32 using namespace ARDOUR;
35 TempoDialog::TempoDialog (TempoMap& map, nframes_t frame, const string & action)
36 : ArdourDialog (_("edit tempo")),
37 bpm_adjustment (60.0, 1.0, 999.9, 0.1, 1.0, 1.0),
38 bpm_spinner (bpm_adjustment),
39 bpm_frame (_("Tempo")),
41 cancel_button (_("Cancel")),
42 when_bar_label (_("Bar"), ALIGN_LEFT, ALIGN_CENTER),
43 when_beat_label (_("Beat"), ALIGN_LEFT, ALIGN_CENTER),
45 when_frame (_("Location"))
48 Tempo tempo (map.tempo_at (frame));
49 map.bbt_time (frame, when);
51 init (when, tempo.beats_per_minute(), tempo.note_type(), true);
54 TempoDialog::TempoDialog (TempoSection& section, const string & action)
55 : ArdourDialog ("tempo dialog"),
56 bpm_adjustment (60.0, 1.0, 999.9, 0.1, 1.0, 1.0),
57 bpm_spinner (bpm_adjustment),
58 bpm_frame (_("Tempo")),
60 cancel_button (_("Cancel")),
61 when_bar_label (_("Bar"), ALIGN_LEFT, ALIGN_CENTER),
62 when_beat_label (_("Beat"), ALIGN_LEFT, ALIGN_CENTER),
64 when_frame (_("Location"))
66 init (section.start(), section.beats_per_minute(), section.note_type(), section.movable());
70 TempoDialog::init (const BBT_Time& when, double bpm, double note_type, bool movable)
72 bpm_spinner.set_numeric (true);
73 bpm_spinner.set_digits (2);
74 bpm_spinner.set_wrap (true);
75 bpm_spinner.set_value (bpm);
77 strings.push_back (_("whole (1)"));
78 strings.push_back (_("second (2)"));
79 strings.push_back (_("third (3)"));
80 strings.push_back (_("quarter (4)"));
81 strings.push_back (_("eighth (8)"));
82 strings.push_back (_("sixteenth (16)"));
83 strings.push_back (_("thirty-second (32)"));
85 /* the string here needs to be the longest one to display */
86 const guint32 FUDGE = 20; // Combo's are stupid - they steal space from the entry for the button
87 // TRANSLATORS: this is not a mis-spelling of "thirty", we're including a vertical
88 // descender to make sure the height gets computed properly.
89 Gtkmm2ext::set_size_request_to_display_given_text (note_types, "thirtq-second (32)", 7+FUDGE, 15);
91 set_popdown_strings (note_types, strings);
94 note_types.set_active_text (_("whole (1)"));
95 else if (note_type==2.0f)
96 note_types.set_active_text (_("second (2)"));
97 else if (note_type==3.0f)
98 note_types.set_active_text (_("third (3)"));
99 else if (note_type==4.0f)
100 note_types.set_active_text (_("quarter (4)"));
101 else if (note_type==8.0f)
102 note_types.set_active_text (_("eighth (8)"));
103 else if (note_type==16.0f)
104 note_types.set_active_text (_("sixteenth (16)"));
105 else if (note_type==32.0f)
106 note_types.set_active_text (_("thirty-second (32)"));
108 note_types.set_active_text (_("quarter (4)"));
110 Label* bpm_label = manage(new Label(_("Beats Per Minute:"), ALIGN_LEFT, ALIGN_CENTER));
112 hspacer1.set_border_width (6);
113 hspacer1.pack_end (bpm_spinner, PACK_EXPAND_PADDING);
114 hspacer1.pack_start (*bpm_label, PACK_EXPAND_PADDING);
115 vspacer1.set_border_width (6);
116 vspacer1.pack_start (hspacer1, PACK_EXPAND_PADDING);
118 hspacer2.set_border_width (6);
119 hspacer2.pack_start (note_types, PACK_EXPAND_PADDING);
121 bpm_frame.add (vspacer1);
124 snprintf (buf, sizeof (buf), "%" PRIu32, when.bars);
125 when_bar_entry.set_text (buf);
126 snprintf (buf, sizeof (buf), "%" PRIu32, when.beats);
127 when_beat_entry.set_text (buf);
129 when_bar_entry.set_name ("MetricEntry");
130 when_beat_entry.set_name ("MetricEntry");
132 when_bar_label.set_name ("MetricLabel");
133 when_beat_label.set_name ("MetricLabel");
135 Gtkmm2ext::set_size_request_to_display_given_text (when_bar_entry, "999g", 5, 7);
136 Gtkmm2ext::set_size_request_to_display_given_text (when_beat_entry, "999g", 5, 7);
138 when_table.set_homogeneous (true);
139 when_table.set_row_spacings (2);
140 when_table.set_col_spacings (2);
141 when_table.set_border_width (6);
143 when_table.attach (when_bar_label, 0, 1, 0, 1, AttachOptions(0), FILL|EXPAND);
144 when_table.attach (when_bar_entry, 1, 2, 0, 1, AttachOptions(0), FILL|EXPAND);
146 when_table.attach (when_beat_label, 0, 1, 1, 2, AttachOptions(0), AttachOptions(0));
147 when_table.attach (when_beat_entry, 1, 2, 1, 2, AttachOptions(0), AttachOptions(0));
149 HBox* when_hbox = manage (new HBox());
150 Label* when_label = manage(new Label(_("Tempo Begins at:"), ALIGN_LEFT, ALIGN_TOP));
151 when_hbox->pack_end(when_table, PACK_EXPAND_PADDING, 6);
152 when_hbox->pack_start(*when_label, PACK_EXPAND_PADDING, 6);
154 when_frame.set_name ("MetricDialogFrame");
155 when_frame.add (*when_hbox);
157 get_vbox()->pack_end (when_frame, false, false);
158 when_frame.show_all();
162 bpm_frame.set_name ("MetricDialogFrame");
163 bpm_spinner.set_name ("MetricEntry");
165 get_vbox()->set_border_width (12);
166 get_vbox()->pack_end (bpm_frame, false, false);
168 add_button (Stock::CANCEL, RESPONSE_CANCEL);
169 add_button (Stock::APPLY, RESPONSE_ACCEPT);
170 set_response_sensitive (RESPONSE_ACCEPT, false);
171 set_default_response (RESPONSE_ACCEPT);
173 bpm_frame.show_all ();
176 set_name ("MetricDialog");
178 bpm_spinner.signal_activate().connect (bind (mem_fun (*this, &TempoDialog::response), RESPONSE_ACCEPT));
179 bpm_spinner.signal_button_press_event().connect (mem_fun (*this, &TempoDialog::bpm_button_press), false);
180 bpm_spinner.signal_button_release_event().connect (mem_fun (*this, &TempoDialog::bpm_button_release), false);
181 note_types.signal_changed().connect (mem_fun (*this, &TempoDialog::note_types_change));
185 TempoDialog::bpm_button_press (GdkEventButton* ev)
191 TempoDialog::bpm_button_release (GdkEventButton* ev)
193 /* the value has been modified, accept should work now */
195 set_response_sensitive (RESPONSE_ACCEPT, true);
200 TempoDialog::get_bpm ()
202 return bpm_spinner.get_value ();
206 TempoDialog::get_bbt_time (BBT_Time& requested)
208 if (sscanf (when_bar_entry.get_text().c_str(), "%" PRIu32, &requested.bars) != 1) {
212 if (sscanf (when_beat_entry.get_text().c_str(), "%" PRIu32, &requested.beats) != 1) {
222 TempoDialog::get_note_type ()
224 double note_type = 0;
225 vector<string>::iterator i;
226 string text = note_types.get_active_text();
228 for (i = strings.begin(); i != strings.end(); ++i) {
230 if (sscanf (text.c_str(), "%*[^0-9]%lf", ¬e_type) != 1) {
231 error << string_compose(_("garbaged note type entry (%1)"), text) << endmsg;
239 if (i == strings.end()) {
240 if (sscanf (text.c_str(), "%lf", ¬e_type) != 1) {
241 error << string_compose(_("incomprehensible note type entry (%1)"), text) << endmsg;
250 TempoDialog::note_types_change ()
252 set_response_sensitive (RESPONSE_ACCEPT, true);
256 MeterDialog::MeterDialog (TempoMap& map, nframes_t frame, const string & action)
257 : ArdourDialog ("meter dialog"),
258 bpb_frame (_("Meter")),
260 cancel_button (_("Cancel")),
261 when_bar_label (_("Bar"), ALIGN_LEFT, ALIGN_CENTER),
262 when_beat_label (_("Beat"), ALIGN_LEFT, ALIGN_CENTER),
263 when_frame (_("Location"))
266 frame = map.round_to_bar(frame,0);
267 Meter meter (map.meter_at(frame));
269 map.bbt_time (frame, when);
270 init (when, meter.beats_per_bar(), meter.note_divisor(), true);
273 MeterDialog::MeterDialog (MeterSection& section, const string & action)
274 : ArdourDialog ("meter dialog"),
275 bpb_frame (_("Meter")),
277 cancel_button (_("Cancel")),
278 when_bar_label (_("Bar"), ALIGN_LEFT, ALIGN_CENTER),
279 when_beat_label (_("Beat"), ALIGN_LEFT, ALIGN_CENTER),
280 when_frame (_("Location"))
282 init (section.start(), section.beats_per_bar(), section.note_divisor(), section.movable());
286 MeterDialog::init (const BBT_Time& when, double bpb, double note_type, bool movable)
288 snprintf (buf, sizeof (buf), "%.2f", bpb);
289 bpb_entry.set_text (buf);
290 bpb_entry.select_region (0, -1);
291 Gtkmm2ext::set_size_request_to_display_given_text (bpb_entry, "999999g", 5, 5);
293 strings.push_back (_("whole (1)"));
294 strings.push_back (_("second (2)"));
295 strings.push_back (_("third (3)"));
296 strings.push_back (_("quarter (4)"));
297 strings.push_back (_("eighth (8)"));
298 strings.push_back (_("sixteenth (16)"));
299 strings.push_back (_("thirty-second (32)"));
301 /* the string here needs to be the longest one to display */
302 const guint32 FUDGE = 20; // Combo's are stupid - they steal space from the entry for the button
304 // TRANSLATORS: this is not a mis-spelling of "thirty", we're including a vertical
305 // descender to make sure the height gets computed properly.
306 Gtkmm2ext::set_size_request_to_display_given_text (note_types, _("thirtq-second (32)"), 7+FUDGE, 15);
308 set_popdown_strings (note_types, strings);
311 note_types.set_active_text (_("whole (1)"));
312 else if (note_type==2.0f)
313 note_types.set_active_text (_("second (2)"));
314 else if (note_type==3.0f)
315 note_types.set_active_text (_("third (3)"));
316 else if (note_type==4.0f)
317 note_types.set_active_text (_("quarter (4)"));
318 else if (note_type==8.0f)
319 note_types.set_active_text (_("eighth (8)"));
320 else if (note_type==16.0f)
321 note_types.set_active_text (_("sixteenth (16)"));
322 else if (note_type==32.0f)
323 note_types.set_active_text (_("thirty-second (32)"));
325 note_types.set_active_text (_("quarter (4)"));
327 Label* note_label = manage(new Label(_("Note Value:"), ALIGN_LEFT, ALIGN_CENTER));
328 Label* bpb_label = manage(new Label(_("Beats Per Bar:"), ALIGN_LEFT, ALIGN_CENTER));
329 Table* bpb_table = manage (new Table(2, 2));
331 bpb_table->attach (*bpb_label, 0, 1, 0, 1, FILL|EXPAND, FILL|EXPAND, 6, 6);
332 bpb_table->attach (bpb_entry, 1, 2, 0, 1, FILL|EXPAND, FILL|EXPAND, 6, 6);
333 bpb_table->attach (*note_label, 0, 1, 1, 2, FILL|EXPAND, FILL|EXPAND, 6, 6);
334 bpb_table->attach (note_types, 1, 2, 1, 2, FILL|EXPAND, SHRINK, 6, 6);
335 bpb_frame.add (*bpb_table);
338 snprintf (buf, sizeof (buf), "%" PRIu32, when.bars);
339 when_bar_entry.set_text (buf);
340 snprintf (buf, sizeof (buf), "%" PRIu32, when.beats);
341 when_beat_entry.set_text (buf);
343 when_bar_entry.set_name ("MetricEntry");
344 when_beat_entry.set_name ("MetricEntry");
346 when_bar_label.set_name ("MetricLabel");
347 when_beat_label.set_name ("MetricLabel");
349 Gtkmm2ext::set_size_request_to_display_given_text (when_bar_entry, "999g", 5, 7);
350 Gtkmm2ext::set_size_request_to_display_given_text (when_beat_entry, "999g", 5, 7);
352 when_table.set_homogeneous (true);
353 when_table.set_row_spacings (2);
354 when_table.set_col_spacings (2);
355 when_table.set_border_width (6);
357 when_table.attach (when_bar_label, 0, 1, 0, 1, AttachOptions(0), FILL|EXPAND);
358 when_table.attach (when_bar_entry, 1, 2, 0, 1, AttachOptions(0), FILL|EXPAND);
360 when_table.attach (when_beat_label, 0, 1, 1, 2, AttachOptions(0), AttachOptions(0));
361 when_table.attach (when_beat_entry, 1, 2, 1, 2, AttachOptions(0), AttachOptions(0));
363 HBox* when_hbox = manage (new HBox());
364 Label* when_label = manage(new Label(_("Meter Begins at:"), ALIGN_LEFT, ALIGN_TOP));
365 when_hbox->pack_end(when_table, PACK_EXPAND_PADDING, 6);
366 when_hbox->pack_start(*when_label, PACK_EXPAND_PADDING, 6);
368 when_frame.set_name ("MetricDialogFrame");
369 when_frame.add (*when_hbox);
371 get_vbox()->pack_end (when_frame, false, false);
374 get_vbox()->set_border_width (12);
375 get_vbox()->pack_start (bpb_frame, false, false);
377 bpb_frame.set_name ("MetricDialogFrame");
378 bpb_entry.set_name ("MetricEntry");
380 add_button (Stock::CANCEL, RESPONSE_CANCEL);
381 add_button (Stock::APPLY, RESPONSE_ACCEPT);
382 set_response_sensitive (RESPONSE_ACCEPT, false);
383 set_default_response (RESPONSE_ACCEPT);
385 get_vbox()->show_all ();
387 set_name ("MetricDialog");
388 bpb_entry.signal_activate().connect (bind (mem_fun (*this, &MeterDialog::response), RESPONSE_ACCEPT));
389 bpb_entry.signal_key_press_event().connect (mem_fun (*this, &MeterDialog::bpb_key_press), false);
390 bpb_entry.signal_key_release_event().connect (mem_fun (*this, &MeterDialog::bpb_key_release));
391 note_types.signal_changed().connect (mem_fun (*this, &MeterDialog::note_types_change));
395 MeterDialog::bpb_key_press (GdkEventKey* ev)
398 switch (ev->keyval) {
443 MeterDialog::bpb_key_release (GdkEventKey* ev)
445 if (bpb_entry.get_text() != "") {
446 set_response_sensitive (RESPONSE_ACCEPT, true);
448 set_response_sensitive (RESPONSE_ACCEPT, false);
454 MeterDialog::note_types_change ()
456 set_response_sensitive (RESPONSE_ACCEPT, true);
460 MeterDialog::get_bpb ()
464 if (sscanf (bpb_entry.get_text().c_str(), "%lf", &bpb) != 1) {
472 MeterDialog::get_note_type ()
474 double note_type = 0;
475 vector<string>::iterator i;
476 string text = note_types.get_active_text();
478 for (i = strings.begin(); i != strings.end(); ++i) {
480 if (sscanf (text.c_str(), "%*[^0-9]%lf", ¬e_type) != 1) {
481 error << string_compose(_("garbaged note type entry (%1)"), text) << endmsg;
489 if (i == strings.end()) {
490 if (sscanf (text.c_str(), "%lf", ¬e_type) != 1) {
491 error << string_compose(_("incomprehensible note type entry (%1)"), text) << endmsg;
500 MeterDialog::get_bbt_time (BBT_Time& requested)
503 if (sscanf (when_bar_entry.get_text().c_str(), "%" PRIu32, &requested.bars) != 1) {
507 if (sscanf (when_beat_entry.get_text().c_str(), "%" PRIu32, &requested.beats) != 1) {