pixbufs instead of pixmaps; function-scope local fd's for reading from a FileSource
[ardour.git] / libs / gtkmm2ext / slider_controller.cc
1 /*
2     Copyright (C) 1998-99 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
23 #include <midi++/controllable.h>
24
25 #include <gtkmm2ext/gtk_ui.h>
26 #include <gtkmm2ext/slider_controller.h>
27 #include <gtkmm2ext/pixscroller.h>
28
29 #include "i18n.h"
30
31 using namespace Gtkmm2ext;
32
33 SliderController::SliderController (Glib::RefPtr<Gdk::Pixbuf> slide,
34                                     Glib::RefPtr<Gdk::Pixbuf> rail,
35                                     Gtk::Adjustment *adj,
36                                     MIDI::Controllable *mc,
37                                     bool with_numeric)
38
39         : PixScroller (*adj, slide, rail),
40           spin (*adj, 0, 2),
41           prompter (Gtk::WIN_POS_MOUSE, 30000, false),
42           midi_control (mc),
43           bind_button (2),
44           bind_statemask (Gdk::CONTROL_MASK)
45
46 {                         
47         signal_button_press_event().connect (mem_fun (this, &SliderController::button_press));
48         spin.set_name ("SliderControllerValue");
49         spin.set_size_request (70,-1); // should be based on font size somehow
50         spin.set_numeric (true);
51         spin.set_snap_to_ticks (false);
52
53         prompter.signal_unmap_event().connect (mem_fun (*this, &SliderController::prompter_hiding));
54         
55         prompting = false;
56         unprompting = false;
57         
58         if (mc) {
59                 mc->learning_started.connect (mem_fun (*this, &SliderController::midicontrol_prompt));
60                 mc->learning_stopped.connect (mem_fun (*this, &SliderController::midicontrol_unprompt));
61         }
62 }
63
64 void
65 SliderController::set_value (float v)
66 {
67         adj.set_value (v);
68 }
69
70 void
71 SliderController::set_bind_button_state (guint button, guint statemask)
72 {
73         bind_button = button;
74         bind_statemask = statemask;
75 }
76
77 void
78 SliderController::get_bind_button_state (guint &button, guint &statemask)
79 {
80         button = bind_button;
81         statemask = bind_statemask;
82 }
83
84 void
85 SliderController::midi_learn()
86 {
87         if (midi_control) {
88                 prompting = true;
89                 midi_control->learn_about_external_control ();
90         }
91 }
92
93 bool
94 SliderController::button_press (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 void
105 SliderController::midicontrol_set_tip ()
106
107 {
108         if (midi_control) {
109                 // Gtkmm2ext::UI::instance()->set_tip (this, midi_control->control_description());
110         }
111 }
112
113 bool
114 SliderController::prompter_hiding (GdkEventAny *ev)
115 {
116         if (unprompting) {
117                 if (midi_control) {
118                         midi_control->stop_learning();
119                 }
120                 unprompting = false;
121         }
122         
123         return false;
124 }
125
126 void
127 SliderController::midicontrol_prompt ()
128
129 {
130         if (prompting) {
131
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 SliderController::midicontrol_unprompt ()
143
144 {
145         if (unprompting) {
146                 Gtkmm2ext::UI::instance()->touch_display (&prompter);
147                 unprompting = false;
148         }
149 }
150
151
152 VSliderController::VSliderController (Glib::RefPtr<Gdk::Pixbuf> slide,
153                                       Glib::RefPtr<Gdk::Pixbuf> rail,
154                                       Gtk::Adjustment *adj,
155                                       MIDI::Controllable *mcontrol,
156                                       bool with_numeric)
157
158         : SliderController (slide, rail, adj, mcontrol, with_numeric)
159 {
160         if (with_numeric) {
161                 spin_frame.add (spin);
162                 spin_frame.set_shadow_type (Gtk::SHADOW_IN);
163                 spin_frame.set_name ("BaseFrame");
164                 spin_hbox.pack_start (spin_frame, false, true);
165                 // pack_start (spin_hbox, false, false);
166         }
167 }
168
169 HSliderController::HSliderController (Glib::RefPtr<Gdk::Pixbuf> slide,
170                                       Glib::RefPtr<Gdk::Pixbuf> rail,
171                                       Gtk::Adjustment *adj,
172                                       MIDI::Controllable *mcontrol,
173                                       bool with_numeric)
174         
175         : SliderController (slide, rail, adj, mcontrol, with_numeric)
176 {
177         if (with_numeric) {
178                 spin_frame.add (spin);
179                 //spin_frame.set_shadow_type (Gtk::SHADOW_IN);
180                 spin_frame.set_name ("BaseFrame");
181                 spin_hbox.pack_start (spin_frame, false, true);
182                 // pack_start (spin_hbox, false, false);
183         }
184 }