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/selection.h"
26 #include "ardour/session.h"
27 #include "ardour/slavable.h"
28 #include "ardour/vca.h"
29 #include "ardour/vca_manager.h"
33 using namespace ARDOUR;
34 using namespace Glib::Threads;
38 string VCAManager::xml_node_name (X_("VCAManager"));
40 VCAManager::VCAManager (Session& s)
41 : SessionHandleRef (s)
42 , _vcas_loaded (false)
46 VCAManager::~VCAManager ()
56 Mutex::Lock lm (lock);
57 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
58 if ((*i)->is_selected ()) {
59 _session.selection().remove_stripable_by_id ((*i)->id());
62 (*i)->DropReferences ();
67 if (send && !_session.deletion_in_progress ()) {
69 pc.add (Properties::selected);
70 PresentationInfo::Change (pc);
75 VCAManager::vcas () const
77 Mutex::Lock lm (lock);
82 VCAManager::create_vca (uint32_t howmany, std::string const & name_template)
86 uint32_t n_stripables = _session.nstripables ();
89 Mutex::Lock lm (lock);
91 for (uint32_t n = 0; n < howmany; ++n) {
93 int num = VCA::next_vca_number ();
94 string name = name_template;
96 if (name.find ("%n")) {
97 string sn = PBD::to_string (num);
98 replace_all (name, "%n", sn);
101 boost::shared_ptr<VCA> vca = boost::shared_ptr<VCA> (new VCA (_session, num, name));
102 BOOST_MARK_VCA (vca);
105 vca->set_presentation_order (n + n_stripables);
107 _vcas.push_back (vca);
108 vcal.push_back (vca);
112 VCAAdded (vcal); /* EMIT SIGNAL */
114 _session.set_dirty ();
121 VCAManager::remove_vca (boost::shared_ptr<VCA> vca)
124 Mutex::Lock lm (lock);
128 /* this should cause deassignment and deletion */
130 vca->DropReferences ();
132 if (vca->is_selected () && !_session.deletion_in_progress ()) {
133 _session.selection().remove_stripable_by_id (vca->id());
135 pc.add (Properties::selected);
136 PresentationInfo::Change (pc);
138 _session.set_dirty ();
141 boost::shared_ptr<VCA>
142 VCAManager::vca_by_number (int32_t n) const
144 Mutex::Lock lm (lock);
146 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
147 if ((*i)->number() == n) {
152 return boost::shared_ptr<VCA>();
155 boost::shared_ptr<VCA>
156 VCAManager::vca_by_name (std::string const& name) const
158 Mutex::Lock lm (lock);
160 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
161 if ((*i)->name() == name || (*i)->full_name() == name) {
166 return boost::shared_ptr<VCA>();
170 VCAManager::get_state ()
172 XMLNode* node = new XMLNode (xml_node_name);
175 Mutex::Lock lm (lock);
177 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
178 node->add_child_nocopy ((*i)->get_state());
186 VCAManager::set_state (XMLNode const& node, int version)
188 if (node.name() != xml_node_name) {
192 XMLNodeList const & children = node.children();
195 _vcas_loaded = false;
197 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
198 if ((*i)->name() == VCA::xml_node_name) {
199 boost::shared_ptr<VCA> vca = boost::shared_ptr<VCA> (new VCA (_session, 0, X_("tobereset")));
200 BOOST_MARK_VCA (vca);
202 if (vca->init() || vca->set_state (**i, version)) {
203 error << _("Cannot set state of a VCA") << endmsg;
207 /* can't hold the lock for the entire loop,
208 * because the new VCA maybe slaved and needs
209 * to call back into us to set up its own
210 * slave/master relationship
214 Mutex::Lock lm (lock);
215 _vcas.push_back (vca);
216 vcal.push_back (vca);
223 VCAAdded (vcal); /* EMIT SIGNAL */
229 VCAManager::clear_all_solo_state ()
231 Mutex::Lock lm (lock);
233 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
234 (*i)->clear_all_solo_state ();