tempo dialog uses three decimal places in numeric entry.
[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_RIGHT, ALIGN_CENTER)
44         , when_beat_label (_("beat:"), ALIGN_RIGHT, ALIGN_CENTER)
45         , pulse_selector_label (_("Pulse:"), ALIGN_RIGHT, 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_RIGHT, ALIGN_CENTER)
61         , when_beat_label (_("beat:"), ALIGN_RIGHT, ALIGN_CENTER)
62         , pulse_selector_label (_("Pulse:"), ALIGN_RIGHT, 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 (3);
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_RIGHT, 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_RIGHT, 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()->set_spacing (6);
232         get_vbox()->pack_end (tap_tempo_button);
233         bpm_spinner.grab_focus ();
234
235         set_name ("MetricDialog");
236
237         bpm_spinner.signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &TempoDialog::response), RESPONSE_ACCEPT));
238         bpm_spinner.signal_button_press_event().connect (sigc::mem_fun (*this, &TempoDialog::bpm_button_press), false);
239         bpm_spinner.signal_button_release_event().connect (sigc::mem_fun (*this, &TempoDialog::bpm_button_release), false);
240         bpm_spinner.signal_changed().connect (sigc::mem_fun (*this, &TempoDialog::bpm_changed));
241         when_bar_entry.signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &TempoDialog::response), RESPONSE_ACCEPT));
242         when_bar_entry.signal_key_release_event().connect (sigc::mem_fun (*this, &TempoDialog::entry_key_release), false);
243         when_beat_entry.signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &TempoDialog::response), RESPONSE_ACCEPT));
244         when_beat_entry.signal_key_release_event().connect (sigc::mem_fun (*this, &TempoDialog::entry_key_release), false);
245         pulse_selector.signal_changed().connect (sigc::mem_fun (*this, &TempoDialog::pulse_change));
246         tempo_type.signal_changed().connect (sigc::mem_fun (*this, &TempoDialog::tempo_type_change));
247         lock_style.signal_changed().connect (sigc::mem_fun (*this, &TempoDialog::lock_style_change));
248         tap_tempo_button.signal_button_press_event().connect (sigc::mem_fun (*this, &TempoDialog::tap_tempo_button_press), false);
249         tap_tempo_button.signal_focus_out_event().connect (sigc::mem_fun (*this, &TempoDialog::tap_tempo_focus_out));
250
251         tapped = false;
252 }
253
254 bool
255 TempoDialog::is_user_input_valid() const
256 {
257         return (when_beat_entry.get_text() != "")
258                 && (when_bar_entry.get_text() != "")
259                 && (when_bar_entry.get_text() != "0");
260 }
261
262 void
263 TempoDialog::bpm_changed ()
264 {
265         set_response_sensitive (RESPONSE_ACCEPT, is_user_input_valid());
266 }
267
268 bool
269 TempoDialog::bpm_button_press (GdkEventButton*)
270 {
271         return false;
272 }
273
274 bool
275 TempoDialog::bpm_button_release (GdkEventButton*)
276 {
277         /* the value has been modified, accept should work now */
278
279         set_response_sensitive (RESPONSE_ACCEPT, is_user_input_valid());
280         return false;
281 }
282
283 bool
284 TempoDialog::entry_key_release (GdkEventKey*)
285 {
286         Timecode::BBT_Time bbt;
287         get_bbt_time (bbt);
288
289         if (_section && is_user_input_valid()) {
290                 set_response_sensitive (RESPONSE_ACCEPT, _map->can_solve_bbt (_section, bbt));
291         } else {
292                 set_response_sensitive (RESPONSE_ACCEPT, is_user_input_valid());
293         }
294
295         return false;
296 }
297
298 double
299 TempoDialog::get_bpm ()
300 {
301         return bpm_spinner.get_value ();
302 }
303
304 bool
305 TempoDialog::get_bbt_time (Timecode::BBT_Time& requested)
306 {
307         if (sscanf (when_bar_entry.get_text().c_str(), "%" PRIu32, &requested.bars) != 1) {
308                 return false;
309         }
310
311         if (sscanf (when_beat_entry.get_text().c_str(), "%" PRIu32, &requested.beats) != 1) {
312                 return false;
313         }
314
315         requested.ticks = 0;
316
317         return true;
318 }
319
320 double
321 TempoDialog::get_note_type ()
322 {
323         NoteTypes::iterator x = note_types.find (pulse_selector.get_active_text());
324
325         if (x == note_types.end()) {
326                 error << string_compose(_("incomprehensible pulse note type (%1)"), pulse_selector.get_active_text()) << endmsg;
327                 return 0;
328         }
329
330         return x->second;
331 }
332
333 TempoSection::Type
334 TempoDialog::get_tempo_type ()
335 {
336         TempoTypes::iterator x = tempo_types.find (tempo_type.get_active_text());
337
338         if (x == tempo_types.end()) {
339                 error << string_compose(_("incomprehensible tempo type (%1)"), tempo_type.get_active_text()) << endmsg;
340                 return TempoSection::Constant;
341         }
342
343         return x->second;
344 }
345
346 PositionLockStyle
347 TempoDialog::get_lock_style ()
348 {
349         LockStyles::iterator x = lock_styles.find (lock_style.get_active_text());
350
351         if (x == lock_styles.end()) {
352                 error << string_compose(_("incomprehensible lock style (%1)"), lock_style.get_active_text()) << endmsg;
353                 return MusicTime;
354         }
355
356         return x->second;
357 }
358
359 void
360 TempoDialog::pulse_change ()
361 {
362         set_response_sensitive (RESPONSE_ACCEPT, is_user_input_valid());
363 }
364
365 void
366 TempoDialog::tempo_type_change ()
367 {
368         set_response_sensitive (RESPONSE_ACCEPT, is_user_input_valid());
369 }
370
371 void
372 TempoDialog::lock_style_change ()
373 {
374         set_response_sensitive (RESPONSE_ACCEPT, is_user_input_valid());
375 }
376
377 bool
378 TempoDialog::tap_tempo_button_press (GdkEventButton *ev)
379 {
380         double t;
381
382         // Linear least-squares regression
383         if (tapped) {
384                 t = 1e-6 * (g_get_monotonic_time () - first_t); // Subtract first_t to avoid precision problems
385
386                 double n = tap_count;
387                 sum_y += t;
388                 sum_x += n;
389                 sum_xy += n * t;
390                 sum_xx += n * n;
391                 double T = (sum_xy/n - sum_x/n * sum_y/n) / (sum_xx/n - sum_x/n * sum_x/n);
392
393                 if (t - last_t < T / 1.2 || t - last_t > T * 1.2) {
394                         tapped = false;
395                 } else {
396                         bpm_spinner.set_value (60.0 / T);
397                 }
398         }
399         if (!tapped) {
400                 first_t = g_get_monotonic_time ();
401                 t = 0.0;
402                 sum_y = 0.0;
403                 sum_x = 1.0;
404                 sum_xy = 0.0;
405                 sum_xx = 1.0;
406                 tap_count = 1.0;
407
408                 tapped = true;
409         }
410         tap_count++;
411         last_t = t;
412
413         return true;
414 }
415
416 bool
417 TempoDialog::tap_tempo_focus_out (GdkEventFocus* )
418 {
419         tapped = false;
420         return false;
421 }
422
423 MeterDialog::MeterDialog (TempoMap& map, framepos_t frame, const string&)
424         : ArdourDialog (_("New Meter"))
425 {
426         frame = map.round_to_bar(frame, RoundNearest).frame;
427         Timecode::BBT_Time when (map.bbt_at_frame (frame));
428         Meter meter (map.meter_at_frame (frame));
429
430         init (when, meter.divisions_per_bar(), meter.note_divisor(), false, MusicTime);
431 }
432
433 MeterDialog::MeterDialog (TempoMap& map, MeterSection& section, const string&)
434         : ArdourDialog (_("Edit Meter"))
435 {
436         Timecode::BBT_Time when (map.bbt_at_frame (section.frame()));
437
438         init (when, section.divisions_per_bar(), section.note_divisor(), section.initial(), section.position_lock_style());
439 }
440
441 void
442 MeterDialog::init (const Timecode::BBT_Time& when, double bpb, double divisor, bool initial, PositionLockStyle style)
443 {
444         char buf[64];
445         vector<string> strings;
446         NoteTypes::iterator x;
447
448         snprintf (buf, sizeof (buf), "%.2f", bpb);
449         bpb_entry.set_text (buf);
450         bpb_entry.select_region (0, -1);
451         bpb_entry.set_alignment (1.0);
452
453         note_types.insert (make_pair (_("whole"), 1.0));
454         strings.push_back (_("whole"));
455         note_types.insert (make_pair (_("second"), 2.0));
456         strings.push_back (_("second"));
457         note_types.insert (make_pair (_("third"), 3.0));
458         strings.push_back (_("third"));
459         note_types.insert (make_pair (_("quarter"), 4.0));
460         strings.push_back (_("quarter"));
461         note_types.insert (make_pair (_("eighth"), 8.0));
462         strings.push_back (_("eighth"));
463         note_types.insert (make_pair (_("sixteenth"), 16.0));
464         strings.push_back (_("sixteenth"));
465         note_types.insert (make_pair (_("thirty-second"), 32.0));
466         strings.push_back (_("thirty-second"));
467         note_types.insert (make_pair (_("sixty-fourth"), 64.0));
468         strings.push_back (_("sixty-fourth"));
469         note_types.insert (make_pair (_("one-hundred-twenty-eighth"), 128.0));
470         strings.push_back (_("one-hundred-twenty-eighth"));
471
472         set_popdown_strings (note_type, strings);
473
474         for (x = note_types.begin(); x != note_types.end(); ++x) {
475                 if (x->second == divisor) {
476                         note_type.set_active_text (x->first);
477                         break;
478                 }
479         }
480
481         if (x == note_types.end()) {
482                 note_type.set_active_text (strings[3]); // "quarter"
483         }
484
485         strings.clear();
486
487         lock_styles.insert (make_pair (_("music"), MusicTime));
488         strings.push_back (_("music"));
489         lock_styles.insert (make_pair (_("audio"), AudioTime));
490         strings.push_back (_("audio"));
491         set_popdown_strings (lock_style, strings);
492         LockStyles::iterator ls;
493         for (ls = lock_styles.begin(); ls != lock_styles.end(); ++ls) {
494                 if (ls->second == style) {
495                         lock_style.set_active_text (ls->first);
496                         break;
497                 }
498         }
499         if (ls == lock_styles.end()) {
500                 lock_style.set_active_text (strings[0]); // "music"
501         }
502
503         Label* note_label = manage (new Label (_("Note value:"), ALIGN_RIGHT, ALIGN_CENTER));
504         Label* lock_label = manage (new Label (_("Lock style:"), ALIGN_RIGHT, ALIGN_CENTER));
505         Label* bpb_label = manage (new Label (_("Beats per bar:"), ALIGN_RIGHT, ALIGN_CENTER));
506         Table* table = manage (new Table (3, 3));
507         table->set_spacings (6);
508
509         table->attach (*bpb_label, 0, 1, 0, 1, FILL|EXPAND, FILL|EXPAND);
510         table->attach (bpb_entry, 1, 2, 0, 1, FILL|EXPAND, FILL|EXPAND);
511         table->attach (*note_label, 0, 1, 1, 2, FILL|EXPAND, FILL|EXPAND);
512         table->attach (note_type, 1, 2, 1, 2, FILL|EXPAND, FILL|EXPAND);
513
514         snprintf (buf, sizeof (buf), "%" PRIu32, when.bars);
515         when_bar_entry.set_text (buf);
516         when_bar_entry.set_alignment (1.0);
517
518         if (!initial) {
519                 Label* when_label = manage (new Label(_("Meter begins at bar:"), ALIGN_LEFT, ALIGN_CENTER));
520
521                 table->attach (*when_label, 0, 1, 2, 3, FILL | EXPAND, FILL | EXPAND);
522                 table->attach (when_bar_entry, 1, 2, 2, 3, FILL | EXPAND, FILL | EXPAND);
523
524                 table->attach (*lock_label, 0, 1, 3, 4, FILL|EXPAND, FILL|EXPAND);
525                 table->attach (lock_style, 1, 2, 3, 4, FILL|EXPAND, SHRINK);
526         }
527
528         get_vbox()->set_border_width (12);
529         get_vbox()->pack_start (*table, false, false);
530
531         add_button (Stock::CANCEL, RESPONSE_CANCEL);
532         add_button (Stock::APPLY, RESPONSE_ACCEPT);
533         set_response_sensitive (RESPONSE_ACCEPT, true);
534         set_default_response (RESPONSE_ACCEPT);
535
536         get_vbox()->show_all ();
537
538         set_name ("MetricDialog");
539         bpb_entry.signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &MeterDialog::response), RESPONSE_ACCEPT));
540         bpb_entry.signal_key_press_event().connect (sigc::mem_fun (*this, &MeterDialog::entry_key_press), false);
541         bpb_entry.signal_key_release_event().connect (sigc::mem_fun (*this, &MeterDialog::entry_key_release));
542         when_bar_entry.signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &MeterDialog::response), RESPONSE_ACCEPT));
543         when_bar_entry.signal_key_press_event().connect (sigc::mem_fun (*this, &MeterDialog::entry_key_press), false);
544         when_bar_entry.signal_key_release_event().connect (sigc::mem_fun (*this, &MeterDialog::entry_key_release));
545         note_type.signal_changed().connect (sigc::mem_fun (*this, &MeterDialog::note_type_change));
546         lock_style.signal_changed().connect (sigc::mem_fun (*this, &MeterDialog::lock_style_change));
547
548 }
549
550 bool
551 MeterDialog::is_user_input_valid() const
552 {
553         return (when_bar_entry.get_text() != "")
554                 && (when_bar_entry.get_text() != "0")
555                 && (bpb_entry.get_text() != "");
556 }
557
558 bool
559 MeterDialog::entry_key_press (GdkEventKey* ev)
560 {
561
562         switch (ev->keyval) {
563
564         case GDK_0:
565         case GDK_1:
566         case GDK_2:
567         case GDK_3:
568         case GDK_4:
569         case GDK_5:
570         case GDK_6:
571         case GDK_7:
572         case GDK_8:
573         case GDK_9:
574         case GDK_KP_0:
575         case GDK_KP_1:
576         case GDK_KP_2:
577         case GDK_KP_3:
578         case GDK_KP_4:
579         case GDK_KP_5:
580         case GDK_KP_6:
581         case GDK_KP_7:
582         case GDK_KP_8:
583         case GDK_KP_9:
584         case GDK_period:
585         case GDK_comma:
586         case  GDK_KP_Delete:
587         case  GDK_KP_Enter:
588         case  GDK_Delete:
589         case  GDK_BackSpace:
590         case  GDK_Escape:
591         case  GDK_Return:
592         case  GDK_Home:
593         case  GDK_End:
594         case  GDK_Left:
595         case  GDK_Right:
596         case  GDK_Num_Lock:
597         case  GDK_Tab:
598                 return FALSE;
599         default:
600                 break;
601         }
602
603         return TRUE;
604 }
605
606 bool
607 MeterDialog::entry_key_release (GdkEventKey*)
608 {
609         set_response_sensitive (RESPONSE_ACCEPT, is_user_input_valid());
610         return false;
611 }
612
613 void
614 MeterDialog::note_type_change ()
615 {
616         set_response_sensitive (RESPONSE_ACCEPT, is_user_input_valid());
617 }
618
619 void
620 MeterDialog::lock_style_change ()
621 {
622         set_response_sensitive (RESPONSE_ACCEPT, is_user_input_valid());
623 }
624
625 double
626 MeterDialog::get_bpb ()
627 {
628         double bpb = 0;
629
630         if (sscanf (bpb_entry.get_text().c_str(), "%lf", &bpb) != 1) {
631                 return 0;
632         }
633
634         return bpb;
635 }
636
637 double
638 MeterDialog::get_note_type ()
639 {
640         NoteTypes::iterator x = note_types.find (note_type.get_active_text());
641
642         if (x == note_types.end()) {
643                 error << string_compose(_("incomprehensible meter note type (%1)"), note_type.get_active_text()) << endmsg;
644                 return 0;
645         }
646
647         return x->second;
648 }
649
650 PositionLockStyle
651 MeterDialog::get_lock_style ()
652 {
653         LockStyles::iterator x = lock_styles.find (lock_style.get_active_text());
654
655         if (x == lock_styles.end()) {
656                 error << string_compose(_("incomprehensible meter lock style (%1)"), lock_style.get_active_text()) << endmsg;
657                 return MusicTime;
658         }
659
660         return x->second;
661 }
662
663 bool
664 MeterDialog::get_bbt_time (Timecode::BBT_Time& requested)
665 {
666         if (sscanf (when_bar_entry.get_text().c_str(), "%" PRIu32, &requested.bars) != 1) {
667                 return false;
668         }
669
670         requested.beats = 1;
671         requested.ticks = 0;
672
673         return true;
674 }