summaryrefslogtreecommitdiff
path: root/gtk2_ardour
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2011-06-17 21:47:20 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2011-06-17 21:47:20 +0000
commit01e006e46e6d4dd0ab25e08bd44d13dd1e195886 (patch)
tree3ed1b959caa20fd0e117de2fcfa557738ae5aa86 /gtk2_ardour
parentcb8bc87a542e35794a12e76a23594e63b3bad521 (diff)
some changes to try to make the monitor section gain controls work as intended, and along the way start to rationalize MotionFeedback/VolumeController classes
git-svn-id: svn://localhost/ardour2/branches/3.0@9746 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'gtk2_ardour')
-rw-r--r--gtk2_ardour/monitor_section.cc57
-rw-r--r--gtk2_ardour/monitor_section.h7
-rw-r--r--gtk2_ardour/volume_controller.cc111
-rw-r--r--gtk2_ardour/volume_controller.h26
4 files changed, 110 insertions, 91 deletions
diff --git a/gtk2_ardour/monitor_section.cc b/gtk2_ardour/monitor_section.cc
index c4729a857b..9d1811b1d4 100644
--- a/gtk2_ardour/monitor_section.cc
+++ b/gtk2_ardour/monitor_section.cc
@@ -37,13 +37,9 @@ MonitorSection::MonitorSection (Session* s)
, RouteUI (s)
, main_table (2, 3)
, _tearoff (0)
- , gain_adjustment (0.781787, 0.0, 1.0, 0.01, 0.1) // initial value is unity gain
, gain_control (0)
- , dim_adjustment (0.2, 0.0, 1.0, 0.01, 0.1) // upper+lower will be reset to match model
, dim_control (0)
- , solo_boost_adjustment (1.0, 1.0, 3.0, 0.01, 0.1) // upper and lower will be reset to match model
, solo_boost_control (0)
- , solo_cut_adjustment (0.0, 0.0, 1.0, 0.01, 0.1)
, solo_cut_control (0)
, solo_in_place_button (solo_model_group, _("SiP"))
, afl_button (solo_model_group, _("AFL"))
@@ -74,7 +70,7 @@ MonitorSection::MonitorSection (Session* s)
/* Dim */
- dim_control = new VolumeController (little_knob_pixbuf, &dim_adjustment, false, 30, 30);
+ dim_control = new VolumeController (little_knob_pixbuf, boost::shared_ptr<Controllable>(), 0.0, 0.01, 0.1, true, 30, 30, true, true);
HBox* dim_packer = manage (new HBox);
dim_packer->show ();
@@ -87,7 +83,7 @@ MonitorSection::MonitorSection (Session* s)
spin_packer->pack_start (*spin_label, false, false);
dim_packer->set_spacing (12);
- dim_packer->pack_start (*spin_packer, true, true);
+ dim_packer->pack_start (*spin_packer, true, false);
/* Rude Solo */
@@ -138,7 +134,7 @@ MonitorSection::MonitorSection (Session* s)
/* Solo Boost */
- solo_boost_control = new VolumeController (little_knob_pixbuf, &solo_boost_adjustment, false, 30, 30);
+ solo_boost_control = new VolumeController (little_knob_pixbuf, boost::shared_ptr<Controllable>(), 0.0, 0.01, 0.1, true, 30, 30, true, true);
HBox* solo_packer = manage (new HBox);
solo_packer->set_spacing (12);
@@ -151,11 +147,11 @@ MonitorSection::MonitorSection (Session* s)
spin_packer->pack_start (*solo_boost_control, false, false);
spin_packer->pack_start (*spin_label, false, false);
- solo_packer->pack_start (*spin_packer, true, true);
+ solo_packer->pack_start (*spin_packer, false, true);
/* Solo (SiP) cut */
- solo_cut_control = new VolumeController (little_knob_pixbuf, &solo_cut_adjustment, false, 30, 30);
+ solo_cut_control = new VolumeController (little_knob_pixbuf, boost::shared_ptr<Controllable>(), 0.0, 0.01, 0.1, true, 30, 30, false, false);
spin_label = manage (new Label (_("SiP Cut")));
spin_packer = manage (new VBox);
@@ -164,7 +160,7 @@ MonitorSection::MonitorSection (Session* s)
spin_packer->pack_start (*solo_cut_control, false, false);
spin_packer->pack_start (*spin_label, false, false);
- solo_packer->pack_start (*spin_packer, true, true);
+ solo_packer->pack_start (*spin_packer, false, true);
exclusive_solo_button.set_name (X_("MonitorOptButton"));
ARDOUR_UI::instance()->set_tip (&exclusive_solo_button, _("Exclusive solo means that only 1 solo is active at a time"));
@@ -238,7 +234,7 @@ MonitorSection::MonitorSection (Session* s)
/* Gain */
- gain_control = new VolumeController (big_knob_pixbuf, &gain_adjustment, false, 80, 80);
+ gain_control = new VolumeController (big_knob_pixbuf, boost::shared_ptr<Controllable>(), 0.781787, 0.01, 0.1, true, 80, 80, false, false);
spin_label = manage (new Label (_("Gain")));
spin_packer = manage (new VBox);
@@ -763,26 +759,6 @@ MonitorSection::setup_knob_images ()
}
-bool
-MonitorSection::nonlinear_gain_printer (SpinButton* button)
-{
- double val = button->get_adjustment()->get_value();
- char buf[16];
- snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (slider_position_to_gain (val)));
- button->set_text (buf);
- return true;
-}
-
-bool
-MonitorSection::linear_gain_printer (SpinButton* button)
-{
- double val = button->get_adjustment()->get_value();
- char buf[16];
- snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (val));
- button->set_text (buf);
- return true;
-}
-
void
MonitorSection::update_solo_model ()
{
@@ -818,10 +794,6 @@ MonitorSection::map_state ()
return;
}
- gain_control->get_adjustment()->set_value (gain_to_slider_position (_route->gain_control()->get_value()));
- dim_control->get_adjustment()->set_value (_monitor->dim_level());
- solo_boost_control->get_adjustment()->set_value (_monitor->solo_boost_level());
-
Glib::RefPtr<Action> act;
update_solo_model ();
@@ -987,8 +959,6 @@ MonitorSection::parameter_changed (std::string name)
if (name == "solo-control-is-listen-control" ||
name == "listen-position") {
update_solo_model ();
- } else if (name == "solo-mute-gain") {
- solo_cut_adjustment.set_value (gain_to_slider_position (Config->get_solo_mute_gain()));
}
}
@@ -1005,7 +975,6 @@ MonitorSection::assign_controllables ()
if (_session) {
boost::shared_ptr<Controllable> c = _session->solo_cut_control();
solo_cut_control->set_controllable (c);
- solo_cut_control->get_adjustment()->set_value (gain_to_slider_position (c->get_value()));
} else {
solo_cut_control->set_controllable (none);
}
@@ -1025,16 +994,8 @@ MonitorSection::assign_controllables ()
mono_button.set_controllable (_monitor->mono_control());
mono_button.watch ();
- boost::shared_ptr<Controllable> c (_monitor->dim_level_control ());
-
- dim_control->set_controllable (c);
- dim_adjustment.set_lower (c->lower());
- dim_adjustment.set_upper (c->upper());
-
- c = _monitor->solo_boost_control ();
- solo_boost_control->set_controllable (c);
- solo_boost_adjustment.set_lower (c->lower());
- solo_boost_adjustment.set_upper (c->upper());
+ dim_control->set_controllable (_monitor->dim_level_control ());
+ solo_boost_control->set_controllable (_monitor->solo_boost_control ());
} else {
diff --git a/gtk2_ardour/monitor_section.h b/gtk2_ardour/monitor_section.h
index 6a8f25c7e3..133e773186 100644
--- a/gtk2_ardour/monitor_section.h
+++ b/gtk2_ardour/monitor_section.h
@@ -64,13 +64,9 @@ class MonitorSection : public RouteUI
typedef std::vector<ChannelButtonSet*> ChannelButtons;
ChannelButtons _channel_buttons;
- Gtk::Adjustment gain_adjustment;
VolumeController* gain_control;
- Gtk::Adjustment dim_adjustment;
VolumeController* dim_control;
- Gtk::Adjustment solo_boost_adjustment;
VolumeController* solo_boost_control;
- Gtk::Adjustment solo_cut_adjustment;
VolumeController* solo_cut_control;
void populate_buttons ();
@@ -99,9 +95,6 @@ class MonitorSection : public RouteUI
void solo_boost_changed ();
void gain_value_changed ();
- bool nonlinear_gain_printer (Gtk::SpinButton*);
- bool linear_gain_printer (Gtk::SpinButton*);
-
Gtk::RadioButtonGroup solo_model_group;
Gtk::RadioButton solo_in_place_button;
Gtk::RadioButton afl_button;
diff --git a/gtk2_ardour/volume_controller.cc b/gtk2_ardour/volume_controller.cc
index bb6a5f1db3..8a382f6cb1 100644
--- a/gtk2_ardour/volume_controller.cc
+++ b/gtk2_ardour/volume_controller.cc
@@ -17,12 +17,17 @@
$Id: volume_controller.cc,v 1.4 2000/05/03 15:54:21 pbd Exp $
*/
+#include <algorithm>
+
#include <string.h>
#include <limits.h>
#include "pbd/controllable.h"
+#include "pbd/stacktrace.h"
#include "gtkmm2ext/gui_thread.h"
+
+#include "ardour/dB.h"
#include "ardour/utils.h"
#include "volume_controller.h"
@@ -30,45 +35,99 @@
using namespace Gtk;
VolumeController::VolumeController (Glib::RefPtr<Gdk::Pixbuf> p,
- Gtk::Adjustment *adj,
+ boost::shared_ptr<PBD::Controllable> c,
+ double def,
+ double step,
+ double page,
bool with_numeric,
- int subw, int subh)
-
- : MotionFeedback (p, MotionFeedback::Rotary, "", adj, with_numeric, subw, subh)
+ int subw,
+ int subh,
+ bool linear,
+ bool dB)
+
+ : MotionFeedback (p, MotionFeedback::Rotary, c, def, step, page, "", with_numeric, subw, subh)
+ , _linear (linear)
+ , _controllable_uses_dB (dB)
{
- get_adjustment()->signal_value_changed().connect (mem_fun (*this,&VolumeController::adjustment_value_changed));
+ set_print_func (VolumeController::_dB_printer, this);
+
+ if (step < 1.0) {
+ value->set_width_chars (6 + abs ((int) ceil (log10 (step))));
+ } else {
+ value->set_width_chars (5); // -NNdB
+ }
+
}
void
-VolumeController::set_controllable (boost::shared_ptr<PBD::Controllable> c)
+VolumeController::_dB_printer (char buf[32], const boost::shared_ptr<PBD::Controllable>& c, void* arg)
{
- MotionFeedback::set_controllable (c);
-
- controllable_connection.disconnect ();
-
- if (c) {
- c->Changed.connect (controllable_connection, MISSING_INVALIDATOR, boost::bind (&VolumeController::controllable_value_changed, this), gui_context());
- }
-
- controllable_value_changed ();
+ VolumeController* vc = reinterpret_cast<VolumeController*>(arg);
+ vc->dB_printer (buf, c);
}
void
-VolumeController::controllable_value_changed ()
+VolumeController::dB_printer (char buf[32], const boost::shared_ptr<PBD::Controllable>& c)
{
- boost::shared_ptr<PBD::Controllable> c = controllable();
- if (c) {
- get_adjustment()->set_value (gain_to_slider_position (c->get_value ()));
- }
+ if (c) {
+
+ if (_linear) {
+ /* controllable units are in dB so just show the value */
+ if (step_inc < 1.0) {
+ snprintf (buf, 32, "%.2f dB", c->get_value());
+ } else {
+ snprintf (buf, 32, "%ld dB", lrint (c->get_value()));
+ }
+ } else {
+
+ double gain_coefficient;
+
+ if (!_controllable_uses_dB) {
+ gain_coefficient = c->get_value();
+ } else {
+ double fract = (c->get_value() - c->lower()) / (c->upper() - c->lower());
+ gain_coefficient = slider_position_to_gain (fract);
+ }
+
+ if (step_inc < 1.0) {
+ snprintf (buf, 32, "%.2f dB", accurate_coefficient_to_dB (gain_coefficient));
+ } else {
+ snprintf (buf, 32, "%ld dB", lrint (accurate_coefficient_to_dB (gain_coefficient)));
+ }
+ }
+ } else {
+ snprintf (buf, sizeof (buf), "--");
+ }
}
-void
-VolumeController::adjustment_value_changed ()
+double
+VolumeController::to_control_value (double display_value)
{
- boost::shared_ptr<PBD::Controllable> c = controllable();
- if (c) {
- c->set_value (slider_position_to_gain (get_adjustment()->get_value()));
- }
+ double v;
+
+ /* display value is always clamped to 0.0 .. 1.0 */
+ display_value = std::max (0.0, std::min (1.0, display_value));
+
+ if (_linear) {
+ v = _controllable->lower() + ((_controllable->upper() - _controllable->lower()) * display_value);
+ } else {
+
+ v = slider_position_to_gain (display_value);
+ }
+
+ return v;
}
+double
+VolumeController::to_display_value (double control_value)
+{
+ double v;
+
+ if (_linear) {
+ v = (control_value - _controllable->lower ()) / (_controllable->upper() - _controllable->lower());
+ } else {
+ v = gain_to_slider_position (control_value);
+ }
+ return v;
+}
diff --git a/gtk2_ardour/volume_controller.h b/gtk2_ardour/volume_controller.h
index d55e654930..8693f5f0da 100644
--- a/gtk2_ardour/volume_controller.h
+++ b/gtk2_ardour/volume_controller.h
@@ -24,27 +24,33 @@
#include "gtkmm2ext/motionfeedback.h"
-// march 2010: this exists as a placeholder to add a controllable, but maybe it will
-// end up in MotionFeedback
-
class VolumeController : public Gtkmm2ext::MotionFeedback
{
public:
VolumeController (Glib::RefPtr<Gdk::Pixbuf>,
- Gtk::Adjustment *adj,
+ boost::shared_ptr<PBD::Controllable>,
+ double def,
+ double step,
+ double page,
bool with_numeric = true,
int image_width = 40,
- int image_height = 40);
+ int image_height = 40,
+ bool linear = true,
+ bool dB = false);
virtual ~VolumeController () {}
- void set_controllable (boost::shared_ptr<PBD::Controllable> c);
+
+ static void _dB_printer (char buf[32], const boost::shared_ptr<PBD::Controllable>& adj, void* arg);
+
+ protected:
+ double to_control_value (double);
+ double to_display_value (double);
private:
- Gtk::Adjustment *adjustment;
- PBD::ScopedConnection controllable_connection;
+ bool _linear;
+ bool _controllable_uses_dB;
- void adjustment_value_changed ();
- void controllable_value_changed ();
+ void dB_printer (char buf[32], const boost::shared_ptr<PBD::Controllable>& adj);
};
#endif // __gtk_ardour_vol_controller_h__