Tempo ramps - respect tempo note type and meter note divisor correctly.
[ardour.git] / gtk2_ardour / tempo_dialog.cc
1 /*
2     Copyright (C) 2000-2007 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #include <cstdio> // for snprintf, grrr
21
22 #include <gtkmm/stock.h>
23
24 #include "gtkmm2ext/utils.h"
25
26 #include "tempo_dialog.h"
27 #include "ui_config.h"
28
29 #include "i18n.h"
30
31 using namespace std;
32 using namespace Gtk;
33 using namespace Gtkmm2ext;
34 using namespace ARDOUR;
35 using namespace PBD;
36
37 TempoDialog::TempoDialog (TempoMap& map, framepos_t frame, const string&)
38         : ArdourDialog (_("New Tempo"))
39         , _map (&map)
40         , _section (0)
41         , bpm_adjustment (60.0, 1.0, 999.9, 0.1, 1.0)
42         , bpm_spinner (bpm_adjustment)
43         , when_bar_label (_("bar:"), ALIGN_LEFT, ALIGN_CENTER)
44         , when_beat_label (_("beat:"), ALIGN_LEFT, ALIGN_CENTER)
45         , pulse_selector_label (_("Pulse note"), ALIGN_LEFT, ALIGN_CENTER)
46         , tap_tempo_button (_("Tap tempo"))
47 {
48         Timecode::BBT_Time when;
49         Tempo tempo (map.tempo_at (frame));
50         map.bbt_time (frame, when);
51
52         init (when, tempo.beats_per_minute(), tempo.note_type(), TempoSection::Constant, true, PositionLockStyle::MusicTime);
53 }
54
55 TempoDialog::TempoDialog (TempoMap& map, TempoSection& section, const string&)
56         : ArdourDialog (_("Edit Tempo"))
57         , _map (&map)
58         , _section (&section)
59         , bpm_adjustment (60.0, 1.0, 999.9, 0.1, 1.0)
60         , bpm_spinner (bpm_adjustment)
61         , when_bar_label (_("bar:"), ALIGN_LEFT, ALIGN_CENTER)
62         , when_beat_label (_("beat:"), ALIGN_LEFT, ALIGN_CENTER)
63         , pulse_selector_label (_("Pulse note"), ALIGN_LEFT, ALIGN_CENTER)
64         , tap_tempo_button (_("Tap tempo"))
65 {
66         Timecode::BBT_Time when;
67         map.bbt_time (section.frame(), when);
68         init (when, section.beats_per_minute(), section.note_type(), section.type(), section.movable(), section.position_lock_style());
69 }
70
71 void
72 TempoDialog::init (const Timecode::BBT_Time& when, double bpm, double note_type, TempoSection::Type type, bool movable, PositionLockStyle style)
73 {
74         vector<string> strings;
75         NoteTypes::iterator x;
76
77         bpm_spinner.set_numeric (true);
78         bpm_spinner.set_digits (2);
79         bpm_spinner.set_wrap (true);
80         bpm_spinner.set_value (bpm);
81         bpm_spinner.set_alignment (1.0);
82
83         note_types.insert (make_pair (_("whole"), 1.0));
84         strings.push_back (_("whole"));
85         note_types.insert (make_pair (_("second"), 2.0));
86         strings.push_back (_("second"));
87         note_types.insert (make_pair (_("third"), 3.0));
88         strings.push_back (_("third"));
89         note_types.insert (make_pair (_("quarter"), 4.0));
90         strings.push_back (_("quarter"));
91         note_types.insert (make_pair (_("eighth"), 8.0));
92         strings.push_back (_("eighth"));
93         note_types.insert (make_pair (_("sixteenth"), 16.0));
94         strings.push_back (_("sixteenth"));
95         note_types.insert (make_pair (_("thirty-second"), 32.0));
96         strings.push_back (_("thirty-second"));
97         note_types.insert (make_pair (_("sixty-fourth"), 64.0));
98         strings.push_back (_("sixty-fourth"));
99         note_types.insert (make_pair (_("one-hundred-twenty-eighth"), 128.0));
100         strings.push_back (_("one-hundred-twenty-eighth"));
101
102         set_popdown_strings (pulse_selector, strings);
103
104         for (x = note_types.begin(); x != note_types.end(); ++x) {
105                 if (x->second == note_type) {
106                         pulse_selector.set_active_text (x->first);
107                         break;
108                 }
109         }
110
111         if (x == note_types.end()) {
112                 pulse_selector.set_active_text (strings[3]); // "quarter"
113         }
114
115         strings.clear();
116
117         tempo_types.insert (make_pair (_("ramped"), TempoSection::Ramp));
118         strings.push_back (_("ramped"));
119         tempo_types.insert (make_pair (_("constant"), TempoSection::Constant));
120         strings.push_back (_("constant"));
121         set_popdown_strings (tempo_type, strings);
122         TempoTypes::iterator tt;
123         for (tt = tempo_types.begin(); tt != tempo_types.end(); ++tt) {
124                 if (tt->second == type) {
125                         tempo_type.set_active_text (tt->first);
126                         break;
127                 }
128         }
129         if (tt == tempo_types.end()) {
130                 tempo_type.set_active_text (strings[1]); // "constant"
131         }
132
133         strings.clear();
134
135         lock_styles.insert (make_pair (_("music"), PositionLockStyle::MusicTime));
136         strings.push_back (_("music"));
137         lock_styles.insert (make_pair (_("audio"), PositionLockStyle::AudioTime));
138         strings.push_back (_("audio"));
139         set_popdown_strings (lock_style, strings);
140         LockStyles::iterator ls;
141         for (ls = lock_styles.begin(); ls != lock_styles.end(); ++ls) {
142                 if (ls->second == style) {
143                         lock_style.set_active_text (ls->first);
144                         break;
145                 }
146         }
147         if (ls == lock_styles.end()) {
148                 lock_style.set_active_text (strings[0]); // "music"
149         }
150
151         Table* table;
152
153         if (UIConfiguration::instance().get_allow_non_quarter_pulse()) {
154                 table = manage (new Table (5, 7));
155         } else {
156                 table = manage (new Table (5, 6));
157         }
158
159         table->set_spacings (6);
160         table->set_homogeneous (false);
161
162         int row;
163         Label* bpm_label = manage (new Label(_("Beats per minute:"), ALIGN_LEFT, ALIGN_CENTER));
164         table->attach (*bpm_label, 0, 1, 0, 1);
165         table->attach (bpm_spinner, 1, 5, 0, 1);
166
167         if (UIConfiguration::instance().get_allow_non_quarter_pulse()) {
168                 table->attach (pulse_selector_label, 0, 1, 1, 2);
169                 table->attach (pulse_selector, 1, 5, 1, 2);
170                 row = 2;
171         } else {
172                 row = 1;
173         }
174
175         char buf[64];
176
177         snprintf (buf, sizeof (buf), "%" PRIu32, when.bars);
178         when_bar_entry.set_text (buf);
179         snprintf (buf, sizeof (buf), "%" PRIu32, when.beats);
180         when_beat_entry.set_text (buf);
181
182         if (movable) {
183                 when_bar_entry.set_width_chars(4);
184                 when_beat_entry.set_width_chars (4);
185                 when_bar_entry.set_alignment (1.0);
186                 when_beat_entry.set_alignment (1.0);
187
188                 when_bar_label.set_name ("MetricLabel");
189                 when_beat_label.set_name ("MetricLabel");
190
191                 table->attach (when_bar_label, 1, 2, row, row+1, Gtk::AttachOptions(0), Gtk::AttachOptions(0));
192                 table->attach (when_bar_entry, 2, 3, row, row+1, Gtk::AttachOptions(0), Gtk::AttachOptions(0));
193
194                 table->attach (when_beat_label, 3, 4, row, row+1, Gtk::AttachOptions(0), Gtk::AttachOptions(0));
195                 table->attach (when_beat_entry, 4, 5, row, row+1, Gtk::AttachOptions(0), Gtk::AttachOptions(0));
196
197                 Label* when_label = manage (new Label(_("Tempo begins at"), ALIGN_LEFT, ALIGN_CENTER));
198                 table->attach (*when_label, 0, 1, row, row+1);
199         }
200
201         Label* tempo_type_label = manage (new Label(_("Tempo Type:"), ALIGN_LEFT, ALIGN_CENTER));
202         table->attach (*tempo_type_label, 0, 1, row+1, row+2);
203         table->attach (tempo_type, 1, 2, row+1, row + 2);
204         get_vbox()->set_border_width (12);
205         get_vbox()->pack_end (*table);
206
207         Label* lock_style_label = manage (new Label(_("Lock Style:"), ALIGN_LEFT, ALIGN_CENTER));
208         table->attach (*lock_style_label, 0, 1, row+2, row+3);
209         table->attach (lock_style, 1, 2, row+2, row + 3);
210         get_vbox()->set_border_width (12);
211         get_vbox()->pack_end (*table);
212
213         table->show_all ();
214
215         add_button (Stock::CANCEL, RESPONSE_CANCEL);
216         add_button (Stock::APPLY, RESPONSE_ACCEPT);
217         set_response_sensitive (RESPONSE_ACCEPT, true);
218         set_default_response (RESPONSE_ACCEPT);
219
220         bpm_spinner.show ();
221         tap_tempo_button.show ();
222         get_vbox()->pack_end (tap_tempo_button);
223         bpm_spinner.grab_focus ();
224
225         set_name ("MetricDialog");
226
227         bpm_spinner.signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &TempoDialog::response), RESPONSE_ACCEPT));
228         bpm_spinner.signal_button_press_event().connect (sigc::mem_fun (*this, &TempoDialog::bpm_button_press), false);
229         bpm_spinner.signal_button_release_event().connect (sigc::mem_fun (*this, &TempoDialog::bpm_button_release), false);
230         bpm_spinner.signal_changed().connect (sigc::mem_fun (*this, &TempoDialog::bpm_changed));
231         when_bar_entry.signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &TempoDialog::response), RESPONSE_ACCEPT));
232         when_bar_entry.signal_key_release_event().connect (sigc::mem_fun (*this, &TempoDialog::entry_key_release), false);
233         when_beat_entry.signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &TempoDialog::response), RESPONSE_ACCEPT));
234         when_beat_entry.signal_key_release_event().connect (sigc::mem_fun (*this, &TempoDialog::entry_key_release), false);
235         pulse_selector.signal_changed().connect (sigc::mem_fun (*this, &TempoDialog::pulse_change));
236         tempo_type.signal_changed().connect (sigc::mem_fun (*this, &TempoDialog::tempo_type_change));
237         lock_style.signal_changed().connect (sigc::mem_fun (*this, &TempoDialog::lock_style_change));
238         tap_tempo_button.signal_button_press_event().connect (sigc::mem_fun (*this, &TempoDialog::tap_tempo_button_press), false);
239         tap_tempo_button.signal_focus_out_event().connect (sigc::mem_fun (*this, &TempoDialog::tap_tempo_focus_out));
240
241         tapped = false;
242 }
243
244 bool
245 TempoDialog::is_user_input_valid() const
246 {
247         return (when_beat_entry.get_text() != "")
248                 && (when_bar_entry.get_text() != "")
249                 && (when_bar_entry.get_text() != "0");
250 }
251
252 void
253 TempoDialog::bpm_changed ()
254 {
255         set_response_sensitive (RESPONSE_ACCEPT, is_user_input_valid());
256 }
257
258 bool
259 TempoDialog::bpm_button_press (GdkEventButton*)
260 {
261         return false;
262 }
263
264 bool
265 TempoDialog::bpm_button_release (GdkEventButton*)
266 {
267         /* the value has been modified, accept should work now */
268
269         set_response_sensitive (RESPONSE_ACCEPT, is_user_input_valid());
270         return false;
271 }
272
273 bool
274 TempoDialog::entry_key_release (GdkEventKey*)
275 {
276         Timecode::BBT_Time bbt;
277         get_bbt_time (bbt);
278
279         if (_section && is_user_input_valid()) {
280                 set_response_sensitive (RESPONSE_ACCEPT, _map->can_solve_bbt (_section, Tempo (get_bpm(), get_note_type()), bbt));
281         } else {
282                 set_response_sensitive (RESPONSE_ACCEPT, is_user_input_valid());
283         }
284
285         return false;
286 }
287
288 double
289 TempoDialog::get_bpm ()
290 {
291         return bpm_spinner.get_value ();
292 }
293
294 bool
295 TempoDialog::get_bbt_time (Timecode::BBT_Time& requested)
296 {
297         if (sscanf (when_bar_entry.get_text().c_str(), "%" PRIu32, &requested.bars) != 1) {
298                 return false;
299         }
300
301         if (sscanf (when_beat_entry.get_text().c_str(), "%" PRIu32, &requested.beats) != 1) {
302                 return false;
303         }
304
305         requested.ticks = 0;
306
307         return true;
308 }
309
310 double
311 TempoDialog::get_note_type ()
312 {
313         NoteTypes::iterator x = note_types.find (pulse_selector.get_active_text());
314
315         if (x == note_types.end()) {
316                 error << string_compose(_("incomprehensible pulse note type (%1)"), pulse_selector.get_active_text()) << endmsg;
317                 return 0;
318         }
319
320         return x->second;
321 }
322
323 TempoSection::Type
324 TempoDialog::get_tempo_type ()
325 {
326         TempoTypes::iterator x = tempo_types.find (tempo_type.get_active_text());
327
328         if (x == tempo_types.end()) {
329                 error << string_compose(_("incomprehensible tempo type (%1)"), tempo_type.get_active_text()) << endmsg;
330                 return TempoSection::Constant;
331         }
332
333         return x->second;
334 }
335
336 PositionLockStyle
337 TempoDialog::get_lock_style ()
338 {
339         LockStyles::iterator x = lock_styles.find (lock_style.get_active_text());
340
341         if (x == lock_styles.end()) {
342                 error << string_compose(_("incomprehensible lock style (%1)"), lock_style.get_active_text()) << endmsg;
343                 return PositionLockStyle::MusicTime;
344         }
345
346         return x->second;
347 }
348
349 void
350 TempoDialog::pulse_change ()
351 {
352         set_response_sensitive (RESPONSE_ACCEPT, is_user_input_valid());
353 }
354
355 void
356 TempoDialog::tempo_type_change ()
357 {
358         set_response_sensitive (RESPONSE_ACCEPT, is_user_input_valid());
359 }
360
361 void
362 TempoDialog::lock_style_change ()
363 {
364         set_response_sensitive (RESPONSE_ACCEPT, is_user_input_valid());
365 }
366
367 bool
368 TempoDialog::tap_tempo_button_press (GdkEventButton *ev)
369 {
370         double t;
371
372         // Linear least-squares regression
373         if (tapped) {
374                 t = 1e-6 * (g_get_monotonic_time () - first_t); // Subtract first_t to avoid precision problems
375
376                 double n = tap_count;
377                 sum_y += t;
378                 sum_x += n;
379                 sum_xy += n * t;
380                 sum_xx += n * n;
381                 double T = (sum_xy/n - sum_x/n * sum_y/n) / (sum_xx/n - sum_x/n * sum_x/n);
382
383                 if (t - last_t < T / 1.2 || t - last_t > T * 1.2) {
384                         tapped = false;
385                 } else {
386                         bpm_spinner.set_value (60.0 / T);
387                 }
388         }
389         if (!tapped) {
390                 first_t = g_get_monotonic_time ();
391                 t = 0.0;
392                 sum_y = 0.0;
393                 sum_x = 1.0;
394                 sum_xy = 0.0;
395                 sum_xx = 1.0;
396                 tap_count = 1.0;
397
398                 tapped = true;
399         }
400         tap_count++;
401         last_t = t;
402
403         return true;
404 }
405
406 bool
407 TempoDialog::tap_tempo_focus_out (GdkEventFocus* )
408 {
409         tapped = false;
410         return false;
411 }
412
413 MeterDialog::MeterDialog (TempoMap& map, framepos_t frame, const string&)
414         : ArdourDialog (_("New Meter"))
415 {
416         Timecode::BBT_Time when;
417         frame = map.round_to_bar(frame, RoundNearest);
418         Meter meter (map.meter_at(frame));
419
420         map.bbt_time (frame, when);
421         init (when, meter.divisions_per_bar(), meter.note_divisor(), true, PositionLockStyle::MusicTime);
422 }
423
424 MeterDialog::MeterDialog (TempoMap& map, MeterSection& section, const string&)
425         : ArdourDialog (_("Edit Meter"))
426 {
427         Timecode::BBT_Time when;
428         map.bbt_time (section.frame(), when);
429         init (when, section.divisions_per_bar(), section.note_divisor(), section.movable(), section.position_lock_style());
430 }
431
432 void
433 MeterDialog::init (const Timecode::BBT_Time& when, double bpb, double divisor, bool movable, PositionLockStyle style)
434 {
435         char buf[64];
436         vector<string> strings;
437         NoteTypes::iterator x;
438
439         snprintf (buf, sizeof (buf), "%.2f", bpb);
440         bpb_entry.set_text (buf);
441         bpb_entry.select_region (0, -1);
442         bpb_entry.set_alignment (1.0);
443
444         note_types.insert (make_pair (_("whole"), 1.0));
445         strings.push_back (_("whole"));
446         note_types.insert (make_pair (_("second"), 2.0));
447         strings.push_back (_("second"));
448         note_types.insert (make_pair (_("third"), 3.0));
449         strings.push_back (_("third"));
450         note_types.insert (make_pair (_("quarter"), 4.0));
451         strings.push_back (_("quarter"));
452         note_types.insert (make_pair (_("eighth"), 8.0));
453         strings.push_back (_("eighth"));
454         note_types.insert (make_pair (_("sixteenth"), 16.0));
455         strings.push_back (_("sixteenth"));
456         note_types.insert (make_pair (_("thirty-second"), 32.0));
457         strings.push_back (_("thirty-second"));
458         note_types.insert (make_pair (_("sixty-fourth"), 64.0));
459         strings.push_back (_("sixty-fourth"));
460         note_types.insert (make_pair (_("one-hundred-twenty-eighth"), 128.0));
461         strings.push_back (_("one-hundred-twenty-eighth"));
462
463         set_popdown_strings (note_type, strings);
464
465         for (x = note_types.begin(); x != note_types.end(); ++x) {
466                 if (x->second == divisor) {
467                         note_type.set_active_text (x->first);
468                         break;
469                 }
470         }
471
472         if (x == note_types.end()) {
473                 note_type.set_active_text (strings[3]); // "quarter"
474         }
475
476         strings.clear();
477
478         lock_styles.insert (make_pair (_("music"), PositionLockStyle::MusicTime));
479         strings.push_back (_("music"));
480         lock_styles.insert (make_pair (_("audio"), PositionLockStyle::AudioTime));
481         strings.push_back (_("audio"));
482         set_popdown_strings (lock_style, strings);
483         LockStyles::iterator ls;
484         for (ls = lock_styles.begin(); ls != lock_styles.end(); ++ls) {
485                 if (ls->second == style) {
486                         lock_style.set_active_text (ls->first);
487                         break;
488                 }
489         }
490         if (ls == lock_styles.end()) {
491                 lock_style.set_active_text (strings[0]); // "music"
492         }
493
494         Label* note_label = manage (new Label (_("Note value:"), ALIGN_LEFT, ALIGN_CENTER));
495         Label* lock_label = manage (new Label (_("Lock style:"), ALIGN_LEFT, ALIGN_CENTER));
496         Label* bpb_label = manage (new Label (_("Beats per bar:"), ALIGN_LEFT, ALIGN_CENTER));
497         Table* table = manage (new Table (3, 3));
498         table->set_spacings (6);
499
500         table->attach (*bpb_label, 0, 1, 0, 1, FILL|EXPAND, FILL|EXPAND);
501         table->attach (bpb_entry, 1, 2, 0, 1, FILL|EXPAND, FILL|EXPAND);
502         table->attach (*note_label, 0, 1, 1, 2, FILL|EXPAND, FILL|EXPAND);
503         table->attach (note_type, 1, 2, 1, 2, FILL|EXPAND, FILL|EXPAND);
504
505         snprintf (buf, sizeof (buf), "%" PRIu32, when.bars);
506         when_bar_entry.set_text (buf);
507         when_bar_entry.set_alignment (1.0);
508
509         if (movable) {
510                 Label* when_label = manage (new Label(_("Meter begins at bar:"), ALIGN_LEFT, ALIGN_CENTER));
511
512                 table->attach (*when_label, 0, 1, 2, 3, FILL | EXPAND, FILL | EXPAND);
513                 table->attach (when_bar_entry, 1, 2, 2, 3, FILL | EXPAND, FILL | EXPAND);
514
515                 table->attach (*lock_label, 0, 1, 3, 4, FILL|EXPAND, FILL|EXPAND);
516                 table->attach (lock_style, 1, 2, 3, 4, FILL|EXPAND, SHRINK);
517         } else {
518                 table->attach (*lock_label, 0, 1, 2, 3, FILL|EXPAND, FILL|EXPAND);
519                 table->attach (lock_style, 1, 2, 2, 3, FILL|EXPAND, SHRINK);
520         }
521
522         get_vbox()->set_border_width (12);
523         get_vbox()->pack_start (*table, false, false);
524
525         add_button (Stock::CANCEL, RESPONSE_CANCEL);
526         add_button (Stock::APPLY, RESPONSE_ACCEPT);
527         set_response_sensitive (RESPONSE_ACCEPT, true);
528         set_default_response (RESPONSE_ACCEPT);
529
530         get_vbox()->show_all ();
531
532         set_name ("MetricDialog");
533         bpb_entry.signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &MeterDialog::response), RESPONSE_ACCEPT));
534         bpb_entry.signal_key_press_event().connect (sigc::mem_fun (*this, &MeterDialog::entry_key_press), false);
535         bpb_entry.signal_key_release_event().connect (sigc::mem_fun (*this, &MeterDialog::entry_key_release));
536         when_bar_entry.signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &MeterDialog::response), RESPONSE_ACCEPT));
537         when_bar_entry.signal_key_press_event().connect (sigc::mem_fun (*this, &MeterDialog::entry_key_press), false);
538         when_bar_entry.signal_key_release_event().connect (sigc::mem_fun (*this, &MeterDialog::entry_key_release));
539         note_type.signal_changed().connect (sigc::mem_fun (*this, &MeterDialog::note_type_change));
540         lock_style.signal_changed().connect (sigc::mem_fun (*this, &MeterDialog::lock_style_change));
541
542 }
543
544 bool
545 MeterDialog::is_user_input_valid() const
546 {
547         return (when_bar_entry.get_text() != "")
548                 && (when_bar_entry.get_text() != "0")
549                 && (bpb_entry.get_text() != "");
550 }
551
552 bool
553 MeterDialog::entry_key_press (GdkEventKey* ev)
554 {
555
556         switch (ev->keyval) {
557
558         case GDK_0:
559         case GDK_1:
560         case GDK_2:
561         case GDK_3:
562         case GDK_4:
563         case GDK_5:
564         case GDK_6:
565         case GDK_7:
566         case GDK_8:
567         case GDK_9:
568         case GDK_KP_0:
569         case GDK_KP_1:
570         case GDK_KP_2:
571         case GDK_KP_3:
572         case GDK_KP_4:
573         case GDK_KP_5:
574         case GDK_KP_6:
575         case GDK_KP_7:
576         case GDK_KP_8:
577         case GDK_KP_9:
578         case GDK_period:
579         case GDK_comma:
580         case  GDK_KP_Delete:
581         case  GDK_KP_Enter:
582         case  GDK_Delete:
583         case  GDK_BackSpace:
584         case  GDK_Escape:
585         case  GDK_Return:
586         case  GDK_Home:
587         case  GDK_End:
588         case  GDK_Left:
589         case  GDK_Right:
590         case  GDK_Num_Lock:
591         case  GDK_Tab:
592                 return FALSE;
593         default:
594                 break;
595         }
596
597         return TRUE;
598 }
599
600 bool
601 MeterDialog::entry_key_release (GdkEventKey*)
602 {
603         set_response_sensitive (RESPONSE_ACCEPT, is_user_input_valid());
604         return false;
605 }
606
607 void
608 MeterDialog::note_type_change ()
609 {
610         set_response_sensitive (RESPONSE_ACCEPT, is_user_input_valid());
611 }
612
613 void
614 MeterDialog::lock_style_change ()
615 {
616         set_response_sensitive (RESPONSE_ACCEPT, is_user_input_valid());
617 }
618
619 double
620 MeterDialog::get_bpb ()
621 {
622         double bpb = 0;
623
624         if (sscanf (bpb_entry.get_text().c_str(), "%lf", &bpb) != 1) {
625                 return 0;
626         }
627
628         return bpb;
629 }
630
631 double
632 MeterDialog::get_note_type ()
633 {
634         NoteTypes::iterator x = note_types.find (note_type.get_active_text());
635
636         if (x == note_types.end()) {
637                 error << string_compose(_("incomprehensible meter note type (%1)"), note_type.get_active_text()) << endmsg;
638                 return 0;
639         }
640
641         return x->second;
642 }
643
644 PositionLockStyle
645 MeterDialog::get_lock_style ()
646 {
647         LockStyles::iterator x = lock_styles.find (lock_style.get_active_text());
648
649         if (x == lock_styles.end()) {
650                 error << string_compose(_("incomprehensible meter lock style (%1)"), lock_style.get_active_text()) << endmsg;
651                 return PositionLockStyle::MusicTime;
652         }
653
654         return x->second;
655 }
656
657 bool
658 MeterDialog::get_bbt_time (Timecode::BBT_Time& requested)
659 {
660         if (sscanf (when_bar_entry.get_text().c_str(), "%" PRIu32, &requested.bars) != 1) {
661                 return false;
662         }
663
664         requested.beats = 1;
665         requested.ticks = 0;
666
667         return true;
668 }