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 (0);
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 when_bar_entry.signal_activate().connect (bind (mem_fun (*this, &TempoDialog::response), RESPONSE_ACCEPT));
182 when_bar_entry.signal_key_release_event().connect (mem_fun (*this, &TempoDialog::entry_key_release), false);
183 when_beat_entry.signal_activate().connect (bind (mem_fun (*this, &TempoDialog::response), RESPONSE_ACCEPT));
184 when_beat_entry.signal_key_release_event().connect (mem_fun (*this, &TempoDialog::entry_key_release), false);
185 note_types.signal_changed().connect (mem_fun (*this, &TempoDialog::note_types_change));
189 TempoDialog::bpm_button_press (GdkEventButton* ev)
195 TempoDialog::bpm_button_release (GdkEventButton* ev)
197 /* the value has been modified, accept should work now */
199 set_response_sensitive (RESPONSE_ACCEPT, true);
204 TempoDialog::entry_key_release (GdkEventKey* ev)
206 if (when_beat_entry.get_text() != "" && when_bar_entry.get_text() != "") {
207 set_response_sensitive (RESPONSE_ACCEPT, true);
209 set_response_sensitive (RESPONSE_ACCEPT, false);
215 TempoDialog::get_bpm ()
217 return bpm_spinner.get_value ();
221 TempoDialog::get_bbt_time (BBT_Time& requested)
223 if (sscanf (when_bar_entry.get_text().c_str(), "%" PRIu32, &requested.bars) != 1) {
227 if (sscanf (when_beat_entry.get_text().c_str(), "%" PRIu32, &requested.beats) != 1) {
237 TempoDialog::get_note_type ()
239 double note_type = 0;
240 vector<string>::iterator i;
241 string text = note_types.get_active_text();
243 for (i = strings.begin(); i != strings.end(); ++i) {
245 if (sscanf (text.c_str(), "%*[^0-9]%lf", ¬e_type) != 1) {
246 error << string_compose(_("garbaged note type entry (%1)"), text) << endmsg;
254 if (i == strings.end()) {
255 if (sscanf (text.c_str(), "%lf", ¬e_type) != 1) {
256 error << string_compose(_("incomprehensible note type entry (%1)"), text) << endmsg;
265 TempoDialog::note_types_change ()
267 set_response_sensitive (RESPONSE_ACCEPT, true);
271 MeterDialog::MeterDialog (TempoMap& map, nframes_t frame, const string & action)
272 : ArdourDialog ("meter dialog"),
273 bpb_frame (_("Meter")),
275 cancel_button (_("Cancel")),
276 when_frame (_("Location"))
279 frame = map.round_to_bar(frame,0);
280 Meter meter (map.meter_at(frame));
282 map.bbt_time (frame, when);
283 init (when, meter.beats_per_bar(), meter.note_divisor(), true);
286 MeterDialog::MeterDialog (MeterSection& section, const string & action)
287 : ArdourDialog ("meter dialog"),
288 bpb_frame (_("Meter")),
290 cancel_button (_("Cancel")),
291 when_frame (_("Location"))
293 init (section.start(), section.beats_per_bar(), section.note_divisor(), section.movable());
297 MeterDialog::init (const BBT_Time& when, double bpb, double note_type, bool movable)
299 snprintf (buf, sizeof (buf), "%.2f", bpb);
300 bpb_entry.set_text (buf);
301 bpb_entry.select_region (0, -1);
302 Gtkmm2ext::set_size_request_to_display_given_text (bpb_entry, "999999g", 5, 5);
304 strings.push_back (_("whole (1)"));
305 strings.push_back (_("second (2)"));
306 strings.push_back (_("third (3)"));
307 strings.push_back (_("quarter (4)"));
308 strings.push_back (_("eighth (8)"));
309 strings.push_back (_("sixteenth (16)"));
310 strings.push_back (_("thirty-second (32)"));
312 /* the string here needs to be the longest one to display */
313 const guint32 FUDGE = 20; // Combo's are stupid - they steal space from the entry for the button
315 // TRANSLATORS: this is not a mis-spelling of "thirty", we're including a vertical
316 // descender to make sure the height gets computed properly.
317 Gtkmm2ext::set_size_request_to_display_given_text (note_types, _("thirtq-second (32)"), 7+FUDGE, 15);
319 set_popdown_strings (note_types, strings);
322 note_types.set_active_text (_("whole (1)"));
323 else if (note_type==2.0f)
324 note_types.set_active_text (_("second (2)"));
325 else if (note_type==3.0f)
326 note_types.set_active_text (_("third (3)"));
327 else if (note_type==4.0f)
328 note_types.set_active_text (_("quarter (4)"));
329 else if (note_type==8.0f)
330 note_types.set_active_text (_("eighth (8)"));
331 else if (note_type==16.0f)
332 note_types.set_active_text (_("sixteenth (16)"));
333 else if (note_type==32.0f)
334 note_types.set_active_text (_("thirty-second (32)"));
336 note_types.set_active_text (_("quarter (4)"));
338 Label* note_label = manage(new Label(_("Note Value:"), ALIGN_LEFT, ALIGN_CENTER));
339 Label* bpb_label = manage(new Label(_("Beats Per Bar:"), ALIGN_LEFT, ALIGN_CENTER));
340 Table* bpb_table = manage (new Table(2, 2));
342 bpb_table->attach (*bpb_label, 0, 1, 0, 1, FILL|EXPAND, FILL|EXPAND, 6, 6);
343 bpb_table->attach (bpb_entry, 1, 2, 0, 1, FILL|EXPAND, FILL|EXPAND, 6, 6);
344 bpb_table->attach (*note_label, 0, 1, 1, 2, FILL|EXPAND, FILL|EXPAND, 6, 6);
345 bpb_table->attach (note_types, 1, 2, 1, 2, FILL|EXPAND, SHRINK, 6, 6);
346 bpb_frame.add (*bpb_table);
349 snprintf (buf, sizeof (buf), "%" PRIu32, when.bars);
350 when_bar_entry.set_text (buf);
352 when_bar_entry.set_name ("MetricEntry");
354 Gtkmm2ext::set_size_request_to_display_given_text (when_bar_entry, "999g", 5, 7);
356 HBox* when_hbox = manage (new HBox());
357 Label* when_label = manage(new Label(_("Meter Begins at Bar:"), ALIGN_LEFT, ALIGN_TOP));
358 when_hbox->pack_end(when_bar_entry, PACK_EXPAND_PADDING, 6);
359 when_hbox->pack_start(*when_label, PACK_EXPAND_PADDING, 6);
361 when_frame.set_name ("MetricDialogFrame");
362 when_frame.add (*when_hbox);
364 get_vbox()->pack_end (when_frame, false, false);
367 get_vbox()->set_border_width (12);
368 get_vbox()->pack_start (bpb_frame, false, false);
370 bpb_frame.set_name ("MetricDialogFrame");
371 bpb_entry.set_name ("MetricEntry");
373 add_button (Stock::CANCEL, RESPONSE_CANCEL);
374 add_button (Stock::APPLY, RESPONSE_ACCEPT);
375 set_response_sensitive (RESPONSE_ACCEPT, false);
376 set_default_response (RESPONSE_ACCEPT);
378 get_vbox()->show_all ();
380 set_name ("MetricDialog");
381 bpb_entry.signal_activate().connect (bind (mem_fun (*this, &MeterDialog::response), RESPONSE_ACCEPT));
382 bpb_entry.signal_key_press_event().connect (mem_fun (*this, &MeterDialog::entry_key_press), false);
383 bpb_entry.signal_key_release_event().connect (mem_fun (*this, &MeterDialog::entry_key_release));
384 when_bar_entry.signal_activate().connect (bind (mem_fun (*this, &MeterDialog::response), RESPONSE_ACCEPT));
385 when_bar_entry.signal_key_press_event().connect (mem_fun (*this, &MeterDialog::entry_key_press), false);
386 when_bar_entry.signal_key_release_event().connect (mem_fun (*this, &MeterDialog::entry_key_release));
388 note_types.signal_changed().connect (mem_fun (*this, &MeterDialog::note_types_change));
392 MeterDialog::entry_key_press (GdkEventKey* ev)
395 switch (ev->keyval) {
440 MeterDialog::entry_key_release (GdkEventKey* ev)
442 if (when_bar_entry.get_text() != "" && bpb_entry.get_text() != "") {
443 set_response_sensitive (RESPONSE_ACCEPT, true);
445 set_response_sensitive (RESPONSE_ACCEPT, false);
451 MeterDialog::note_types_change ()
453 set_response_sensitive (RESPONSE_ACCEPT, true);
457 MeterDialog::get_bpb ()
461 if (sscanf (bpb_entry.get_text().c_str(), "%lf", &bpb) != 1) {
469 MeterDialog::get_note_type ()
471 double note_type = 0;
472 vector<string>::iterator i;
473 string text = note_types.get_active_text();
475 for (i = strings.begin(); i != strings.end(); ++i) {
477 if (sscanf (text.c_str(), "%*[^0-9]%lf", ¬e_type) != 1) {
478 error << string_compose(_("garbaged note type entry (%1)"), text) << endmsg;
486 if (i == strings.end()) {
487 if (sscanf (text.c_str(), "%lf", ¬e_type) != 1) {
488 error << string_compose(_("incomprehensible note type entry (%1)"), text) << endmsg;
497 MeterDialog::get_bbt_time (BBT_Time& requested)
500 if (sscanf (when_bar_entry.get_text().c_str(), "%" PRIu32, &requested.bars) != 1) {