X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=libs%2Fgtkmm2ext%2Fbindable_button.cc;h=5c0cc3c958b6fc22a76c563b73c3b9d43eca049d;hb=2b955b33a32bd3ea2e20653dc75185cc7e340c90;hp=c2516a9219b1ca8fc6c8aab8e3c4f70123f89c92;hpb=d09f6b3016bacbc2871a8946cbb24ad705076509;p=ardour.git diff --git a/libs/gtkmm2ext/bindable_button.cc b/libs/gtkmm2ext/bindable_button.cc index c2516a9219..5c0cc3c958 100644 --- a/libs/gtkmm2ext/bindable_button.cc +++ b/libs/gtkmm2ext/bindable_button.cc @@ -18,138 +18,43 @@ */ #include -#include #include -#include +#include "pbd/controllable.h" -#include -#include +#include "gtkmm2ext/gtk_ui.h" +#include "gtkmm2ext/bindable_button.h" +#include "gtkmm2ext/gui_thread.h" #include "i18n.h" using namespace Gtkmm2ext; using namespace std; - -BindableToggleButton::BindableToggleButton (MIDI::Controllable *mc) - : ToggleButton (), - prompter (Gtk::WIN_POS_MOUSE, 30000, false), - midi_control (mc), - bind_button (2), - bind_statemask (Gdk::CONTROL_MASK) - -{ - init_events (); -} - -BindableToggleButton::BindableToggleButton(MIDI::Controllable *mc, const string &label) - : ToggleButton (label), - prompter (Gtk::WIN_POS_MOUSE, 30000, false), - midi_control (mc), - bind_button (2), - bind_statemask (Gdk::CONTROL_MASK) -{ - init_events (); -} - - -void -BindableToggleButton::init_events () -{ - signal_button_press_event().connect (mem_fun (*this, &BindableToggleButton::button_press)); - - prompter.signal_unmap_event().connect (mem_fun (*this, &BindableToggleButton::prompter_hiding)); - - prompting = false; - unprompting = false; - - if (midi_control) { - midi_control->learning_started.connect (mem_fun (*this, &BindableToggleButton::midicontrol_prompt)); - midi_control->learning_stopped.connect (mem_fun (*this, &BindableToggleButton::midicontrol_unprompt)); - } -} +using namespace PBD; void -BindableToggleButton::set_bind_button_state (guint button, guint statemask) +BindableToggleButton::set_controllable (boost::shared_ptr c) { - bind_button = button; - bind_statemask = statemask; + watch_connection.disconnect (); + binding_proxy.set_controllable (c); } void -BindableToggleButton::get_bind_button_state (guint &button, guint &statemask) +BindableToggleButton::watch () { - button = bind_button; - statemask = bind_statemask; -} + boost::shared_ptr c (binding_proxy.get_controllable ()); -void -BindableToggleButton::midi_learn() -{ - if (midi_control) { - prompting = true; - midi_control->learn_about_external_control (); - } -} - - -gint -BindableToggleButton::button_press (GdkEventButton *ev) -{ - - if ((ev->state & bind_statemask) && ev->button == bind_button) { - midi_learn (); - return TRUE; - } + if (!c) { + warning << _("button cannot watch state of non-existing Controllable\n") << endl; + return; + } - return FALSE; + c->Changed.connect (watch_connection, invalidator(*this), boost::bind (&BindableToggleButton::controllable_changed, this), gui_context()); } -gint -BindableToggleButton::prompter_hiding (GdkEventAny *ev) -{ - if (unprompting) { - if (midi_control) { - midi_control->stop_learning(); - } - unprompting = false; - } - - return FALSE; -} - - void -BindableToggleButton::midicontrol_set_tip () - +BindableToggleButton::controllable_changed () { - if (midi_control) { - // Gtkmm2ext::UI::instance()->set_tip (evbox, midi_control->control_description()); - } + float val = binding_proxy.get_controllable()->get_value(); + set_active (fabs (val) >= 0.5f); } - -void -BindableToggleButton::midicontrol_prompt () - -{ - if (prompting) { - string prompt = _("operate MIDI controller now"); - prompter.set_text (prompt); - Gtkmm2ext::UI::instance()->touch_display (&prompter); - - unprompting = true; - prompting = false; - } -} - -void -BindableToggleButton::midicontrol_unprompt () - -{ - if (unprompting) { - Gtkmm2ext::UI::instance()->touch_display (&prompter); - unprompting = false; - } -} - -