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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
|
/* -*- 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 <[email protected]>,
Chris Cannam <[email protected]>,
Richard Bown <[email protected]>
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 "AudioInstrumentParameterPanel.h"
#include <tqlayout.h>
#include <kapplication.h>
#include <klocale.h>
#include "misc/Debug.h"
#include "misc/Strings.h"
#include "base/AudioPluginInstance.h"
#include "base/Instrument.h"
#include "base/MidiProgram.h"
#include "document/RosegardenGUIDoc.h"
#include "gui/studio/AudioPluginManager.h"
#include "gui/studio/AudioPlugin.h"
#include "gui/studio/StudioControl.h"
#include "gui/widgets/AudioFaderBox.h"
#include "gui/widgets/AudioVUMeter.h"
#include "gui/widgets/Fader.h"
#include "gui/widgets/Rotary.h"
#include "gui/widgets/AudioRouteMenu.h"
#include "InstrumentParameterPanel.h"
#include "sound/MappedCommon.h"
#include "sound/MappedStudio.h"
#include <tqcolor.h>
#include <tqframe.h>
#include <tqlabel.h>
#include <tqpalette.h>
#include <tqpixmap.h>
#include <tqpushbutton.h>
#include <tqstring.h>
#include <tqtooltip.h>
#include <tqwidget.h>
#include <tqsignalmapper.h>
namespace Rosegarden
{
void
AudioInstrumentParameterPanel::slotSelectAudioLevel(float dB)
{
if (m_selectedInstrument == 0)
return ;
if (m_selectedInstrument->getType() == Instrument::Audio ||
m_selectedInstrument->getType() == Instrument::SoftSynth) {
m_selectedInstrument->setLevel(dB);
StudioControl::setStudioObjectProperty
(MappedObjectId(m_selectedInstrument->getMappedId()),
MappedAudioFader::FaderLevel,
MappedObjectValue(dB));
}
emit updateAllBoxes();
emit instrumentParametersChanged(m_selectedInstrument->getId());
}
void
AudioInstrumentParameterPanel::slotSelectAudioRecordLevel(float dB)
{
if (m_selectedInstrument == 0)
return ;
// std::cerr << "AudioInstrumentParameterPanel::slotSelectAudioRecordLevel("
// << dB << ")" << std::endl;
if (m_selectedInstrument->getType() == Instrument::Audio) {
m_selectedInstrument->setRecordLevel(dB);
StudioControl::setStudioObjectProperty
(MappedObjectId(m_selectedInstrument->getMappedId()),
MappedAudioFader::FaderRecordLevel,
MappedObjectValue(dB));
emit updateAllBoxes();
emit instrumentParametersChanged(m_selectedInstrument->getId());
}
}
void
AudioInstrumentParameterPanel::slotPluginSelected(InstrumentId instrumentId,
int index, int plugin)
{
if (!m_selectedInstrument ||
instrumentId != m_selectedInstrument->getId())
return ;
RG_DEBUG << "AudioInstrumentParameterPanel::slotPluginSelected - "
<< "instrument = " << instrumentId
<< ", index = " << index
<< ", plugin = " << plugin << endl;
TQColor pluginBackgroundColour = TQt::black;
bool bypassed = false;
TQPushButton *button = 0;
TQString noneText;
// updates synth gui button &c:
m_audioFader->slotSetInstrument(&m_doc->getStudio(), m_selectedInstrument);
if (index == (int)Instrument::SYNTH_PLUGIN_POSITION) {
button = m_audioFader->m_synthButton;
noneText = i18n("<no synth>");
} else {
button = m_audioFader->m_plugins[index];
noneText = i18n("<no plugin>");
}
if (!button)
return ;
if (plugin == -1) {
button->setText(noneText);
TQToolTip::add
(button, noneText);
} else {
AudioPlugin *pluginClass = m_doc->getPluginManager()->getPlugin(plugin);
if (pluginClass) {
button->setText(pluginClass->getLabel());
TQToolTip::add
(button, pluginClass->getLabel());
pluginBackgroundColour = pluginClass->getColour();
}
}
AudioPluginInstance *inst =
m_selectedInstrument->getPlugin(index);
if (inst)
bypassed = inst->isBypassed();
setButtonColour(index, bypassed, pluginBackgroundColour);
if (index == (int)Instrument::SYNTH_PLUGIN_POSITION) {
emit changeInstrumentLabel(instrumentId, button->text());
}
}
void
AudioInstrumentParameterPanel::slotPluginBypassed(InstrumentId instrumentId,
int pluginIndex, bool bp)
{
if (!m_selectedInstrument ||
instrumentId != m_selectedInstrument->getId())
return ;
AudioPluginInstance *inst =
m_selectedInstrument->getPlugin(pluginIndex);
TQColor backgroundColour = TQt::black; // default background colour
if (inst && inst->isAssigned()) {
AudioPlugin *pluginClass
= m_doc->getPluginManager()->getPlugin(
m_doc->getPluginManager()->
getPositionByIdentifier(inst->getIdentifier().c_str()));
/// Set the colour on the button
//
if (pluginClass)
backgroundColour = pluginClass->getColour();
}
setButtonColour(pluginIndex, bp, backgroundColour);
}
void
AudioInstrumentParameterPanel::setButtonColour(
int pluginIndex, bool bypassState, const TQColor &colour)
{
RG_DEBUG << "AudioInstrumentParameterPanel::setButtonColour "
<< "pluginIndex = " << pluginIndex
<< ", bypassState = " << bypassState
<< ", rgb = " << TQString(colour.name()).ascii() << endl;
TQPushButton *button = 0;
if (pluginIndex == Instrument::SYNTH_PLUGIN_POSITION) {
button = m_audioFader->m_synthButton;
} else {
button = m_audioFader->m_plugins[pluginIndex];
}
if (!button)
return ;
// Set the bypass colour on the plugin button
if (bypassState) {
button->
setPaletteForegroundColor(kapp->palette().
color(TQPalette::Active, TQColorGroup::Button));
button->
setPaletteBackgroundColor(kapp->palette().
color(TQPalette::Active, TQColorGroup::ButtonText));
} else if (colour == TQt::black) {
button->
setPaletteForegroundColor(kapp->palette().
color(TQPalette::Active, TQColorGroup::ButtonText));
button->
setPaletteBackgroundColor(kapp->palette().
color(TQPalette::Active, TQColorGroup::Button));
} else {
button->
setPaletteForegroundColor(TQt::white);
button->
setPaletteBackgroundColor(colour);
}
}
AudioInstrumentParameterPanel::AudioInstrumentParameterPanel(RosegardenGUIDoc* doc, TQWidget* parent)
: InstrumentParameterPanel(doc, parent),
m_audioFader(new AudioFaderBox(this))
{
TQGridLayout *gridLayout = new TQGridLayout(this, 3, 2, 5, 5);
// Instrument label : first row, all cols
gridLayout->addMultiCellWidget(m_instrumentLabel, 0, 0, 0, 1, AlignCenter);
// fader and connect it
gridLayout->addMultiCellWidget(m_audioFader, 1, 1, 0, 1);
gridLayout->setRowStretch(2, 1);
connect(m_audioFader, TQT_SIGNAL(audioChannelsChanged(int)),
this, TQT_SLOT(slotAudioChannels(int)));
connect(m_audioFader->m_signalMapper, TQT_SIGNAL(mapped(int)),
this, TQT_SLOT(slotSelectPlugin(int)));
connect(m_audioFader->m_fader, TQT_SIGNAL(faderChanged(float)),
this, TQT_SLOT(slotSelectAudioLevel(float)));
connect(m_audioFader->m_recordFader, TQT_SIGNAL(faderChanged(float)),
this, TQT_SLOT(slotSelectAudioRecordLevel(float)));
connect(m_audioFader->m_pan, TQT_SIGNAL(valueChanged(float)),
this, TQT_SLOT(slotSetPan(float)));
connect(m_audioFader->m_audioOutput, TQT_SIGNAL(changed()),
this, TQT_SLOT(slotAudioRoutingChanged()));
connect(m_audioFader->m_audioInput, TQT_SIGNAL(changed()),
this, TQT_SLOT(slotAudioRoutingChanged()));
connect(m_audioFader->m_synthButton, TQT_SIGNAL(clicked()),
this, TQT_SLOT(slotSynthButtonClicked()));
connect(m_audioFader->m_synthGUIButton, TQT_SIGNAL(clicked()),
this, TQT_SLOT(slotSynthGUIButtonClicked()));
}
void
AudioInstrumentParameterPanel::slotSynthButtonClicked()
{
slotSelectPlugin(Instrument::SYNTH_PLUGIN_POSITION);
}
void
AudioInstrumentParameterPanel::slotSynthGUIButtonClicked()
{
emit showPluginGUI(m_selectedInstrument->getId(),
Instrument::SYNTH_PLUGIN_POSITION);
}
void
AudioInstrumentParameterPanel::slotSetPan(float pan)
{
RG_DEBUG << "AudioInstrumentParameterPanel::slotSetPan - "
<< "pan = " << pan << endl;
StudioControl::setStudioObjectProperty
(MappedObjectId(m_selectedInstrument->getMappedId()),
MappedAudioFader::Pan,
MappedObjectValue(pan));
m_selectedInstrument->setPan(MidiByte(pan + 100.0));
emit instrumentParametersChanged(m_selectedInstrument->getId());
}
void
AudioInstrumentParameterPanel::setAudioMeter(float dBleft, float dBright,
float recDBleft, float recDBright)
{
// RG_DEBUG << "AudioInstrumentParameterPanel::setAudioMeter: (" << dBleft
// << "," << dBright << ")" << endl;
if (m_selectedInstrument) {
// Always set stereo, because we have to reflect what's happening
// with the pan setting even on mono tracks
m_audioFader->m_vuMeter->setLevel(dBleft, dBright);
m_audioFader->m_vuMeter->setRecordLevel(recDBleft, recDBright);
}
}
void
AudioInstrumentParameterPanel::setupForInstrument(Instrument* instrument)
{
blockSignals(true);
m_selectedInstrument = instrument;
m_instrumentLabel->setText(strtoqstr(instrument->getName()));
m_audioFader->m_recordFader->setFader(instrument->getRecordLevel());
m_audioFader->m_fader->setFader(instrument->getLevel());
m_audioFader->slotSetInstrument(&m_doc->getStudio(), instrument);
int start = 0;
if (instrument->getType() == Instrument::SoftSynth)
start = -1;
for (int i = start; i < int(m_audioFader->m_plugins.size()); i++) {
int index;
TQPushButton *button;
TQString noneText;
if (i == -1) {
index = Instrument::SYNTH_PLUGIN_POSITION;
button = m_audioFader->m_synthButton;
noneText = i18n("<no synth>");
} else {
index = i;
button = m_audioFader->m_plugins[i];
noneText = i18n("<no plugin>");
}
button->show();
AudioPluginInstance *inst = instrument->getPlugin(index);
if (inst && inst->isAssigned()) {
AudioPlugin *pluginClass
= m_doc->getPluginManager()->getPlugin(
m_doc->getPluginManager()->
getPositionByIdentifier(inst->getIdentifier().c_str()));
if (pluginClass) {
button->setText(pluginClass->getLabel());
TQToolTip::add
(button, pluginClass->getLabel());
setButtonColour(index, inst->isBypassed(),
pluginClass->getColour());
}
} else {
button->setText(noneText);
TQToolTip::add
(button, noneText);
setButtonColour(index, inst ? inst->isBypassed() : false, TQt::black);
}
}
// Set the number of channels on the fader widget
//
m_audioFader->setAudioChannels(instrument->getAudioChannels());
// Pan - adjusted backwards
//
m_audioFader->m_pan->setPosition(instrument->getPan() - 100);
// Tell fader box whether to include e.g. audio input selection
//
m_audioFader->setIsSynth(instrument->getType() == Instrument::SoftSynth);
blockSignals(false);
}
void
AudioInstrumentParameterPanel::slotAudioChannels(int channels)
{
RG_DEBUG << "AudioInstrumentParameterPanel::slotAudioChannels - "
<< "channels = " << channels << endl;
m_selectedInstrument->setAudioChannels(channels);
StudioControl::setStudioObjectProperty
(MappedObjectId(m_selectedInstrument->getMappedId()),
MappedAudioFader::Channels,
MappedObjectValue(channels));
emit instrumentParametersChanged(m_selectedInstrument->getId());
}
void
AudioInstrumentParameterPanel::slotAudioRoutingChanged()
{
if (m_selectedInstrument)
emit instrumentParametersChanged(m_selectedInstrument->getId());
}
void
AudioInstrumentParameterPanel::slotSelectPlugin(int index)
{
if (m_selectedInstrument) {
emit selectPlugin(0, m_selectedInstrument->getId(), index);
}
}
}
#include "AudioInstrumentParameterPanel.moc"
|