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