ardour
binding_proxy.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2006 Paul Davis
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; either version 2 of the License, or
6  (at your option) any later version.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 
17  $Id$
18 */
19 
20 #include <string>
21 #include <climits>
22 #include <iostream>
23 
24 #include <pbd/controllable.h>
25 
27 
28 #include "i18n.h"
29 
30 using namespace Gtkmm2ext;
31 using namespace std;
32 using namespace PBD;
33 
35 guint BindingProxy::bind_statemask = Gdk::CONTROL_MASK;
36 
38  : prompter (0),
39  controllable (c)
40 {
41 }
42 
44  : prompter (0)
45 {
46 }
47 
49 {
50  if (prompter) {
51  delete prompter;
52  }
53 }
54 
55 void
57 {
59  controllable = c;
60 }
61 
62 void
63 BindingProxy::set_bind_button_state (guint button, guint statemask)
64 {
65  bind_button = button;
66  bind_statemask = statemask;
67 }
68 
69 bool
70 BindingProxy::is_bind_action (GdkEventButton *ev)
71 {
72  return ( (ev->state & bind_statemask) && ev->button == bind_button );
73 }
74 
75 
76 bool
78 {
79  if ( controllable && is_bind_action(ev) ) {
80  if (Controllable::StartLearning (controllable.get())) {
81  string prompt = _("operate controller now");
82  if (prompter == 0) {
83  prompter = new PopUp (Gtk::WIN_POS_MOUSE, 30000, false);
84  prompter->signal_unmap_event().connect (mem_fun (*this, &BindingProxy::prompter_hiding));
85  }
86  prompter->set_text (prompt);
87  prompter->touch (); // shows popup
88  controllable->LearningFinished.connect_same_thread (learning_connection, boost::bind (&BindingProxy::learning_finished, this));
89  }
90  return true;
91  }
92 
93  return false;
94 }
95 
96 void
98 {
100  if (prompter) {
101  prompter->touch (); // hides popup
102  }
103 }
104 
105 
106 bool
107 BindingProxy::prompter_hiding (GdkEventAny* /*ev*/)
108 {
110  if (controllable) {
111  Controllable::StopLearning (controllable.get());
112  }
113  return false;
114 }
115 
PBD::ScopedConnection learning_connection
Definition: binding_proxy.h:58
void set_text(std::string)
Definition: popup.cc:121
void learning_finished()
void set_controllable(boost::shared_ptr< PBD::Controllable >)
Definition: Beats.hpp:239
void touch()
Definition: popup.cc:94
#define _(Text)
Definition: i18n.h:11
boost::shared_ptr< PBD::Controllable > controllable
Definition: binding_proxy.h:53
static bool is_bind_action(GdkEventButton *)
bool prompter_hiding(GdkEventAny *)
static guint bind_button
Definition: binding_proxy.h:55
static guint bind_statemask
Definition: binding_proxy.h:56
bool button_press_handler(GdkEventButton *)
T * get() const
Definition: shared_ptr.hpp:268
void set_bind_button_state(guint button, guint statemask)
PBD::Signal0< void > LearningFinished
Definition: controllable.h:85
Definition: debug.h:30
Gtkmm2ext::PopUp * prompter
Definition: binding_proxy.h:52
virtual ~BindingProxy()