diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2010-04-06 16:57:35 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2010-04-06 16:57:35 +0000 |
commit | e69aca28426dd17a0f82ea01c7c98e217b4fdcc3 (patch) | |
tree | 32854686f9de3cd61f07a5e801886b0f2d5a7012 /libs/ardour | |
parent | 3a7487d3fa6887c846bc02d2764e376f7f209a03 (diff) |
MIDI/Controllables for monitor section, and related fixes
git-svn-id: svn://localhost/ardour2/branches/3.0@6863 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour')
-rw-r--r-- | libs/ardour/ardour/automation_control.h | 3 | ||||
-rw-r--r-- | libs/ardour/ardour/monitor_processor.h | 158 | ||||
-rw-r--r-- | libs/ardour/monitor_processor.cc | 164 | ||||
-rw-r--r-- | libs/ardour/session.cc | 16 |
4 files changed, 281 insertions, 60 deletions
diff --git a/libs/ardour/ardour/automation_control.h b/libs/ardour/ardour/automation_control.h index 15bac5fef8..3c832ae704 100644 --- a/libs/ardour/ardour/automation_control.h +++ b/libs/ardour/ardour/automation_control.h @@ -83,6 +83,9 @@ public: */ float get_value() const; + float lower() const { return parameter().min(); } + float upper() const { return parameter().max(); } + protected: ARDOUR::Session& _session; }; diff --git a/libs/ardour/ardour/monitor_processor.h b/libs/ardour/ardour/monitor_processor.h index 18c50e5104..8b8e90573d 100644 --- a/libs/ardour/ardour/monitor_processor.h +++ b/libs/ardour/ardour/monitor_processor.h @@ -20,9 +20,12 @@ #ifndef __ardour_monitor_processor_h__ #define __ardour_monitor_processor_h__ +#include <iostream> #include <vector> #include "pbd/signals.h" +#include "pbd/compose.h" +#include "pbd/controllable.h" #include "ardour/types.h" #include "ardour/processor.h" @@ -33,10 +36,77 @@ namespace ARDOUR { class Session; +template<typename T> class MPControl : public PBD::Controllable { + public: + MPControl (T initial, const std::string& name, PBD::Controllable::Flag flag, + float lower = 0.0f, float upper = 1.0f) + : PBD::Controllable (name, flag) + , _value (initial) + , _lower (lower) + , _upper (upper) + {} + + /* Controllable API */ + + void set_value (float v) { + T newval = (T) v; + if (newval != _value) { + _value = newval; + Changed(); /* EMIT SIGNAL */ + } + } + + float get_value () const { + return (float) _value; + } + + float lower () const { return _lower; } + float upper () const { return _upper; } + + /* "access as T" API */ + + MPControl& operator=(const T& v) { + if (v != _value) { + _value = v; + Changed (); /* EMIT SIGNAL */ + } + return *this; + } + + bool operator==(const T& v) const { + return _value == v; + } + + bool operator<(const T& v) const { + return _value < v; + } + + bool operator<=(const T& v) const { + return _value <= v; + } + + bool operator>(const T& v) const { + return _value > v; + } + + bool operator>=(const T& v) const { + return _value >= v; + } + + operator T() const { return _value; } + T val() const { return _value; } + + protected: + T _value; + T _lower; + T _upper; +}; + class MonitorProcessor : public Processor { public: MonitorProcessor (Session&); + ~MonitorProcessor (); bool display_to_user() const; @@ -71,27 +141,89 @@ class MonitorProcessor : public Processor bool mono () const; PBD::Signal0<void> Changed; + + boost::shared_ptr<PBD::Controllable> channel_cut_control (uint32_t) const; + boost::shared_ptr<PBD::Controllable> channel_dim_control (uint32_t) const; + boost::shared_ptr<PBD::Controllable> channel_polarity_control (uint32_t) const; + boost::shared_ptr<PBD::Controllable> channel_solo_control (uint32_t) const; + boost::shared_ptr<PBD::Controllable> dim_control () const { return _dim_all_control; } + boost::shared_ptr<PBD::Controllable> cut_control () const { return _cut_all_control; } + boost::shared_ptr<PBD::Controllable> mono_control () const { return _mono_control; } + boost::shared_ptr<PBD::Controllable> dim_level_control () const { return _dim_level_control; } + boost::shared_ptr<PBD::Controllable> solo_boost_control () const { return _solo_boost_level_control; } + private: struct ChannelRecord { gain_t current_gain; - gain_t cut; - bool dim; - gain_t polarity; - bool soloed; - ChannelRecord () - : current_gain(1.0), cut(1.0), dim(false), polarity(1.0), soloed (false) {} + /* pointers - created first, but managed by boost::shared_ptr<> */ + + MPControl<gain_t>* cut_ptr; + MPControl<bool>* dim_ptr; + MPControl<gain_t>* polarity_ptr; + MPControl<bool>* soloed_ptr; + + /* shared ptr access and lifetime management, for external users */ + + boost::shared_ptr<PBD::Controllable> cut_control; + boost::shared_ptr<PBD::Controllable> dim_control; + boost::shared_ptr<PBD::Controllable> polarity_control; + boost::shared_ptr<PBD::Controllable> soloed_control; + + /* typed controllables for internal use */ + + MPControl<gain_t>& cut; + MPControl<bool>& dim; + MPControl<gain_t>& polarity; + MPControl<bool>& soloed; + + ChannelRecord (uint32_t chn) : current_gain(1.0) + , cut_ptr (new MPControl<gain_t> (1.0, string_compose (_("cut control %1"), chn), PBD::Controllable::GainLike)) + , dim_ptr (new MPControl<bool> (false, string_compose (_("dim control"), chn), PBD::Controllable::Toggle)) + , polarity_ptr (new MPControl<gain_t> (1.0, string_compose (_("polarity control"), chn), PBD::Controllable::Toggle)) + , soloed_ptr (new MPControl<bool> (false, string_compose (_("solo control"), chn), PBD::Controllable::Toggle)) + + , cut_control (cut_ptr) + , dim_control (dim_ptr) + , polarity_control (polarity_ptr) + , soloed_control (soloed_ptr) + + , cut (*cut_ptr) + , dim (*dim_ptr) + , polarity (*polarity_ptr) + , soloed (*soloed_ptr) + + {} }; - - std::vector<ChannelRecord> _channels; + + std::vector<ChannelRecord*> _channels; uint32_t solo_cnt; - bool _dim_all; - bool _cut_all; - bool _mono; - volatile gain_t _dim_level; - volatile gain_t _solo_boost_level; + + /* pointers - created first, but managed by boost::shared_ptr<> */ + + MPControl<bool>* _dim_all_ptr; + MPControl<bool>* _cut_all_ptr; + MPControl<bool>* _mono_ptr; + MPControl<volatile gain_t>* _dim_level_ptr; + MPControl<volatile gain_t>* _solo_boost_level_ptr; + + /* shared ptr access and lifetime management, for external users */ + + boost::shared_ptr<PBD::Controllable> _dim_all_control; + boost::shared_ptr<PBD::Controllable> _cut_all_control; + boost::shared_ptr<PBD::Controllable> _mono_control; + boost::shared_ptr<PBD::Controllable> _dim_level_control; + boost::shared_ptr<PBD::Controllable> _solo_boost_level_control; + + /* typed controllables for internal use */ + + MPControl<bool>& _dim_all; + MPControl<bool>& _cut_all; + MPControl<bool>& _mono; + MPControl<volatile gain_t>& _dim_level; + MPControl<volatile gain_t>& _solo_boost_level; void allocate_channels (uint32_t); }; diff --git a/libs/ardour/monitor_processor.cc b/libs/ardour/monitor_processor.cc index 51bd30a389..80ed2b8e5d 100644 --- a/libs/ardour/monitor_processor.cc +++ b/libs/ardour/monitor_processor.cc @@ -15,30 +15,68 @@ using namespace ARDOUR; using namespace PBD; using namespace std; +/* specialize for bool because of set_value() semantics */ + +namespace ARDOUR { + template<> void MPControl<bool>::set_value (float v) { + bool newval = fabs (v) >= 0.5; + if (newval != _value) { + _value = newval; + Changed(); /* EMIT SIGNAL */ + } + } +} + MonitorProcessor::MonitorProcessor (Session& s) : Processor (s, X_("MonitorOut")) + , solo_cnt (0) + + , _dim_all_ptr (new MPControl<bool> (false, _("monitor dim"), Controllable::Toggle)) + , _cut_all_ptr (new MPControl<bool> (false, _("monitor cut"), Controllable::Toggle)) + , _mono_ptr (new MPControl<bool> (false, _("monitor mono"), Controllable::Toggle)) + , _dim_level_ptr (new MPControl<volatile gain_t> + (0.2, _("monitor mono"), Controllable::Flag (0), 0.0f, 1.0f)) + , _solo_boost_level_ptr (new MPControl<volatile gain_t> + (1.0, _("monitor mono"), Controllable::Flag (0), 1.0f, 3.0f)) + + , _dim_all_control (_dim_all_ptr) + , _cut_all_control (_cut_all_ptr) + , _mono_control (_mono_ptr) + , _dim_level_control (_dim_level_ptr) + , _solo_boost_level_control (_solo_boost_level_ptr) + + , _dim_all (*_dim_all_ptr) + , _cut_all (*_cut_all_ptr) + , _mono (*_mono_ptr) + , _dim_level (*_dim_level_ptr) + , _solo_boost_level (*_solo_boost_level_ptr) + { - solo_cnt = 0; - _cut_all = false; - _dim_all = false; - _dim_level = 0.2; - _solo_boost_level = 1.0; +} + +MonitorProcessor::~MonitorProcessor () +{ + allocate_channels (0); } void MonitorProcessor::allocate_channels (uint32_t size) { while (_channels.size() > size) { - if (_channels.back().soloed) { + if (_channels.back()->soloed) { if (solo_cnt > 0) { --solo_cnt; } } + ChannelRecord* cr = _channels.back(); _channels.pop_back(); + delete cr; } + uint32_t n = _channels.size() + 1; + while (_channels.size() < size) { - _channels.push_back (ChannelRecord()); + _channels.push_back (new ChannelRecord (n)); } } @@ -74,12 +112,12 @@ MonitorProcessor::set_state (const XMLNode& node, int version) allocate_channels (atoi (prop->value())); if ((prop = node.property (X_("dim-level"))) != 0) { - double val = atof (prop->value()); + gain_t val = atof (prop->value()); _dim_level = val; } if ((prop = node.property (X_("solo-boost-level"))) != 0) { - double val = atof (prop->value()); + gain_t val = atof (prop->value()); _solo_boost_level = val; } @@ -118,7 +156,7 @@ MonitorProcessor::set_state (const XMLNode& node, int version) << endmsg; return -1; } - ChannelRecord& cr (_channels[chn]); + ChannelRecord& cr (*_channels[chn]); if ((prop = (*i)->property ("cut")) != 0) { if (string_is_affirmative (prop->value())){ @@ -152,8 +190,8 @@ MonitorProcessor::set_state (const XMLNode& node, int version) solo_cnt = 0; - for (vector<ChannelRecord>::const_iterator x = _channels.begin(); x != _channels.end(); ++x) { - if (x->soloed) { + for (vector<ChannelRecord*>::const_iterator x = _channels.begin(); x != _channels.end(); ++x) { + if ((*x)->soloed) { solo_cnt++; } } @@ -171,10 +209,10 @@ MonitorProcessor::state (bool full) node.add_property (X_("type"), X_("monitor")); - snprintf (buf, sizeof(buf), "%.12g", _dim_level); + snprintf (buf, sizeof(buf), "%.12g", _dim_level.val()); node.add_property (X_("dim-level"), buf); - snprintf (buf, sizeof(buf), "%.12g", _solo_boost_level); + snprintf (buf, sizeof(buf), "%.12g", _solo_boost_level.val()); node.add_property (X_("solo-boost-level"), buf); node.add_property (X_("cut-all"), (_cut_all ? "yes" : "no")); @@ -189,16 +227,16 @@ MonitorProcessor::state (bool full) XMLNode* chn_node; uint32_t chn = 0; - for (vector<ChannelRecord>::const_iterator x = _channels.begin(); x != _channels.end(); ++x, ++chn) { + for (vector<ChannelRecord*>::const_iterator x = _channels.begin(); x != _channels.end(); ++x, ++chn) { chn_node = new XMLNode (X_("Channel")); snprintf (buf, sizeof (buf), "%u", chn); chn_node->add_property ("id", buf); - - chn_node->add_property (X_("cut"), x->cut == 1.0 ? "no" : "yes"); - chn_node->add_property (X_("invert"), x->polarity == 1.0 ? "no" : "yes"); - chn_node->add_property (X_("dim"), x->dim ? "yes" : "no"); - chn_node->add_property (X_("solo"), x->soloed ? "yes" : "no"); + + chn_node->add_property (X_("cut"), (*x)->cut == 1.0f ? "no" : "yes"); + chn_node->add_property (X_("invert"), (*x)->polarity == 1.0f ? "no" : "yes"); + chn_node->add_property (X_("dim"), (*x)->dim ? "yes" : "no"); + chn_node->add_property (X_("solo"), (*x)->soloed ? "yes" : "no"); node.add_child_nocopy (*chn_node); } @@ -226,36 +264,38 @@ MonitorProcessor::run (BufferSet& bufs, sframes_t /*start_frame*/, sframes_t /*e /* don't double-scale by both track dim and global dim coefficients */ - gain_t dim_level = (global_dim == 1.0 ? (_channels[chn].dim ? dim_level_this_time : 1.0) : 1.0); + gain_t dim_level = (global_dim == 1.0 ? (_channels[chn]->dim ? dim_level_this_time : 1.0) : 1.0); - if (_channels[chn].soloed) { - target_gain = _channels[chn].polarity * _channels[chn].cut * dim_level * global_cut * global_dim * solo_boost; + if (_channels[chn]->soloed) { + target_gain = _channels[chn]->polarity * _channels[chn]->cut * dim_level * global_cut * global_dim * solo_boost; } else { if (solo_cnt == 0) { - target_gain = _channels[chn].polarity * _channels[chn].cut * dim_level * global_cut * global_dim * solo_boost; + target_gain = _channels[chn]->polarity * _channels[chn]->cut * dim_level * global_cut * global_dim * solo_boost; } else { target_gain = 0.0; } } DEBUG_TRACE (DEBUG::Monitor, - string_compose("channel %1 sb %2 gc %3 gd %4 cd %5 dl %6 cp %7 cc %8 cs %9 sc %10 TG %11\n", + string_compose("channel %1 SB %12 sb %2 gc %3 gd %4 cd %5 dl %6 cp %7 cc %8 cs %9 sc %10 TG %11\n", chn, solo_boost, global_cut, global_dim, - _channels[chn].dim, + _channels[chn]->dim, dim_level, - _channels[chn].polarity, - _channels[chn].cut, - _channels[chn].soloed, + _channels[chn]->polarity, + _channels[chn]->cut, + _channels[chn]->soloed, solo_cnt, - target_gain)); + target_gain, + (float) _solo_boost_level.val() + )); - if (target_gain != _channels[chn].current_gain || target_gain != 1.0f) { + if (target_gain != _channels[chn]->current_gain || target_gain != 1.0f) { - Amp::apply_gain (*b, nframes, _channels[chn].current_gain, target_gain); - _channels[chn].current_gain = target_gain; + Amp::apply_gain (*b, nframes, _channels[chn]->current_gain, target_gain); + _channels[chn]->current_gain = target_gain; } ++chn; @@ -317,33 +357,33 @@ void MonitorProcessor::set_polarity (uint32_t chn, bool invert) { if (invert) { - _channels[chn].polarity = -1.0f; + _channels[chn]->polarity = -1.0f; } else { - _channels[chn].polarity = 1.0f; + _channels[chn]->polarity = 1.0f; } } void MonitorProcessor::set_dim (uint32_t chn, bool yn) { - _channels[chn].dim = yn; + _channels[chn]->dim = yn; } void MonitorProcessor::set_cut (uint32_t chn, bool yn) { if (yn) { - _channels[chn].cut = 0.0f; + _channels[chn]->cut = 0.0f; } else { - _channels[chn].cut = 1.0f; + _channels[chn]->cut = 1.0f; } } void MonitorProcessor::set_solo (uint32_t chn, bool solo) { - if (solo != _channels[chn].soloed) { - _channels[chn].soloed = solo; + if (solo != _channels[chn]->soloed) { + _channels[chn]->soloed = solo; if (solo) { solo_cnt++; @@ -394,27 +434,27 @@ MonitorProcessor::set_solo_boost_level (gain_t val) bool MonitorProcessor::soloed (uint32_t chn) const { - return _channels[chn].soloed; + return _channels[chn]->soloed; } bool MonitorProcessor::inverted (uint32_t chn) const { - return _channels[chn].polarity < 0.0f; + return _channels[chn]->polarity < 0.0f; } bool MonitorProcessor::cut (uint32_t chn) const { - return _channels[chn].cut == 0.0f; + return _channels[chn]->cut == 0.0f; } bool MonitorProcessor::dimmed (uint32_t chn) const { - return _channels[chn].dim; + return _channels[chn]->dim; } bool @@ -434,3 +474,39 @@ MonitorProcessor::cut_all () const { return _cut_all; } + +boost::shared_ptr<Controllable> +MonitorProcessor::channel_cut_control (uint32_t chn) const +{ + if (chn < _channels.size()) { + return _channels[chn]->cut_control; + } + return boost::shared_ptr<Controllable>(); +} + +boost::shared_ptr<Controllable> +MonitorProcessor::channel_dim_control (uint32_t chn) const +{ + if (chn < _channels.size()) { + return _channels[chn]->dim_control; + } + return boost::shared_ptr<Controllable>(); +} + +boost::shared_ptr<Controllable> +MonitorProcessor::channel_polarity_control (uint32_t chn) const +{ + if (chn < _channels.size()) { + return _channels[chn]->polarity_control; + } + return boost::shared_ptr<Controllable>(); +} + +boost::shared_ptr<Controllable> +MonitorProcessor::channel_solo_control (uint32_t chn) const +{ + if (chn < _channels.size()) { + return _channels[chn]->soloed_control; + } + return boost::shared_ptr<Controllable>(); +} diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index ad04552820..22d2fc8037 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -2245,7 +2245,7 @@ Session::route_solo_changed (void* /*src*/, boost::weak_ptr<Route> wpr) delta = -1; } - /* now mod the solo level of all other routes except master & control outs + /* now mod the solo level of all other routes except master/control outs/auditioner so that they will be silent if appropriate. */ @@ -2269,12 +2269,18 @@ Session::route_solo_changed (void* /*src*/, boost::weak_ptr<Route> wpr) _master_out->mod_solo_by_others (1); } - /* ditto for control outs make sure master is never muted by solo */ + /* ditto for control outs make sure it is never muted by solo */ if (_monitor_out && route != _monitor_out && _monitor_out && _monitor_out->soloed_by_others() == 0) { _monitor_out->mod_solo_by_others (1); } + /* ditto for auditioner make sure it is never muted by solo */ + + if (auditioner) { + auditioner->mod_solo_by_others (1); + } + solo_update_disabled = false; update_route_solo_state (r); SoloChanged (); /* EMIT SIGNAL */ @@ -2300,7 +2306,11 @@ Session::update_route_solo_state (boost::shared_ptr<RouteList> r) } if (!(*i)->is_hidden() && (*i)->listening()) { - listeners++; + if (Config->get_solo_control_is_listen_control()) { + listeners++; + } else { + (*i)->set_listen (false, this); + } } } |