expand and improve VCA API
authorPaul Davis <paul@linuxaudiosystems.com>
Mon, 29 Feb 2016 19:44:25 +0000 (14:44 -0500)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 31 May 2016 19:30:38 +0000 (15:30 -0400)
libs/ardour/ardour/vca.h
libs/ardour/ardour/vca_manager.h
libs/ardour/vca.cc
libs/ardour/vca_manager.cc

index 9a4ff0f602bf84f35bcfdfc62fd51beff6ede7a1..a4e2e9f4df8199cdfe7ee7aab43bbd204a55297e 100644 (file)
@@ -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<Route>);
        void remove (boost::shared_ptr<Route>);
 
+       static std::string default_name_template ();
+       static int next_vca_number ();
   private:
+       uint32_t    _number;
        std::string _name;
        boost::shared_ptr<GainControl> _control;
+
+       static gint next_number;
 };
 
 } /* namespace */
index 54cc14b572016d3957ca61a67909fd78a1f412a8..764b966941e7ba527bf79c37e2fb763c12be64f1 100644 (file)
@@ -42,9 +42,11 @@ class VCAManager : public SessionHandleRef
        VCAManager (ARDOUR::Session&);
        ~VCAManager ();
 
-       boost::shared_ptr<VCA> 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<VCA>);
 
+       boost::shared_ptr<VCA> vca_by_number(uint32_t) const;
+
        typedef std::list<boost::shared_ptr<VCA> > VCAS;
        VCAS vcas() const;
 
index b49489dfe7ded9f97ddda8caa2834470d90c3c34..67ca4733cb94fa60f6c6cc7a2081b33c8024be21 100644 (file)
 #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<AutomationList> ()))
 {
 }
@@ -48,6 +66,7 @@ void
 VCA::add (boost::shared_ptr<Route> r)
 {
        boost::dynamic_pointer_cast<GainControl>(r->gain_control())->add_master (_control);
+       std::cerr << name() << " now controlling " << r->name() << std::endl;
 }
 
 void
index c5164982c343cde5ca4766abb034b1e621065335..476cd02bdad48775bad9c843098f3b81f74a4ce9 100644 (file)
@@ -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<VCA>
-VCAManager::create_vca (std::string const & name)
+int
+VCAManager::create_vca (uint32_t howmany, std::string const & name_template)
 {
-       boost::shared_ptr<VCA> vca = boost::shared_ptr<VCA> (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> vca = boost::shared_ptr<VCA> (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> vca)
        VCARemoved (vcal); /* EMIT SIGNAL */
 }
 
+boost::shared_ptr<VCA>
+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<VCA>();
+}