+/*
+ 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>
using namespace Gtk;
using namespace Gtkmm2ext;
using namespace ARDOUR;
+using namespace PBD;
-TempoDialog::TempoDialog (TempoMap& map, jack_nframes_t frame, stringcr_t 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")),
init (when, tempo.beats_per_minute(), true);
}
-TempoDialog::TempoDialog (TempoSection& section, stringcr_t action)
+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")),
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);
}
bpm_frame.set_name ("MetricDialogFrame");
- bpm_entry.set_name ("MetricEntry");
+ bpm_spinner.set_name ("MetricEntry");
get_vbox()->pack_start (bpm_frame, false, false);
- add_button (Stock::OK, RESPONSE_ACCEPT);
add_button (Stock::CANCEL, RESPONSE_CANCEL);
+ add_button (Stock::APPLY, RESPONSE_ACCEPT);
+ set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
+ set_default_response (RESPONSE_ACCEPT);
get_vbox()->show_all();
- bpm_entry.show();
+ bpm_spinner.show();
set_name ("MetricDialog");
+
+ 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_button_press (GdkEventButton* ev)
+{
+ return false;
+}
+
+bool
+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
}
-MeterDialog::MeterDialog (TempoMap& map, jack_nframes_t frame, stringcr_t action)
+MeterDialog::MeterDialog (TempoMap& map, nframes_t frame, const string & action)
: ArdourDialog ("meter dialog"),
note_frame (_("Meter denominator")),
bpb_frame (_("Beats per bar")),
init (when, meter.beats_per_bar(), meter.note_divisor(), true);
}
-MeterDialog::MeterDialog (MeterSection& section, stringcr_t action)
+MeterDialog::MeterDialog (MeterSection& section, const string & action)
: ArdourDialog ("meter dialog"),
note_frame (_("Meter denominator")),
bpb_frame (_("Beats per bar")),
else
note_types.set_active_text (_("quarter (4)"));
- /* strings.back() just happens to be the longest one to display */
- // GTK2FIX
- // Gtkmm2ext::set_size_request_to_display_given_text (*(note_types.get_entry()), strings.back(), 7, 7);
+ /* the string here needs to be the longest one to display */
+ const guint32 FUDGE = 20; // Combo's are stupid - they steal space from the entry for the button
+ Gtkmm2ext::set_size_request_to_display_given_text (note_types, "thirty-second (32)", 7+FUDGE, 7);
hspacer1.set_border_width (5);
hspacer1.pack_start (note_types, false, false);
get_vbox()->pack_start (when_frame, false, false);
}
-
get_vbox()->pack_start (bpb_frame, false, false);
get_vbox()->pack_start (note_frame, false, false);
note_frame.set_name ("MetricDialogFrame");
bpb_entry.set_name ("MetricEntry");
- add_button (Stock::OK, RESPONSE_ACCEPT);
add_button (Stock::CANCEL, RESPONSE_CANCEL);
+ add_button (Stock::APPLY, RESPONSE_ACCEPT);
+ set_response_sensitive (RESPONSE_ACCEPT, false);
+ set_default_response (RESPONSE_ACCEPT);
get_vbox()->show_all ();
bpb_entry.show ();
set_name ("MetricDialog");
+ bpb_entry.signal_activate().connect (bind (mem_fun (*this, &MeterDialog::response), RESPONSE_ACCEPT));
+ bpb_entry.signal_key_press_event().connect (mem_fun (*this, &MeterDialog::bpb_key_press), false);
+ bpb_entry.signal_key_release_event().connect (mem_fun (*this, &MeterDialog::bpb_key_release));
+ note_types.signal_changed().connect (mem_fun (*this, &MeterDialog::note_types_change));
+}
+
+bool
+MeterDialog::bpb_key_press (GdkEventKey* 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;
+}
+
+bool
+MeterDialog::bpb_key_release (GdkEventKey* ev)
+{
+ if (bpb_entry.get_text() != "") {
+ set_response_sensitive (RESPONSE_ACCEPT, true);
+ } else {
+ set_response_sensitive (RESPONSE_ACCEPT, false);
+ }
+ return false;
+}
+
+void
+MeterDialog::note_types_change ()
+{
+ set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
}
double