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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
// -*- c-basic-offset: 4 -*-
/*
Rosegarden
A sequencer and musical notation editor.
This program is Copyright 2000-2008
Guillaume Laurent <[email protected]>,
Chris Cannam <[email protected]>,
Richard Bown <[email protected]>
The moral right of the authors to claim authorship of this work
has been asserted.
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. See the file
COPYING included with this distribution for more information.
*/
#include "AudioPluginInstance.h"
#include "Instrument.h"
#include <iostream>
#include <cstring>
#include <sstream>
namespace Rosegarden
{
// ------------------ PluginPort ---------------------
//
PluginPort::PluginPort(int number,
std::string name,
PluginPort::PortType type,
PluginPort::PortDisplayHint hint,
PortData lowerBound,
PortData upperBound,
PortData defaultValue):
m_number(number),
m_name(name),
m_type(type),
m_displayHint(hint),
m_lowerBound(lowerBound),
m_upperBound(upperBound),
m_default(defaultValue)
{
}
AudioPluginInstance::AudioPluginInstance(unsigned int position):
m_mappedId(-1),
m_identifier(""),
m_position(position),
m_assigned(false),
m_bypass(false),
m_program("")
{
}
AudioPluginInstance::AudioPluginInstance(std::string identifier,
unsigned int position):
m_mappedId(-1),
m_identifier(identifier),
m_position(position),
m_assigned(true)
{
}
std::string
AudioPluginInstance::toXmlString()
{
std::stringstream plugin;
if (m_assigned == false)
{
#if (__GNUC__ < 3)
plugin << std::ends;
#endif
return plugin.str();
}
if (m_position == Instrument::SYNTH_PLUGIN_POSITION) {
plugin << " <synth ";
} else {
plugin << " <plugin"
<< " position=\""
<< m_position
<< "\" ";
}
plugin << "identifier=\""
<< encode(m_identifier)
<< "\" bypassed=\"";
if (m_bypass)
plugin << "true\" ";
else
plugin << "false\" ";
if (m_program != "") {
plugin << "program=\"" << encode(m_program) << "\"";
}
plugin << ">" << std::endl;
for (unsigned int i = 0; i < m_ports.size(); i++)
{
plugin << " <port id=\""
<< m_ports[i]->number
<< "\" value=\""
<< m_ports[i]->value
<< "\" changed=\""
<< (m_ports[i]->changedSinceProgramChange ? "true" : "false")
<< "\"/>" << std::endl;
}
for (ConfigMap::iterator i = m_config.begin(); i != m_config.end(); ++i) {
plugin << " <configure key=\""
<< encode(i->first) << "\" value=\""
<< encode(i->second) << "\"/>" << std::endl;
}
if (m_position == Instrument::SYNTH_PLUGIN_POSITION) {
plugin << " </synth>";
} else {
plugin << " </plugin>";
}
#if (__GNUC__ < 3)
plugin << std::endl << std::ends;
#else
plugin << std::endl;
#endif
return plugin.str();
}
void
AudioPluginInstance::addPort(int number, PortData value)
{
m_ports.push_back(new PluginPortInstance(number, value));
}
bool
AudioPluginInstance::removePort(int number)
{
PortInstanceIterator it = m_ports.begin();
for (; it != m_ports.end(); ++it)
{
if ((*it)->number == number)
{
delete (*it);
m_ports.erase(it);
return true;
}
}
return false;
}
PluginPortInstance*
AudioPluginInstance::getPort(int number)
{
PortInstanceIterator it = m_ports.begin();
for (; it != m_ports.end(); ++it)
{
if ((*it)->number == number)
return *it;
}
return 0;
}
void
AudioPluginInstance::clearPorts()
{
PortInstanceIterator it = m_ports.begin();
for (; it != m_ports.end(); ++it)
delete (*it);
m_ports.erase(m_ports.begin(), m_ports.end());
}
std::string
AudioPluginInstance::getConfigurationValue(std::string k) const
{
ConfigMap::const_iterator i = m_config.find(k);
if (i != m_config.end()) return i->second;
return "";
}
void
AudioPluginInstance::setProgram(std::string program)
{
m_program = program;
PortInstanceIterator it = m_ports.begin();
for (; it != m_ports.end(); ++it) {
(*it)->changedSinceProgramChange = false;
}
}
void
AudioPluginInstance::setConfigurationValue(std::string k, std::string v)
{
m_config[k] = v;
}
std::string
AudioPluginInstance::getDistinctiveConfigurationText() const
{
std::string base = getConfigurationValue("load");
if (base == "") {
for (ConfigMap::const_iterator i = m_config.begin();
i != m_config.end(); ++i) {
if (!strncmp(i->first.c_str(),
"__ROSEGARDEN__",
strlen("__ROSEGARDEN__"))) continue;
if (i->second != "" && i->second[0] == '/') {
base = i->second;
break;
} else if (base != "") {
base = i->second;
}
}
}
if (base == "") return "";
std::string::size_type s = base.rfind('/');
if (s < base.length() - 1) base = base.substr(s + 1);
std::string::size_type d = base.rfind('.');
if (d < base.length() - 1 && d > 0) base = base.substr(0, d);
return base;
}
}
|