2 Copyright (C) 2016 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "pbd/convert.h"
21 #include "pbd/replace_all.h"
23 #include "ardour/vca.h"
24 #include "ardour/vca_manager.h"
28 using namespace ARDOUR;
29 using namespace Glib::Threads;
32 string VCAManager::xml_node_name (X_("VCAManager"));
34 VCAManager::VCAManager (Session& s)
35 : SessionHandleRef (s)
36 , _vcas_loaded (false)
40 VCAManager::~VCAManager ()
48 Mutex::Lock lm (lock);
53 VCAManager::vcas () const
55 Mutex::Lock lm (lock);
60 VCAManager::create_vca (uint32_t howmany, std::string const & name_template)
65 Mutex::Lock lm (lock);
67 for (uint32_t n = 0; n < howmany; ++n) {
69 int num = VCA::next_vca_number ();
70 string name = name_template;
72 if (name.find ("%n")) {
73 string sn = PBD::to_string (num, std::dec);
74 replace_all (name, "%n", sn);
77 boost::shared_ptr<VCA> vca = boost::shared_ptr<VCA> (new VCA (_session, num, name));
79 _vcas.push_back (vca);
84 VCAAdded (vcal); /* EMIT SIGNAL */
91 VCAManager::remove_vca (boost::shared_ptr<VCA> vca)
94 Mutex::Lock lm (lock);
101 VCARemoved (vcal); /* EMIT SIGNAL */
104 boost::shared_ptr<VCA>
105 VCAManager::vca_by_number (uint32_t n) const
107 Mutex::Lock lm (lock);
109 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
110 if ((*i)->number() == n) {
115 return boost::shared_ptr<VCA>();
119 VCAManager::get_state ()
121 XMLNode* node = new XMLNode (xml_node_name);
124 Mutex::Lock lm (lock);
126 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
127 node->add_child_nocopy ((*i)->get_state());
135 VCAManager::set_state (XMLNode const& node, int version)
137 if (node.name() != xml_node_name) {
141 XMLNodeList const & children = node.children();
144 _vcas_loaded = false;
146 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
147 if ((*i)->name() == VCA::xml_node_name) {
148 boost::shared_ptr<VCA> vca = boost::shared_ptr<VCA> (new VCA (_session, **i, version));
150 /* can't hold the lock for the entire loop,
151 * because the new VCA maybe slaved and needs
152 * to call back into us to set up its own
153 * slave/master relationship
157 Mutex::Lock lm (lock);
158 _vcas.push_back (vca);
159 vcal.push_back (vca);
166 VCAsLoaded (); /* EMIT SIGNAL */
167 VCAAdded (vcal); /* EMIT SIGNAL */