diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2009-07-18 00:50:15 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2009-07-18 00:50:15 +0000 |
commit | 932cca703eafaaa50d7acf1bc25da487a7b3abba (patch) | |
tree | 1be21bf062d518b6f2d649cac79a204b3fc5a87c /libs/gtkmm2ext | |
parent | 9b7e3a892a23bb27a72b915ff3f3e7ac0fd20f0a (diff) |
imported files retain BWF timestamp info (nick murtagh) ; logarithm plugin controls can be properly controlled by generic GUI (nick murtagh); properly delete AU plugin *and* GUI (fixes crashing bug for Carbon-GUI based AU's)
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@5374 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/gtkmm2ext')
-rw-r--r-- | libs/gtkmm2ext/barcontroller.cc | 69 | ||||
-rw-r--r-- | libs/gtkmm2ext/gtkmm2ext/barcontroller.h | 6 |
2 files changed, 68 insertions, 7 deletions
diff --git a/libs/gtkmm2ext/barcontroller.cc b/libs/gtkmm2ext/barcontroller.cc index 4318b1df28..1af639ec6c 100644 --- a/libs/gtkmm2ext/barcontroller.cc +++ b/libs/gtkmm2ext/barcontroller.cc @@ -18,6 +18,7 @@ */ #include <string> +#include <sstream> #include <climits> #include <cstdio> #include <cmath> @@ -51,6 +52,7 @@ BarController::BarController (Gtk::Adjustment& adj, switch_on_release = false; with_text = true; use_parent = false; + logarithmic = false; layout = darea.create_pango_layout(""); @@ -76,12 +78,72 @@ BarController::BarController (Gtk::Adjustment& adj, spinner.signal_activate().connect (mem_fun (*this, &BarController::entry_activated)); spinner.signal_focus_out_event().connect (mem_fun (*this, &BarController::entry_focus_out)); + spinner.signal_output().connect (mem_fun (*this, &BarController::entry_output)); + spinner.signal_input().connect (mem_fun (*this, &BarController::entry_input)); spinner.set_digits (3); + spinner.set_numeric (true); add (darea); show_all (); } +/* + This is called when we need to update the adjustment with the value + from the spinner's text entry. + + We need to use Gtk::Entry::get_text to avoid recursive nastiness :) + + If we're not in logarithmic mode we can return false to use the + default conversion. + + In theory we should check for conversion errors but set numeric + mode to true on the spinner prevents invalid input. +*/ +int +BarController::entry_input (double* new_value) +{ + if (!logarithmic) { + return false; + } + + // extract a double from the string and take its log + Entry *entry = dynamic_cast<Entry *>(&spinner); + stringstream stream(entry->get_text()); + + double value; + stream >> value; + + *new_value = log(value); + return true; +} + +/* + This is called when we need to update the spinner's text entry + with the value of the adjustment. + + We need to use Gtk::Entry::set_text to avoid recursive nastiness :) + + If we're not in logarithmic mode we can return false to use the + default conversion. +*/ +bool +BarController::entry_output () +{ + if (!logarithmic) { + return false; + } + + // generate the exponential and turn it into a string + stringstream stream; + stream.precision(spinner.get_digits()); + stream << fixed << exp(spinner.get_adjustment()->get_value()); + + Entry *entry = dynamic_cast<Entry *>(&spinner); + entry->set_text(stream.str()); + + return true; +} + void BarController::drop_grab () { @@ -436,13 +498,6 @@ BarController::switch_to_spinner () void BarController::entry_activated () { - string text = spinner.get_text (); - float val; - - if (sscanf (text.c_str(), "%f", &val) == 1) { - adjustment.set_value (val); - } - switch_to_bar (); } diff --git a/libs/gtkmm2ext/gtkmm2ext/barcontroller.h b/libs/gtkmm2ext/gtkmm2ext/barcontroller.h index d149ded527..5668a07326 100644 --- a/libs/gtkmm2ext/gtkmm2ext/barcontroller.h +++ b/libs/gtkmm2ext/gtkmm2ext/barcontroller.h @@ -50,6 +50,8 @@ class BarController : public Gtk::Frame void set_use_parent (bool yn); void set_sensitive (bool yn); + + void set_logarithmic (bool yn) { logarithmic = yn; } Gtk::SpinButton& get_spin_button() { return spinner; } @@ -77,6 +79,7 @@ class BarController : public Gtk::Frame GdkWindow* grab_window; Gtk::SpinButton spinner; bool use_parent; + bool logarithmic; virtual bool button_press (GdkEventButton *); virtual bool button_release (GdkEventButton *); @@ -92,6 +95,9 @@ class BarController : public Gtk::Frame void entry_activated (); void drop_grab (); + + int entry_input (double* new_value); + bool entry_output (); }; |