un-triple-buffer fastmeter (not finished), fix mixer strip name button, comment edito...
[ardour.git] / libs / gtkmm2ext / bindable_button.cc
1 /*
2     Copyright (C) 2004 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 <midi++/controllable.h>
25
26 #include <gtkmm2ext/gtk_ui.h>
27 #include <gtkmm2ext/bindable_button.h>
28
29 #include "i18n.h"
30
31 using namespace Gtkmm2ext;
32 using namespace std;
33
34 BindableToggleButton::BindableToggleButton (MIDI::Controllable *mc)
35         : ToggleButton (),
36           prompter (Gtk::WIN_POS_MOUSE, 30000, false),
37           midi_control (mc),
38           bind_button (2),
39           bind_statemask (Gdk::CONTROL_MASK)
40
41 {                         
42         init_events ();
43 }
44
45 BindableToggleButton::BindableToggleButton(MIDI::Controllable *mc, const string &label)
46         : ToggleButton (label),
47           prompter (Gtk::WIN_POS_MOUSE, 30000, false),
48           midi_control (mc),
49           bind_button (2),
50           bind_statemask (Gdk::CONTROL_MASK)
51 {                         
52         init_events ();
53 }
54
55
56 void
57 BindableToggleButton::init_events ()
58 {
59         prompter.signal_unmap_event().connect (mem_fun (*this, &BindableToggleButton::prompter_hiding));
60         
61         prompting = false;
62         unprompting = false;
63         
64         if (midi_control) {
65                 midi_control->learning_started.connect (mem_fun (*this, &BindableToggleButton::midicontrol_prompt));
66                 midi_control->learning_stopped.connect (mem_fun (*this, &BindableToggleButton::midicontrol_unprompt));
67         }
68 }
69
70 void
71 BindableToggleButton::set_bind_button_state (guint button, guint statemask)
72 {
73         bind_button = button;
74         bind_statemask = statemask;
75 }
76
77 void
78 BindableToggleButton::get_bind_button_state (guint &button, guint &statemask)
79 {
80         button = bind_button;
81         statemask = bind_statemask;
82 }
83
84 void
85 BindableToggleButton::midi_learn()
86 {
87         if (midi_control) {
88                 prompting = true;
89                 midi_control->learn_about_external_control ();
90         }
91 }
92
93 bool
94 BindableToggleButton::on_button_press_event (GdkEventButton *ev)
95 {
96         if ((ev->state & bind_statemask) && ev->button == bind_button) { 
97                 midi_learn ();
98                 return true;
99         }
100         
101         return false;
102 }
103
104 bool
105 BindableToggleButton::prompter_hiding (GdkEventAny *ev)
106 {
107         if (unprompting) {
108                 if (midi_control) {
109                         midi_control->stop_learning();
110                 }
111                 unprompting = false;
112         }
113         
114         return false;
115 }
116
117
118 void
119 BindableToggleButton::midicontrol_set_tip ()
120
121 {
122         if (midi_control) {
123                 // Gtkmm2ext::UI::instance()->set_tip (evbox, midi_control->control_description());
124         }
125 }
126
127 void
128 BindableToggleButton::midicontrol_prompt ()
129
130 {
131         if (prompting) {
132                 string prompt = _("operate MIDI controller now");
133                 prompter.set_text (prompt);
134                 Gtkmm2ext::UI::instance()->touch_display (&prompter);
135                 
136                 unprompting = true;
137                 prompting = false;
138         }
139 }
140
141 void
142 BindableToggleButton::midicontrol_unprompt ()
143
144 {
145         if (unprompting) {
146                 Gtkmm2ext::UI::instance()->touch_display (&prompter);
147                 unprompting = false;
148         }
149 }
150
151