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 note_frame (_("BPM denominator")),
38 bpm_adjustment (60.0, 1.0, 999.9, 0.1, 1.0, 1.0),
39 bpm_spinner (bpm_adjustment),
40 bpm_frame (_("Beats per minute")),
42 cancel_button (_("Cancel")),
43 when_bar_label (_("Bar")),
44 when_beat_label (_("Beat")),
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 (_("Beats per minute")),
61 cancel_button (_("Cancel")),
62 when_bar_label (_("Bar")),
63 when_beat_label (_("Beat")),
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 /* the string here needs to be the longest one to display */
87 const guint32 FUDGE = 20; // Combo's are stupid - they steal space from the entry for the button
88 // TRANSLATORS: this is not a mis-spelling of "thirty", we're including a vertical
89 // descender to make sure the height gets computed properly.
90 Gtkmm2ext::set_size_request_to_display_given_text (note_types, "thirtq-second (32)", 7+FUDGE, 15);
92 set_popdown_strings (note_types, strings);
95 note_types.set_active_text (_("whole (1)"));
96 else if (note_type==2.0f)
97 note_types.set_active_text (_("second (2)"));
98 else if (note_type==3.0f)
99 note_types.set_active_text (_("third (3)"));
100 else if (note_type==4.0f)
101 note_types.set_active_text (_("quarter (4)"));
102 else if (note_type==8.0f)
103 note_types.set_active_text (_("eighth (8)"));
104 else if (note_type==16.0f)
105 note_types.set_active_text (_("sixteenth (16)"));
106 else if (note_type==32.0f)
107 note_types.set_active_text (_("thirty-second (32)"));
109 note_types.set_active_text (_("quarter (4)"));
111 hspacer1.set_border_width (5);
112 hspacer1.pack_start (bpm_spinner, false, false);
113 vspacer1.set_border_width (5);
114 vspacer1.pack_start (hspacer1, false, false);
116 hspacer2.set_border_width (5);
117 hspacer2.pack_start (note_types, false, false);
118 vspacer2.set_border_width (5);
119 vspacer2.pack_start (hspacer2, false, false);
121 bpm_frame.add (vspacer1);
122 note_frame.add (vspacer2);
125 snprintf (buf, sizeof (buf), "%" PRIu32, when.bars);
126 when_bar_entry.set_text (buf);
127 snprintf (buf, sizeof (buf), "%" PRIu32, when.beats);
128 when_beat_entry.set_text (buf);
130 when_bar_entry.set_name ("MetricEntry");
131 when_beat_entry.set_name ("MetricEntry");
133 when_bar_label.set_name ("MetricLabel");
134 when_beat_label.set_name ("MetricLabel");
136 Gtkmm2ext::set_size_request_to_display_given_text (when_bar_entry, "999g", 5, 7);
137 Gtkmm2ext::set_size_request_to_display_given_text (when_beat_entry, "999g", 5, 7);
139 when_table.set_homogeneous (true);
140 when_table.set_row_spacings (2);
141 when_table.set_col_spacings (2);
142 when_table.set_border_width (5);
144 when_table.attach (when_bar_label, 0, 1, 0, 1, Gtk::AttachOptions(0), Gtk::FILL|Gtk::EXPAND);
145 when_table.attach (when_bar_entry, 0, 1, 1, 2, Gtk::AttachOptions(0), Gtk::FILL|Gtk::EXPAND);
147 when_table.attach (when_beat_label, 1, 2, 0, 1, Gtk::AttachOptions(0), Gtk::AttachOptions(0));
148 when_table.attach (when_beat_entry, 1, 2, 1, 2, Gtk::AttachOptions(0), Gtk::AttachOptions(0));
150 when_frame.set_name ("MetricDialogFrame");
151 when_frame.add (when_table);
153 get_vbox()->pack_start (when_frame, false, false);
156 bpm_frame.set_name ("MetricDialogFrame");
157 bpm_spinner.set_name ("MetricEntry");
158 note_frame.set_name ("MetricDialogFrame");
160 get_vbox()->set_border_width (12);
161 get_vbox()->pack_start (bpm_frame, false, false);
162 get_vbox()->pack_start (note_frame, false, false);
164 add_button (Stock::CANCEL, RESPONSE_CANCEL);
165 add_button (Stock::APPLY, RESPONSE_ACCEPT);
166 set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
167 set_default_response (RESPONSE_ACCEPT);
169 get_vbox()->show_all();
172 set_name ("MetricDialog");
174 bpm_spinner.signal_activate().connect (bind (mem_fun (*this, &TempoDialog::response), RESPONSE_ACCEPT));
175 bpm_spinner.signal_button_press_event().connect (mem_fun (*this, &TempoDialog::bpm_button_press), false);
176 bpm_spinner.signal_button_release_event().connect (mem_fun (*this, &TempoDialog::bpm_button_release), false);
177 note_types.signal_changed().connect (mem_fun (*this, &TempoDialog::note_types_change));
181 TempoDialog::bpm_button_press (GdkEventButton* ev)
187 TempoDialog::bpm_button_release (GdkEventButton* ev)
189 /* the value has been modified, accept should work now */
191 set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
196 TempoDialog::get_bpm ()
198 return bpm_spinner.get_value ();
202 TempoDialog::get_bbt_time (BBT_Time& requested)
204 if (sscanf (when_bar_entry.get_text().c_str(), "%" PRIu32, &requested.bars) != 1) {
208 if (sscanf (when_beat_entry.get_text().c_str(), "%" PRIu32, &requested.beats) != 1) {
216 TempoDialog::get_note_type ()
218 double note_type = 0;
219 vector<string>::iterator i;
220 string text = note_types.get_active_text();
222 for (i = strings.begin(); i != strings.end(); ++i) {
224 if (sscanf (text.c_str(), "%*[^0-9]%lf", ¬e_type) != 1) {
225 error << string_compose(_("garbaged note type entry (%1)"), text) << endmsg;
233 if (i == strings.end()) {
234 if (sscanf (text.c_str(), "%lf", ¬e_type) != 1) {
235 error << string_compose(_("incomprehensible note type entry (%1)"), text) << endmsg;
240 cerr << "returning " << note_type << " based on " << text << endl;
245 TempoDialog::note_types_change ()
247 set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
251 MeterDialog::MeterDialog (TempoMap& map, nframes_t frame, const string & action)
252 : ArdourDialog ("meter dialog"),
253 note_frame (_("Meter denominator")),
254 bpb_frame (_("Beats per bar")),
256 cancel_button (_("Cancel")),
257 when_bar_label (_("Bar")),
258 when_beat_label (_("Beat")),
259 when_frame (_("Location"))
262 frame = map.round_to_bar(frame,0);
263 Meter meter (map.meter_at(frame));
265 map.bbt_time (frame, when);
266 init (when, meter.beats_per_bar(), meter.note_divisor(), true);
269 MeterDialog::MeterDialog (MeterSection& section, const string & action)
270 : ArdourDialog ("meter dialog"),
271 note_frame (_("Meter denominator")),
272 bpb_frame (_("Beats per bar")),
274 cancel_button (_("Cancel")),
275 when_bar_label (_("Bar")),
276 when_beat_label (_("Beat")),
277 when_frame (_("Location"))
279 init (section.start(), section.beats_per_bar(), section.note_divisor(), section.movable());
283 MeterDialog::init (const BBT_Time& when, double bpb, double note_type, bool movable)
285 snprintf (buf, sizeof (buf), "%.2f", bpb);
286 bpb_entry.set_text (buf);
287 bpb_entry.select_region (0, -1);
288 Gtkmm2ext::set_size_request_to_display_given_text (bpb_entry, "999999g", 5, 5);
290 strings.push_back (_("whole (1)"));
291 strings.push_back (_("second (2)"));
292 strings.push_back (_("third (3)"));
293 strings.push_back (_("quarter (4)"));
294 strings.push_back (_("eighth (8)"));
295 strings.push_back (_("sixteenth (16)"));
296 strings.push_back (_("thirty-second (32)"));
298 /* the string here needs to be the longest one to display */
299 const guint32 FUDGE = 20; // Combo's are stupid - they steal space from the entry for the button
301 // TRANSLATORS: this is not a mis-spelling of "thirty", we're including a vertical
302 // descender to make sure the height gets computed properly.
303 Gtkmm2ext::set_size_request_to_display_given_text (note_types, _("thirtq-second (32)"), 7+FUDGE, 15);
305 set_popdown_strings (note_types, strings);
308 note_types.set_active_text (_("whole (1)"));
309 else if (note_type==2.0f)
310 note_types.set_active_text (_("second (2)"));
311 else if (note_type==3.0f)
312 note_types.set_active_text (_("third (3)"));
313 else if (note_type==4.0f)
314 note_types.set_active_text (_("quarter (4)"));
315 else if (note_type==8.0f)
316 note_types.set_active_text (_("eighth (8)"));
317 else if (note_type==16.0f)
318 note_types.set_active_text (_("sixteenth (16)"));
319 else if (note_type==32.0f)
320 note_types.set_active_text (_("thirty-second (32)"));
322 note_types.set_active_text (_("quarter (4)"));
324 hspacer1.set_border_width (5);
325 hspacer1.pack_start (note_types, false, false);
326 vspacer1.set_border_width (5);
327 vspacer1.pack_start (hspacer1, false, false);
329 hspacer2.set_border_width (5);
330 hspacer2.pack_start (bpb_entry, false, false);
331 vspacer2.set_border_width (5);
332 vspacer2.pack_start (hspacer2, false, false);
334 note_frame.add (vspacer1);
335 bpb_frame.add (vspacer2);
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 (5);
357 when_table.attach (when_bar_label, 0, 1, 0, 1, Gtk::AttachOptions(0), Gtk::FILL|Gtk::EXPAND);
358 when_table.attach (when_bar_entry, 0, 1, 1, 2, Gtk::AttachOptions(0), Gtk::FILL|Gtk::EXPAND);
360 when_table.attach (when_beat_label, 1, 2, 0, 1, Gtk::AttachOptions(0), Gtk::AttachOptions(0));
361 when_table.attach (when_beat_entry, 1, 2, 1, 2, Gtk::AttachOptions(0), Gtk::AttachOptions(0));
363 when_frame.set_name ("MetricDialogFrame");
364 when_frame.add (when_table);
366 get_vbox()->pack_start (when_frame, false, false);
369 get_vbox()->set_border_width (12);
370 get_vbox()->pack_start (bpb_frame, false, false);
371 get_vbox()->pack_start (note_frame, false, false);
373 bpb_frame.set_name ("MetricDialogFrame");
374 note_frame.set_name ("MetricDialogFrame");
375 bpb_entry.set_name ("MetricEntry");
377 add_button (Stock::CANCEL, RESPONSE_CANCEL);
378 add_button (Stock::APPLY, RESPONSE_ACCEPT);
379 set_response_sensitive (RESPONSE_ACCEPT, false);
380 set_default_response (RESPONSE_ACCEPT);
382 get_vbox()->show_all ();
385 set_name ("MetricDialog");
386 bpb_entry.signal_activate().connect (bind (mem_fun (*this, &MeterDialog::response), RESPONSE_ACCEPT));
387 bpb_entry.signal_key_press_event().connect (mem_fun (*this, &MeterDialog::bpb_key_press), false);
388 bpb_entry.signal_key_release_event().connect (mem_fun (*this, &MeterDialog::bpb_key_release));
389 note_types.signal_changed().connect (mem_fun (*this, &MeterDialog::note_types_change));
393 MeterDialog::bpb_key_press (GdkEventKey* ev)
396 switch (ev->keyval) {
441 MeterDialog::bpb_key_release (GdkEventKey* ev)
443 if (bpb_entry.get_text() != "") {
444 set_response_sensitive (RESPONSE_ACCEPT, true);
446 set_response_sensitive (RESPONSE_ACCEPT, false);
452 MeterDialog::note_types_change ()
454 set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
458 MeterDialog::get_bpb ()
462 if (sscanf (bpb_entry.get_text().c_str(), "%lf", &bpb) != 1) {
470 MeterDialog::get_note_type ()
472 double note_type = 0;
473 vector<string>::iterator i;
474 string text = note_types.get_active_text();
476 for (i = strings.begin(); i != strings.end(); ++i) {
478 if (sscanf (text.c_str(), "%*[^0-9]%lf", ¬e_type) != 1) {
479 error << string_compose(_("garbaged note type entry (%1)"), text) << endmsg;
487 if (i == strings.end()) {
488 if (sscanf (text.c_str(), "%lf", ¬e_type) != 1) {
489 error << string_compose(_("incomprehensible note type entry (%1)"), text) << endmsg;
498 MeterDialog::get_bbt_time (BBT_Time& requested)
502 if (sscanf (when_bar_entry.get_text().c_str(), "%" PRIu32, &requested.bars) != 1) {
506 if (sscanf (when_beat_entry.get_text().c_str(), "%" PRIu32, &requested.beats) != 1) {