2008-06-02 17:41:35 -04:00
|
|
|
/*
|
2019-08-02 22:40:09 -04:00
|
|
|
* Copyright (C) 1998 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2017 Robin Gareus <robin@gareus.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2017-07-16 16:13:46 -04:00
|
|
|
#include "gtkmm2ext/gtk_ui.h"
|
2014-11-01 13:22:29 -04:00
|
|
|
#include "pbd/controllable.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2017-07-16 16:13:46 -04:00
|
|
|
#include "widgets/ardour_fader.h"
|
|
|
|
#include "widgets/slider_controller.h"
|
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
using namespace PBD;
|
2017-07-16 16:13:46 -04:00
|
|
|
using namespace ArdourWidgets;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2024-05-14 14:40:12 -04:00
|
|
|
SliderController::SliderController (Gtk::Adjustment *adj, std::shared_ptr<PBD::Controllable> mc, int orien)
|
|
|
|
: FaderWidget (*adj, orien)
|
2014-11-01 13:24:31 -04:00
|
|
|
, _ctrl (mc)
|
|
|
|
, _ctrl_adj (adj)
|
|
|
|
, _spin_adj (0, 0, 1.0, .1, .01)
|
|
|
|
, _spin (_spin_adj, 0, 2)
|
2014-11-01 21:50:28 -04:00
|
|
|
, _ctrl_ignore (false)
|
|
|
|
, _spin_ignore (false)
|
2014-11-01 13:24:31 -04:00
|
|
|
{
|
2020-07-22 15:43:14 -04:00
|
|
|
if (_ctrl) {
|
|
|
|
// TODO consider a more generic method similar to
|
|
|
|
// get_user_string() or value_as_string() for numeric entry.
|
|
|
|
if (_ctrl->is_gain_like()) {
|
|
|
|
/* use a slightly lower threadhold than ardour/dB.h to map -infinity <> -320 */
|
|
|
|
float lower = _ctrl->lower () > 1e-16 ? 20.0f * log10f (_ctrl->lower ()) : -320.0f;
|
|
|
|
float upper = _ctrl->upper () > 1e-16 ? 20.0f * log10f (_ctrl->upper ()) : -320.0f;
|
|
|
|
_spin_adj.set_lower (lower);
|
|
|
|
_spin_adj.set_upper (upper);
|
|
|
|
_spin_adj.set_step_increment(0.1);
|
|
|
|
_spin_adj.set_page_increment(1.0);
|
|
|
|
} else {
|
|
|
|
_spin_adj.set_lower (_ctrl->lower ());
|
|
|
|
_spin_adj.set_upper (_ctrl->upper ());
|
|
|
|
_spin_adj.set_step_increment(_ctrl->interface_to_internal(adj->get_step_increment()) - _ctrl->lower ());
|
|
|
|
_spin_adj.set_page_increment(_ctrl->interface_to_internal(adj->get_page_increment()) - _ctrl->lower ());
|
|
|
|
}
|
2014-11-01 13:24:31 -04:00
|
|
|
|
|
|
|
adj->signal_value_changed().connect (sigc::mem_fun(*this, &SliderController::ctrl_adjusted));
|
|
|
|
_spin_adj.signal_value_changed().connect (sigc::mem_fun(*this, &SliderController::spin_adjusted));
|
|
|
|
|
2020-07-22 15:43:14 -04:00
|
|
|
_binding_proxy.set_controllable (_ctrl);
|
2014-11-01 13:24:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
_spin.set_name ("SliderControllerValue");
|
|
|
|
_spin.set_numeric (true);
|
|
|
|
_spin.set_snap_to_ticks (false);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2014-11-01 13:24:31 -04:00
|
|
|
bool
|
|
|
|
SliderController::on_button_press_event (GdkEventButton *ev)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2014-11-01 13:24:31 -04:00
|
|
|
if (_binding_proxy.button_press_handler (ev)) {
|
2008-06-02 17:41:35 -04:00
|
|
|
return true;
|
|
|
|
}
|
2008-12-08 11:07:28 -05:00
|
|
|
|
2024-05-14 14:40:12 -04:00
|
|
|
return FaderWidget::on_button_press_event (ev);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2017-07-02 12:18:22 -04:00
|
|
|
bool
|
|
|
|
SliderController::on_enter_notify_event (GdkEventCrossing* ev)
|
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<PBD::Controllable> c (_binding_proxy.get_controllable ());
|
2017-07-02 12:18:22 -04:00
|
|
|
if (c) {
|
2023-02-16 18:33:28 -05:00
|
|
|
PBD::Controllable::GUIFocusChanged (std::weak_ptr<PBD::Controllable> (c));
|
2017-07-02 12:18:22 -04:00
|
|
|
}
|
2024-05-14 14:40:12 -04:00
|
|
|
return FaderWidget::on_enter_notify_event (ev);
|
2017-07-02 12:18:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SliderController::on_leave_notify_event (GdkEventCrossing* ev)
|
|
|
|
{
|
|
|
|
if (_binding_proxy.get_controllable()) {
|
2023-02-16 18:33:28 -05:00
|
|
|
PBD::Controllable::GUIFocusChanged (std::weak_ptr<PBD::Controllable> ());
|
2017-07-02 12:18:22 -04:00
|
|
|
}
|
2024-05-14 14:40:12 -04:00
|
|
|
return FaderWidget::on_leave_notify_event (ev);
|
2017-07-02 12:18:22 -04:00
|
|
|
}
|
|
|
|
|
2014-11-01 13:24:31 -04:00
|
|
|
void
|
|
|
|
SliderController::ctrl_adjusted ()
|
|
|
|
{
|
2020-07-22 15:43:14 -04:00
|
|
|
assert (_ctrl); // only used w/BarController
|
2014-11-01 13:24:31 -04:00
|
|
|
if (_spin_ignore) return;
|
|
|
|
_ctrl_ignore = true;
|
2020-07-22 15:43:14 -04:00
|
|
|
|
|
|
|
if (_ctrl->is_gain_like ()) {
|
|
|
|
float coeff = _ctrl->interface_to_internal (_ctrl_adj->get_value());
|
|
|
|
float db = coeff > 1e-16 ? 20.0f * log10f (coeff) : -320.0f;
|
|
|
|
_spin_adj.set_value (db);
|
|
|
|
} else {
|
|
|
|
_spin_adj.set_value (_ctrl->interface_to_internal (_ctrl_adj->get_value()));
|
|
|
|
}
|
2014-11-01 13:24:31 -04:00
|
|
|
_ctrl_ignore = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SliderController::spin_adjusted ()
|
|
|
|
{
|
|
|
|
assert (_ctrl); // only used w/BarController
|
|
|
|
if (_ctrl_ignore) return;
|
|
|
|
_spin_ignore = true;
|
2020-07-22 15:43:14 -04:00
|
|
|
if (_ctrl->is_gain_like ()) {
|
|
|
|
float db = _spin_adj.get_value();
|
|
|
|
float coeff = db > -320.f ? pow (10.0f, db * 0.05f) : 0.0f;
|
|
|
|
_ctrl_adj->set_value(_ctrl->internal_to_interface (coeff));
|
|
|
|
} else {
|
|
|
|
_ctrl_adj->set_value(_ctrl->internal_to_interface (_spin_adj.get_value()));
|
|
|
|
}
|
2014-11-01 13:24:31 -04:00
|
|
|
_spin_ignore = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
VSliderController::VSliderController (Gtk::Adjustment *adj, std::shared_ptr<PBD::Controllable> mc, int fader_length, int fader_girth)
|
2024-05-14 14:40:12 -04:00
|
|
|
: FaderWidget (*adj, VERT)
|
|
|
|
, SliderController (adj, mc, VERT)
|
|
|
|
, ArdourFader (*adj, VERT, fader_length, fader_girth)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
HSliderController::HSliderController (Gtk::Adjustment *adj, std::shared_ptr<PBD::Controllable> mc, int fader_length, int fader_girth)
|
2024-05-14 14:40:12 -04:00
|
|
|
: FaderWidget (*adj, HORIZ)
|
|
|
|
, SliderController (adj, mc, HORIZ)
|
|
|
|
, ArdourFader (*adj, HORIZ, fader_length, fader_girth)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
}
|