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, int version)
142 if (version < 3000) {
143 return set_state_2X (node, version);
146 const XMLProperty *prop;
148 if ((prop = node.property ("name")) != 0) {
149 _name = prop->value();
152 if ((prop = node.property ("flags")) != 0) {
153 _flags = Flag (string_2_enum (prop->value(), _flags));
156 if ((prop = node.property ("properties")) != 0) {
157 _properties = Property (string_2_enum (prop->value(), _properties));
164 RouteGroup::set_state_2X (const XMLNode& node, int /*version*/)
166 XMLProperty const * prop;
168 if ((prop = node.property ("name")) != 0) {
169 _name = prop->value();
172 if ((prop = node.property ("flags")) != 0) {
173 _flags = Flag (string_2_enum (prop->value(), _flags));
176 if (node.name() == "MixGroup") {
177 _properties = Property (Gain | Mute | Solo | RecEnable);
178 } else if (node.name() == "EditGroup") {
179 _properties = Property (Select | Edit);
186 RouteGroup::set_active (bool yn, void *src)
188 if (is_active() == yn) {
192 _flags = Flag (_flags | Active);
194 _flags = Flag (_flags & ~Active);
196 _session.set_dirty ();
197 FlagsChanged (src); /* EMIT SIGNAL */
201 RouteGroup::set_relative (bool yn, void *src)
204 if (is_relative() == yn) {
208 _flags = Flag (_flags | Relative);
210 _flags = Flag (_flags & ~Relative);
212 _session.set_dirty ();
213 FlagsChanged (src); /* EMIT SIGNAL */
217 RouteGroup::set_hidden (bool yn, void *src)
220 if (is_hidden() == yn) {
224 _flags = Flag (_flags | Hidden);
225 if (Config->get_hiding_groups_deactivates_groups()) {
226 _flags = Flag (_flags & ~Active);
229 _flags = Flag (_flags & ~Hidden);
230 if (Config->get_hiding_groups_deactivates_groups()) {
231 _flags = Flag (_flags | Active);
234 _session.set_dirty ();
235 FlagsChanged (src); /* EMIT SIGNAL */
239 RouteGroup::audio_track_group (set<AudioTrack*>& ats)
241 for (list<Route*>::iterator i = routes.begin(); i != routes.end(); ++i) {
242 AudioTrack* at = dynamic_cast<AudioTrack*>(*i);
250 RouteGroup::make_subgroup ()
255 /* since we don't do MIDI Busses yet, check quickly ... */
257 for (list<Route*>::iterator i = routes.begin(); i != routes.end(); ++i) {
258 if ((*i)->output()->n_ports().n_midi() != 0) {
259 PBD::info << _("You cannot subgroup MIDI tracks at this time") << endmsg;
264 for (list<Route*>::iterator i = routes.begin(); i != routes.end(); ++i) {
265 nin = max (nin, (*i)->output()->n_ports().n_audio());
269 /* use master bus etc. to determine default nouts */
270 rl = _session.new_audio_route (false, nin, 2, 0, 1);
275 subgroup_bus = rl.front();
276 subgroup_bus->set_name (_name);
278 boost::shared_ptr<Bundle> bundle = subgroup_bus->input()->bundle ();
280 for (list<Route*>::iterator i = routes.begin(); i != routes.end(); ++i) {
281 (*i)->output()->disconnect (this);
282 (*i)->output()->connect_ports_to_bundle (bundle, this);
287 RouteGroup::destroy_subgroup ()
293 for (list<Route*>::iterator i = routes.begin(); i != routes.end(); ++i) {
294 (*i)->output()->disconnect (this);
295 /* XXX find a new bundle to connect to */
298 _session.remove_route (subgroup_bus);
299 subgroup_bus.reset ();