1 #include <cstdio> // for snprintf, grrr
3 #include <gtkmm/stock.h>
4 #include <gtkmm2ext/utils.h>
6 #include "tempo_dialog.h"
12 using namespace Gtkmm2ext;
13 using namespace ARDOUR;
15 TempoDialog::TempoDialog (TempoMap& map, jack_nframes_t frame, const string & action)
16 : ArdourDialog ("tempo dialog"),
17 bpm_frame (_("Beats per minute")),
19 cancel_button (_("Cancel")),
20 when_bar_label (_("Bar")),
21 when_beat_label (_("Beat")),
23 when_frame (_("Location"))
26 Tempo tempo (map.tempo_at (frame));
27 map.bbt_time (frame, when);
29 init (when, tempo.beats_per_minute(), true);
32 TempoDialog::TempoDialog (TempoSection& section, const string & action)
33 : ArdourDialog ("tempo dialog"),
34 bpm_frame (_("Beats per minute")),
36 cancel_button (_("Cancel")),
37 when_bar_label (_("Bar")),
38 when_beat_label (_("Beat")),
40 when_frame (_("Location"))
42 init (section.start(), section.beats_per_minute(), section.movable());
46 TempoDialog::init (const BBT_Time& when, double bpm, bool movable)
48 snprintf (buf, sizeof (buf), "%.2f", bpm);
49 bpm_entry.set_text (buf);
50 bpm_entry.select_region (0, -1);
52 hspacer1.set_border_width (5);
53 hspacer1.pack_start (bpm_entry, false, false);
54 vspacer1.set_border_width (5);
55 vspacer1.pack_start (hspacer1, false, false);
57 bpm_frame.add (vspacer1);
60 snprintf (buf, sizeof (buf), "%" PRIu32, when.bars);
61 when_bar_entry.set_text (buf);
62 snprintf (buf, sizeof (buf), "%" PRIu32, when.beats);
63 when_beat_entry.set_text (buf);
65 when_bar_entry.set_name ("MetricEntry");
66 when_beat_entry.set_name ("MetricEntry");
68 when_bar_label.set_name ("MetricLabel");
69 when_beat_label.set_name ("MetricLabel");
71 Gtkmm2ext::set_size_request_to_display_given_text (when_bar_entry, "999g", 5, 7);
72 Gtkmm2ext::set_size_request_to_display_given_text (when_beat_entry, "999g", 5, 7);
74 when_table.set_homogeneous (true);
75 when_table.set_row_spacings (2);
76 when_table.set_col_spacings (2);
77 when_table.set_border_width (5);
79 when_table.attach (when_bar_label, 0, 1, 0, 1, Gtk::AttachOptions(0), Gtk::FILL|Gtk::EXPAND);
80 when_table.attach (when_bar_entry, 0, 1, 1, 2, Gtk::AttachOptions(0), Gtk::FILL|Gtk::EXPAND);
82 when_table.attach (when_beat_label, 1, 2, 0, 1, Gtk::AttachOptions(0), Gtk::AttachOptions(0));
83 when_table.attach (when_beat_entry, 1, 2, 1, 2, Gtk::AttachOptions(0), Gtk::AttachOptions(0));
85 when_frame.set_name ("MetricDialogFrame");
86 when_frame.add (when_table);
88 get_vbox()->pack_start (when_frame, false, false);
91 bpm_frame.set_name ("MetricDialogFrame");
92 bpm_entry.set_name ("MetricEntry");
94 get_vbox()->pack_start (bpm_frame, false, false);
96 add_button (Stock::CANCEL, RESPONSE_CANCEL);
97 add_button (Stock::APPLY, RESPONSE_ACCEPT);
98 set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
99 set_default_response (RESPONSE_ACCEPT);
101 get_vbox()->show_all();
104 set_name ("MetricDialog");
105 bpm_entry.signal_key_press_event().connect (mem_fun (*this, &TempoDialog::bpm_key_press), false);
106 bpm_entry.signal_activate().connect (bind (mem_fun (*this, &TempoDialog::response), RESPONSE_ACCEPT));
107 bpm_entry.signal_key_release_event().connect (mem_fun (*this, &TempoDialog::bpm_key_release));
111 TempoDialog::bpm_key_press (GdkEventKey* ev)
114 switch (ev->keyval) {
159 TempoDialog::bpm_key_release (GdkEventKey* ev)
161 if (bpm_entry.get_text() != "") {
162 set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
164 set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
170 TempoDialog::get_bpm ()
174 if (sscanf (bpm_entry.get_text().c_str(), "%lf", &bpm) != 1) {
182 TempoDialog::get_bbt_time (BBT_Time& requested)
184 if (sscanf (when_bar_entry.get_text().c_str(), "%" PRIu32, &requested.bars) != 1) {
188 if (sscanf (when_beat_entry.get_text().c_str(), "%" PRIu32, &requested.beats) != 1) {
196 MeterDialog::MeterDialog (TempoMap& map, jack_nframes_t frame, const string & action)
197 : ArdourDialog ("meter dialog"),
198 note_frame (_("Meter denominator")),
199 bpb_frame (_("Beats per bar")),
201 cancel_button (_("Cancel")),
202 when_bar_label (_("Bar")),
203 when_beat_label (_("Beat")),
204 when_frame (_("Location"))
207 frame = map.round_to_bar(frame,0);
208 Meter meter (map.meter_at(frame));
210 map.bbt_time (frame, when);
211 init (when, meter.beats_per_bar(), meter.note_divisor(), true);
214 MeterDialog::MeterDialog (MeterSection& section, const string & action)
215 : ArdourDialog ("meter dialog"),
216 note_frame (_("Meter denominator")),
217 bpb_frame (_("Beats per bar")),
219 cancel_button (_("Cancel")),
220 when_bar_label (_("Bar")),
221 when_beat_label (_("Beat")),
222 when_frame (_("Location"))
224 init (section.start(), section.beats_per_bar(), section.note_divisor(), section.movable());
228 MeterDialog::init (const BBT_Time& when, double bpb, double note_type, bool movable)
230 snprintf (buf, sizeof (buf), "%.2f", bpb);
231 bpb_entry.set_text (buf);
232 bpb_entry.select_region (0, -1);
233 Gtkmm2ext::set_size_request_to_display_given_text (bpb_entry, "999999g", 5, 5);
235 strings.push_back (_("whole (1)"));
236 strings.push_back (_("second (2)"));
237 strings.push_back (_("third (3)"));
238 strings.push_back (_("quarter (4)"));
239 strings.push_back (_("eighth (8)"));
240 strings.push_back (_("sixteenth (16)"));
241 strings.push_back (_("thirty-second (32)"));
243 set_popdown_strings (note_types, strings);
246 note_types.set_active_text (_("whole (1)"));
247 else if (note_type==2.0f)
248 note_types.set_active_text (_("second (2)"));
249 else if (note_type==3.0f)
250 note_types.set_active_text (_("third (3)"));
251 else if (note_type==4.0f)
252 note_types.set_active_text (_("quarter (4)"));
253 else if (note_type==8.0f)
254 note_types.set_active_text (_("eighth (8)"));
255 else if (note_type==16.0f)
256 note_types.set_active_text (_("sixteenth (16)"));
257 else if (note_type==32.0f)
258 note_types.set_active_text (_("thirty-second (32)"));
260 note_types.set_active_text (_("quarter (4)"));
262 /* strings.back() just happens to be the longest one to display */
264 //Gtkmm2ext::set_size_request_to_display_given_text (note_types, "thirty-second (32)", 7, 7);
266 hspacer1.set_border_width (5);
267 hspacer1.pack_start (note_types, false, false);
268 vspacer1.set_border_width (5);
269 vspacer1.pack_start (hspacer1, false, false);
271 hspacer2.set_border_width (5);
272 hspacer2.pack_start (bpb_entry, false, false);
273 vspacer2.set_border_width (5);
274 vspacer2.pack_start (hspacer2, false, false);
276 note_frame.add (vspacer1);
277 bpb_frame.add (vspacer2);
280 snprintf (buf, sizeof (buf), "%" PRIu32, when.bars);
281 when_bar_entry.set_text (buf);
282 snprintf (buf, sizeof (buf), "%" PRIu32, when.beats);
283 when_beat_entry.set_text (buf);
285 when_bar_entry.set_name ("MetricEntry");
286 when_beat_entry.set_name ("MetricEntry");
288 when_bar_label.set_name ("MetricLabel");
289 when_beat_label.set_name ("MetricLabel");
291 Gtkmm2ext::set_size_request_to_display_given_text (when_bar_entry, "999g", 5, 7);
292 Gtkmm2ext::set_size_request_to_display_given_text (when_beat_entry, "999g", 5, 7);
294 when_table.set_homogeneous (true);
295 when_table.set_row_spacings (2);
296 when_table.set_col_spacings (2);
297 when_table.set_border_width (5);
299 when_table.attach (when_bar_label, 0, 1, 0, 1, Gtk::AttachOptions(0), Gtk::FILL|Gtk::EXPAND);
300 when_table.attach (when_bar_entry, 0, 1, 1, 2, Gtk::AttachOptions(0), Gtk::FILL|Gtk::EXPAND);
302 when_table.attach (when_beat_label, 1, 2, 0, 1, Gtk::AttachOptions(0), Gtk::AttachOptions(0));
303 when_table.attach (when_beat_entry, 1, 2, 1, 2, Gtk::AttachOptions(0), Gtk::AttachOptions(0));
305 when_frame.set_name ("MetricDialogFrame");
306 when_frame.add (when_table);
308 get_vbox()->pack_start (when_frame, false, false);
310 get_vbox()->pack_start (bpb_frame, false, false);
311 get_vbox()->pack_start (note_frame, false, false);
313 bpb_frame.set_name ("MetricDialogFrame");
314 note_frame.set_name ("MetricDialogFrame");
315 bpb_entry.set_name ("MetricEntry");
317 add_button (Stock::CANCEL, RESPONSE_CANCEL);
318 add_button (Stock::APPLY, RESPONSE_ACCEPT);
319 set_response_sensitive (RESPONSE_ACCEPT, false);
320 set_default_response (RESPONSE_ACCEPT);
322 get_vbox()->show_all ();
325 set_name ("MetricDialog");
326 bpb_entry.signal_activate().connect (bind (mem_fun (*this, &MeterDialog::response), RESPONSE_ACCEPT));
327 bpb_entry.signal_key_release_event().connect (mem_fun (*this, &MeterDialog::bpb_key_release));
328 note_types.signal_changed().connect (mem_fun (*this, &MeterDialog::note_types_change));
332 MeterDialog::bpb_key_press (GdkEventKey* ev)
335 switch (ev->keyval) {
380 MeterDialog::bpb_key_release (GdkEventKey* ev)
382 if (bpb_entry.get_text() != "") {
383 set_response_sensitive (RESPONSE_ACCEPT, true);
385 set_response_sensitive (RESPONSE_ACCEPT, false);
391 MeterDialog::note_types_change ()
393 set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
397 MeterDialog::get_bpb ()
401 if (sscanf (bpb_entry.get_text().c_str(), "%lf", &bpb) != 1) {
409 MeterDialog::get_note_type ()
411 double note_type = 0;
412 vector<string>::iterator i;
413 string text = note_types.get_active_text();
415 for (i = strings.begin(); i != strings.end(); ++i) {
417 if (sscanf (text.c_str(), "%*[^0-9]%lf", ¬e_type) != 1) {
418 error << string_compose(_("garbaged note type entry (%1)"), text) << endmsg;
426 if (i == strings.end()) {
427 if (sscanf (text.c_str(), "%lf", ¬e_type) != 1) {
428 error << string_compose(_("incomprehensible note type entry (%1)"), text) << endmsg;
437 MeterDialog::get_bbt_time (BBT_Time& requested)
441 if (sscanf (when_bar_entry.get_text().c_str(), "%" PRIu32, &requested.bars) != 1) {
445 if (sscanf (when_beat_entry.get_text().c_str(), "%" PRIu32, &requested.beats) != 1) {