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/route_group.h"
31 #include "ardour/audio_track.h"
32 #include "ardour/audio_diskstream.h"
33 #include "ardour/configuration.h"
34 #include "ardour/session.h"
36 using namespace ARDOUR;
40 RouteGroup::RouteGroup (Session& s, const string &n, Flag f)
41 : _session (s), _name (n), _flags (f)
46 RouteGroup::set_name (string str)
49 _session.set_dirty ();
50 FlagsChanged (0); /* EMIT SIGNAL */
54 RouteGroup::add (Route *r)
57 r->GoingAway.connect (sigc::bind (mem_fun (*this, &RouteGroup::remove_when_going_away), r));
58 _session.set_dirty ();
59 changed (); /* EMIT SIGNAL */
64 RouteGroup::remove_when_going_away (Route *r)
70 RouteGroup::remove (Route *r)
72 list<Route *>::iterator i;
74 if ((i = find (routes.begin(), routes.end(), r)) != routes.end()) {
76 _session.set_dirty ();
77 changed (); /* EMIT SIGNAL */
85 RouteGroup::get_min_factor(gain_t factor)
89 for (list<Route *>::iterator i = routes.begin(); i != routes.end(); i++) {
92 if ( (g+g*factor) >= 0.0f)
95 if ( g <= 0.0000003f )
98 factor = 0.0000003f/g - 1.0f;
104 RouteGroup::get_max_factor(gain_t factor)
108 for (list<Route *>::iterator i = routes.begin(); i != routes.end(); i++) {
111 // if the current factor woulnd't raise this route above maximum
112 if ( (g+g*factor) <= 1.99526231f)
115 // if route gain is already at peak, return 0.0f factor
119 // factor is calculated so that it would raise current route to max
120 factor = 1.99526231f/g - 1.0f;
127 RouteGroup::get_state (void)
129 XMLNode *node = new XMLNode ("RouteGroup");
130 node->add_property ("name", _name);
131 node->add_property ("flags", enum_2_string (_flags));
136 RouteGroup::set_state (const XMLNode& node)
138 const XMLProperty *prop;
140 if ((prop = node.property ("name")) != 0) {
141 _name = prop->value();
144 if ((prop = node.property ("flags")) != 0) {
145 _flags = Flag (string_2_enum (prop->value(), _flags));
152 RouteGroup::set_active (bool yn, void *src)
154 if (is_active() == yn) {
158 _flags = Flag (_flags | Active);
160 _flags = Flag (_flags & ~Active);
162 _session.set_dirty ();
163 FlagsChanged (src); /* EMIT SIGNAL */
167 RouteGroup::set_relative (bool yn, void *src)
170 if (is_relative() == yn) {
174 _flags = Flag (_flags | Relative);
176 _flags = Flag (_flags & ~Relative);
178 _session.set_dirty ();
179 FlagsChanged (src); /* EMIT SIGNAL */
183 RouteGroup::set_hidden (bool yn, void *src)
186 if (is_hidden() == yn) {
190 _flags = Flag (_flags | Hidden);
191 if (Config->get_hiding_groups_deactivates_groups()) {
192 _flags = Flag (_flags & ~Active);
195 _flags = Flag (_flags & ~Hidden);
196 if (Config->get_hiding_groups_deactivates_groups()) {
197 _flags = Flag (_flags | Active);
200 _session.set_dirty ();
201 FlagsChanged (src); /* EMIT SIGNAL */
205 RouteGroup::audio_track_group (set<AudioTrack*>& ats)
207 for (list<Route*>::iterator i = routes.begin(); i != routes.end(); ++i) {
208 AudioTrack* at = dynamic_cast<AudioTrack*>(*i);