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"
28
#include "ardour/amp.h"
29
#include "ardour/audio_track.h"
30
#include "ardour/route.h"
31
#include "ardour/route_group.h"
32
#include "ardour/session.h"
36
using namespace ARDOUR;
41
namespace Properties {
42
PropertyDescriptor<bool> relative;
43
PropertyDescriptor<bool> active;
44
PropertyDescriptor<bool> gain;
45
PropertyDescriptor<bool> mute;
46
PropertyDescriptor<bool> solo;
47
PropertyDescriptor<bool> recenable;
48
PropertyDescriptor<bool> select;
49
PropertyDescriptor<bool> route_active;
50
PropertyDescriptor<bool> color;
51
PropertyDescriptor<bool> monitoring;
56
RouteGroup::make_property_quarks ()
58
Properties::relative.property_id = g_quark_from_static_string (X_("relative"));
59
DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for relative = %1\n", Properties::relative.property_id));
60
Properties::active.property_id = g_quark_from_static_string (X_("active"));
61
DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for active = %1\n", Properties::active.property_id));
62
Properties::hidden.property_id = g_quark_from_static_string (X_("hidden"));
63
DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for hidden = %1\n", Properties::hidden.property_id));
64
Properties::gain.property_id = g_quark_from_static_string (X_("gain"));
65
DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for gain = %1\n", Properties::gain.property_id));
66
Properties::mute.property_id = g_quark_from_static_string (X_("mute"));
67
DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for mute = %1\n", Properties::mute.property_id));
68
Properties::solo.property_id = g_quark_from_static_string (X_("solo"));
69
DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for solo = %1\n", Properties::solo.property_id));
70
Properties::recenable.property_id = g_quark_from_static_string (X_("recenable"));
71
DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for recenable = %1\n", Properties::recenable.property_id));
72
Properties::select.property_id = g_quark_from_static_string (X_("select"));
73
DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for select = %1\n", Properties::select.property_id));
74
Properties::route_active.property_id = g_quark_from_static_string (X_("route-active"));
75
DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for route-active = %1\n", Properties::route_active.property_id));
76
Properties::color.property_id = g_quark_from_static_string (X_("color"));
77
DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for color = %1\n", Properties::color.property_id));
78
Properties::monitoring.property_id = g_quark_from_static_string (X_("monitoring"));
79
DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for monitoring = %1\n", Properties::monitoring.property_id));
82
#define ROUTE_GROUP_DEFAULT_PROPERTIES _relative (Properties::relative, false) \
83
, _active (Properties::active, false) \
84
, _hidden (Properties::hidden, false) \
85
, _gain (Properties::gain, false) \
86
, _mute (Properties::mute, false) \
87
, _solo (Properties::solo, false) \
88
, _recenable (Properties::recenable, false) \
89
, _select (Properties::select, false) \
90
, _route_active (Properties::route_active, false) \
91
, _color (Properties::color, false) \
92
, _monitoring (Properties::monitoring, false)
94
RouteGroup::RouteGroup (Session& s, const string &n)
95
: SessionObject (s, n)
96
, routes (new RouteList)
97
, ROUTE_GROUP_DEFAULT_PROPERTIES
99
_xml_node_name = X_("RouteGroup");
101
add_property (_relative);
102
add_property (_active);
103
add_property (_hidden);
104
add_property (_gain);
105
add_property (_mute);
106
add_property (_solo);
107
add_property (_recenable);
108
add_property (_select);
109
add_property (_route_active);
110
add_property (_color);
111
add_property (_monitoring);
114
RouteGroup::~RouteGroup ()
116
for (RouteList::iterator i = routes->begin(); i != routes->end();) {
117
RouteList::iterator tmp = i;
120
(*i)->set_route_group (0);
126
/** Add a route to a group. Adding a route which is already in the group is allowed; nothing will happen.
127
* @param r Route to add.
130
RouteGroup::add (boost::shared_ptr<Route> r)
132
if (find (routes->begin(), routes->end(), r) != routes->end()) {
136
if (r->route_group()) {
137
r->route_group()->remove (r);
140
routes->push_back (r);
142
r->set_route_group (this);
143
r->DropReferences.connect_same_thread (*this, boost::bind (&RouteGroup::remove_when_going_away, this, boost::weak_ptr<Route> (r)));
145
_session.set_dirty ();
146
RouteAdded (this, boost::weak_ptr<Route> (r)); /* EMIT SIGNAL */
151
RouteGroup::remove_when_going_away (boost::weak_ptr<Route> wr)
153
boost::shared_ptr<Route> r (wr.lock());
161
RouteGroup::remove (boost::shared_ptr<Route> r)
163
RouteList::iterator i;
165
if ((i = find (routes->begin(), routes->end(), r)) != routes->end()) {
166
r->set_route_group (0);
168
_session.set_dirty ();
169
RouteRemoved (this, boost::weak_ptr<Route> (r)); /* EMIT SIGNAL */
178
RouteGroup::get_min_factor (gain_t factor)
180
for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
181
gain_t const g = (*i)->amp()->gain();
183
if ((g + g * factor) >= 0.0f) {
187
if (g <= 0.0000003f) {
191
factor = 0.0000003f / g - 1.0f;
198
RouteGroup::get_max_factor (gain_t factor)
200
for (RouteList::iterator i = routes->begin(); i != routes->end(); i++) {
201
gain_t const g = (*i)->amp()->gain();
203
// if the current factor woulnd't raise this route above maximum
204
if ((g + g * factor) <= 1.99526231f) {
208
// if route gain is already at peak, return 0.0f factor
209
if (g >= 1.99526231f) {
213
// factor is calculated so that it would raise current route to max
214
factor = 1.99526231f / g - 1.0f;
221
RouteGroup::get_state ()
223
XMLNode *node = new XMLNode ("RouteGroup");
226
id().print (buf, sizeof (buf));
227
node->add_property ("id", buf);
229
add_properties (*node);
231
if (!routes->empty()) {
234
for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
235
str << (*i)->id () << ' ';
238
node->add_property ("routes", str.str());
245
RouteGroup::set_state (const XMLNode& node, int version)
247
if (version < 3000) {
248
return set_state_2X (node, version);
251
const XMLProperty *prop;
256
if ((prop = node.property ("routes")) != 0) {
257
stringstream str (prop->value());
259
split (str.str(), ids, ' ');
261
for (vector<string>::iterator i = ids.begin(); i != ids.end(); ++i) {
263
boost::shared_ptr<Route> r = _session.route_by_id (id);
275
RouteGroup::set_state_2X (const XMLNode& node, int /*version*/)
279
if (node.name() == "MixGroup") {
284
_route_active = true;
286
} else if (node.name() == "EditGroup") {
291
_route_active = false;
299
RouteGroup::set_gain (bool yn)
301
if (is_gain() == yn) {
305
send_change (PropertyChange (Properties::gain));
309
RouteGroup::set_mute (bool yn)
311
if (is_mute() == yn) {
315
send_change (PropertyChange (Properties::mute));
319
RouteGroup::set_solo (bool yn)
321
if (is_solo() == yn) {
325
send_change (PropertyChange (Properties::solo));
329
RouteGroup::set_recenable (bool yn)
331
if (is_recenable() == yn) {
335
send_change (PropertyChange (Properties::recenable));
339
RouteGroup::set_select (bool yn)
341
if (is_select() == yn) {
345
send_change (PropertyChange (Properties::select));
349
RouteGroup::set_route_active (bool yn)
351
if (is_route_active() == yn) {
355
send_change (PropertyChange (Properties::route_active));
359
RouteGroup::set_color (bool yn)
361
if (is_color() == yn) {
366
send_change (PropertyChange (Properties::color));
368
/* This is a bit of a hack, but this might change
369
our route's effective color, so emit gui_changed
373
for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
374
(*i)->gui_changed (X_("color"), this);
379
RouteGroup::set_monitoring (bool yn)
381
if (is_monitoring() == yn) {
386
send_change (PropertyChange (Properties::monitoring));
388
_session.set_dirty ();
392
RouteGroup::set_active (bool yn, void* /*src*/)
394
if (is_active() == yn) {
399
send_change (PropertyChange (Properties::active));
400
_session.set_dirty ();
404
RouteGroup::set_relative (bool yn, void* /*src*/)
406
if (is_relative() == yn) {
410
send_change (PropertyChange (Properties::relative));
411
_session.set_dirty ();
415
RouteGroup::set_hidden (bool yn, void* /*src*/)
417
if (is_hidden() == yn) {
423
if (Config->get_hiding_groups_deactivates_groups()) {
428
if (Config->get_hiding_groups_deactivates_groups()) {
433
send_change (Properties::hidden);
435
_session.set_dirty ();
439
RouteGroup::audio_track_group (set<boost::shared_ptr<AudioTrack> >& ats)
441
for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
442
boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack>(*i);
450
RouteGroup::make_subgroup (bool aux, Placement placement)
455
/* since we don't do MIDI Busses yet, check quickly ... */
457
for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
458
if ((*i)->output()->n_ports().n_midi() != 0) {
459
PBD::info << _("You cannot subgroup MIDI tracks at this time") << endmsg;
464
for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
465
nin = max (nin, (*i)->output()->n_ports().n_audio());
469
/* use master bus etc. to determine default nouts */
470
rl = _session.new_audio_route (nin, 2, 0, 1);
475
subgroup_bus = rl.front();
476
subgroup_bus->set_name (_name);
480
_session.add_internal_sends (subgroup_bus, placement, routes);
484
boost::shared_ptr<Bundle> bundle = subgroup_bus->input()->bundle ();
486
for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
487
(*i)->output()->disconnect (this);
488
(*i)->output()->connect_ports_to_bundle (bundle, false, this);
494
RouteGroup::destroy_subgroup ()
500
for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
501
(*i)->output()->disconnect (this);
502
/* XXX find a new bundle to connect to */
505
_session.remove_route (subgroup_bus);
506
subgroup_bus.reset ();
510
RouteGroup::has_subgroup() const
512
return subgroup_bus != 0;
516
RouteGroup::enabled_property (PBD::PropertyID prop)
518
OwnedPropertyList::iterator i = _properties->find (prop);
519
if (i == _properties->end()) {
523
return dynamic_cast<const PropertyTemplate<bool>* > (i->second)->val ();