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.
20 #define __STDC_FORMAT_MACROS
26 #include "pbd/error.h"
27 #include "pbd/enumwriter.h"
28 #include "pbd/strsplit.h"
30 #include "ardour/amp.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;
57 RouteGroup::make_property_quarks ()
59 Properties::relative.id = g_quark_from_static_string (X_("relative"));
60 Properties::active.id = g_quark_from_static_string (X_("active"));
61 Properties::hidden.id = g_quark_from_static_string (X_("hidden"));
62 Properties::gain.id = g_quark_from_static_string (X_("gain"));
63 Properties::mute.id = g_quark_from_static_string (X_("mute"));
64 Properties::solo.id = g_quark_from_static_string (X_("solo"));
65 Properties::recenable.id = g_quark_from_static_string (X_("recenable"));
66 Properties::select.id = g_quark_from_static_string (X_("select"));
67 Properties::edit.id = g_quark_from_static_string (X_("edit"));
70 #define ROUTE_GROUP_DEFAULT_PROPERTIES _relative (Properties::relative, false) \
71 , _active (Properties::active, false) \
72 , _hidden (Properties::hidden, false) \
73 , _gain (Properties::gain, false) \
74 , _mute (Properties::mute, false) \
75 , _solo (Properties::solo, false) \
76 , _recenable (Properties::recenable, false) \
77 , _select (Properties::select, false) \
78 , _edit (Properties::edit, false)
80 RouteGroup::RouteGroup (Session& s, const string &n)
81 : SessionObject (s, n)
82 , routes (new RouteList)
83 , ROUTE_GROUP_DEFAULT_PROPERTIES
85 _xml_node_name = X_("RegionGroup");
87 add_property (_relative);
88 add_property (_active);
89 add_property (_hidden);
93 add_property (_recenable);
94 add_property (_select);
98 RouteGroup::~RouteGroup ()
100 for (RouteList::iterator i = routes->begin(); i != routes->end();) {
101 RouteList::iterator tmp = i;
104 (*i)->leave_route_group ();
110 /** Add a route to a group. Adding a route which is already in the group is allowed; nothing will happen.
111 * @param r Route to add.
114 RouteGroup::add (boost::shared_ptr<Route> r)
116 if (find (routes->begin(), routes->end(), r) != routes->end()) {
120 r->leave_route_group ();
122 routes->push_back (r);
124 r->join_route_group (this);
125 r->DropReferences.connect_same_thread (*this, boost::bind (&RouteGroup::remove_when_going_away, this, boost::weak_ptr<Route> (r)));
127 _session.set_dirty ();
128 changed (); /* EMIT SIGNAL */
133 RouteGroup::remove_when_going_away (boost::weak_ptr<Route> wr)
135 boost::shared_ptr<Route> r (wr.lock());
143 RouteGroup::remove (boost::shared_ptr<Route> r)
145 RouteList::iterator i;
147 if ((i = find (routes->begin(), routes->end(), r)) != routes->end()) {
148 r->leave_route_group ();
150 _session.set_dirty ();
151 changed (); /* EMIT SIGNAL */
160 RouteGroup::get_min_factor(gain_t factor)
164 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
165 g = (*i)->amp()->gain();
167 if ( (g+g*factor) >= 0.0f)
170 if ( g <= 0.0000003f )
173 factor = 0.0000003f/g - 1.0f;
179 RouteGroup::get_max_factor(gain_t factor)
183 for (RouteList::iterator i = routes->begin(); i != routes->end(); i++) {
184 g = (*i)->amp()->gain();
186 // if the current factor woulnd't raise this route above maximum
187 if ( (g+g*factor) <= 1.99526231f)
190 // if route gain is already at peak, return 0.0f factor
194 // factor is calculated so that it would raise current route to max
195 factor = 1.99526231f/g - 1.0f;
202 RouteGroup::get_state (void)
204 XMLNode *node = new XMLNode ("RouteGroup");
206 add_properties (*node);
208 if (!routes->empty()) {
211 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
212 str << (*i)->id () << ' ';
215 node->add_property ("routes", str.str());
222 RouteGroup::set_state (const XMLNode& node, int version)
224 if (version < 3000) {
225 return set_state_2X (node, version);
228 const XMLProperty *prop;
230 if ((prop = node.property ("routes")) != 0) {
231 stringstream str (prop->value());
233 split (str.str(), ids, ' ');
235 for (vector<string>::iterator i = ids.begin(); i != ids.end(); ++i) {
237 boost::shared_ptr<Route> r = _session.route_by_id (id);
249 RouteGroup::set_state_2X (const XMLNode& node, int /*version*/)
251 set_properties (node);
253 if (node.name() == "MixGroup") {
259 } else if (node.name() == "EditGroup") {
271 RouteGroup::set_gain (bool yn)
273 if (is_gain() == yn) {
280 RouteGroup::set_mute (bool yn)
282 if (is_mute() == yn) {
289 RouteGroup::set_solo (bool yn)
291 if (is_solo() == yn) {
298 RouteGroup::set_recenable (bool yn)
300 if (is_recenable() == yn) {
307 RouteGroup::set_select (bool yn)
309 if (is_select() == yn) {
316 RouteGroup::set_edit (bool yn)
318 if (is_edit() == yn) {
325 RouteGroup::set_active (bool yn, void *src)
327 if (is_active() == yn) {
331 _session.set_dirty ();
332 FlagsChanged (src); /* EMIT SIGNAL */
336 RouteGroup::set_relative (bool yn, void *src)
339 if (is_relative() == yn) {
343 _session.set_dirty ();
344 FlagsChanged (src); /* EMIT SIGNAL */
348 RouteGroup::set_hidden (bool yn, void *src)
350 if (is_hidden() == yn) {
355 if (Config->get_hiding_groups_deactivates_groups()) {
360 if (Config->get_hiding_groups_deactivates_groups()) {
364 _session.set_dirty ();
365 FlagsChanged (src); /* EMIT SIGNAL */
369 RouteGroup::audio_track_group (set<boost::shared_ptr<AudioTrack> >& ats)
371 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
372 boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack>(*i);
380 RouteGroup::make_subgroup ()
385 /* since we don't do MIDI Busses yet, check quickly ... */
387 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
388 if ((*i)->output()->n_ports().n_midi() != 0) {
389 PBD::info << _("You cannot subgroup MIDI tracks at this time") << endmsg;
394 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
395 nin = max (nin, (*i)->output()->n_ports().n_audio());
399 /* use master bus etc. to determine default nouts */
400 rl = _session.new_audio_route (false, nin, 2, 0, 1);
405 subgroup_bus = rl.front();
406 subgroup_bus->set_name (_name);
408 boost::shared_ptr<Bundle> bundle = subgroup_bus->input()->bundle ();
410 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
411 (*i)->output()->disconnect (this);
412 (*i)->output()->connect_ports_to_bundle (bundle, this);
417 RouteGroup::destroy_subgroup ()
423 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
424 (*i)->output()->disconnect (this);
425 /* XXX find a new bundle to connect to */
428 _session.remove_route (subgroup_bus);
429 subgroup_bus.reset ();
433 RouteGroup::enabled_property (PBD::PropertyID prop)
435 if (Properties::relative.id == prop) {
436 return is_relative();
437 } else if (Properties::active.id == prop) {
439 } else if (Properties::hidden.id == prop) {
441 } else if (Properties::gain.id == prop) {
443 } else if (Properties::mute.id == prop) {
445 } else if (Properties::solo.id == prop) {
447 } else if (Properties::recenable.id == prop) {
448 return is_recenable();
449 } else if (Properties::select.id == prop) {
451 } else if (Properties::edit.id == prop) {