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 <QDragEnterEvent> |
|
|
|
29 |
#include <QUrl> |
#include <QUrl> |
30 |
|
|
31 |
#include <math.h> |
#include <math.h> |
35 |
|
|
36 |
namespace QSampler { |
namespace QSampler { |
37 |
|
|
38 |
ChannelStrip::ChannelStrip(QWidget* parent, Qt::WFlags f) : QWidget(parent, f) { |
ChannelStrip::ChannelStrip ( QWidget* pParent, Qt::WindowFlags wflags ) |
39 |
ui.setupUi(this); |
: QWidget(pParent, wflags) |
40 |
|
{ |
41 |
|
m_ui.setupUi(this); |
42 |
|
|
43 |
// Initialize locals. |
// Initialize locals. |
44 |
m_pChannel = NULL; |
m_pChannel = NULL; |
48 |
// Try to restore normal window positioning. |
// Try to restore normal window positioning. |
49 |
adjustSize(); |
adjustSize(); |
50 |
|
|
51 |
QObject::connect(ui.ChannelSetupPushButton, |
QObject::connect(m_ui.ChannelSetupPushButton, |
52 |
SIGNAL(clicked()), |
SIGNAL(clicked()), |
53 |
SLOT(channelSetup())); |
SLOT(channelSetup())); |
54 |
QObject::connect(ui.ChannelMutePushButton, |
QObject::connect(m_ui.ChannelMutePushButton, |
55 |
SIGNAL(toggled(bool)), |
SIGNAL(toggled(bool)), |
56 |
SLOT(channelMute(bool))); |
SLOT(channelMute(bool))); |
57 |
QObject::connect(ui.ChannelSoloPushButton, |
QObject::connect(m_ui.ChannelSoloPushButton, |
58 |
SIGNAL(toggled(bool)), |
SIGNAL(toggled(bool)), |
59 |
SLOT(channelSolo(bool))); |
SLOT(channelSolo(bool))); |
60 |
QObject::connect(ui.VolumeSlider, |
QObject::connect(m_ui.VolumeSlider, |
61 |
SIGNAL(valueChanged(int)), |
SIGNAL(valueChanged(int)), |
62 |
SLOT(volumeChanged(int))); |
SLOT(volumeChanged(int))); |
63 |
QObject::connect(ui.VolumeSpinBox, |
QObject::connect(m_ui.VolumeSpinBox, |
64 |
SIGNAL(valueChanged(int)), |
SIGNAL(valueChanged(int)), |
65 |
SLOT(volumeChanged(int))); |
SLOT(volumeChanged(int))); |
66 |
QObject::connect(ui.ChannelEditPushButton, |
QObject::connect(m_ui.ChannelEditPushButton, |
67 |
SIGNAL(clicked()), |
SIGNAL(clicked()), |
68 |
SLOT(channelEdit())); |
SLOT(channelEdit())); |
69 |
} |
} |
76 |
} |
} |
77 |
|
|
78 |
|
|
79 |
// Drag'n'drop file handler. |
// Window drag-n-drop event handlers. |
80 |
bool ChannelStrip::decodeDragFile ( const QMimeSource *pEvent, QString& sInstrumentFile ) |
void ChannelStrip::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent ) |
81 |
{ |
{ |
82 |
if (m_pChannel == NULL) |
if (m_pChannel == NULL) |
83 |
return false; |
return; |
84 |
if (Q3TextDrag::canDecode(pEvent)) { |
|
85 |
QString sText; |
bool bAccept = false; |
86 |
if (Q3TextDrag::decode(pEvent, sText)) { |
|
87 |
QStringList files = QStringList::split('\n', sText); |
if (pDragEnterEvent->source() == NULL) { |
88 |
for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) { |
const QMimeData *pMimeData = pDragEnterEvent->mimeData(); |
89 |
*iter = QUrl((*iter).stripWhiteSpace().replace(QRegExp("^file:"), QString::null)).path(); |
if (pMimeData && pMimeData->hasUrls()) { |
90 |
if (qsamplerChannel::isInstrumentFile(*iter)) { |
QListIterator<QUrl> iter(pMimeData->urls()); |
91 |
sInstrumentFile = *iter; |
while (iter.hasNext()) { |
92 |
return true; |
const QString& sFilename = iter.next().toLocalFile(); |
93 |
|
if (!sFilename.isEmpty()) { |
94 |
|
bAccept = qsamplerChannel::isInstrumentFile(sFilename); |
95 |
|
break; |
96 |
} |
} |
97 |
} |
} |
98 |
} |
} |
99 |
} |
} |
|
// Fail. |
|
|
return false; |
|
|
} |
|
|
|
|
100 |
|
|
101 |
// Window drag-n-drop event handlers. |
if (bAccept) |
102 |
void ChannelStrip::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent ) |
pDragEnterEvent->accept(); |
103 |
{ |
else |
104 |
QString sInstrumentFile; |
pDragEnterEvent->ignore(); |
|
pDragEnterEvent->accept(decodeDragFile(pDragEnterEvent, sInstrumentFile)); |
|
105 |
} |
} |
106 |
|
|
107 |
|
|
108 |
void ChannelStrip::dropEvent ( QDropEvent* pDropEvent ) |
void ChannelStrip::dropEvent ( QDropEvent* pDropEvent ) |
109 |
{ |
{ |
110 |
QString sInstrumentFile; |
if (m_pChannel == NULL) |
111 |
|
return; |
112 |
|
|
113 |
|
if (pDropEvent->source()) |
114 |
|
return; |
115 |
|
|
116 |
if (decodeDragFile(pDropEvent, sInstrumentFile)) { |
const QMimeData *pMimeData = pDropEvent->mimeData(); |
117 |
// Go and set the dropped instrument filename... |
if (pMimeData && pMimeData->hasUrls()) { |
118 |
m_pChannel->setInstrument(sInstrumentFile, 0); |
QStringList files; |
119 |
// Open up the channel dialog. |
QListIterator<QUrl> iter(pMimeData->urls()); |
120 |
channelSetup(); |
while (iter.hasNext()) { |
121 |
|
const QString& sFilename = iter.next().toLocalFile(); |
122 |
|
if (!sFilename.isEmpty()) { |
123 |
|
// Go and set the dropped instrument filename... |
124 |
|
m_pChannel->setInstrument(sFilename, 0); |
125 |
|
// Open up the channel dialog. |
126 |
|
channelSetup(); |
127 |
|
break; |
128 |
|
} |
129 |
|
} |
130 |
} |
} |
131 |
} |
} |
132 |
|
|
151 |
} |
} |
152 |
|
|
153 |
// Channel secriptor accessor. |
// Channel secriptor accessor. |
154 |
qsamplerChannel *ChannelStrip::channel (void) |
qsamplerChannel *ChannelStrip::channel (void) const |
155 |
{ |
{ |
156 |
return m_pChannel; |
return m_pChannel; |
157 |
} |
} |
158 |
|
|
159 |
|
|
160 |
// Messages view font accessors. |
// Messages view font accessors. |
161 |
QFont ChannelStrip::displayFont (void) |
QFont ChannelStrip::displayFont (void) const |
162 |
{ |
{ |
163 |
return ui.EngineNameTextLabel->font(); |
return m_ui.EngineNameTextLabel->font(); |
164 |
} |
} |
165 |
|
|
166 |
void ChannelStrip::setDisplayFont ( const QFont & font ) |
void ChannelStrip::setDisplayFont ( const QFont & font ) |
167 |
{ |
{ |
168 |
ui.EngineNameTextLabel->setFont(font); |
m_ui.EngineNameTextLabel->setFont(font); |
169 |
ui.MidiPortChannelTextLabel->setFont(font); |
m_ui.MidiPortChannelTextLabel->setFont(font); |
170 |
ui.InstrumentNameTextLabel->setFont(font); |
m_ui.InstrumentNameTextLabel->setFont(font); |
171 |
ui.InstrumentStatusTextLabel->setFont(font); |
m_ui.InstrumentStatusTextLabel->setFont(font); |
172 |
} |
} |
173 |
|
|
174 |
|
|
175 |
// Channel display background effect. |
// Channel display background effect. |
176 |
void ChannelStrip::setDisplayEffect ( bool bDisplayEffect ) |
void ChannelStrip::setDisplayEffect ( bool bDisplayEffect ) |
177 |
{ |
{ |
178 |
QPixmap pm = |
QPalette pal; |
179 |
(bDisplayEffect) ? |
pal.setColor(QPalette::Foreground, Qt::yellow); |
180 |
QPixmap(":/icons/displaybg1.png") : QPixmap(); |
m_ui.EngineNameTextLabel->setPalette(pal); |
181 |
setDisplayBackground(pm); |
m_ui.MidiPortChannelTextLabel->setPalette(pal); |
182 |
} |
pal.setColor(QPalette::Foreground, Qt::green); |
183 |
|
if (bDisplayEffect) { |
184 |
|
QPixmap pm(":/icons/displaybg1.png"); |
185 |
// Update main display background pixmap. |
pal.setBrush(QPalette::Background, QBrush(pm)); |
186 |
void ChannelStrip::setDisplayBackground ( const QPixmap& pm ) |
} else { |
187 |
{ |
pal.setColor(QPalette::Background, Qt::black); |
188 |
// Set the main origin... |
} |
189 |
ui.ChannelInfoFrame->setPaletteBackgroundPixmap(pm); |
m_ui.ChannelInfoFrame->setPalette(pal); |
190 |
|
m_ui.StreamVoiceCountTextLabel->setPalette(pal); |
|
// Iterate for every child text label... |
|
|
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); |
|
191 |
} |
} |
192 |
|
|
193 |
|
|
195 |
void ChannelStrip::setMaxVolume ( int iMaxVolume ) |
void ChannelStrip::setMaxVolume ( int iMaxVolume ) |
196 |
{ |
{ |
197 |
m_iDirtyChange++; |
m_iDirtyChange++; |
198 |
ui.VolumeSlider->setRange(0, iMaxVolume); |
m_ui.VolumeSlider->setRange(0, iMaxVolume); |
199 |
ui.VolumeSpinBox->setRange(0, iMaxVolume); |
m_ui.VolumeSpinBox->setRange(0, iMaxVolume); |
200 |
m_iDirtyChange--; |
m_iDirtyChange--; |
201 |
} |
} |
202 |
|
|
288 |
// Instrument name... |
// Instrument name... |
289 |
if (m_pChannel->instrumentName().isEmpty()) { |
if (m_pChannel->instrumentName().isEmpty()) { |
290 |
if (m_pChannel->instrumentStatus() >= 0) |
if (m_pChannel->instrumentStatus() >= 0) |
291 |
ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::loadingInstrument()); |
m_ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::loadingInstrument()); |
292 |
else |
else |
293 |
ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::noInstrumentName()); |
m_ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::noInstrumentName()); |
294 |
} else |
} else |
295 |
ui.InstrumentNameTextLabel->setText(' ' + m_pChannel->instrumentName()); |
m_ui.InstrumentNameTextLabel->setText(' ' + m_pChannel->instrumentName()); |
296 |
|
|
297 |
return true; |
return true; |
298 |
} |
} |
324 |
|
|
325 |
// Flag it here, to avoid infinite recursion. |
// Flag it here, to avoid infinite recursion. |
326 |
m_iDirtyChange++; |
m_iDirtyChange++; |
327 |
ui.VolumeSlider->setValue(iVolume); |
m_ui.VolumeSlider->setValue(iVolume); |
328 |
ui.VolumeSpinBox->setValue(iVolume); |
m_ui.VolumeSpinBox->setValue(iVolume); |
329 |
m_iDirtyChange--; |
m_iDirtyChange--; |
330 |
|
|
331 |
return true; |
return true; |
344 |
|
|
345 |
// Update strip caption. |
// Update strip caption. |
346 |
QString sText = m_pChannel->channelName(); |
QString sText = m_pChannel->channelName(); |
347 |
setCaption(sText); |
setWindowTitle(sText); |
348 |
ui.ChannelSetupPushButton->setText(sText); |
m_ui.ChannelSetupPushButton->setText(sText); |
349 |
|
|
350 |
// Check if we're up and connected. |
// Check if we're up and connected. |
351 |
MainForm* pMainForm = MainForm::getInstance(); |
MainForm* pMainForm = MainForm::getInstance(); |
357 |
|
|
358 |
// Engine name... |
// Engine name... |
359 |
if (m_pChannel->engineName().isEmpty()) |
if (m_pChannel->engineName().isEmpty()) |
360 |
ui.EngineNameTextLabel->setText(' ' + qsamplerChannel::noEngineName()); |
m_ui.EngineNameTextLabel->setText(' ' + qsamplerChannel::noEngineName()); |
361 |
else |
else |
362 |
ui.EngineNameTextLabel->setText(' ' + m_pChannel->engineName()); |
m_ui.EngineNameTextLabel->setText(' ' + m_pChannel->engineName()); |
363 |
|
|
364 |
// Instrument name... |
// Instrument name... |
365 |
updateInstrumentName(false); |
updateInstrumentName(false); |
370 |
sMidiPortChannel += tr("All"); |
sMidiPortChannel += tr("All"); |
371 |
else |
else |
372 |
sMidiPortChannel += QString::number(m_pChannel->midiChannel() + 1); |
sMidiPortChannel += QString::number(m_pChannel->midiChannel() + 1); |
373 |
ui.MidiPortChannelTextLabel->setText(sMidiPortChannel); |
m_ui.MidiPortChannelTextLabel->setText(sMidiPortChannel); |
374 |
|
|
375 |
|
// Common palette... |
376 |
|
QPalette pal; |
377 |
|
const QColor& rgbFore = pal.color(QPalette::Foreground); |
378 |
|
|
379 |
// Instrument status... |
// Instrument status... |
380 |
int iInstrumentStatus = m_pChannel->instrumentStatus(); |
int iInstrumentStatus = m_pChannel->instrumentStatus(); |
381 |
if (iInstrumentStatus < 0) { |
if (iInstrumentStatus < 0) { |
382 |
ui.InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red); |
pal.setColor(QPalette::Foreground, Qt::red); |
383 |
ui.InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus)); |
m_ui.InstrumentStatusTextLabel->setPalette(pal); |
384 |
|
m_ui.InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus)); |
385 |
m_iErrorCount++; |
m_iErrorCount++; |
386 |
return false; |
return false; |
387 |
} |
} |
388 |
// All seems normal... |
// All seems normal... |
389 |
ui.InstrumentStatusTextLabel->setPaletteForegroundColor(iInstrumentStatus < 100 ? Qt::yellow : Qt::green); |
pal.setColor(QPalette::Foreground, |
390 |
ui.InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + '%'); |
iInstrumentStatus < 100 ? Qt::yellow : Qt::green); |
391 |
|
m_ui.InstrumentStatusTextLabel->setPalette(pal); |
392 |
|
m_ui.InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + '%'); |
393 |
m_iErrorCount = 0; |
m_iErrorCount = 0; |
394 |
|
|
395 |
#ifdef CONFIG_MUTE_SOLO |
#ifdef CONFIG_MUTE_SOLO |
396 |
// Mute/Solo button state coloring... |
// Mute/Solo button state coloring... |
|
const QColor& rgbNormal = ChannelSetupPushButton->paletteBackgroundColor(); |
|
397 |
bool bMute = m_pChannel->channelMute(); |
bool bMute = m_pChannel->channelMute(); |
398 |
ChannelMutePushButton->setPaletteBackgroundColor(bMute ? Qt::yellow : rgbNormal); |
const QColor& rgbButton = pal.color(QPalette::Button); |
399 |
ChannelMutePushButton->setDown(bMute); |
pal.setColor(QPalette::Foreground, rgbFore); |
400 |
|
pal.setColor(QPalette::Button, bMute ? Qt::yellow : rgbButton); |
401 |
|
m_ui.ChannelMutePushButton->setPalette(pal); |
402 |
|
m_ui.ChannelMutePushButton->setDown(bMute); |
403 |
bool bSolo = m_pChannel->channelSolo(); |
bool bSolo = m_pChannel->channelSolo(); |
404 |
ChannelSoloPushButton->setPaletteBackgroundColor(bSolo ? Qt::cyan : rgbNormal); |
pal.setColor(QPalette::Button, bSolo ? Qt::cyan : rgbButton); |
405 |
ChannelSoloPushButton->setDown(bSolo); |
m_ui.ChannelSoloPushButton->setPalette(pal); |
406 |
|
m_ui.ChannelSoloPushButton->setDown(bSolo); |
407 |
#else |
#else |
408 |
ui.ChannelMutePushButton->setEnabled(false); |
m_ui.ChannelMutePushButton->setEnabled(false); |
409 |
ui.ChannelSoloPushButton->setEnabled(false); |
m_ui.ChannelSoloPushButton->setEnabled(false); |
410 |
#endif |
#endif |
411 |
|
|
412 |
// And update the both GUI volume elements; |
// And update the both GUI volume elements; |
431 |
|
|
432 |
// Get current channel voice count. |
// Get current channel voice count. |
433 |
int iVoiceCount = ::lscp_get_channel_voice_count(pMainForm->client(), m_pChannel->channelID()); |
int iVoiceCount = ::lscp_get_channel_voice_count(pMainForm->client(), m_pChannel->channelID()); |
434 |
// Get current stream count. |
// Get current stream count. |
435 |
int iStreamCount = ::lscp_get_channel_stream_count(pMainForm->client(), m_pChannel->channelID()); |
int iStreamCount = ::lscp_get_channel_stream_count(pMainForm->client(), m_pChannel->channelID()); |
436 |
// Get current channel buffer fill usage. |
// Get current channel buffer fill usage. |
437 |
// As benno has suggested this is the percentage usage |
// As benno has suggested this is the percentage usage |
439 |
int iStreamUsage = ::lscp_get_channel_stream_usage(pMainForm->client(), m_pChannel->channelID());; |
int iStreamUsage = ::lscp_get_channel_stream_usage(pMainForm->client(), m_pChannel->channelID());; |
440 |
|
|
441 |
// Update the GUI elements... |
// Update the GUI elements... |
442 |
ui.StreamUsageProgressBar->setValue(iStreamUsage); |
m_ui.StreamUsageProgressBar->setValue(iStreamUsage); |
443 |
ui.StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount)); |
m_ui.StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount)); |
444 |
|
|
445 |
// We're clean. |
// We're clean. |
446 |
return true; |
return true; |