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/error.h"
22 #include "pbd/replace_all.h"
24 #include "ardour/boost_debug.h"
25 #include "ardour/slavable.h"
26 #include "ardour/vca.h"
27 #include "ardour/vca_manager.h"
31 using namespace ARDOUR;
32 using namespace Glib::Threads;
36 string VCAManager::xml_node_name (X_("VCAManager"));
38 VCAManager::VCAManager (Session& s)
39 : SessionHandleRef (s)
40 , _vcas_loaded (false)
44 VCAManager::~VCAManager ()
52 Mutex::Lock lm (lock);
53 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
54 (*i)->DropReferences ();
60 VCAManager::vcas () const
62 Mutex::Lock lm (lock);
67 VCAManager::create_vca (uint32_t howmany, std::string const & name_template)
72 Mutex::Lock lm (lock);
74 for (uint32_t n = 0; n < howmany; ++n) {
76 int num = VCA::next_vca_number ();
77 string name = name_template;
79 if (name.find ("%n")) {
80 string sn = PBD::to_string (num, std::dec);
81 replace_all (name, "%n", sn);
84 boost::shared_ptr<VCA> vca = boost::shared_ptr<VCA> (new VCA (_session, num, name));
89 _vcas.push_back (vca);
94 VCAAdded (vcal); /* EMIT SIGNAL */
101 VCAManager::remove_vca (boost::shared_ptr<VCA> vca)
104 Mutex::Lock lm (lock);
108 /* this should cause deassignment and deletion */
110 vca->DropReferences ();
113 boost::shared_ptr<VCA>
114 VCAManager::vca_by_number (uint32_t n) const
116 Mutex::Lock lm (lock);
118 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
119 if ((*i)->number() == n) {
124 return boost::shared_ptr<VCA>();
128 VCAManager::get_state ()
130 XMLNode* node = new XMLNode (xml_node_name);
133 Mutex::Lock lm (lock);
135 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
136 node->add_child_nocopy ((*i)->get_state());
144 VCAManager::set_state (XMLNode const& node, int version)
146 if (node.name() != xml_node_name) {
150 XMLNodeList const & children = node.children();
153 _vcas_loaded = false;
155 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
156 if ((*i)->name() == VCA::xml_node_name) {
157 boost::shared_ptr<VCA> vca = boost::shared_ptr<VCA> (new VCA (_session, 0, X_("tobereset")));
158 BOOST_MARK_VCA (vca);
160 if (vca->init() || vca->set_state (**i, version)) {
161 error << _("Cannot set state of a VCA") << endmsg;
165 /* can't hold the lock for the entire loop,
166 * because the new VCA maybe slaved and needs
167 * to call back into us to set up its own
168 * slave/master relationship
172 Mutex::Lock lm (lock);
173 _vcas.push_back (vca);
174 vcal.push_back (vca);
181 VCAAdded (vcal); /* EMIT SIGNAL */
187 VCAManager::clear_all_solo_state ()
189 Mutex::Lock lm (lock);
191 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
192 (*i)->clear_all_solo_state ();