From f44cac5cc60c0ad93da3a44db2517f09cc82f345 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 29 Feb 2016 14:44:25 -0500 Subject: expand and improve VCA API --- libs/ardour/ardour/vca.h | 8 ++++++- libs/ardour/ardour/vca_manager.h | 4 +++- libs/ardour/vca.cc | 23 ++++++++++++++++++-- libs/ardour/vca_manager.cc | 45 +++++++++++++++++++++++++++++++++------- 4 files changed, 68 insertions(+), 12 deletions(-) diff --git a/libs/ardour/ardour/vca.h b/libs/ardour/ardour/vca.h index 9a4ff0f602..a4e2e9f4df 100644 --- a/libs/ardour/ardour/vca.h +++ b/libs/ardour/ardour/vca.h @@ -33,9 +33,10 @@ class Route; class LIBARDOUR_API VCA : public SessionHandleRef { public: - VCA (Session& session, const std::string& name); + VCA (Session& session, const std::string& name, uint32_t num); std::string name() const { return _name; } + uint32_t number () const { return _number; } void set_value (double val, PBD::Controllable::GroupControlDisposition group_override); double get_value () const; @@ -45,9 +46,14 @@ class LIBARDOUR_API VCA : public SessionHandleRef { void add (boost::shared_ptr); void remove (boost::shared_ptr); + static std::string default_name_template (); + static int next_vca_number (); private: + uint32_t _number; std::string _name; boost::shared_ptr _control; + + static gint next_number; }; } /* namespace */ diff --git a/libs/ardour/ardour/vca_manager.h b/libs/ardour/ardour/vca_manager.h index 54cc14b572..764b966941 100644 --- a/libs/ardour/ardour/vca_manager.h +++ b/libs/ardour/ardour/vca_manager.h @@ -42,9 +42,11 @@ class VCAManager : public SessionHandleRef VCAManager (ARDOUR::Session&); ~VCAManager (); - boost::shared_ptr create_vca (std::string const & name = std::string()); + int create_vca (uint32_t n, std::string const & name = std::string()); void remove_vca (boost::shared_ptr); + boost::shared_ptr vca_by_number(uint32_t) const; + typedef std::list > VCAS; VCAS vcas() const; diff --git a/libs/ardour/vca.cc b/libs/ardour/vca.cc index b49489dfe7..67ca4733cb 100644 --- a/libs/ardour/vca.cc +++ b/libs/ardour/vca.cc @@ -21,13 +21,31 @@ #include "ardour/route.h" #include "ardour/vca.h" +#include "i18n.h" + using namespace ARDOUR; using namespace PBD; using std::string; -VCA::VCA (Session& s, const string& n) +gint VCA::next_number = 0; + +string +VCA::default_name_template () +{ + return _("VCA %n"); +} + +int +VCA::next_vca_number () +{ + /* recall that atomic_int_add() returns the value before the add */ + return g_atomic_int_add (&next_number, 1) + 1; +} + +VCA::VCA (Session& s, const string& name, uint32_t num) : SessionHandleRef (s) - , _name (n) + , _number (num) + , _name (name) , _control (new GainControl (s, Evoral::Parameter (GainAutomation), boost::shared_ptr ())) { } @@ -48,6 +66,7 @@ void VCA::add (boost::shared_ptr r) { boost::dynamic_pointer_cast(r->gain_control())->add_master (_control); + std::cerr << name() << " now controlling " << r->name() << std::endl; } void diff --git a/libs/ardour/vca_manager.cc b/libs/ardour/vca_manager.cc index c5164982c3..476cd02bda 100644 --- a/libs/ardour/vca_manager.cc +++ b/libs/ardour/vca_manager.cc @@ -17,6 +17,9 @@ */ +#include "pbd/convert.h" +#include "pbd/replace_all.h" + #include "ardour/vca.h" #include "ardour/vca_manager.h" @@ -41,21 +44,34 @@ VCAManager::vcas () const return _vcas; } -boost::shared_ptr -VCAManager::create_vca (std::string const & name) +int +VCAManager::create_vca (uint32_t howmany, std::string const & name_template) { - boost::shared_ptr vca = boost::shared_ptr (new VCA (_session, name)); + VCAList vcal; + { Mutex::Lock lm (lock); - _vcas.push_back (vca); - } - VCAList vcal; - vcal.push_back (vca); + for (uint32_t n = 0; n < howmany; ++n) { + + int num = VCA::next_vca_number (); + string name = name_template; + + if (name.find ("%n")) { + string sn = PBD::to_string (n, std::dec); + replace_all (name, "%n", sn); + } + + boost::shared_ptr vca = boost::shared_ptr (new VCA (_session, name, num)); + + _vcas.push_back (vca); + vcal.push_back (vca); + } + } VCAAdded (vcal); /* EMIT SIGNAL */ - return vca; + return 0; } @@ -73,3 +89,16 @@ VCAManager::remove_vca (boost::shared_ptr vca) VCARemoved (vcal); /* EMIT SIGNAL */ } +boost::shared_ptr +VCAManager::vca_by_number (uint32_t n) const +{ + Mutex::Lock lm (lock); + + for (VCAS::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) { + if ((*i)->number() == n) { + return *i; + } + } + + return boost::shared_ptr(); +} -- cgit v1.2.3