2 Copyright (C) 2000-2002 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
25 #include <sigc++/bind.h>
27 #include "pbd/error.h"
28 #include "pbd/enumwriter.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"
37 using namespace ARDOUR;
41 RouteGroup::RouteGroup (Session& s, const string &n, Flag f, Property p)
42 : _session (s), _name (n), _flags (f), _properties (Property (p))
47 RouteGroup::set_name (string str)
50 _session.set_dirty ();
51 FlagsChanged (0); /* EMIT SIGNAL */
55 RouteGroup::add (Route *r)
58 r->GoingAway.connect (sigc::bind (mem_fun (*this, &RouteGroup::remove_when_going_away), r));
59 _session.set_dirty ();
60 changed (); /* EMIT SIGNAL */
65 RouteGroup::remove_when_going_away (Route *r)
71 RouteGroup::remove (Route *r)
73 list<Route *>::iterator i;
75 if ((i = find (routes.begin(), routes.end(), r)) != routes.end()) {
77 _session.set_dirty ();
78 changed (); /* EMIT SIGNAL */
86 RouteGroup::get_min_factor(gain_t factor)
90 for (list<Route *>::iterator i = routes.begin(); i != routes.end(); i++) {
91 g = (*i)->amp()->gain();
93 if ( (g+g*factor) >= 0.0f)
96 if ( g <= 0.0000003f )
99 factor = 0.0000003f/g - 1.0f;
105 RouteGroup::get_max_factor(gain_t factor)
109 for (list<Route *>::iterator i = routes.begin(); i != routes.end(); i++) {
110 g = (*i)->amp()->gain();
112 // if the current factor woulnd't raise this route above maximum
113 if ( (g+g*factor) <= 1.99526231f)
116 // if route gain is already at peak, return 0.0f factor
120 // factor is calculated so that it would raise current route to max
121 factor = 1.99526231f/g - 1.0f;
128 RouteGroup::get_state (void)
130 XMLNode *node = new XMLNode ("RouteGroup");
131 node->add_property ("name", _name);
132 node->add_property ("flags", enum_2_string (_flags));
133 node->add_property ("properties", enum_2_string (_properties));
138 RouteGroup::set_state (const XMLNode& node)
140 const XMLProperty *prop;
142 if ((prop = node.property ("name")) != 0) {
143 _name = prop->value();
146 if ((prop = node.property ("flags")) != 0) {
147 _flags = Flag (string_2_enum (prop->value(), _flags));
150 if ((prop = node.property ("properties")) != 0) {
151 _properties = Property (string_2_enum (prop->value(), _properties));
158 RouteGroup::set_active (bool yn, void *src)
160 if (is_active() == yn) {
164 _flags = Flag (_flags | Active);
166 _flags = Flag (_flags & ~Active);
168 _session.set_dirty ();
169 FlagsChanged (src); /* EMIT SIGNAL */
173 RouteGroup::set_relative (bool yn, void *src)
176 if (is_relative() == yn) {
180 _flags = Flag (_flags | Relative);
182 _flags = Flag (_flags & ~Relative);
184 _session.set_dirty ();
185 FlagsChanged (src); /* EMIT SIGNAL */
189 RouteGroup::set_hidden (bool yn, void *src)
192 if (is_hidden() == yn) {
196 _flags = Flag (_flags | Hidden);
197 if (Config->get_hiding_groups_deactivates_groups()) {
198 _flags = Flag (_flags & ~Active);
201 _flags = Flag (_flags & ~Hidden);
202 if (Config->get_hiding_groups_deactivates_groups()) {
203 _flags = Flag (_flags | Active);
206 _session.set_dirty ();
207 FlagsChanged (src); /* EMIT SIGNAL */
211 RouteGroup::audio_track_group (set<AudioTrack*>& ats)
213 for (list<Route*>::iterator i = routes.begin(); i != routes.end(); ++i) {
214 AudioTrack* at = dynamic_cast<AudioTrack*>(*i);
222 RouteGroup::make_subgroup ()
227 for (list<Route*>::iterator i = routes.begin(); i != routes.end(); ++i) {
228 nin = max (nin, (*i)->output()->n_ports().n_audio());
232 /* use master bus etc. to determine default nouts */
233 rl = _session.new_audio_route (nin, 2, 0, 1);
238 subgroup_bus = rl.front();
239 subgroup_bus->set_name (_name);
241 boost::shared_ptr<Bundle> bundle = subgroup_bus->input()->bundle ();
243 for (list<Route*>::iterator i = routes.begin(); i != routes.end(); ++i) {
244 (*i)->output()->disconnect (this);
245 (*i)->output()->connect_ports_to_bundle (bundle, this);
250 RouteGroup::destroy_subgroup ()
256 for (list<Route*>::iterator i = routes.begin(); i != routes.end(); ++i) {
257 (*i)->output()->disconnect (this);
258 /* XXX find a new bundle to connect to */
261 _session.remove_route (subgroup_bus);
262 subgroup_bus.reset ();