2 * Copyright (C) 1998 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "gtkmm2ext/gtk_ui.h"
23 #include "pbd/controllable.h"
25 #include "widgets/ardour_fader.h"
26 #include "widgets/slider_controller.h"
31 using namespace ArdourWidgets;
33 SliderController::SliderController (Gtk::Adjustment *adj, boost::shared_ptr<PBD::Controllable> mc, int orientation, int fader_length, int fader_girth)
34 : ArdourFader (*adj, orientation, fader_length, fader_girth)
37 , _spin_adj (0, 0, 1.0, .1, .01)
38 , _spin (_spin_adj, 0, 2)
39 , _ctrl_ignore (false)
40 , _spin_ignore (false)
43 _spin_adj.set_lower (mc->lower ());
44 _spin_adj.set_upper (mc->upper ());
45 _spin_adj.set_step_increment(_ctrl->interface_to_internal(adj->get_step_increment()) - mc->lower ());
46 _spin_adj.set_page_increment(_ctrl->interface_to_internal(adj->get_page_increment()) - mc->lower ());
48 adj->signal_value_changed().connect (sigc::mem_fun(*this, &SliderController::ctrl_adjusted));
49 _spin_adj.signal_value_changed().connect (sigc::mem_fun(*this, &SliderController::spin_adjusted));
51 _binding_proxy.set_controllable (mc);
54 _spin.set_name ("SliderControllerValue");
55 _spin.set_numeric (true);
56 _spin.set_snap_to_ticks (false);
60 SliderController::on_button_press_event (GdkEventButton *ev)
62 if (_binding_proxy.button_press_handler (ev)) {
66 return ArdourFader::on_button_press_event (ev);
70 SliderController::on_enter_notify_event (GdkEventCrossing* ev)
72 boost::shared_ptr<PBD::Controllable> c (_binding_proxy.get_controllable ());
74 PBD::Controllable::GUIFocusChanged (boost::weak_ptr<PBD::Controllable> (c));
76 return ArdourFader::on_enter_notify_event (ev);
80 SliderController::on_leave_notify_event (GdkEventCrossing* ev)
82 if (_binding_proxy.get_controllable()) {
83 PBD::Controllable::GUIFocusChanged (boost::weak_ptr<PBD::Controllable> ());
85 return ArdourFader::on_leave_notify_event (ev);
89 SliderController::ctrl_adjusted ()
91 assert (_ctrl); // only used w/BarControlle
92 if (_spin_ignore) return;
94 // TODO consider using internal_to_user, too (amp, dB)
95 // (also needs _spin_adj min/max range changed accordingly
96 // and dedicated support for log-scale, revert parts of ceff2e3a62f839)
97 _spin_adj.set_value (_ctrl->interface_to_internal (_ctrl_adj->get_value()));
102 SliderController::spin_adjusted ()
104 assert (_ctrl); // only used w/BarController
105 if (_ctrl_ignore) return;
107 // TODO consider using user_to_internal, as well
108 _ctrl_adj->set_value(_ctrl->internal_to_interface (_spin_adj.get_value()));
109 _spin_ignore = false;
114 VSliderController::VSliderController (Gtk::Adjustment *adj, boost::shared_ptr<PBD::Controllable> mc, int fader_length, int fader_girth)
115 : SliderController (adj, mc, VERT, fader_length, fader_girth)
119 HSliderController::HSliderController (Gtk::Adjustment *adj, boost::shared_ptr<PBD::Controllable> mc, int fader_length, int fader_girth)
120 : SliderController (adj, mc, HORIZ, fader_length, fader_girth)