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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Rosegarden
A MIDI and audio sequencer and musical notation editor.
This program is Copyright 2000-2008
Guillaume Laurent <glaurent@telegraph-road.org>,
Chris Cannam <cannam@all-day-breakfast.com>,
Richard Bown <richard.bown@ferventsoftware.com>
The moral rights of Guillaume Laurent, Chris Cannam, and Richard
Bown to claim authorship of this work have been asserted.
Other copyrights also apply to some parts of this work. Please
see the AUTHORS file and individual file headers for details.
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 "AudioPluginManager.h"
#include "misc/Debug.h"
#include "AudioPluginClipboard.h"
#include "AudioPlugin.h"
#include "base/AudioPluginInstance.h"
#include "gui/application/RosegardenApplication.h"
#include "sound/PluginFactory.h"
#include "sound/PluginIdentifier.h"
#include <tqcstring.h>
#include <tqdatastream.h>
#include <tqmutex.h>
#include <tqstring.h>
#include <tqthread.h>
#include <unistd.h>
namespace Rosegarden
{
AudioPluginManager::AudioPluginManager() :
m_sampleRate(0),
m_enumerator(this)
{
// std::cerr << "AudioPluginManager[" << this << "]::AudioPluginManager - "
// << "trace is ";
// std::cerr << kdBacktrace() << std::endl;
// fetch from sequencer
fetchSampleRate();
// Clear the plugin clipboard
//
m_pluginClipboard.m_pluginNumber = -1;
m_pluginClipboard.m_program = "";
m_pluginClipboard.m_controlValues.clear();
m_enumerator.start();
}
AudioPluginManager::Enumerator::Enumerator(AudioPluginManager *manager) :
m_manager(manager),
m_done(false)
{}
void
AudioPluginManager::Enumerator::run()
{
TQMutexLocker locker(&(m_manager->m_mutex));
MappedObjectPropertyList rawPlugins;
RG_DEBUG << "\n\nAudioPluginManager::Enumerator::run()\n\n" << endl;
if (!rgapp->noSequencerMode()) {
// We only waste the time looking for plugins here if we
// know we're actually going to be able to use them.
PluginFactory::enumerateAllPlugins(rawPlugins);
}
unsigned int i = 0;
while (i < rawPlugins.size()) {
TQString identifier = rawPlugins[i++];
TQString name = rawPlugins[i++];
unsigned long uniqueId = rawPlugins[i++].toLong();
TQString label = rawPlugins[i++];
TQString author = rawPlugins[i++];
TQString copyright = rawPlugins[i++];
bool isSynth = ((rawPlugins[i++]).lower() == "true");
bool isGrouped = ((rawPlugins[i++]).lower() == "true");
TQString category = rawPlugins[i++];
unsigned int portCount = rawPlugins[i++].toInt();
// std::cerr << "PLUGIN: " << i << ": " << (identifier ? identifier : "(null)") << " unique id " << uniqueId << " / CATEGORY: \"" << (category ? category : "(null)") << "\"" << std::endl;
AudioPlugin *aP = m_manager->addPlugin(identifier,
name,
uniqueId,
label,
author,
copyright,
isSynth,
isGrouped,
category);
for (unsigned int j = 0; j < portCount; j++) {
int number = rawPlugins[i++].toInt();
name = rawPlugins[i++];
PluginPort::PortType type =
PluginPort::PortType(rawPlugins[i++].toInt());
PluginPort::PortDisplayHint hint =
PluginPort::PortDisplayHint(rawPlugins[i++].toInt());
PortData lowerBound = rawPlugins[i++].toFloat();
PortData upperBound = rawPlugins[i++].toFloat();
PortData defaultValue = rawPlugins[i++].toFloat();
aP->addPort(number,
name,
type,
hint,
lowerBound,
upperBound,
defaultValue);
}
}
m_done = true;
RG_DEBUG << "\n\nAudioPluginManager::Enumerator::run() - done\n\n" << endl;
}
AudioPlugin*
AudioPluginManager::addPlugin(const TQString &identifier,
const TQString &name,
unsigned long uniqueId,
const TQString &label,
const TQString &author,
const TQString ©right,
bool isSynth,
bool isGrouped,
const TQString &category)
{
AudioPlugin *newPlugin = new AudioPlugin(identifier,
name,
uniqueId,
label,
author,
copyright,
isSynth,
isGrouped,
category);
m_plugins.push_back(newPlugin);
return newPlugin;
}
bool
AudioPluginManager::removePlugin(const TQString &identifier)
{
std::vector<AudioPlugin*>::iterator it = m_plugins.begin();
for (; it != m_plugins.end(); ++it) {
if ((*it)->getIdentifier() == identifier) {
delete *it;
m_plugins.erase(it);
return true;
}
}
return false;
}
std::vector<TQString>
AudioPluginManager::getPluginNames()
{
awaitEnumeration();
std::vector<TQString> names;
PluginIterator it = m_plugins.begin();
for (; it != m_plugins.end(); ++it)
names.push_back((*it)->getName());
return names;
}
AudioPlugin*
AudioPluginManager::getPlugin(int number)
{
awaitEnumeration();
if (number < 0 || number > (int(m_plugins.size()) - 1))
return 0;
return m_plugins[number];
}
int
AudioPluginManager::getPositionByIdentifier(TQString identifier)
{
awaitEnumeration();
int pos = 0;
PluginIterator it = m_plugins.begin();
for (; it != m_plugins.end(); ++it) {
if ((*it)->getIdentifier() == identifier)
return pos;
pos++;
}
pos = 0;
it = m_plugins.begin();
for (; it != m_plugins.end(); ++it) {
if (PluginIdentifier::areIdentifiersSimilar((*it)->getIdentifier(), identifier))
return pos;
pos++;
}
return -1;
}
AudioPlugin*
AudioPluginManager::getPluginByIdentifier(TQString identifier)
{
awaitEnumeration();
PluginIterator it = m_plugins.begin();
for (; it != m_plugins.end(); ++it) {
if ((*it)->getIdentifier() == identifier)
return (*it);
}
it = m_plugins.begin();
for (; it != m_plugins.end(); ++it) {
if (PluginIdentifier::areIdentifiersSimilar((*it)->getIdentifier(), identifier))
return (*it);
}
return 0;
}
AudioPlugin*
AudioPluginManager::getPluginByUniqueId(unsigned long uniqueId)
{
awaitEnumeration();
PluginIterator it = m_plugins.begin();
for (; it != m_plugins.end(); ++it) {
if ((*it)->getUniqueId() == uniqueId)
return (*it);
}
return 0;
}
PluginIterator
AudioPluginManager::begin()
{
awaitEnumeration();
return m_plugins.begin();
}
PluginIterator
AudioPluginManager::end()
{
awaitEnumeration();
return m_plugins.end();
}
void
AudioPluginManager::awaitEnumeration()
{
while (!m_enumerator.isDone()) {
RG_DEBUG << "\n\nAudioPluginManager::awaitEnumeration() - waiting\n\n" << endl;
// m_mutex.lock();
usleep(100000);
// m_mutex.unlock();
}
}
void
AudioPluginManager::fetchSampleRate()
{
TQCString replyType;
TQByteArray replyData;
if (rgapp->sequencerCall("getSampleRate()", replyType, replyData)) {
TQDataStream streamIn(replyData, IO_ReadOnly);
unsigned int result;
streamIn >> result;
m_sampleRate = result;
}
}
}
|