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 ();
120 VCAManager::remove_vca (boost::shared_ptr<VCA> vca)
123 Mutex::Lock lm (lock);
127 /* this should cause deassignment and deletion */
129 vca->DropReferences ();
131 if (vca->is_selected () && !_session.deletion_in_progress ()) {
132 _session.selection().remove_stripable_by_id (vca->id());
134 pc.add (Properties::selected);
135 PresentationInfo::Change (pc);
137 _session.set_dirty ();
140 boost::shared_ptr<VCA>
141 VCAManager::vca_by_number (int32_t n) const
143 Mutex::Lock lm (lock);
145 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
146 if ((*i)->number() == n) {
151 return boost::shared_ptr<VCA>();
154 boost::shared_ptr<VCA>
155 VCAManager::vca_by_name (std::string const& name) const
157 Mutex::Lock lm (lock);
159 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
160 if ((*i)->name() == name || (*i)->full_name() == name) {
165 return boost::shared_ptr<VCA>();
169 VCAManager::get_state ()
171 XMLNode* node = new XMLNode (xml_node_name);
174 Mutex::Lock lm (lock);
176 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
177 node->add_child_nocopy ((*i)->get_state());
185 VCAManager::set_state (XMLNode const& node, int version)
187 if (node.name() != xml_node_name) {
191 XMLNodeList const & children = node.children();
194 _vcas_loaded = false;
196 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
197 if ((*i)->name() == VCA::xml_node_name) {
198 boost::shared_ptr<VCA> vca = boost::shared_ptr<VCA> (new VCA (_session, 0, X_("tobereset")));
199 BOOST_MARK_VCA (vca);
201 if (vca->init() || vca->set_state (**i, version)) {
202 error << _("Cannot set state of a VCA") << endmsg;
206 /* can't hold the lock for the entire loop,
207 * because the new VCA maybe slaved and needs
208 * to call back into us to set up its own
209 * slave/master relationship
213 Mutex::Lock lm (lock);
214 _vcas.push_back (vca);
215 vcal.push_back (vca);
222 VCAAdded (vcal); /* EMIT SIGNAL */
228 VCAManager::clear_all_solo_state ()
230 Mutex::Lock lm (lock);
232 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
233 (*i)->clear_all_solo_state ();