2 Copyright (C) 2000-2009 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.
24 #include "pbd/error.h"
25 #include "pbd/enumwriter.h"
26 #include "pbd/strsplit.h"
27 #include "pbd/debug.h"
29 #include "ardour/amp.h"
30 #include "ardour/audio_track.h"
31 #include "ardour/monitor_control.h"
32 #include "ardour/route.h"
33 #include "ardour/route_group.h"
34 #include "ardour/session.h"
38 using namespace ARDOUR;
43 namespace Properties {
44 PropertyDescriptor<bool> relative;
45 PropertyDescriptor<bool> active;
46 PropertyDescriptor<bool> gain;
47 PropertyDescriptor<bool> mute;
48 PropertyDescriptor<bool> solo;
49 PropertyDescriptor<bool> recenable;
50 PropertyDescriptor<bool> select;
51 PropertyDescriptor<bool> route_active;
52 PropertyDescriptor<bool> color;
53 PropertyDescriptor<bool> monitoring;
58 RouteGroup::make_property_quarks ()
60 Properties::relative.property_id = g_quark_from_static_string (X_("relative"));
61 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for relative = %1\n", Properties::relative.property_id));
62 Properties::active.property_id = g_quark_from_static_string (X_("active"));
63 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for active = %1\n", Properties::active.property_id));
64 Properties::hidden.property_id = g_quark_from_static_string (X_("hidden"));
65 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for hidden = %1\n", Properties::hidden.property_id));
66 Properties::gain.property_id = g_quark_from_static_string (X_("gain"));
67 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for gain = %1\n", Properties::gain.property_id));
68 Properties::mute.property_id = g_quark_from_static_string (X_("mute"));
69 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for mute = %1\n", Properties::mute.property_id));
70 Properties::solo.property_id = g_quark_from_static_string (X_("solo"));
71 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for solo = %1\n", Properties::solo.property_id));
72 Properties::recenable.property_id = g_quark_from_static_string (X_("recenable"));
73 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for recenable = %1\n", Properties::recenable.property_id));
74 Properties::select.property_id = g_quark_from_static_string (X_("select"));
75 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for select = %1\n", Properties::select.property_id));
76 Properties::route_active.property_id = g_quark_from_static_string (X_("route-active"));
77 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for route-active = %1\n", Properties::route_active.property_id));
78 Properties::color.property_id = g_quark_from_static_string (X_("color"));
79 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for color = %1\n", Properties::color.property_id));
80 Properties::monitoring.property_id = g_quark_from_static_string (X_("monitoring"));
81 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for monitoring = %1\n", Properties::monitoring.property_id));
84 #define ROUTE_GROUP_DEFAULT_PROPERTIES _relative (Properties::relative, true) \
85 , _active (Properties::active, true) \
86 , _hidden (Properties::hidden, false) \
87 , _gain (Properties::gain, true) \
88 , _mute (Properties::mute, true) \
89 , _solo (Properties::solo, true) \
90 , _recenable (Properties::recenable, true) \
91 , _select (Properties::select, true) \
92 , _route_active (Properties::route_active, true) \
93 , _color (Properties::color, true) \
94 , _monitoring (Properties::monitoring, true)
96 RouteGroup::RouteGroup (Session& s, const string &n)
97 : SessionObject (s, n)
98 , routes (new RouteList)
99 , ROUTE_GROUP_DEFAULT_PROPERTIES
100 , _solo_group (new ControlGroup (SoloAutomation))
101 , _mute_group (new ControlGroup (MuteAutomation))
102 , _rec_enable_group (new ControlGroup (RecEnableAutomation))
103 , _gain_group (new ControlGroup (GainAutomation))
104 , _monitoring_group (new ControlGroup (MonitoringAutomation))
106 _xml_node_name = X_("RouteGroup");
108 add_property (_relative);
109 add_property (_active);
110 add_property (_hidden);
111 add_property (_gain);
112 add_property (_mute);
113 add_property (_solo);
114 add_property (_recenable);
115 add_property (_select);
116 add_property (_route_active);
117 add_property (_color);
118 add_property (_monitoring);
121 RouteGroup::~RouteGroup ()
123 _solo_group->clear ();
124 _mute_group->clear ();
125 _gain_group->clear ();
126 _rec_enable_group->clear ();
127 _monitoring_group->clear ();
129 for (RouteList::iterator i = routes->begin(); i != routes->end();) {
130 RouteList::iterator tmp = i;
133 (*i)->set_route_group (0);
139 /** Add a route to a group. Adding a route which is already in the group is allowed; nothing will happen.
140 * @param r Route to add.
143 RouteGroup::add (boost::shared_ptr<Route> r)
145 if (find (routes->begin(), routes->end(), r) != routes->end()) {
149 if (r->route_group()) {
150 r->route_group()->remove (r);
153 routes->push_back (r);
155 _solo_group->add_control (r->solo_control());
156 _mute_group->add_control (r->mute_control());
157 _gain_group->add_control (r->gain_control());
158 boost::shared_ptr<Track> trk = boost::dynamic_pointer_cast<Track> (r);
160 _rec_enable_group->add_control (trk->rec_enable_control());
161 _monitoring_group->add_control (trk->monitoring_control());
164 r->set_route_group (this);
165 r->DropReferences.connect_same_thread (*this, boost::bind (&RouteGroup::remove_when_going_away, this, boost::weak_ptr<Route> (r)));
167 _session.set_dirty ();
168 RouteAdded (this, boost::weak_ptr<Route> (r)); /* EMIT SIGNAL */
173 RouteGroup::remove_when_going_away (boost::weak_ptr<Route> wr)
175 boost::shared_ptr<Route> r (wr.lock());
183 RouteGroup::remove (boost::shared_ptr<Route> r)
185 RouteList::iterator i;
187 if ((i = find (routes->begin(), routes->end(), r)) != routes->end()) {
188 r->set_route_group (0);
189 _solo_group->remove_control (r->solo_control());
190 _mute_group->remove_control (r->mute_control());
191 _gain_group->remove_control (r->gain_control());
192 boost::shared_ptr<Track> trk = boost::dynamic_pointer_cast<Track> (r);
194 _rec_enable_group->remove_control (trk->rec_enable_control());
195 _monitoring_group->remove_control (trk->monitoring_control());
198 _session.set_dirty ();
199 RouteRemoved (this, boost::weak_ptr<Route> (r)); /* EMIT SIGNAL */
208 RouteGroup::get_state ()
210 XMLNode *node = new XMLNode ("RouteGroup");
213 id().print (buf, sizeof (buf));
214 node->add_property ("id", buf);
216 add_properties (*node);
218 if (!routes->empty()) {
221 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
222 str << (*i)->id () << ' ';
225 node->add_property ("routes", str.str());
232 RouteGroup::set_state (const XMLNode& node, int version)
234 if (version < 3000) {
235 return set_state_2X (node, version);
238 XMLProperty const * prop;
243 if ((prop = node.property ("routes")) != 0) {
244 stringstream str (prop->value());
246 split (str.str(), ids, ' ');
248 for (vector<string>::iterator i = ids.begin(); i != ids.end(); ++i) {
250 boost::shared_ptr<Route> r = _session.route_by_id (id);
264 RouteGroup::set_state_2X (const XMLNode& node, int /*version*/)
268 if (node.name() == "MixGroup") {
273 _route_active = true;
275 } else if (node.name() == "EditGroup") {
280 _route_active = false;
290 RouteGroup::set_gain (bool yn)
292 if (is_gain() == yn) {
296 _gain_group->set_active (yn);
298 send_change (PropertyChange (Properties::gain));
302 RouteGroup::set_mute (bool yn)
304 if (is_mute() == yn) {
308 _mute_group->set_active (yn);
309 send_change (PropertyChange (Properties::mute));
313 RouteGroup::set_solo (bool yn)
315 if (is_solo() == yn) {
319 _solo_group->set_active (yn);
320 send_change (PropertyChange (Properties::solo));
324 RouteGroup::set_recenable (bool yn)
326 if (is_recenable() == yn) {
330 _rec_enable_group->set_active (yn);
331 send_change (PropertyChange (Properties::recenable));
335 RouteGroup::set_select (bool yn)
337 if (is_select() == yn) {
341 send_change (PropertyChange (Properties::select));
345 RouteGroup::set_route_active (bool yn)
347 if (is_route_active() == yn) {
351 send_change (PropertyChange (Properties::route_active));
355 RouteGroup::set_color (bool yn)
357 if (is_color() == yn) {
362 send_change (PropertyChange (Properties::color));
364 /* This is a bit of a hack, but this might change
365 our route's effective color, so emit gui_changed
369 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
370 (*i)->gui_changed (X_("color"), this);
375 RouteGroup::set_monitoring (bool yn)
377 if (is_monitoring() == yn) {
382 _monitoring_group->set_active (yn);
384 send_change (PropertyChange (Properties::monitoring));
386 _session.set_dirty ();
390 RouteGroup::set_active (bool yn, void* /*src*/)
392 if (is_active() == yn) {
397 send_change (PropertyChange (Properties::active));
398 _session.set_dirty ();
402 RouteGroup::set_relative (bool yn, void* /*src*/)
404 if (is_relative() == yn) {
408 send_change (PropertyChange (Properties::relative));
409 _session.set_dirty ();
413 RouteGroup::set_hidden (bool yn, void* /*src*/)
415 if (is_hidden() == yn) {
421 if (Config->get_hiding_groups_deactivates_groups()) {
426 if (Config->get_hiding_groups_deactivates_groups()) {
431 send_change (Properties::hidden);
433 _session.set_dirty ();
437 RouteGroup::audio_track_group (set<boost::shared_ptr<AudioTrack> >& ats)
439 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
440 boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack>(*i);
448 RouteGroup::make_subgroup (bool aux, Placement placement)
453 /* since we don't do MIDI Busses yet, check quickly ... */
455 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
456 if ((*i)->output()->n_ports().n_midi() != 0) {
457 PBD::warning << _("You cannot subgroup MIDI tracks at this time") << endmsg;
462 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
463 if (!aux && nin != 0 && nin != (*i)->output()->n_ports().n_audio()) {
464 PBD::warning << _("You cannot subgroup tracks with different number of outputs at this time.") << endmsg;
467 nin = max (nin, (*i)->output()->n_ports().n_audio());
471 /* use master bus etc. to determine default nouts.
473 * (since tracks can't have fewer outs than ins,
474 * "nin" currently defines the number of outpus if nin > 2)
476 rl = _session.new_audio_route (nin, 2 /*XXX*/, 0, 1);
481 subgroup_bus = rl.front();
482 subgroup_bus->set_name (_name);
486 _session.add_internal_sends (subgroup_bus, placement, routes);
490 boost::shared_ptr<Bundle> bundle = subgroup_bus->input()->bundle ();
492 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
493 (*i)->output()->disconnect (this);
494 (*i)->output()->connect_ports_to_bundle (bundle, false, this);
500 RouteGroup::destroy_subgroup ()
506 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
507 (*i)->output()->disconnect (this);
508 /* XXX find a new bundle to connect to */
511 _session.remove_route (subgroup_bus);
512 subgroup_bus.reset ();
516 RouteGroup::has_subgroup() const
518 return subgroup_bus != 0;
522 RouteGroup::enabled_property (PBD::PropertyID prop)
524 OwnedPropertyList::iterator i = _properties->find (prop);
525 if (i == _properties->end()) {
529 return dynamic_cast<const PropertyTemplate<bool>* > (i->second)->val ();
533 RouteGroup::post_set (PBD::PropertyChange const &)
539 RouteGroup::push_to_groups ()
541 _gain_group->set_active (_gain);
542 _solo_group->set_active (_solo);
543 _mute_group->set_active (_mute);
544 _rec_enable_group->set_active (_recenable);
545 _monitoring_group->set_active (_monitoring);