2 * Copyright (C) 2016 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2017-2019 Robin Gareus <robin@gareus.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 if (!vcal.empty ()) {
115 VCACreated (); /* EMIT SIGNAL */
118 _session.set_dirty ();
124 VCAManager::remove_vca (boost::shared_ptr<VCA> vca)
127 Mutex::Lock lm (lock);
131 /* this should cause deassignment and deletion */
133 vca->DropReferences ();
135 if (vca->is_selected () && !_session.deletion_in_progress ()) {
136 _session.selection().remove_stripable_by_id (vca->id());
138 pc.add (Properties::selected);
139 PresentationInfo::Change (pc);
141 _session.set_dirty ();
144 boost::shared_ptr<VCA>
145 VCAManager::vca_by_number (int32_t n) const
147 Mutex::Lock lm (lock);
149 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
150 if ((*i)->number() == n) {
155 return boost::shared_ptr<VCA>();
158 boost::shared_ptr<VCA>
159 VCAManager::vca_by_name (std::string const& name) const
161 Mutex::Lock lm (lock);
163 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
164 if ((*i)->name() == name || (*i)->full_name() == name) {
169 return boost::shared_ptr<VCA>();
173 VCAManager::get_state ()
175 XMLNode* node = new XMLNode (xml_node_name);
178 Mutex::Lock lm (lock);
180 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
181 node->add_child_nocopy ((*i)->get_state());
189 VCAManager::set_state (XMLNode const& node, int version)
191 if (node.name() != xml_node_name) {
195 XMLNodeList const & children = node.children();
198 _vcas_loaded = false;
200 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
201 if ((*i)->name() == VCA::xml_node_name) {
202 boost::shared_ptr<VCA> vca = boost::shared_ptr<VCA> (new VCA (_session, 0, X_("tobereset")));
203 BOOST_MARK_VCA (vca);
205 if (vca->init() || vca->set_state (**i, version)) {
206 error << _("Cannot set state of a VCA") << endmsg;
210 /* can't hold the lock for the entire loop,
211 * because the new VCA maybe slaved and needs
212 * to call back into us to set up its own
213 * slave/master relationship
217 Mutex::Lock lm (lock);
218 _vcas.push_back (vca);
219 vcal.push_back (vca);
226 VCAAdded (vcal); /* EMIT SIGNAL */
232 VCAManager::clear_all_solo_state ()
234 Mutex::Lock lm (lock);
236 for (VCAList::const_iterator i = _vcas.begin(); i != _vcas.end(); ++i) {
237 (*i)->clear_all_solo_state ();