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/vca.h"
25 #include "ardour/vca_manager.h"
29 using namespace ARDOUR;
30 using namespace Glib::Threads;
34 string VCAManager::xml_node_name (X_("VCAManager"));
36 VCAManager::VCAManager (Session& s)
37 : SessionHandleRef (s)
38 , _vcas_loaded (false)
42 VCAManager::~VCAManager ()
50 Mutex::Lock lm (lock);
55 VCAManager::vcas () const
57 Mutex::Lock lm (lock);
62 VCAManager::create_vca (uint32_t howmany, std::string const & name_template)
67 Mutex::Lock lm (lock);
69 for (uint32_t n = 0; n < howmany; ++n) {
71 int num = VCA::next_vca_number ();
72 string name = name_template;
74 if (name.find ("%n")) {
75 string sn = PBD::to_string (num, std::dec);
76 replace_all (name, "%n", sn);
79 boost::shared_ptr<VCA> vca = boost::shared_ptr<VCA> (new VCA (_session, num, name));
83 _vcas.push_back (vca);
88 VCAAdded (vcal); /* EMIT SIGNAL */
95 VCAManager::remove_vca (boost::shared_ptr<VCA> vca)
98 Mutex::Lock lm (lock);
103 vcal.push_back (vca);
105 VCARemoved (vcal); /* EMIT SIGNAL */
108 boost::shared_ptr<VCA>
109 VCAManager::vca_by_number (uint32_t n) const
111 Mutex::Lock lm (lock);
113 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
114 if ((*i)->number() == n) {
119 return boost::shared_ptr<VCA>();
123 VCAManager::get_state ()
125 XMLNode* node = new XMLNode (xml_node_name);
128 Mutex::Lock lm (lock);
130 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
131 node->add_child_nocopy ((*i)->get_state());
139 VCAManager::set_state (XMLNode const& node, int version)
141 if (node.name() != xml_node_name) {
145 XMLNodeList const & children = node.children();
148 _vcas_loaded = false;
150 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
151 if ((*i)->name() == VCA::xml_node_name) {
152 boost::shared_ptr<VCA> vca = boost::shared_ptr<VCA> (new VCA (_session, 0, X_("tobereset")));
154 if (vca->init() || vca->set_state (**i, version)) {
155 error << _("Cannot set state of a VCA") << endmsg;
159 /* can't hold the lock for the entire loop,
160 * because the new VCA maybe slaved and needs
161 * to call back into us to set up its own
162 * slave/master relationship
166 Mutex::Lock lm (lock);
167 _vcas.push_back (vca);
168 vcal.push_back (vca);
175 VCAsLoaded (); /* EMIT SIGNAL */
176 VCAAdded (vcal); /* EMIT SIGNAL */