another redirect dialog fix
[ardour.git] / gtk2_ardour / tempo_dialog.cc
index 7eb03625801e077dd3e26c60c82cf48b4be0b201..d69acf7ef1c43fea000ad5b8836bdbfc9f62582b 100644 (file)
@@ -1,3 +1,22 @@
+/*
+    Copyright (C) 2000-2007 Paul Davis 
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
 #include <cstdio> // for snprintf, grrr 
 
 #include <gtkmm/stock.h>
@@ -13,8 +32,10 @@ using namespace Gtkmm2ext;
 using namespace ARDOUR;
 using namespace PBD;
 
-TempoDialog::TempoDialog (TempoMap& map, jack_nframes_t frame, const string & action)
-       : ArdourDialog ("tempo dialog"),
+TempoDialog::TempoDialog (TempoMap& map, nframes_t frame, const string & action)
+       : ArdourDialog (_("edit tempo")),
+         bpm_adjustment (60.0, 1.0, 999.9, 0.1, 1.0, 1.0),
+         bpm_spinner (bpm_adjustment),
          bpm_frame (_("Beats per minute")),
          ok_button (action),
          cancel_button (_("Cancel")),
@@ -32,6 +53,8 @@ TempoDialog::TempoDialog (TempoMap& map, jack_nframes_t frame, const string & ac
 
 TempoDialog::TempoDialog (TempoSection& section, const string & action)
        : ArdourDialog ("tempo dialog"),
+         bpm_adjustment (60.0, 1.0, 999.9, 0.1, 1.0, 1.0),
+         bpm_spinner (bpm_adjustment),
          bpm_frame (_("Beats per minute")),
          ok_button (action),
          cancel_button (_("Cancel")),
@@ -46,12 +69,13 @@ TempoDialog::TempoDialog (TempoSection& section, const string & action)
 void
 TempoDialog::init (const BBT_Time& when, double bpm, bool movable)
 {
-       snprintf (buf, sizeof (buf), "%.2f", bpm);
-       bpm_entry.set_text (buf);
-       bpm_entry.select_region (0, -1);
-       
+       bpm_spinner.set_numeric (true);
+       bpm_spinner.set_digits (1);
+       bpm_spinner.set_wrap (true);
+       bpm_spinner.set_value (bpm);
+
        hspacer1.set_border_width (5);
-       hspacer1.pack_start (bpm_entry, false, false);
+       hspacer1.pack_start (bpm_spinner, false, false);
        vspacer1.set_border_width (5);
        vspacer1.pack_start (hspacer1, false, false);
 
@@ -90,7 +114,7 @@ TempoDialog::init (const BBT_Time& when, double bpm, bool movable)
        }
 
        bpm_frame.set_name ("MetricDialogFrame");
-       bpm_entry.set_name ("MetricEntry");
+       bpm_spinner.set_name ("MetricEntry");
 
        get_vbox()->pack_start (bpm_frame, false, false);
        
@@ -100,83 +124,34 @@ TempoDialog::init (const BBT_Time& when, double bpm, bool movable)
        set_default_response (RESPONSE_ACCEPT);
 
        get_vbox()->show_all();
-       bpm_entry.show();
+       bpm_spinner.show();
 
        set_name ("MetricDialog");
-       bpm_entry.signal_activate().connect (bind (mem_fun (*this, &TempoDialog::response), RESPONSE_ACCEPT));
-       bpm_entry.signal_key_release_event().connect (mem_fun (*this, &TempoDialog::bpm_key_release));
-       bpm_entry.signal_key_press_event().connect (mem_fun (*this, &TempoDialog::bpm_key_press), false);
+
+       bpm_spinner.signal_activate().connect (bind (mem_fun (*this, &TempoDialog::response), RESPONSE_ACCEPT));
+       bpm_spinner.signal_button_press_event().connect (mem_fun (*this, &TempoDialog::bpm_button_press), false);
+       bpm_spinner.signal_button_release_event().connect (mem_fun (*this, &TempoDialog::bpm_button_release), false);
 }
 
 bool
-TempoDialog::bpm_key_press (GdkEventKey* ev)
+TempoDialog::bpm_button_press (GdkEventButton* ev)
 {
-
-switch (ev->keyval) { 
-
- case GDK_0:
- case GDK_1:
- case GDK_2:
- case GDK_3:
- case GDK_4:
- case GDK_5:
- case GDK_6:
- case GDK_7:
- case GDK_8:
- case GDK_9:
- case GDK_KP_0:
- case GDK_KP_1:
- case GDK_KP_2:
- case GDK_KP_3:
- case GDK_KP_4:
- case GDK_KP_5:
- case GDK_KP_6:
- case GDK_KP_7:
- case GDK_KP_8:
- case GDK_KP_9:
- case GDK_period:
- case GDK_comma:
- case  GDK_KP_Delete:
- case  GDK_KP_Enter:
- case  GDK_Delete:
- case  GDK_BackSpace:
- case  GDK_Escape:
- case  GDK_Return:
- case  GDK_Home:
- case  GDK_End:
- case  GDK_Left:
- case  GDK_Right:
- case  GDK_Num_Lock:
- case  GDK_Tab:
-    return FALSE;
- default:
-      break;
- }
-
-   return TRUE;
+       return false;
 }
 
 bool
-TempoDialog::bpm_key_release (GdkEventKey* ev)
-{
-        if (bpm_entry.get_text() != "") {
-               set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
-       } else {
-               set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
-       }
+TempoDialog::bpm_button_release (GdkEventButton* ev)
+{      
+       /* the value has been modified, accept should work now */
+
+       set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
        return false;
 }
 
 double 
 TempoDialog::get_bpm ()
 {
-       double bpm;
-       
-       if (sscanf (bpm_entry.get_text().c_str(), "%lf", &bpm) != 1) {
-               return 0;
-       }
-
-       return bpm;
+       return bpm_spinner.get_value ();
 }      
 
 bool
@@ -194,7 +169,7 @@ TempoDialog::get_bbt_time (BBT_Time& requested)
 }
 
 
-MeterDialog::MeterDialog (TempoMap& map, jack_nframes_t frame, const string & action)
+MeterDialog::MeterDialog (TempoMap& map, nframes_t frame, const string & action)
        : ArdourDialog ("meter dialog"),
          note_frame (_("Meter denominator")),
          bpb_frame (_("Beats per bar")),