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"
39 using namespace ARDOUR;
43 RouteGroup::RouteGroup (Session& s, const string &n, Flag f, Property p)
44 : _session (s), _name (n), _flags (f), _properties (Property (p))
49 RouteGroup::set_name (string str)
52 _session.set_dirty ();
53 FlagsChanged (0); /* EMIT SIGNAL */
57 RouteGroup::add (Route *r)
60 r->GoingAway.connect (sigc::bind (mem_fun (*this, &RouteGroup::remove_when_going_away), r));
61 _session.set_dirty ();
62 changed (); /* EMIT SIGNAL */
67 RouteGroup::remove_when_going_away (Route *r)
73 RouteGroup::remove (Route *r)
75 list<Route *>::iterator i;
77 if ((i = find (routes.begin(), routes.end(), r)) != routes.end()) {
79 _session.set_dirty ();
80 changed (); /* EMIT SIGNAL */
88 RouteGroup::get_min_factor(gain_t factor)
92 for (list<Route *>::iterator i = routes.begin(); i != routes.end(); i++) {
93 g = (*i)->amp()->gain();
95 if ( (g+g*factor) >= 0.0f)
98 if ( g <= 0.0000003f )
101 factor = 0.0000003f/g - 1.0f;
107 RouteGroup::get_max_factor(gain_t factor)
111 for (list<Route *>::iterator i = routes.begin(); i != routes.end(); i++) {
112 g = (*i)->amp()->gain();
114 // if the current factor woulnd't raise this route above maximum
115 if ( (g+g*factor) <= 1.99526231f)
118 // if route gain is already at peak, return 0.0f factor
122 // factor is calculated so that it would raise current route to max
123 factor = 1.99526231f/g - 1.0f;
130 RouteGroup::get_state (void)
132 XMLNode *node = new XMLNode ("RouteGroup");
133 node->add_property ("name", _name);
134 node->add_property ("flags", enum_2_string (_flags));
135 node->add_property ("properties", enum_2_string (_properties));
140 RouteGroup::set_state (const XMLNode& node)
142 const XMLProperty *prop;
144 if ((prop = node.property ("name")) != 0) {
145 _name = prop->value();
148 if ((prop = node.property ("flags")) != 0) {
149 _flags = Flag (string_2_enum (prop->value(), _flags));
152 if ((prop = node.property ("properties")) != 0) {
153 _properties = Property (string_2_enum (prop->value(), _properties));
160 RouteGroup::set_active (bool yn, void *src)
162 if (is_active() == yn) {
166 _flags = Flag (_flags | Active);
168 _flags = Flag (_flags & ~Active);
170 _session.set_dirty ();
171 FlagsChanged (src); /* EMIT SIGNAL */
175 RouteGroup::set_relative (bool yn, void *src)
178 if (is_relative() == yn) {
182 _flags = Flag (_flags | Relative);
184 _flags = Flag (_flags & ~Relative);
186 _session.set_dirty ();
187 FlagsChanged (src); /* EMIT SIGNAL */
191 RouteGroup::set_hidden (bool yn, void *src)
194 if (is_hidden() == yn) {
198 _flags = Flag (_flags | Hidden);
199 if (Config->get_hiding_groups_deactivates_groups()) {
200 _flags = Flag (_flags & ~Active);
203 _flags = Flag (_flags & ~Hidden);
204 if (Config->get_hiding_groups_deactivates_groups()) {
205 _flags = Flag (_flags | Active);
208 _session.set_dirty ();
209 FlagsChanged (src); /* EMIT SIGNAL */
213 RouteGroup::audio_track_group (set<AudioTrack*>& ats)
215 for (list<Route*>::iterator i = routes.begin(); i != routes.end(); ++i) {
216 AudioTrack* at = dynamic_cast<AudioTrack*>(*i);
224 RouteGroup::make_subgroup ()
229 /* since we don't do MIDI Busses yet, check quickly ... */
231 for (list<Route*>::iterator i = routes.begin(); i != routes.end(); ++i) {
232 if ((*i)->output()->n_ports().n_midi() != 0) {
233 PBD::info << _("You cannot subgroup MIDI tracks at this time") << endmsg;
238 for (list<Route*>::iterator i = routes.begin(); i != routes.end(); ++i) {
239 nin = max (nin, (*i)->output()->n_ports().n_audio());
243 /* use master bus etc. to determine default nouts */
244 rl = _session.new_audio_route (nin, 2, 0, 1);
249 subgroup_bus = rl.front();
250 subgroup_bus->set_name (_name);
252 boost::shared_ptr<Bundle> bundle = subgroup_bus->input()->bundle ();
254 for (list<Route*>::iterator i = routes.begin(); i != routes.end(); ++i) {
255 (*i)->output()->disconnect (this);
256 (*i)->output()->connect_ports_to_bundle (bundle, this);
261 RouteGroup::destroy_subgroup ()
267 for (list<Route*>::iterator i = routes.begin(); i != routes.end(); ++i) {
268 (*i)->output()->disconnect (this);
269 /* XXX find a new bundle to connect to */
272 _session.remove_route (subgroup_bus);
273 subgroup_bus.reset ();