summaryrefslogtreecommitdiff
path: root/libs/ardour/stripable.cc
blob: 6ab83c8922ba63f9a8ee91bad60200446b0cf4ad (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
/*
 * Copyright (C) 2016-2017 Paul Davis <paul@linuxaudiosystems.com>
 * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
 *
 * 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.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <boost/algorithm/string.hpp>

#include "pbd/compose.h"
#include "pbd/convert.h"
#include "pbd/i18n.h"


#include "ardour/debug.h"
#include "ardour/rc_configuration.h"
#include "ardour/session.h"
#include "ardour/selection.h"
#include "ardour/stripable.h"

using namespace ARDOUR;
using namespace PBD;
using std::string;

Stripable::Stripable (Session& s, string const & name, PresentationInfo const & pi)
	: SessionObject (s, name)
	, Automatable (s)
	, _presentation_info (pi)
	, _active_color_picker (0)
{
}

Stripable::~Stripable ()
{
	if (!_session.deletion_in_progress ()) {
		_session.selection().remove_stripable_by_id (id());
	}
}

void
Stripable::set_presentation_order (PresentationInfo::order_t order)
{
	_presentation_info.set_order (order);
}

int
Stripable::set_state (XMLNode const& node, int version)
{
	const XMLProperty *prop;
	XMLNodeList const & nlist (node.children());
	XMLNodeConstIterator niter;
	XMLNode *child;

	if (version > 3001) {

		for (niter = nlist.begin(); niter != nlist.end(); ++niter){
			child = *niter;

			if (child->name() == PresentationInfo::state_node_name) {
				_presentation_info.set_state (*child, version);
			}
		}

	} else {

		/* Older versions of Ardour stored "_flags" as a property of the Route
		 * node, only for 3 special Routes (MasterOut, MonitorOut, Auditioner.
		 *
		 * Their presentation order was stored in a node called "RemoteControl"
		 *
		 * This information is now part of the PresentationInfo of every Stripable.
		 */

		if ((prop = node.property (X_("flags"))) != 0) {

			/* 4.x and earlier - didn't have Stripable but the
			 * relevant enums have the same names (MasterOut,
			 * MonitorOut, Auditioner), so we can use string_2_enum
			 */

			PresentationInfo::Flag flags;

			if (version < 3000) {
				string f (prop->value());
				boost::replace_all (f, "ControlOut", "MonitorOut");
				flags = PresentationInfo::Flag (string_2_enum (f, flags));
			} else {
				flags = PresentationInfo::Flag (string_2_enum (prop->value(), flags));
			}

			_presentation_info.set_flags (flags);

		}

		if (!_presentation_info.special(false)) {
			if ((prop = node.property (X_("order-key"))) != 0) {
				_presentation_info.set_order (atol (prop->value()));
			}
		}
	}

	return 0;
}

bool
Stripable::is_selected() const
{
	try {
		boost::shared_ptr<const Stripable> s (shared_from_this());
	} catch (...) {
		std::cerr << "cannot shared-from-this for " << this << std::endl;
		abort ();
	}
	return _session.selection().selected (shared_from_this());
}

bool
Stripable::Sorter::operator() (boost::shared_ptr<ARDOUR::Stripable> a, boost::shared_ptr<ARDOUR::Stripable> b)
{
	const PresentationInfo::Flag a_flag = a->presentation_info().flags ();
	const PresentationInfo::Flag b_flag = b->presentation_info().flags ();

	if (a_flag == b_flag) {
		return a->presentation_info().order() < b->presentation_info().order();
	}

	int cmp_a = 0;
	int cmp_b = 0;

	if (a->is_auditioner ()) { cmp_a = -2; }
	if (b->is_auditioner ()) { cmp_b = -2; }
	if (a->is_monitor ())    { cmp_a = -1; }
	if (b->is_monitor ())    { cmp_b = -1; }

	/* ARDOUR-Editor: [Track|Bus|Master] (0) < VCA (3)
	 * ARDOUR-Mixer : [Track|Bus] (0) < VCA (3) < Master (4)
	 *
	 * Mixbus-Editor: [Track|Bus] (0) < Mixbus (1) < VCA (3) < Master (4)
	 * Mixbus-Mixer : [Track|Bus] (0) < Mixbus (1) < Master (2) < VCA (3)
	 */

	if (a_flag & ARDOUR::PresentationInfo::VCA) {
		cmp_a = 3;
	}
#ifdef MIXBUS
	else if (a_flag & ARDOUR::PresentationInfo::MasterOut) {
		cmp_a = _mixer_order ? 2 : 4;
	}
	else if (a_flag & ARDOUR::PresentationInfo::Mixbus) {
		cmp_a = 1;
	}
#endif
	else if (_mixer_order && (a_flag & ARDOUR::PresentationInfo::MasterOut)) {
		cmp_a = 4;
	}


	if (b_flag & ARDOUR::PresentationInfo::VCA) {
		cmp_b = 3;
	}
#ifdef MIXBUS
	else if (b_flag & ARDOUR::PresentationInfo::MasterOut) {
		cmp_b = _mixer_order ? 2 : 4;
	}
	else if (b_flag & ARDOUR::PresentationInfo::Mixbus) {
		cmp_b = 1;
	}
#endif
	else if (_mixer_order && (b_flag & ARDOUR::PresentationInfo::MasterOut)) {
		cmp_b = 4;
	}

	if (cmp_a == cmp_b) {
		return a->presentation_info().order() < b->presentation_info().order();
	}
	return cmp_a < cmp_b;
}