28 |
#include <QDragEnterEvent> |
#include <QDragEnterEvent> |
29 |
#include <QUrl> |
#include <QUrl> |
30 |
|
|
|
#include <math.h> |
|
|
|
|
31 |
// Channel status/usage usage limit control. |
// Channel status/usage usage limit control. |
32 |
#define QSAMPLER_ERROR_LIMIT 3 |
#define QSAMPLER_ERROR_LIMIT 3 |
33 |
|
|
34 |
|
// Needed for lroundf() |
35 |
|
#include <math.h> |
36 |
|
|
37 |
namespace QSampler { |
namespace QSampler { |
38 |
|
|
39 |
ChannelStrip::ChannelStrip(QWidget* parent, Qt::WFlags f) : QWidget(parent, f) { |
#ifndef CONFIG_ROUND |
40 |
ui.setupUi(this); |
static inline long lroundf ( float x ) |
41 |
|
{ |
42 |
|
if (x >= 0.0f) |
43 |
|
return long(x + 0.5f); |
44 |
|
else |
45 |
|
return long(x - 0.5f); |
46 |
|
} |
47 |
|
#endif |
48 |
|
|
49 |
|
ChannelStrip::ChannelStrip ( QWidget* pParent, Qt::WindowFlags wflags ) |
50 |
|
: QWidget(pParent, wflags) |
51 |
|
{ |
52 |
|
m_ui.setupUi(this); |
53 |
|
|
54 |
// Initialize locals. |
// Initialize locals. |
55 |
m_pChannel = NULL; |
m_pChannel = NULL; |
56 |
m_iDirtyChange = 0; |
m_iDirtyChange = 0; |
57 |
m_iErrorCount = 0; |
m_iErrorCount = 0; |
58 |
|
|
59 |
// Try to restore normal window positioning. |
// Try to restore normal window positioning. |
60 |
adjustSize(); |
adjustSize(); |
61 |
|
|
62 |
QObject::connect(ui.ChannelSetupPushButton, |
QObject::connect(m_ui.ChannelSetupPushButton, |
63 |
SIGNAL(clicked()), |
SIGNAL(clicked()), |
64 |
SLOT(channelSetup())); |
SLOT(channelSetup())); |
65 |
QObject::connect(ui.ChannelMutePushButton, |
QObject::connect(m_ui.ChannelMutePushButton, |
66 |
SIGNAL(toggled(bool)), |
SIGNAL(toggled(bool)), |
67 |
SLOT(channelMute(bool))); |
SLOT(channelMute(bool))); |
68 |
QObject::connect(ui.ChannelSoloPushButton, |
QObject::connect(m_ui.ChannelSoloPushButton, |
69 |
SIGNAL(toggled(bool)), |
SIGNAL(toggled(bool)), |
70 |
SLOT(channelSolo(bool))); |
SLOT(channelSolo(bool))); |
71 |
QObject::connect(ui.VolumeSlider, |
QObject::connect(m_ui.VolumeSlider, |
72 |
SIGNAL(valueChanged(int)), |
SIGNAL(valueChanged(int)), |
73 |
SLOT(volumeChanged(int))); |
SLOT(volumeChanged(int))); |
74 |
QObject::connect(ui.VolumeSpinBox, |
QObject::connect(m_ui.VolumeSpinBox, |
75 |
SIGNAL(valueChanged(int)), |
SIGNAL(valueChanged(int)), |
76 |
SLOT(volumeChanged(int))); |
SLOT(volumeChanged(int))); |
77 |
QObject::connect(ui.ChannelEditPushButton, |
QObject::connect(m_ui.ChannelEditPushButton, |
78 |
SIGNAL(clicked()), |
SIGNAL(clicked()), |
79 |
SLOT(channelEdit())); |
SLOT(channelEdit())); |
80 |
} |
} |
81 |
|
|
82 |
ChannelStrip::~ChannelStrip() { |
ChannelStrip::~ChannelStrip() { |
83 |
// Destroy existing channel descriptor. |
// Destroy existing channel descriptor. |
84 |
if (m_pChannel) |
if (m_pChannel) |
85 |
delete m_pChannel; |
delete m_pChannel; |
86 |
m_pChannel = NULL; |
m_pChannel = NULL; |
87 |
} |
} |
88 |
|
|
89 |
|
|
145 |
// Channel strip setup formal initializer. |
// Channel strip setup formal initializer. |
146 |
void ChannelStrip::setup ( qsamplerChannel *pChannel ) |
void ChannelStrip::setup ( qsamplerChannel *pChannel ) |
147 |
{ |
{ |
148 |
// Destroy any previous channel descriptor; |
// Destroy any previous channel descriptor; |
149 |
// (remember that once setup we own it!) |
// (remember that once setup we own it!) |
150 |
if (m_pChannel) |
if (m_pChannel) |
151 |
delete m_pChannel; |
delete m_pChannel; |
152 |
|
|
153 |
// Set the new one... |
// Set the new one... |
154 |
m_pChannel = pChannel; |
m_pChannel = pChannel; |
155 |
|
|
156 |
// Stabilize this around. |
// Stabilize this around. |
157 |
updateChannelInfo(); |
updateChannelInfo(); |
158 |
|
|
159 |
// We'll accept drops from now on... |
// We'll accept drops from now on... |
160 |
if (m_pChannel) |
if (m_pChannel) |
162 |
} |
} |
163 |
|
|
164 |
// Channel secriptor accessor. |
// Channel secriptor accessor. |
165 |
qsamplerChannel *ChannelStrip::channel (void) |
qsamplerChannel *ChannelStrip::channel (void) const |
166 |
{ |
{ |
167 |
return m_pChannel; |
return m_pChannel; |
168 |
} |
} |
169 |
|
|
170 |
|
|
171 |
// Messages view font accessors. |
// Messages view font accessors. |
172 |
QFont ChannelStrip::displayFont (void) |
QFont ChannelStrip::displayFont (void) const |
173 |
{ |
{ |
174 |
return ui.EngineNameTextLabel->font(); |
return m_ui.EngineNameTextLabel->font(); |
175 |
} |
} |
176 |
|
|
177 |
void ChannelStrip::setDisplayFont ( const QFont & font ) |
void ChannelStrip::setDisplayFont ( const QFont & font ) |
178 |
{ |
{ |
179 |
ui.EngineNameTextLabel->setFont(font); |
m_ui.EngineNameTextLabel->setFont(font); |
180 |
ui.MidiPortChannelTextLabel->setFont(font); |
m_ui.MidiPortChannelTextLabel->setFont(font); |
181 |
ui.InstrumentNameTextLabel->setFont(font); |
m_ui.InstrumentNameTextLabel->setFont(font); |
182 |
ui.InstrumentStatusTextLabel->setFont(font); |
m_ui.InstrumentStatusTextLabel->setFont(font); |
183 |
} |
} |
184 |
|
|
185 |
|
|
187 |
void ChannelStrip::setDisplayEffect ( bool bDisplayEffect ) |
void ChannelStrip::setDisplayEffect ( bool bDisplayEffect ) |
188 |
{ |
{ |
189 |
QPalette pal; |
QPalette pal; |
190 |
|
pal.setColor(QPalette::Foreground, Qt::yellow); |
191 |
|
m_ui.EngineNameTextLabel->setPalette(pal); |
192 |
|
m_ui.MidiPortChannelTextLabel->setPalette(pal); |
193 |
pal.setColor(QPalette::Foreground, Qt::green); |
pal.setColor(QPalette::Foreground, Qt::green); |
194 |
if (bDisplayEffect) { |
if (bDisplayEffect) { |
195 |
QPixmap pm(":/icons/displaybg1.png"); |
QPixmap pm(":/icons/displaybg1.png"); |
197 |
} else { |
} else { |
198 |
pal.setColor(QPalette::Background, Qt::black); |
pal.setColor(QPalette::Background, Qt::black); |
199 |
} |
} |
200 |
ui.ChannelInfoFrame->setPalette(pal); |
m_ui.ChannelInfoFrame->setPalette(pal); |
201 |
ui.StreamVoiceCountTextLabel->setPalette(pal); |
m_ui.StreamVoiceCountTextLabel->setPalette(pal); |
202 |
} |
} |
203 |
|
|
204 |
|
|
205 |
// Maximum volume slider accessors. |
// Maximum volume slider accessors. |
206 |
void ChannelStrip::setMaxVolume ( int iMaxVolume ) |
void ChannelStrip::setMaxVolume ( int iMaxVolume ) |
207 |
{ |
{ |
208 |
m_iDirtyChange++; |
m_iDirtyChange++; |
209 |
ui.VolumeSlider->setRange(0, iMaxVolume); |
m_ui.VolumeSlider->setRange(0, iMaxVolume); |
210 |
ui.VolumeSpinBox->setRange(0, iMaxVolume); |
m_ui.VolumeSpinBox->setRange(0, iMaxVolume); |
211 |
m_iDirtyChange--; |
m_iDirtyChange--; |
212 |
} |
} |
213 |
|
|
214 |
|
|
299 |
// Instrument name... |
// Instrument name... |
300 |
if (m_pChannel->instrumentName().isEmpty()) { |
if (m_pChannel->instrumentName().isEmpty()) { |
301 |
if (m_pChannel->instrumentStatus() >= 0) |
if (m_pChannel->instrumentStatus() >= 0) |
302 |
ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::loadingInstrument()); |
m_ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::loadingInstrument()); |
303 |
else |
else |
304 |
ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::noInstrumentName()); |
m_ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::noInstrumentName()); |
305 |
} else |
} else |
306 |
ui.InstrumentNameTextLabel->setText(' ' + m_pChannel->instrumentName()); |
m_ui.InstrumentNameTextLabel->setText(' ' + m_pChannel->instrumentName()); |
307 |
|
|
308 |
return true; |
return true; |
309 |
} |
} |
312 |
// Do the dirty volume change. |
// Do the dirty volume change. |
313 |
bool ChannelStrip::updateChannelVolume (void) |
bool ChannelStrip::updateChannelVolume (void) |
314 |
{ |
{ |
315 |
if (m_pChannel == NULL) |
if (m_pChannel == NULL) |
316 |
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 |
|
317 |
|
|
318 |
// And clip... |
// Convert... |
319 |
if (iVolume < 0) |
int iVolume = ::lroundf(100.0f * m_pChannel->volume()); |
320 |
iVolume = 0; |
// And clip... |
321 |
|
if (iVolume < 0) |
322 |
// Flag it here, to avoid infinite recursion. |
iVolume = 0; |
323 |
m_iDirtyChange++; |
|
324 |
ui.VolumeSlider->setValue(iVolume); |
// Flag it here, to avoid infinite recursion. |
325 |
ui.VolumeSpinBox->setValue(iVolume); |
m_iDirtyChange++; |
326 |
m_iDirtyChange--; |
m_ui.VolumeSlider->setValue(iVolume); |
327 |
|
m_ui.VolumeSpinBox->setValue(iVolume); |
328 |
|
m_iDirtyChange--; |
329 |
|
|
330 |
return true; |
return true; |
331 |
} |
} |
332 |
|
|
333 |
|
|
334 |
// Update whole channel info state. |
// Update whole channel info state. |
335 |
bool ChannelStrip::updateChannelInfo (void) |
bool ChannelStrip::updateChannelInfo (void) |
336 |
{ |
{ |
337 |
if (m_pChannel == NULL) |
if (m_pChannel == NULL) |
338 |
return false; |
return false; |
339 |
|
|
340 |
// Check for error limit/recycle... |
// Check for error limit/recycle... |
341 |
if (m_iErrorCount > QSAMPLER_ERROR_LIMIT) |
if (m_iErrorCount > QSAMPLER_ERROR_LIMIT) |
342 |
return true; |
return true; |
343 |
|
|
344 |
// Update strip caption. |
// Update strip caption. |
345 |
QString sText = m_pChannel->channelName(); |
QString sText = m_pChannel->channelName(); |
346 |
setWindowTitle(sText); |
setWindowTitle(sText); |
347 |
ui.ChannelSetupPushButton->setText(sText); |
m_ui.ChannelSetupPushButton->setText(sText); |
348 |
|
|
349 |
// Check if we're up and connected. |
// Check if we're up and connected. |
350 |
MainForm* pMainForm = MainForm::getInstance(); |
MainForm* pMainForm = MainForm::getInstance(); |
351 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
352 |
return false; |
return false; |
353 |
|
|
354 |
// Read actual channel information. |
// Read actual channel information. |
355 |
m_pChannel->updateChannelInfo(); |
m_pChannel->updateChannelInfo(); |
356 |
|
|
357 |
// Engine name... |
// Engine name... |
358 |
if (m_pChannel->engineName().isEmpty()) |
if (m_pChannel->engineName().isEmpty()) |
359 |
ui.EngineNameTextLabel->setText(' ' + qsamplerChannel::noEngineName()); |
m_ui.EngineNameTextLabel->setText(' ' + qsamplerChannel::noEngineName()); |
360 |
else |
else |
361 |
ui.EngineNameTextLabel->setText(' ' + m_pChannel->engineName()); |
m_ui.EngineNameTextLabel->setText(' ' + m_pChannel->engineName()); |
362 |
|
|
363 |
// Instrument name... |
// Instrument name... |
364 |
updateInstrumentName(false); |
updateInstrumentName(false); |
365 |
|
|
366 |
// MIDI Port/Channel... |
// MIDI Port/Channel... |
367 |
QString sMidiPortChannel = QString::number(m_pChannel->midiPort()) + " / "; |
QString sMidiPortChannel = QString::number(m_pChannel->midiPort()) + " / "; |
368 |
if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL) |
if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL) |
369 |
sMidiPortChannel += tr("All"); |
sMidiPortChannel += tr("All"); |
370 |
else |
else |
371 |
sMidiPortChannel += QString::number(m_pChannel->midiChannel() + 1); |
sMidiPortChannel += QString::number(m_pChannel->midiChannel() + 1); |
372 |
ui.MidiPortChannelTextLabel->setText(sMidiPortChannel); |
m_ui.MidiPortChannelTextLabel->setText(sMidiPortChannel); |
373 |
|
|
374 |
// Common palette... |
// Common palette... |
375 |
QPalette pal; |
QPalette pal; |
376 |
const QColor& rgbFore = pal.color(QPalette::Foreground); |
const QColor& rgbFore = pal.color(QPalette::Foreground); |
377 |
|
|
378 |
// Instrument status... |
// Instrument status... |
379 |
int iInstrumentStatus = m_pChannel->instrumentStatus(); |
int iInstrumentStatus = m_pChannel->instrumentStatus(); |
380 |
if (iInstrumentStatus < 0) { |
if (iInstrumentStatus < 0) { |
381 |
pal.setColor(QPalette::Foreground, Qt::red); |
pal.setColor(QPalette::Foreground, Qt::red); |
382 |
ui.InstrumentStatusTextLabel->setPalette(pal); |
m_ui.InstrumentStatusTextLabel->setPalette(pal); |
383 |
ui.InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus)); |
m_ui.InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus)); |
384 |
m_iErrorCount++; |
m_iErrorCount++; |
385 |
return false; |
return false; |
386 |
} |
} |
387 |
// All seems normal... |
// All seems normal... |
388 |
pal.setColor(QPalette::Foreground, |
pal.setColor(QPalette::Foreground, |
389 |
iInstrumentStatus < 100 ? Qt::yellow : Qt::green); |
iInstrumentStatus < 100 ? Qt::yellow : Qt::green); |
390 |
ui.InstrumentStatusTextLabel->setPalette(pal); |
m_ui.InstrumentStatusTextLabel->setPalette(pal); |
391 |
ui.InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + '%'); |
m_ui.InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + '%'); |
392 |
m_iErrorCount = 0; |
m_iErrorCount = 0; |
393 |
|
|
394 |
#ifdef CONFIG_MUTE_SOLO |
#ifdef CONFIG_MUTE_SOLO |
395 |
// Mute/Solo button state coloring... |
// Mute/Solo button state coloring... |
396 |
bool bMute = m_pChannel->channelMute(); |
bool bMute = m_pChannel->channelMute(); |
397 |
const QColor& rgbButton = pal.color(QPalette::Button); |
const QColor& rgbButton = pal.color(QPalette::Button); |
398 |
pal.setColor(QPalette::Foreground, rgbFore); |
pal.setColor(QPalette::Foreground, rgbFore); |
399 |
pal.setColor(QPalette::Button, bMute ? Qt::yellow : rgbButton); |
pal.setColor(QPalette::Button, bMute ? Qt::yellow : rgbButton); |
400 |
ui.ChannelMutePushButton->setPalette(pal); |
m_ui.ChannelMutePushButton->setPalette(pal); |
401 |
ui.ChannelMutePushButton->setDown(bMute); |
m_ui.ChannelMutePushButton->setDown(bMute); |
402 |
bool bSolo = m_pChannel->channelSolo(); |
bool bSolo = m_pChannel->channelSolo(); |
403 |
pal.setColor(QPalette::Button, bSolo ? Qt::cyan : rgbButton); |
pal.setColor(QPalette::Button, bSolo ? Qt::cyan : rgbButton); |
404 |
ui.ChannelSoloPushButton->setPalette(pal); |
m_ui.ChannelSoloPushButton->setPalette(pal); |
405 |
ui.ChannelSoloPushButton->setDown(bSolo); |
m_ui.ChannelSoloPushButton->setDown(bSolo); |
406 |
#else |
#else |
407 |
ui.ChannelMutePushButton->setEnabled(false); |
m_ui.ChannelMutePushButton->setEnabled(false); |
408 |
ui.ChannelSoloPushButton->setEnabled(false); |
m_ui.ChannelSoloPushButton->setEnabled(false); |
409 |
#endif |
#endif |
410 |
|
|
411 |
// And update the both GUI volume elements; |
// And update the both GUI volume elements; |
412 |
// return success if, and only if, intrument is fully loaded... |
// return success if, and only if, intrument is fully loaded... |
413 |
return updateChannelVolume() && (iInstrumentStatus == 100); |
return updateChannelVolume() && (iInstrumentStatus == 100); |
414 |
} |
} |
415 |
|
|
416 |
|
|
417 |
// Update whole channel usage state. |
// Update whole channel usage state. |
418 |
bool ChannelStrip::updateChannelUsage (void) |
bool ChannelStrip::updateChannelUsage (void) |
419 |
{ |
{ |
420 |
if (m_pChannel == NULL) |
if (m_pChannel == NULL) |
421 |
return false; |
return false; |
422 |
|
|
423 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
424 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
426 |
|
|
427 |
// This only makes sense on fully loaded channels... |
// This only makes sense on fully loaded channels... |
428 |
if (m_pChannel->instrumentStatus() < 100) |
if (m_pChannel->instrumentStatus() < 100) |
429 |
return false; |
return false; |
430 |
|
|
431 |
// Get current channel voice count. |
// Get current channel voice count. |
432 |
int iVoiceCount = ::lscp_get_channel_voice_count(pMainForm->client(), m_pChannel->channelID()); |
int iVoiceCount = ::lscp_get_channel_voice_count(pMainForm->client(), m_pChannel->channelID()); |
433 |
// Get current stream count. |
// Get current stream count. |
434 |
int iStreamCount = ::lscp_get_channel_stream_count(pMainForm->client(), m_pChannel->channelID()); |
int iStreamCount = ::lscp_get_channel_stream_count(pMainForm->client(), m_pChannel->channelID()); |
435 |
// Get current channel buffer fill usage. |
// Get current channel buffer fill usage. |
436 |
// As benno has suggested this is the percentage usage |
// As benno has suggested this is the percentage usage |
437 |
// of the least filled buffer stream... |
// of the least filled buffer stream... |
438 |
int iStreamUsage = ::lscp_get_channel_stream_usage(pMainForm->client(), m_pChannel->channelID());; |
int iStreamUsage = ::lscp_get_channel_stream_usage(pMainForm->client(), m_pChannel->channelID());; |
439 |
|
|
440 |
// Update the GUI elements... |
// Update the GUI elements... |
441 |
ui.StreamUsageProgressBar->setValue(iStreamUsage); |
m_ui.StreamUsageProgressBar->setValue(iStreamUsage); |
442 |
ui.StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount)); |
m_ui.StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount)); |
443 |
|
|
444 |
// We're clean. |
// We're clean. |
445 |
return true; |
return true; |
446 |
} |
} |
447 |
|
|
448 |
|
|
449 |
// Volume change slot. |
// Volume change slot. |
450 |
void ChannelStrip::volumeChanged ( int iVolume ) |
void ChannelStrip::volumeChanged ( int iVolume ) |
451 |
{ |
{ |
452 |
if (m_pChannel == NULL) |
if (m_pChannel == NULL) |
453 |
return; |
return; |
454 |
|
|
455 |
|
// Avoid recursion. |
456 |
|
if (m_iDirtyChange > 0) |
457 |
|
return; |
458 |
|
|
459 |
// Avoid recursion. |
// Convert and clip. |
460 |
if (m_iDirtyChange > 0) |
float fVolume = (float) iVolume / 100.0f; |
461 |
return; |
if (fVolume < 0.001f) |
462 |
|
fVolume = 0.0f; |
463 |
// Convert and clip. |
|
464 |
float fVolume = (float) iVolume / 100.0; |
// Update the GUI elements. |
465 |
if (fVolume < 0.001) |
if (m_pChannel->setVolume(fVolume)) { |
466 |
fVolume = 0.0; |
updateChannelVolume(); |
467 |
|
emit channelChanged(this); |
468 |
// Update the GUI elements. |
} |
|
if (m_pChannel->setVolume(fVolume)) { |
|
|
updateChannelVolume(); |
|
|
emit channelChanged(this); |
|
|
} |
|
469 |
} |
} |
470 |
|
|
471 |
|
|
472 |
// Context menu event handler. |
// Context menu event handler. |
473 |
void ChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent ) |
void ChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent ) |
474 |
{ |
{ |
475 |
if (m_pChannel == NULL) |
if (m_pChannel == NULL) |
476 |
return; |
return; |
477 |
|
|
478 |
// We'll just show up the main form's edit menu (thru qsamplerChannel). |
// We'll just show up the main form's edit menu (thru qsamplerChannel). |
479 |
m_pChannel->contextMenuEvent(pEvent); |
m_pChannel->contextMenuEvent(pEvent); |
480 |
} |
} |
481 |
|
|
482 |
|
|