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/error.h"
21 #include "pbd/replace_all.h"
22 #include "pbd/string_convert.h"
24 #include "ardour/boost_debug.h"
25 #include "ardour/session.h"
26 #include "ardour/slavable.h"
27 #include "ardour/vca.h"
28 #include "ardour/vca_manager.h"
32 using namespace ARDOUR;
33 using namespace Glib::Threads;
37 string VCAManager::xml_node_name (X_("VCAManager"));
39 VCAManager::VCAManager (Session& s)
40 : SessionHandleRef (s)
41 , _vcas_loaded (false)
45 VCAManager::~VCAManager ()
53 Mutex::Lock lm (lock);
54 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
55 (*i)->DropReferences ();
61 VCAManager::vcas () const
63 Mutex::Lock lm (lock);
68 VCAManager::create_vca (uint32_t howmany, std::string const & name_template)
72 uint32_t n_stripables = _session.nstripables ();
75 Mutex::Lock lm (lock);
77 for (uint32_t n = 0; n < howmany; ++n) {
79 int num = VCA::next_vca_number ();
80 string name = name_template;
82 if (name.find ("%n")) {
83 string sn = PBD::to_string (num);
84 replace_all (name, "%n", sn);
87 boost::shared_ptr<VCA> vca = boost::shared_ptr<VCA> (new VCA (_session, num, name));
91 vca->set_presentation_order (n + n_stripables);
93 _vcas.push_back (vca);
98 VCAAdded (vcal); /* EMIT SIGNAL */
100 _session.set_dirty ();
107 VCAManager::remove_vca (boost::shared_ptr<VCA> vca)
110 Mutex::Lock lm (lock);
114 /* this should cause deassignment and deletion */
116 vca->DropReferences ();
118 _session.set_dirty ();
121 boost::shared_ptr<VCA>
122 VCAManager::vca_by_number (int32_t n) const
124 Mutex::Lock lm (lock);
126 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
127 if ((*i)->number() == n) {
132 return boost::shared_ptr<VCA>();
136 VCAManager::get_state ()
138 XMLNode* node = new XMLNode (xml_node_name);
141 Mutex::Lock lm (lock);
143 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
144 node->add_child_nocopy ((*i)->get_state());
152 VCAManager::set_state (XMLNode const& node, int version)
154 if (node.name() != xml_node_name) {
158 XMLNodeList const & children = node.children();
161 _vcas_loaded = false;
163 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
164 if ((*i)->name() == VCA::xml_node_name) {
165 boost::shared_ptr<VCA> vca = boost::shared_ptr<VCA> (new VCA (_session, 0, X_("tobereset")));
166 BOOST_MARK_VCA (vca);
168 if (vca->init() || vca->set_state (**i, version)) {
169 error << _("Cannot set state of a VCA") << endmsg;
173 /* can't hold the lock for the entire loop,
174 * because the new VCA maybe slaved and needs
175 * to call back into us to set up its own
176 * slave/master relationship
180 Mutex::Lock lm (lock);
181 _vcas.push_back (vca);
182 vcal.push_back (vca);
189 VCAAdded (vcal); /* EMIT SIGNAL */
195 VCAManager::clear_all_solo_state ()
197 Mutex::Lock lm (lock);
199 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
200 (*i)->clear_all_solo_state ();