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 ();
111 std::cerr << "After DR, uc = " << vca.use_count() << std::endl;
114 boost::shared_ptr<VCA>
115 VCAManager::vca_by_number (uint32_t n) const
117 Mutex::Lock lm (lock);
119 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
120 if ((*i)->number() == n) {
125 return boost::shared_ptr<VCA>();
129 VCAManager::get_state ()
131 XMLNode* node = new XMLNode (xml_node_name);
134 Mutex::Lock lm (lock);
136 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
137 node->add_child_nocopy ((*i)->get_state());
145 VCAManager::set_state (XMLNode const& node, int version)
147 if (node.name() != xml_node_name) {
151 XMLNodeList const & children = node.children();
154 _vcas_loaded = false;
156 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
157 if ((*i)->name() == VCA::xml_node_name) {
158 boost::shared_ptr<VCA> vca = boost::shared_ptr<VCA> (new VCA (_session, 0, X_("tobereset")));
159 BOOST_MARK_VCA (vca);
161 if (vca->init() || vca->set_state (**i, version)) {
162 error << _("Cannot set state of a VCA") << endmsg;
166 /* can't hold the lock for the entire loop,
167 * because the new VCA maybe slaved and needs
168 * to call back into us to set up its own
169 * slave/master relationship
173 Mutex::Lock lm (lock);
174 _vcas.push_back (vca);
175 vcal.push_back (vca);
182 VCAAdded (vcal); /* EMIT SIGNAL */
188 VCAManager::clear_all_solo_state ()
190 Mutex::Lock lm (lock);
192 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
193 (*i)->clear_all_solo_state ();