2 Copyright (C) 2014 Paul Davis
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.
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.
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.
24 #include <pangomm/layout.h>
26 #include "pbd/compose.h"
27 #include "pbd/controllable.h"
28 #include "pbd/error.h"
29 #include "pbd/stacktrace.h"
31 #include "gtkmm2ext/utils.h"
32 #include "gtkmm2ext/rgb_macros.h"
33 #include "gtkmm2ext/gui_thread.h"
34 #include "gtkmm2ext/keyboard.h"
36 #include "widgets/ardour_display.h"
40 using namespace Gtkmm2ext;
45 using namespace ArdourWidgets;
50 ArdourDisplay::ArdourDisplay (Element e)
52 add_elements(ArdourButton::Text);
55 ArdourDisplay::~ArdourDisplay ()
61 ArdourDisplay::on_scroll_event (GdkEventScroll* ev)
66 if (ev->state & Keyboard::GainFineScaleModifier) {
67 if (ev->state & Keyboard::GainExtraFineScaleModifier) {
74 boost::shared_ptr<PBD::Controllable> c = binding_proxy.get_controllable();
76 float val = c->get_interface();
78 if ( ev->direction == GDK_SCROLL_UP )
79 val += 0.05 * scale; //by default, we step in 1/20ths of the knob travel
83 c->set_interface(val);
91 ArdourDisplay::add_controllable_preset (const char *txt, float val)
93 using namespace Menu_Helpers;
94 AddMenuElem(MenuElem (txt, sigc::bind (sigc::mem_fun(*this, &ArdourDisplay::handle_controllable_preset), val)));
97 static inline float dB_to_coefficient (float dB) {
98 return dB > -318.8f ? pow (10.0f, dB * 0.05f) : 0.0f;
102 ArdourDisplay::handle_controllable_preset (float p)
104 boost::shared_ptr<PBD::Controllable> c = binding_proxy.get_controllable();
108 /* This should not use dB_to_coefficient(), but the Controllable's value.
110 * The only user of this API is currently monitor_section.cc which conveniently
111 * binds dB values. Once there are other use-cases, for this, this (GUI only) API
114 c->set_value(dB_to_coefficient (p), Controllable::NoGroup);
119 ArdourDisplay::set_controllable (boost::shared_ptr<Controllable> c)
121 watch_connection.disconnect (); //stop watching the old controllable
125 binding_proxy.set_controllable (c);
127 c->Changed.connect (watch_connection, invalidator(*this), boost::bind (&ArdourDisplay::controllable_changed, this), gui_context());
129 controllable_changed();
133 ArdourDisplay::controllable_changed ()
135 boost::shared_ptr<PBD::Controllable> c = binding_proxy.get_controllable();
139 set_text(c->get_user_string());