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.
25 #include "pbd/error.h"
26 #include "pbd/enumwriter.h"
27 #include "pbd/strsplit.h"
29 #include "ardour/amp.h"
30 #include "ardour/debug.h"
31 #include "ardour/route_group.h"
32 #include "ardour/audio_track.h"
33 #include "ardour/audio_diskstream.h"
34 #include "ardour/configuration.h"
35 #include "ardour/session.h"
39 using namespace ARDOUR;
44 namespace Properties {
45 PropertyDescriptor<bool> relative;
46 PropertyDescriptor<bool> active;
47 PropertyDescriptor<bool> gain;
48 PropertyDescriptor<bool> mute;
49 PropertyDescriptor<bool> solo;
50 PropertyDescriptor<bool> recenable;
51 PropertyDescriptor<bool> select;
52 PropertyDescriptor<bool> edit;
53 PropertyDescriptor<bool> route_active;
54 PropertyDescriptor<bool> color;
59 RouteGroup::make_property_quarks ()
61 Properties::relative.property_id = g_quark_from_static_string (X_("relative"));
62 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for relative = %1\n", Properties::relative.property_id));
63 Properties::active.property_id = g_quark_from_static_string (X_("active"));
64 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for active = %1\n", Properties::active.property_id));
65 Properties::hidden.property_id = g_quark_from_static_string (X_("hidden"));
66 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for hidden = %1\n", Properties::hidden.property_id));
67 Properties::gain.property_id = g_quark_from_static_string (X_("gain"));
68 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for gain = %1\n", Properties::gain.property_id));
69 Properties::mute.property_id = g_quark_from_static_string (X_("mute"));
70 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for mute = %1\n", Properties::mute.property_id));
71 Properties::solo.property_id = g_quark_from_static_string (X_("solo"));
72 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for solo = %1\n", Properties::solo.property_id));
73 Properties::recenable.property_id = g_quark_from_static_string (X_("recenable"));
74 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for recenable = %1\n", Properties::recenable.property_id));
75 Properties::select.property_id = g_quark_from_static_string (X_("select"));
76 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for select = %1\n", Properties::select.property_id));
77 Properties::edit.property_id = g_quark_from_static_string (X_("edit"));
78 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for edit = %1\n", Properties::edit.property_id));
79 Properties::route_active.property_id = g_quark_from_static_string (X_("route-active"));
80 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for route-active = %1\n", Properties::route_active.property_id));
81 Properties::color.property_id = g_quark_from_static_string (X_("color"));
82 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for color = %1\n", Properties::color.property_id));
85 #define ROUTE_GROUP_DEFAULT_PROPERTIES _relative (Properties::relative, false) \
86 , _active (Properties::active, false) \
87 , _hidden (Properties::hidden, false) \
88 , _gain (Properties::gain, false) \
89 , _mute (Properties::mute, false) \
90 , _solo (Properties::solo, false) \
91 , _recenable (Properties::recenable, false) \
92 , _select (Properties::select, false) \
93 , _edit (Properties::edit, false) \
94 , _route_active (Properties::route_active, false) \
95 , _color (Properties::color, false)
97 RouteGroup::RouteGroup (Session& s, const string &n)
98 : SessionObject (s, n)
99 , routes (new RouteList)
100 , ROUTE_GROUP_DEFAULT_PROPERTIES
102 _xml_node_name = X_("RouteGroup");
104 add_property (_relative);
105 add_property (_active);
106 add_property (_hidden);
107 add_property (_gain);
108 add_property (_mute);
109 add_property (_solo);
110 add_property (_recenable);
111 add_property (_select);
112 add_property (_edit);
113 add_property (_route_active);
114 add_property (_color);
117 RouteGroup::~RouteGroup ()
119 for (RouteList::iterator i = routes->begin(); i != routes->end();) {
120 RouteList::iterator tmp = i;
123 (*i)->leave_route_group ();
129 /** Add a route to a group. Adding a route which is already in the group is allowed; nothing will happen.
130 * @param r Route to add.
133 RouteGroup::add (boost::shared_ptr<Route> r)
135 if (find (routes->begin(), routes->end(), r) != routes->end()) {
139 r->leave_route_group ();
141 routes->push_back (r);
143 r->join_route_group (this);
144 r->DropReferences.connect_same_thread (*this, boost::bind (&RouteGroup::remove_when_going_away, this, boost::weak_ptr<Route> (r)));
146 _session.set_dirty ();
147 MembershipChanged (); /* EMIT SIGNAL */
152 RouteGroup::remove_when_going_away (boost::weak_ptr<Route> wr)
154 boost::shared_ptr<Route> r (wr.lock());
162 RouteGroup::remove (boost::shared_ptr<Route> r)
164 RouteList::iterator i;
166 if ((i = find (routes->begin(), routes->end(), r)) != routes->end()) {
167 r->leave_route_group ();
169 _session.set_dirty ();
170 MembershipChanged (); /* EMIT SIGNAL */
179 RouteGroup::get_min_factor (gain_t factor)
181 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
182 gain_t const g = (*i)->amp()->gain();
184 if ((g + g * factor) >= 0.0f) {
188 if (g <= 0.0000003f) {
192 factor = 0.0000003f / g - 1.0f;
199 RouteGroup::get_max_factor (gain_t factor)
201 for (RouteList::iterator i = routes->begin(); i != routes->end(); i++) {
202 gain_t const g = (*i)->amp()->gain();
204 // if the current factor woulnd't raise this route above maximum
205 if ((g + g * factor) <= 1.99526231f) {
209 // if route gain is already at peak, return 0.0f factor
210 if (g >= 1.99526231f) {
214 // factor is calculated so that it would raise current route to max
215 factor = 1.99526231f / g - 1.0f;
222 RouteGroup::get_state ()
224 XMLNode *node = new XMLNode ("RouteGroup");
227 id().print (buf, sizeof (buf));
228 node->add_property ("id", buf);
230 add_properties (*node);
232 if (!routes->empty()) {
235 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
236 str << (*i)->id () << ' ';
239 node->add_property ("routes", str.str());
246 RouteGroup::set_state (const XMLNode& node, int version)
248 if (version < 3000) {
249 return set_state_2X (node, version);
252 const XMLProperty *prop;
254 if ((prop = node.property ("id")) != 0) {
260 if ((prop = node.property ("routes")) != 0) {
261 stringstream str (prop->value());
263 split (str.str(), ids, ' ');
265 for (vector<string>::iterator i = ids.begin(); i != ids.end(); ++i) {
267 boost::shared_ptr<Route> r = _session.route_by_id (id);
279 RouteGroup::set_state_2X (const XMLNode& node, int /*version*/)
283 if (node.name() == "MixGroup") {
289 _route_active = true;
291 } else if (node.name() == "EditGroup") {
297 _route_active = false;
305 RouteGroup::set_gain (bool yn)
307 if (is_gain() == yn) {
314 RouteGroup::set_mute (bool yn)
316 if (is_mute() == yn) {
323 RouteGroup::set_solo (bool yn)
325 if (is_solo() == yn) {
332 RouteGroup::set_recenable (bool yn)
334 if (is_recenable() == yn) {
341 RouteGroup::set_select (bool yn)
343 if (is_select() == yn) {
350 RouteGroup::set_edit (bool yn)
352 if (is_edit() == yn) {
359 RouteGroup::set_route_active (bool yn)
361 if (is_route_active() == yn) {
368 RouteGroup::set_color (bool yn)
370 if (is_color() == yn) {
375 /* This is a bit of a hack, but this might change
376 our route's effective color, so emit gui_changed
380 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
381 (*i)->gui_changed (X_("color"), this);
386 RouteGroup::set_active (bool yn, void* /*src*/)
388 if (is_active() == yn) {
393 send_change (PropertyChange (Properties::active));
395 _session.set_dirty ();
399 RouteGroup::set_relative (bool yn, void* /*src*/)
401 if (is_relative() == yn) {
405 _session.set_dirty ();
409 RouteGroup::set_hidden (bool yn, void* /*src*/)
411 if (is_hidden() == yn) {
417 if (Config->get_hiding_groups_deactivates_groups()) {
422 if (Config->get_hiding_groups_deactivates_groups()) {
427 send_change (Properties::hidden);
429 _session.set_dirty ();
433 RouteGroup::audio_track_group (set<boost::shared_ptr<AudioTrack> >& ats)
435 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
436 boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack>(*i);
444 RouteGroup::make_subgroup (bool aux, Placement placement)
449 /* since we don't do MIDI Busses yet, check quickly ... */
451 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
452 if ((*i)->output()->n_ports().n_midi() != 0) {
453 PBD::info << _("You cannot subgroup MIDI tracks at this time") << endmsg;
458 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
459 nin = max (nin, (*i)->output()->n_ports().n_audio());
463 /* use master bus etc. to determine default nouts */
464 rl = _session.new_audio_route (nin, 2, 0, 1);
469 subgroup_bus = rl.front();
470 subgroup_bus->set_name (_name);
474 _session.add_internal_sends (subgroup_bus, placement, routes);
478 boost::shared_ptr<Bundle> bundle = subgroup_bus->input()->bundle ();
480 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
481 (*i)->output()->disconnect (this);
482 (*i)->output()->connect_ports_to_bundle (bundle, this);
488 RouteGroup::destroy_subgroup ()
494 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
495 (*i)->output()->disconnect (this);
496 /* XXX find a new bundle to connect to */
499 _session.remove_route (subgroup_bus);
500 subgroup_bus.reset ();
504 RouteGroup::enabled_property (PBD::PropertyID prop)
506 OwnedPropertyList::iterator i = _properties->find (prop);
507 if (i == _properties->end()) {
511 return dynamic_cast<const PropertyTemplate<bool>* > (i->second)->val ();