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