1 |
// qsamplerChannelStrip.cpp |
// qsamplerChannelStrip.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2010, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
Copyright (C) 2007, Christian Schoenebeck |
Copyright (C) 2007, 2008 Christian Schoenebeck |
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU General Public License |
modify it under the terms of the GNU General Public License |
20 |
|
|
21 |
*****************************************************************************/ |
*****************************************************************************/ |
22 |
|
|
23 |
|
#include "qsamplerAbout.h" |
24 |
#include "qsamplerChannelStrip.h" |
#include "qsamplerChannelStrip.h" |
25 |
|
|
26 |
#include "qsamplerMainForm.h" |
#include "qsamplerMainForm.h" |
27 |
|
|
28 |
#include <q3dragobject.h> |
#include "qsamplerChannelFxForm.h" |
29 |
|
|
30 |
|
#include <QMessageBox> |
31 |
|
#include <QDragEnterEvent> |
32 |
|
#include <QTimer> |
33 |
#include <QUrl> |
#include <QUrl> |
34 |
|
|
|
#include <math.h> |
|
35 |
|
|
36 |
// Channel status/usage usage limit control. |
// Channel status/usage usage limit control. |
37 |
#define QSAMPLER_ERROR_LIMIT 3 |
#define QSAMPLER_ERROR_LIMIT 3 |
38 |
|
|
39 |
|
// Needed for lroundf() |
40 |
|
#include <math.h> |
41 |
|
|
42 |
|
#ifndef CONFIG_ROUND |
43 |
|
static inline long lroundf ( float x ) |
44 |
|
{ |
45 |
|
if (x >= 0.0f) |
46 |
|
return long(x + 0.5f); |
47 |
|
else |
48 |
|
return long(x - 0.5f); |
49 |
|
} |
50 |
|
#endif |
51 |
|
|
52 |
|
|
53 |
namespace QSampler { |
namespace QSampler { |
54 |
|
|
55 |
ChannelStrip::ChannelStrip(QWidget* parent, Qt::WFlags f) : QWidget(parent, f) { |
//------------------------------------------------------------------------- |
56 |
ui.setupUi(this); |
// QSampler::ChannelStrip -- Channel strip form implementation. |
57 |
|
// |
58 |
|
|
59 |
// Initialize locals. |
// MIDI activity pixmap common resources. |
60 |
m_pChannel = NULL; |
int ChannelStrip::g_iMidiActivityRefCount = 0; |
61 |
m_iDirtyChange = 0; |
QPixmap *ChannelStrip::g_pMidiActivityLedOn = NULL; |
62 |
m_iErrorCount = 0; |
QPixmap *ChannelStrip::g_pMidiActivityLedOff = NULL; |
63 |
|
|
64 |
|
// Channel strip activation/selection. |
65 |
|
ChannelStrip *ChannelStrip::g_pSelectedStrip = NULL; |
66 |
|
|
67 |
|
ChannelStrip::ChannelStrip ( QWidget* pParent, Qt::WindowFlags wflags ) |
68 |
|
: QWidget(pParent, wflags) |
69 |
|
{ |
70 |
|
m_ui.setupUi(this); |
71 |
|
|
72 |
|
// Initialize locals. |
73 |
|
m_pChannel = NULL; |
74 |
|
m_iDirtyChange = 0; |
75 |
|
m_iErrorCount = 0; |
76 |
|
|
77 |
|
if (++g_iMidiActivityRefCount == 1) { |
78 |
|
g_pMidiActivityLedOn = new QPixmap(":/icons/ledon1.png"); |
79 |
|
g_pMidiActivityLedOff = new QPixmap(":/icons/ledoff1.png"); |
80 |
|
} |
81 |
|
|
82 |
|
m_ui.MidiActivityLabel->setPixmap(*g_pMidiActivityLedOff); |
83 |
|
|
84 |
|
#ifndef CONFIG_EVENT_CHANNEL_MIDI |
85 |
|
m_ui.MidiActivityLabel->setToolTip("MIDI activity (disabled)"); |
86 |
|
#endif |
87 |
|
|
88 |
// Try to restore normal window positioning. |
m_pMidiActivityTimer = new QTimer(this); |
89 |
adjustSize(); |
m_pMidiActivityTimer->setSingleShot(true); |
90 |
|
|
91 |
QObject::connect(ui.ChannelSetupPushButton, |
QObject::connect(m_pMidiActivityTimer, |
92 |
|
SIGNAL(timeout()), |
93 |
|
SLOT(midiActivityLedOff()) |
94 |
|
); |
95 |
|
|
96 |
|
// Try to restore normal window positioning. |
97 |
|
adjustSize(); |
98 |
|
|
99 |
|
QObject::connect(m_ui.ChannelSetupPushButton, |
100 |
SIGNAL(clicked()), |
SIGNAL(clicked()), |
101 |
SLOT(channelSetup())); |
SLOT(channelSetup())); |
102 |
QObject::connect(ui.ChannelMutePushButton, |
QObject::connect(m_ui.ChannelMutePushButton, |
103 |
SIGNAL(toggled(bool)), |
SIGNAL(toggled(bool)), |
104 |
SLOT(channelMute(bool))); |
SLOT(channelMute(bool))); |
105 |
QObject::connect(ui.ChannelSoloPushButton, |
QObject::connect(m_ui.ChannelSoloPushButton, |
106 |
SIGNAL(toggled(bool)), |
SIGNAL(toggled(bool)), |
107 |
SLOT(channelSolo(bool))); |
SLOT(channelSolo(bool))); |
108 |
QObject::connect(ui.VolumeSlider, |
QObject::connect(m_ui.VolumeSlider, |
109 |
SIGNAL(valueChanged(int)), |
SIGNAL(valueChanged(int)), |
110 |
SLOT(volumeChanged(int))); |
SLOT(volumeChanged(int))); |
111 |
QObject::connect(ui.VolumeSpinBox, |
QObject::connect(m_ui.VolumeSpinBox, |
112 |
SIGNAL(valueChanged(int)), |
SIGNAL(valueChanged(int)), |
113 |
SLOT(volumeChanged(int))); |
SLOT(volumeChanged(int))); |
114 |
QObject::connect(ui.ChannelEditPushButton, |
QObject::connect(m_ui.ChannelEditPushButton, |
115 |
SIGNAL(clicked()), |
SIGNAL(clicked()), |
116 |
SLOT(channelEdit())); |
SLOT(channelEdit())); |
117 |
} |
QObject::connect(m_ui.FxPushButton, |
118 |
|
SIGNAL(clicked()), |
119 |
|
SLOT(channelFxEdit())); |
120 |
|
|
121 |
ChannelStrip::~ChannelStrip() { |
setSelected(false); |
|
// Destroy existing channel descriptor. |
|
|
if (m_pChannel) |
|
|
delete m_pChannel; |
|
|
m_pChannel = NULL; |
|
122 |
} |
} |
123 |
|
|
124 |
|
|
125 |
// Drag'n'drop file handler. |
ChannelStrip::~ChannelStrip (void) |
|
bool ChannelStrip::decodeDragFile ( const QMimeSource *pEvent, QString& sInstrumentFile ) |
|
126 |
{ |
{ |
127 |
if (m_pChannel == NULL) |
setSelected(false); |
128 |
return false; |
|
129 |
if (Q3TextDrag::canDecode(pEvent)) { |
// Destroy existing channel descriptor. |
130 |
QString sText; |
if (m_pChannel) |
131 |
if (Q3TextDrag::decode(pEvent, sText)) { |
delete m_pChannel; |
132 |
QStringList files = QStringList::split('\n', sText); |
m_pChannel = NULL; |
133 |
for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) { |
|
134 |
*iter = QUrl((*iter).stripWhiteSpace().replace(QRegExp("^file:"), QString::null)).path(); |
if (--g_iMidiActivityRefCount == 0) { |
135 |
if (qsamplerChannel::isInstrumentFile(*iter)) { |
if (g_pMidiActivityLedOn) |
136 |
sInstrumentFile = *iter; |
delete g_pMidiActivityLedOn; |
137 |
return true; |
g_pMidiActivityLedOn = NULL; |
138 |
} |
if (g_pMidiActivityLedOff) |
139 |
} |
delete g_pMidiActivityLedOff; |
140 |
} |
g_pMidiActivityLedOff = NULL; |
141 |
} |
} |
|
// Fail. |
|
|
return false; |
|
142 |
} |
} |
143 |
|
|
144 |
|
|
145 |
// Window drag-n-drop event handlers. |
// Window drag-n-drop event handlers. |
146 |
void ChannelStrip::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent ) |
void ChannelStrip::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent ) |
147 |
{ |
{ |
148 |
QString sInstrumentFile; |
if (m_pChannel == NULL) |
149 |
pDragEnterEvent->accept(decodeDragFile(pDragEnterEvent, sInstrumentFile)); |
return; |
150 |
|
|
151 |
|
bool bAccept = false; |
152 |
|
|
153 |
|
if (pDragEnterEvent->source() == NULL) { |
154 |
|
const QMimeData *pMimeData = pDragEnterEvent->mimeData(); |
155 |
|
if (pMimeData && pMimeData->hasUrls()) { |
156 |
|
QListIterator<QUrl> iter(pMimeData->urls()); |
157 |
|
while (iter.hasNext()) { |
158 |
|
const QString& sFilename = iter.next().toLocalFile(); |
159 |
|
if (!sFilename.isEmpty()) { |
160 |
|
bAccept = Channel::isInstrumentFile(sFilename); |
161 |
|
break; |
162 |
|
} |
163 |
|
} |
164 |
|
} |
165 |
|
} |
166 |
|
|
167 |
|
if (bAccept) |
168 |
|
pDragEnterEvent->accept(); |
169 |
|
else |
170 |
|
pDragEnterEvent->ignore(); |
171 |
} |
} |
172 |
|
|
173 |
|
|
174 |
void ChannelStrip::dropEvent ( QDropEvent* pDropEvent ) |
void ChannelStrip::dropEvent ( QDropEvent* pDropEvent ) |
175 |
{ |
{ |
176 |
QString sInstrumentFile; |
if (m_pChannel == NULL) |
177 |
|
return; |
178 |
|
|
179 |
if (decodeDragFile(pDropEvent, sInstrumentFile)) { |
if (pDropEvent->source()) |
180 |
// Go and set the dropped instrument filename... |
return; |
181 |
m_pChannel->setInstrument(sInstrumentFile, 0); |
|
182 |
// Open up the channel dialog. |
const QMimeData *pMimeData = pDropEvent->mimeData(); |
183 |
channelSetup(); |
if (pMimeData && pMimeData->hasUrls()) { |
184 |
|
QStringList files; |
185 |
|
QListIterator<QUrl> iter(pMimeData->urls()); |
186 |
|
while (iter.hasNext()) { |
187 |
|
const QString& sFilename = iter.next().toLocalFile(); |
188 |
|
if (!sFilename.isEmpty()) { |
189 |
|
// Go and set the dropped instrument filename... |
190 |
|
m_pChannel->setInstrument(sFilename, 0); |
191 |
|
// Open up the channel dialog. |
192 |
|
channelSetup(); |
193 |
|
break; |
194 |
|
} |
195 |
|
} |
196 |
} |
} |
197 |
} |
} |
198 |
|
|
199 |
|
|
200 |
// Channel strip setup formal initializer. |
// Channel strip setup formal initializer. |
201 |
void ChannelStrip::setup ( qsamplerChannel *pChannel ) |
void ChannelStrip::setup ( Channel *pChannel ) |
202 |
{ |
{ |
203 |
// Destroy any previous channel descriptor; |
// Destroy any previous channel descriptor; |
204 |
// (remember that once setup we own it!) |
// (remember that once setup we own it!) |
205 |
if (m_pChannel) |
if (m_pChannel) |
206 |
delete m_pChannel; |
delete m_pChannel; |
207 |
|
|
208 |
// Set the new one... |
// Set the new one... |
209 |
m_pChannel = pChannel; |
m_pChannel = pChannel; |
210 |
|
|
211 |
// Stabilize this around. |
// Stabilize this around. |
212 |
updateChannelInfo(); |
updateChannelInfo(); |
213 |
|
|
214 |
// We'll accept drops from now on... |
// We'll accept drops from now on... |
215 |
if (m_pChannel) |
if (m_pChannel) |
216 |
setAcceptDrops(true); |
setAcceptDrops(true); |
217 |
} |
} |
218 |
|
|
219 |
|
|
220 |
// Channel secriptor accessor. |
// Channel secriptor accessor. |
221 |
qsamplerChannel *ChannelStrip::channel (void) |
Channel *ChannelStrip::channel (void) const |
222 |
{ |
{ |
223 |
return m_pChannel; |
return m_pChannel; |
224 |
} |
} |
225 |
|
|
226 |
|
|
227 |
// Messages view font accessors. |
// Messages view font accessors. |
228 |
QFont ChannelStrip::displayFont (void) |
QFont ChannelStrip::displayFont (void) const |
229 |
{ |
{ |
230 |
return ui.EngineNameTextLabel->font(); |
return m_ui.EngineNameTextLabel->font(); |
231 |
} |
} |
232 |
|
|
233 |
void ChannelStrip::setDisplayFont ( const QFont & font ) |
void ChannelStrip::setDisplayFont ( const QFont & font ) |
234 |
{ |
{ |
235 |
ui.EngineNameTextLabel->setFont(font); |
m_ui.EngineNameTextLabel->setFont(font); |
236 |
ui.MidiPortChannelTextLabel->setFont(font); |
m_ui.MidiPortChannelTextLabel->setFont(font); |
237 |
ui.InstrumentNameTextLabel->setFont(font); |
m_ui.InstrumentNameTextLabel->setFont(font); |
238 |
ui.InstrumentStatusTextLabel->setFont(font); |
m_ui.InstrumentStatusTextLabel->setFont(font); |
239 |
} |
} |
240 |
|
|
241 |
|
|
242 |
// Channel display background effect. |
// Channel display background effect. |
243 |
void ChannelStrip::setDisplayEffect ( bool bDisplayEffect ) |
void ChannelStrip::setDisplayEffect ( bool bDisplayEffect ) |
244 |
{ |
{ |
245 |
QPixmap pm = |
QPalette pal; |
246 |
(bDisplayEffect) ? |
pal.setColor(QPalette::Foreground, Qt::yellow); |
247 |
QPixmap(":/qsampler/pixmaps/displaybg1.png") : QPixmap(); |
m_ui.EngineNameTextLabel->setPalette(pal); |
248 |
setDisplayBackground(pm); |
m_ui.MidiPortChannelTextLabel->setPalette(pal); |
249 |
} |
pal.setColor(QPalette::Foreground, Qt::green); |
250 |
|
if (bDisplayEffect) { |
251 |
|
QPixmap pm(":/icons/displaybg1.png"); |
252 |
// Update main display background pixmap. |
pal.setBrush(QPalette::Background, QBrush(pm)); |
253 |
void ChannelStrip::setDisplayBackground ( const QPixmap& pm ) |
} else { |
254 |
{ |
pal.setColor(QPalette::Background, Qt::black); |
255 |
// Set the main origin... |
} |
256 |
ui.ChannelInfoFrame->setPaletteBackgroundPixmap(pm); |
m_ui.ChannelInfoFrame->setPalette(pal); |
257 |
|
m_ui.InstrumentNameTextLabel->setPalette(pal); |
258 |
// Iterate for every child text label... |
m_ui.StreamVoiceCountTextLabel->setPalette(pal); |
|
QList<QObject*> list = ui.ChannelInfoFrame->queryList("QLabel"); |
|
|
for (QList<QObject*>::iterator iter = list.begin(); iter != list.end(); iter++) { |
|
|
static_cast<QLabel*>(*iter)->setPaletteBackgroundPixmap(pm); |
|
|
} |
|
|
|
|
|
// And this standalone too. |
|
|
ui.StreamVoiceCountTextLabel->setPaletteBackgroundPixmap(pm); |
|
259 |
} |
} |
260 |
|
|
261 |
|
|
262 |
// Maximum volume slider accessors. |
// Maximum volume slider accessors. |
263 |
void ChannelStrip::setMaxVolume ( int iMaxVolume ) |
void ChannelStrip::setMaxVolume ( int iMaxVolume ) |
264 |
{ |
{ |
265 |
m_iDirtyChange++; |
m_iDirtyChange++; |
266 |
ui.VolumeSlider->setRange(0, iMaxVolume); |
m_ui.VolumeSlider->setRange(0, iMaxVolume); |
267 |
ui.VolumeSpinBox->setRange(0, iMaxVolume); |
m_ui.VolumeSpinBox->setRange(0, iMaxVolume); |
268 |
m_iDirtyChange--; |
m_iDirtyChange--; |
269 |
} |
} |
270 |
|
|
271 |
|
|
326 |
m_pChannel->editChannel(); |
m_pChannel->editChannel(); |
327 |
} |
} |
328 |
|
|
329 |
|
bool ChannelStrip::channelFxEdit (void) |
330 |
|
{ |
331 |
|
MainForm *pMainForm = MainForm::getInstance(); |
332 |
|
if (!pMainForm || !channel()) |
333 |
|
return false; |
334 |
|
|
335 |
|
pMainForm->appendMessages(QObject::tr("channel fx sends...")); |
336 |
|
|
337 |
|
bool bResult = false; |
338 |
|
|
339 |
|
#if CONFIG_FXSEND |
340 |
|
ChannelFxForm *pChannelFxForm = |
341 |
|
new ChannelFxForm(channel(), parentWidget()); |
342 |
|
if (pChannelFxForm) { |
343 |
|
//pChannelForm->setup(this); |
344 |
|
bResult = pChannelFxForm->exec(); |
345 |
|
delete pChannelFxForm; |
346 |
|
} |
347 |
|
#else // CONFIG_FXSEND |
348 |
|
QMessageBox::critical(this, |
349 |
|
QSAMPLER_TITLE ": " + tr("Unavailable"), |
350 |
|
tr("Sorry, QSampler was built without FX send support!\n\n" |
351 |
|
"(Make sure you have a recent liblscp when recompiling QSampler)")); |
352 |
|
#endif // CONFIG_FXSEND |
353 |
|
|
354 |
|
return bResult; |
355 |
|
} |
356 |
|
|
357 |
// Channel reset slot. |
// Channel reset slot. |
358 |
bool ChannelStrip::channelReset (void) |
bool ChannelStrip::channelReset (void) |
382 |
|
|
383 |
// Instrument name... |
// Instrument name... |
384 |
if (m_pChannel->instrumentName().isEmpty()) { |
if (m_pChannel->instrumentName().isEmpty()) { |
385 |
if (m_pChannel->instrumentStatus() >= 0) |
if (m_pChannel->instrumentStatus() >= 0) { |
386 |
ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::loadingInstrument()); |
m_ui.InstrumentNameTextLabel->setText( |
387 |
else |
' ' + Channel::loadingInstrument()); |
388 |
ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::noInstrumentName()); |
} else { |
389 |
} else |
m_ui.InstrumentNameTextLabel->setText( |
390 |
ui.InstrumentNameTextLabel->setText(' ' + m_pChannel->instrumentName()); |
' ' + Channel::noInstrumentName()); |
391 |
|
} |
392 |
|
} else { |
393 |
|
m_ui.InstrumentNameTextLabel->setText( |
394 |
|
' ' + m_pChannel->instrumentName()); |
395 |
|
} |
396 |
|
|
397 |
return true; |
return true; |
398 |
} |
} |
401 |
// Do the dirty volume change. |
// Do the dirty volume change. |
402 |
bool ChannelStrip::updateChannelVolume (void) |
bool ChannelStrip::updateChannelVolume (void) |
403 |
{ |
{ |
404 |
if (m_pChannel == NULL) |
if (m_pChannel == NULL) |
405 |
return false; |
return false; |
|
|
|
|
// Convert... |
|
|
#ifdef CONFIG_ROUND |
|
|
int iVolume = (int) ::round(100.0 * m_pChannel->volume()); |
|
|
#else |
|
|
double fIPart = 0.0; |
|
|
double fFPart = ::modf(100.0 * m_pChannel->volume(), &fIPart); |
|
|
int iVolume = (int) fIPart; |
|
|
if (fFPart >= +0.5) |
|
|
iVolume++; |
|
|
else |
|
|
if (fFPart <= -0.5) |
|
|
iVolume--; |
|
|
#endif |
|
406 |
|
|
407 |
// And clip... |
// Convert... |
408 |
if (iVolume < 0) |
int iVolume = ::lroundf(100.0f * m_pChannel->volume()); |
409 |
iVolume = 0; |
// And clip... |
410 |
|
if (iVolume < 0) |
411 |
// Flag it here, to avoid infinite recursion. |
iVolume = 0; |
412 |
m_iDirtyChange++; |
|
413 |
ui.VolumeSlider->setValue(iVolume); |
// Flag it here, to avoid infinite recursion. |
414 |
ui.VolumeSpinBox->setValue(iVolume); |
m_iDirtyChange++; |
415 |
m_iDirtyChange--; |
m_ui.VolumeSlider->setValue(iVolume); |
416 |
|
m_ui.VolumeSpinBox->setValue(iVolume); |
417 |
|
m_iDirtyChange--; |
418 |
|
|
419 |
return true; |
return true; |
420 |
} |
} |
421 |
|
|
422 |
|
|
423 |
// Update whole channel info state. |
// Update whole channel info state. |
424 |
bool ChannelStrip::updateChannelInfo (void) |
bool ChannelStrip::updateChannelInfo (void) |
425 |
{ |
{ |
426 |
if (m_pChannel == NULL) |
if (m_pChannel == NULL) |
427 |
return false; |
return false; |
428 |
|
|
429 |
// Check for error limit/recycle... |
// Check for error limit/recycle... |
430 |
if (m_iErrorCount > QSAMPLER_ERROR_LIMIT) |
if (m_iErrorCount > QSAMPLER_ERROR_LIMIT) |
431 |
return true; |
return true; |
432 |
|
|
433 |
// Update strip caption. |
// Update strip caption. |
434 |
QString sText = m_pChannel->channelName(); |
QString sText = m_pChannel->channelName(); |
435 |
setCaption(sText); |
setWindowTitle(sText); |
436 |
ui.ChannelSetupPushButton->setText(sText); |
m_ui.ChannelSetupPushButton->setText('&' + sText); |
437 |
|
|
438 |
// Check if we're up and connected. |
// Check if we're up and connected. |
439 |
MainForm* pMainForm = MainForm::getInstance(); |
MainForm* pMainForm = MainForm::getInstance(); |
440 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
441 |
return false; |
return false; |
442 |
|
|
443 |
// Read actual channel information. |
// Read actual channel information. |
444 |
m_pChannel->updateChannelInfo(); |
m_pChannel->updateChannelInfo(); |
445 |
|
|
446 |
// Engine name... |
// Engine name... |
447 |
if (m_pChannel->engineName().isEmpty()) |
if (m_pChannel->engineName().isEmpty()) { |
448 |
ui.EngineNameTextLabel->setText(' ' + qsamplerChannel::noEngineName()); |
m_ui.EngineNameTextLabel->setText( |
449 |
else |
' ' + Channel::noEngineName()); |
450 |
ui.EngineNameTextLabel->setText(' ' + m_pChannel->engineName()); |
} else { |
451 |
|
m_ui.EngineNameTextLabel->setText( |
452 |
|
' ' + m_pChannel->engineName()); |
453 |
|
} |
454 |
|
|
455 |
// Instrument name... |
// Instrument name... |
456 |
updateInstrumentName(false); |
updateInstrumentName(false); |
457 |
|
|
458 |
// MIDI Port/Channel... |
// MIDI Port/Channel... |
459 |
QString sMidiPortChannel = QString::number(m_pChannel->midiPort()) + " / "; |
QString sMidiPortChannel = QString::number(m_pChannel->midiPort()) + " / "; |
460 |
if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL) |
if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL) |
461 |
sMidiPortChannel += tr("All"); |
sMidiPortChannel += tr("All"); |
462 |
else |
else |
463 |
sMidiPortChannel += QString::number(m_pChannel->midiChannel() + 1); |
sMidiPortChannel += QString::number(m_pChannel->midiChannel() + 1); |
464 |
ui.MidiPortChannelTextLabel->setText(sMidiPortChannel); |
m_ui.MidiPortChannelTextLabel->setText(sMidiPortChannel); |
465 |
|
|
466 |
// Instrument status... |
// Common palette... |
467 |
int iInstrumentStatus = m_pChannel->instrumentStatus(); |
QPalette pal; |
468 |
if (iInstrumentStatus < 0) { |
const QColor& rgbFore = pal.color(QPalette::Foreground); |
469 |
ui.InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red); |
|
470 |
ui.InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus)); |
// Instrument status... |
471 |
m_iErrorCount++; |
int iInstrumentStatus = m_pChannel->instrumentStatus(); |
472 |
return false; |
if (iInstrumentStatus < 0) { |
473 |
} |
pal.setColor(QPalette::Foreground, Qt::red); |
474 |
// All seems normal... |
m_ui.InstrumentStatusTextLabel->setPalette(pal); |
475 |
ui.InstrumentStatusTextLabel->setPaletteForegroundColor(iInstrumentStatus < 100 ? Qt::yellow : Qt::green); |
m_ui.InstrumentStatusTextLabel->setText( |
476 |
ui.InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + '%'); |
tr("ERR%1").arg(iInstrumentStatus)); |
477 |
m_iErrorCount = 0; |
m_iErrorCount++; |
478 |
|
return false; |
479 |
|
} |
480 |
|
// All seems normal... |
481 |
|
pal.setColor(QPalette::Foreground, |
482 |
|
iInstrumentStatus < 100 ? Qt::yellow : Qt::green); |
483 |
|
m_ui.InstrumentStatusTextLabel->setPalette(pal); |
484 |
|
m_ui.InstrumentStatusTextLabel->setText( |
485 |
|
QString::number(iInstrumentStatus) + '%'); |
486 |
|
m_iErrorCount = 0; |
487 |
|
|
488 |
#ifdef CONFIG_MUTE_SOLO |
#ifdef CONFIG_MUTE_SOLO |
489 |
// Mute/Solo button state coloring... |
// Mute/Solo button state coloring... |
490 |
const QColor& rgbNormal = ChannelSetupPushButton->paletteBackgroundColor(); |
bool bMute = m_pChannel->channelMute(); |
491 |
bool bMute = m_pChannel->channelMute(); |
const QColor& rgbButton = pal.color(QPalette::Button); |
492 |
ChannelMutePushButton->setPaletteBackgroundColor(bMute ? Qt::yellow : rgbNormal); |
const QColor& rgbButtonText = pal.color(QPalette::ButtonText); |
493 |
ChannelMutePushButton->setDown(bMute); |
pal.setColor(QPalette::Foreground, rgbFore); |
494 |
bool bSolo = m_pChannel->channelSolo(); |
pal.setColor(QPalette::Button, bMute ? Qt::yellow : rgbButton); |
495 |
ChannelSoloPushButton->setPaletteBackgroundColor(bSolo ? Qt::cyan : rgbNormal); |
pal.setColor(QPalette::ButtonText, bMute ? Qt::darkYellow : rgbButtonText); |
496 |
ChannelSoloPushButton->setDown(bSolo); |
m_ui.ChannelMutePushButton->setPalette(pal); |
497 |
|
m_ui.ChannelMutePushButton->setDown(bMute); |
498 |
|
bool bSolo = m_pChannel->channelSolo(); |
499 |
|
pal.setColor(QPalette::Button, bSolo ? Qt::cyan : rgbButton); |
500 |
|
pal.setColor(QPalette::ButtonText, bSolo ? Qt::darkCyan : rgbButtonText); |
501 |
|
m_ui.ChannelSoloPushButton->setPalette(pal); |
502 |
|
m_ui.ChannelSoloPushButton->setDown(bSolo); |
503 |
#else |
#else |
504 |
ui.ChannelMutePushButton->setEnabled(false); |
m_ui.ChannelMutePushButton->setEnabled(false); |
505 |
ui.ChannelSoloPushButton->setEnabled(false); |
m_ui.ChannelSoloPushButton->setEnabled(false); |
506 |
#endif |
#endif |
507 |
|
|
508 |
// And update the both GUI volume elements; |
// And update the both GUI volume elements; |
509 |
// return success if, and only if, intrument is fully loaded... |
// return success if, and only if, intrument is fully loaded... |
510 |
return updateChannelVolume() && (iInstrumentStatus == 100); |
return updateChannelVolume() && (iInstrumentStatus == 100); |
511 |
} |
} |
512 |
|
|
513 |
|
|
514 |
// Update whole channel usage state. |
// Update whole channel usage state. |
515 |
bool ChannelStrip::updateChannelUsage (void) |
bool ChannelStrip::updateChannelUsage (void) |
516 |
{ |
{ |
517 |
if (m_pChannel == NULL) |
if (m_pChannel == NULL) |
518 |
return false; |
return false; |
519 |
|
|
520 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
521 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
523 |
|
|
524 |
// This only makes sense on fully loaded channels... |
// This only makes sense on fully loaded channels... |
525 |
if (m_pChannel->instrumentStatus() < 100) |
if (m_pChannel->instrumentStatus() < 100) |
526 |
return false; |
return false; |
527 |
|
|
528 |
// Get current channel voice count. |
// Get current channel voice count. |
529 |
int iVoiceCount = ::lscp_get_channel_voice_count(pMainForm->client(), m_pChannel->channelID()); |
int iVoiceCount = ::lscp_get_channel_voice_count( |
530 |
// Get current stream count. |
pMainForm->client(), m_pChannel->channelID()); |
531 |
int iStreamCount = ::lscp_get_channel_stream_count(pMainForm->client(), m_pChannel->channelID()); |
// Get current stream count. |
532 |
// Get current channel buffer fill usage. |
int iStreamCount = ::lscp_get_channel_stream_count( |
533 |
// As benno has suggested this is the percentage usage |
pMainForm->client(), m_pChannel->channelID()); |
534 |
// of the least filled buffer stream... |
// Get current channel buffer fill usage. |
535 |
int iStreamUsage = ::lscp_get_channel_stream_usage(pMainForm->client(), m_pChannel->channelID());; |
// As benno has suggested this is the percentage usage |
536 |
|
// of the least filled buffer stream... |
537 |
// Update the GUI elements... |
int iStreamUsage = ::lscp_get_channel_stream_usage( |
538 |
ui.StreamUsageProgressBar->setValue(iStreamUsage); |
pMainForm->client(), m_pChannel->channelID());; |
539 |
ui.StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount)); |
|
540 |
|
// Update the GUI elements... |
541 |
|
m_ui.StreamUsageProgressBar->setValue(iStreamUsage); |
542 |
|
m_ui.StreamVoiceCountTextLabel->setText( |
543 |
|
QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount)); |
544 |
|
|
545 |
// We're clean. |
// We're clean. |
546 |
return true; |
return true; |
547 |
} |
} |
548 |
|
|
549 |
|
|
550 |
// Volume change slot. |
// Volume change slot. |
551 |
void ChannelStrip::volumeChanged ( int iVolume ) |
void ChannelStrip::volumeChanged ( int iVolume ) |
552 |
{ |
{ |
553 |
if (m_pChannel == NULL) |
if (m_pChannel == NULL) |
554 |
return; |
return; |
555 |
|
|
556 |
// Avoid recursion. |
// Avoid recursion. |
557 |
if (m_iDirtyChange > 0) |
if (m_iDirtyChange > 0) |
558 |
return; |
return; |
559 |
|
|
560 |
// Convert and clip. |
// Convert and clip. |
561 |
float fVolume = (float) iVolume / 100.0; |
float fVolume = (float) iVolume / 100.0f; |
562 |
if (fVolume < 0.001) |
if (fVolume < 0.001f) |
563 |
fVolume = 0.0; |
fVolume = 0.0f; |
564 |
|
|
565 |
// Update the GUI elements. |
// Update the GUI elements. |
566 |
if (m_pChannel->setVolume(fVolume)) { |
if (m_pChannel->setVolume(fVolume)) { |
567 |
updateChannelVolume(); |
updateChannelVolume(); |
568 |
emit channelChanged(this); |
emit channelChanged(this); |
569 |
} |
} |
570 |
} |
} |
571 |
|
|
572 |
|
|
573 |
// Context menu event handler. |
// Context menu event handler. |
574 |
void ChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent ) |
void ChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent ) |
575 |
{ |
{ |
576 |
if (m_pChannel == NULL) |
if (m_pChannel == NULL) |
577 |
return; |
return; |
578 |
|
|
579 |
|
// We'll just show up the main form's edit menu (thru qsamplerChannel). |
580 |
|
m_pChannel->contextMenuEvent(pEvent); |
581 |
|
} |
582 |
|
|
583 |
|
|
584 |
|
void ChannelStrip::midiActivityLedOn (void) |
585 |
|
{ |
586 |
|
m_ui.MidiActivityLabel->setPixmap(*g_pMidiActivityLedOn); |
587 |
|
m_pMidiActivityTimer->start(100); |
588 |
|
} |
589 |
|
|
590 |
|
|
591 |
// We'll just show up the main form's edit menu (thru qsamplerChannel). |
void ChannelStrip::midiActivityLedOff (void) |
592 |
m_pChannel->contextMenuEvent(pEvent); |
{ |
593 |
|
m_ui.MidiActivityLabel->setPixmap(*g_pMidiActivityLedOff); |
594 |
} |
} |
595 |
|
|
596 |
|
|
600 |
m_iErrorCount = 0; |
m_iErrorCount = 0; |
601 |
} |
} |
602 |
|
|
603 |
|
|
604 |
|
// Channel strip activation/selection. |
605 |
|
void ChannelStrip::setSelected ( bool bSelected ) |
606 |
|
{ |
607 |
|
if (bSelected) { |
608 |
|
if (g_pSelectedStrip == this) |
609 |
|
return; |
610 |
|
if (g_pSelectedStrip) |
611 |
|
g_pSelectedStrip->setSelected(false); |
612 |
|
g_pSelectedStrip = this; |
613 |
|
} else { |
614 |
|
if (g_pSelectedStrip == this) |
615 |
|
g_pSelectedStrip = NULL; |
616 |
|
} |
617 |
|
|
618 |
|
QPalette pal; |
619 |
|
if (bSelected) { |
620 |
|
const QColor& color = pal.midlight().color(); |
621 |
|
pal.setColor(QPalette::Background, color.dark(150)); |
622 |
|
pal.setColor(QPalette::Foreground, color.light(150)); |
623 |
|
} |
624 |
|
QWidget::setPalette(pal); |
625 |
|
} |
626 |
|
|
627 |
|
|
628 |
|
bool ChannelStrip::isSelected (void) const |
629 |
|
{ |
630 |
|
return (this == g_pSelectedStrip); |
631 |
|
} |
632 |
|
|
633 |
|
|
634 |
} // namespace QSampler |
} // namespace QSampler |
635 |
|
|
636 |
|
|