allow sending OSC from inline display UIs
[ardour.git] / gtk2_ardour / ardour_display.cc
1 /*
2     Copyright (C) 2014 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <iostream>
21 #include <cmath>
22 #include <algorithm>
23
24 #include <pangomm/layout.h>
25
26 #include "pbd/compose.h"
27 #include "pbd/controllable.h"
28 #include "pbd/error.h"
29 #include "pbd/stacktrace.h"
30
31 #include "gtkmm2ext/utils.h"
32 #include "gtkmm2ext/rgb_macros.h"
33 #include "gtkmm2ext/gui_thread.h"
34 #include "gtkmm2ext/keyboard.h"
35
36 #include "ardour/rc_configuration.h" // for widget prelight preference
37
38 #include "ardour_display.h"
39
40 #include "pbd/i18n.h"
41
42 using namespace Gtkmm2ext;
43 using namespace Gdk;
44 using namespace Gtk;
45 using namespace Glib;
46 using namespace PBD;
47 using std::max;
48 using std::min;
49 using namespace std;
50
51
52 ArdourDisplay::ArdourDisplay (Element e)
53 {
54         add_elements(ArdourButton::Text);
55 }
56
57 ArdourDisplay::~ArdourDisplay ()
58 {
59 }
60
61
62 bool
63 ArdourDisplay::on_scroll_event (GdkEventScroll* ev)
64 {
65         /* mouse wheel */
66
67         float scale = 1.0;
68         if (ev->state & Keyboard::GainFineScaleModifier) {
69                 if (ev->state & Keyboard::GainExtraFineScaleModifier) {
70                         scale *= 0.01;
71                 } else {
72                         scale *= 0.10;
73                 }
74         }
75
76         boost::shared_ptr<PBD::Controllable> c = binding_proxy.get_controllable();
77         if (c) {
78                 float val = c->get_interface();
79
80                 if ( ev->direction == GDK_SCROLL_UP )
81                         val += 0.05 * scale;  //by default, we step in 1/20ths of the knob travel
82                 else
83                         val -= 0.05 * scale;
84
85                 c->set_interface(val);
86         }
87
88         return true;
89 }
90
91
92 void
93 ArdourDisplay::add_controllable_preset (const char *txt, float val)
94 {
95         using namespace Menu_Helpers;
96         AddMenuElem(MenuElem (txt, sigc::bind (sigc::mem_fun(*this, &ArdourDisplay::handle_controllable_preset), val)));
97 }
98
99
100 void
101 ArdourDisplay::handle_controllable_preset (float p)
102 {
103         boost::shared_ptr<PBD::Controllable> c = binding_proxy.get_controllable();
104
105         if (!c) return;
106
107         c->set_user(p);
108 }
109
110
111 void
112 ArdourDisplay::set_controllable (boost::shared_ptr<Controllable> c)
113 {
114     watch_connection.disconnect ();  //stop watching the old controllable
115
116         if (!c) return;
117
118         binding_proxy.set_controllable (c);
119
120         c->Changed.connect (watch_connection, invalidator(*this), boost::bind (&ArdourDisplay::controllable_changed, this), gui_context());
121
122         controllable_changed();
123 }
124
125 void
126 ArdourDisplay::controllable_changed ()
127 {
128         boost::shared_ptr<PBD::Controllable> c = binding_proxy.get_controllable();
129
130         if (!c) return;
131
132         set_text(c->get_user_string());
133
134         set_dirty();
135 }