2 * Copyright (C) 2006 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2017-2019 Robin Gareus <robin@gareus.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "pbd/controllable.h"
25 #include "gtkmm2ext/gui_thread.h"
26 #include "gtkmm2ext/keyboard.h"
27 #include "widgets/binding_proxy.h"
28 #include "widgets/popup.h"
34 using namespace Gtkmm2ext;
35 using namespace ArdourWidgets;
37 guint BindingProxy::bind_button = 2;
38 guint BindingProxy::bind_statemask = Gdk::CONTROL_MASK;
40 BindingProxy::BindingProxy (boost::shared_ptr<Controllable> c)
45 c->DropReferences.connect (
46 _controllable_going_away_connection, invalidator (*this),
47 boost::bind (&BindingProxy::set_controllable, this, boost::shared_ptr<Controllable> ()),
52 BindingProxy::BindingProxy ()
57 BindingProxy::~BindingProxy ()
65 BindingProxy::set_controllable (boost::shared_ptr<Controllable> c)
70 _controllable_going_away_connection.disconnect ();
72 c->DropReferences.connect (
73 _controllable_going_away_connection, invalidator (*this),
74 boost::bind (&BindingProxy::set_controllable, this, boost::shared_ptr<Controllable> ()),
80 BindingProxy::set_bind_button_state (guint button, guint statemask)
83 bind_statemask = statemask;
87 BindingProxy::is_bind_action (GdkEventButton *ev)
89 return (Keyboard::modifier_state_equals (ev->state, bind_statemask) && ev->button == bind_button );
93 BindingProxy::button_press_handler (GdkEventButton *ev)
95 if ( controllable && is_bind_action(ev) ) {
96 if (Controllable::StartLearning (controllable)) {
97 string prompt = _("operate controller now");
99 prompter = new PopUp (Gtk::WIN_POS_MOUSE, 30000, false);
100 prompter->signal_unmap_event().connect (mem_fun (*this, &BindingProxy::prompter_hiding));
102 prompter->set_text (prompt);
103 prompter->touch (); // shows popup
104 controllable->LearningFinished.connect_same_thread (learning_connection, boost::bind (&BindingProxy::learning_finished, this));
113 BindingProxy::learning_finished ()
115 learning_connection.disconnect ();
117 prompter->touch (); // hides popup
122 BindingProxy::prompter_hiding (GdkEventAny* /*ev*/)
124 learning_connection.disconnect ();
126 Controllable::StopLearning (controllable);