2 Copyright (C) 2009 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 #include <io.h> // Microsoft's nearest equivalent to <unistd.h>
21 #include <ardourext/misc.h>
26 #include "pbd/strsplit.h"
27 #include "pbd/convert.h"
29 #include "ardour/controllable_descriptor.h"
33 using namespace ARDOUR;
36 ControllableDescriptor::set (const std::string& str)
38 string::size_type first_space = str.find_first_of (" ");
40 if (first_space == string::npos) {
44 string front = str.substr (0, first_space);
45 string back = str.substr (first_space);
48 split (front, path, '/');
50 if (path.size() < 2) {
55 split (back, rest, ' ');
57 if (rest.size() < 1) {
61 bool stripable = false;
62 regex_t compiled_pattern;
63 const char * const pattern = "^[BS]?[0-9]+";
65 if (path[0] == "route" || path[0] == "rid") {
67 /* this is not going to fail */
68 regcomp (&compiled_pattern, pattern, REG_EXTENDED|REG_NOSUB);
69 bool matched = (regexec (&compiled_pattern, rest[0].c_str(), 0, 0, 0) == 0);
70 regfree (&compiled_pattern);
73 _top_level_type = PresentationOrderRoute;
76 _top_level_type = NamedRoute;
77 _top_level_name = rest[0];
80 } else if (path[0] == "vca") {
81 _top_level_type = PresentationOrderVCA;
83 } else if (path[0] == "bus") {
84 /* digits, or B<digits> or S<digits> will be used as for route;
85 anything else will be treated as a track name.
88 /* this is not going to fail */
90 regcomp (&compiled_pattern, pattern, REG_EXTENDED|REG_NOSUB);
91 bool matched = (regexec (&compiled_pattern, rest[0].c_str(), 0, 0, 0) == 0);
92 regfree (&compiled_pattern);
95 _top_level_type = PresentationOrderBus;
98 _top_level_type = NamedRoute;
99 _top_level_name = rest[0];
102 } else if (path[0] == "track") {
104 /* digits, or B<digits> or S<digits> will be used as for route;
105 anything else will be treated as a track name.
108 /* this is not going to fail */
109 regcomp (&compiled_pattern, pattern, REG_EXTENDED|REG_NOSUB);
110 bool matched = (regexec (&compiled_pattern, rest[0].c_str(), 0, 0, 0) == 0);
111 regfree (&compiled_pattern);
114 _top_level_type = PresentationOrderTrack;
117 _top_level_type = NamedRoute;
118 _top_level_name = rest[0];
123 if (rest[0][0] == 'B') {
125 _presentation_order = atoi (rest[0].substr (1));
126 } else if (rest[0][0] == 'S') {
127 _top_level_type = SelectionCount;
129 _selection_id = atoi (rest[0].substr (1));
130 } else if (isdigit (rest[0][0])) {
132 _presentation_order = atoi (rest[0]);
137 _presentation_order -= 1; /* order is zero-based, but maps use 1-based */
140 if (path[1] == "gain") {
143 } else if (path[1] == "trim") {
146 } else if (path[1] == "solo") {
149 } else if (path[1] == "mute") {
152 } else if (path[1] == "recenable") {
153 _subtype = Recenable;
155 } else if (path[1] == "balance") {
158 } else if (path[1] == "panwidth") {
161 } else if (path[1] == "pandirection") {
162 _subtype = PanDirection;
164 } else if (path[1] == "plugin") {
165 if (path.size() == 3 && rest.size() == 3) {
166 if (path[2] == "parameter") {
167 _subtype = PluginParameter;
168 _target.push_back (atoi (rest[1]));
169 _target.push_back (atoi (rest[2]));
176 } else if (path[1] == "send") {
178 if (path.size() == 3 && rest.size() == 2) {
179 if (path[2] == "gain") {
181 _target.push_back (atoi (rest[1]));
194 ControllableDescriptor::presentation_order () const
197 return _presentation_order + _bank_offset;
200 return _presentation_order;
204 ControllableDescriptor::selection_id () const
207 return _selection_id + _bank_offset;
210 return _selection_id;
214 ControllableDescriptor::target (uint32_t n) const
216 if (n < _target.size()) {