summaryrefslogtreecommitdiff
path: root/libs/ardour/route_group.cc
blob: 57306237427ff581a17e352b615d29516ccf3bc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
    Copyright (C) 2000-2002 Paul Davis 

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

    $Id$
*/

#define __STDC_FORMAT_MACROS
#include <inttypes.h>

#include <algorithm>

#include <sigc++/bind.h>

#include <pbd/error.h>

#include <ardour/route_group.h>
#include <ardour/audio_track.h>
#include <ardour/audio_diskstream.h>
#include <ardour/configuration.h>

using namespace ARDOUR;
using namespace sigc;
using namespace std;

RouteGroup::RouteGroup (Session& s, const string &n, Flag f)
	: _session (s), _name (n), _flags (f) 
{
}

void
RouteGroup::set_name (string str)
{
	_name = str;
	_session.set_dirty ();
	FlagsChanged (0); /* EMIT SIGNAL */
}

int
RouteGroup::add (Route *r)
{
	routes.push_back (r);
	r->GoingAway.connect (sigc::bind (mem_fun (*this, &RouteGroup::remove_when_going_away), r));
	_session.set_dirty ();
	changed (); /* EMIT SIGNAL */
	return 0;
}

void
RouteGroup::remove_when_going_away (Route *r)
{
	remove (r);
}
    
int
RouteGroup::remove (Route *r) 
{
	list<Route *>::iterator i;

	if ((i = find (routes.begin(), routes.end(), r)) != routes.end()) {
		routes.erase (i);
		_session.set_dirty ();
		changed (); /* EMIT SIGNAL */
		return 0;
	}
	return -1;
}


gain_t
RouteGroup::get_min_factor(gain_t factor)
{
	gain_t g;
	
	for (list<Route *>::iterator i = routes.begin(); i != routes.end(); i++) {
		g = (*i)->gain();

		if ( (g+g*factor) >= 0.0f)
			continue;

		if ( g <= 0.0000003f )
			return 0.0f;
		
		factor = 0.0000003f/g - 1.0f;
	}	
	return factor;
}

gain_t
RouteGroup::get_max_factor(gain_t factor)
{
	gain_t g;
	
	for (list<Route *>::iterator i = routes.begin(); i != routes.end(); i++) {
		g = (*i)->gain();
		
		// if the current factor woulnd't raise this route above maximum
		if ( (g+g*factor) <= 1.99526231f) 
			continue;
		
		// if route gain is already at peak, return 0.0f factor
	    if (g>=1.99526231f)
			return 0.0f;

		// factor is calculated so that it would raise current route to max
		factor = 1.99526231f/g - 1.0f;
	}

	return factor;
}

XMLNode&
RouteGroup::get_state (void)
{
	char buf[32];
	XMLNode *node = new XMLNode ("RouteGroup");
	node->add_property ("name", _name);
	snprintf (buf, sizeof (buf), "%" PRIu32, (uint32_t) _flags);
	node->add_property ("flags", buf);
	return *node;
}

int 
RouteGroup::set_state (const XMLNode& node)
{
	const XMLProperty *prop;

	if ((prop = node.property ("name")) != 0) {
		_name = prop->value();
	}

	if ((prop = node.property ("flags")) != 0) {
		_flags = atoi (prop->value().c_str());
	}

	return 0;
}

void
RouteGroup::set_active (bool yn, void *src)

{
	if (is_active() == yn) {
		return;
	}
	if (yn) {
		_flags |= Active;
	} else {
		_flags &= ~Active;
	}
	_session.set_dirty ();
	FlagsChanged (src); /* EMIT SIGNAL */
}

void
RouteGroup::set_relative (bool yn, void *src)

{
	if (is_relative() == yn) {
		return;
	}
	if (yn) {
		_flags |= Relative;
	} else {
		_flags &= ~Relative;
	}
	_session.set_dirty ();
	FlagsChanged (src); /* EMIT SIGNAL */
}

void
RouteGroup::set_hidden (bool yn, void *src)

{
	if (is_hidden() == yn) {
		return;
	}
	if (yn) {
		_flags |= Hidden;
		if (Config->get_hiding_groups_deactivates_groups()) {
			_flags &= ~Active;
		}
	} else {
         	_flags &= ~Hidden;
		if (Config->get_hiding_groups_deactivates_groups()) {
			_flags |= Active;
		}
	}
	_session.set_dirty ();
	FlagsChanged (src); /* EMIT SIGNAL */
}

void
RouteGroup::audio_track_group (set<AudioTrack*>& ats) 
{	
	for (list<Route*>::iterator i = routes.begin(); i != routes.end(); ++i) {
		AudioTrack* at = dynamic_cast<AudioTrack*>(*i);
		if (at) {
			ats.insert (at);
		}
	}
}