2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2007, 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 |
25 |
|
|
26 |
#include "qsamplerMainForm.h" |
#include "qsamplerMainForm.h" |
27 |
|
|
28 |
|
#include "qsamplerChannelFxForm.h" |
29 |
|
|
30 |
|
#include <QMessageBox> |
31 |
#include <QDragEnterEvent> |
#include <QDragEnterEvent> |
32 |
#include <QUrl> |
#include <QUrl> |
33 |
|
|
34 |
|
#define MIDI_OFF_COLOR Qt::darkGreen |
35 |
|
#define MIDI_ON_COLOR Qt::green |
36 |
|
|
37 |
// Channel status/usage usage limit control. |
// Channel status/usage usage limit control. |
38 |
#define QSAMPLER_ERROR_LIMIT 3 |
#define QSAMPLER_ERROR_LIMIT 3 |
39 |
|
|
40 |
// Needed for lroundf() |
// Needed for lroundf() |
41 |
#include <math.h> |
#include <math.h> |
42 |
|
|
|
namespace QSampler { |
|
|
|
|
43 |
#ifndef CONFIG_ROUND |
#ifndef CONFIG_ROUND |
44 |
static inline long lroundf ( float x ) |
static inline long lroundf ( float x ) |
45 |
{ |
{ |
50 |
} |
} |
51 |
#endif |
#endif |
52 |
|
|
53 |
|
|
54 |
|
namespace QSampler { |
55 |
|
|
56 |
|
//------------------------------------------------------------------------- |
57 |
|
// QSampler::ChannelStrip -- Channel strip form implementation. |
58 |
|
// |
59 |
|
|
60 |
|
// Channel strip activation/selection. |
61 |
|
ChannelStrip *ChannelStrip::g_pSelectedStrip = NULL; |
62 |
|
|
63 |
ChannelStrip::ChannelStrip ( QWidget* pParent, Qt::WindowFlags wflags ) |
ChannelStrip::ChannelStrip ( QWidget* pParent, Qt::WindowFlags wflags ) |
64 |
: QWidget(pParent, wflags) |
: QWidget(pParent, wflags) |
65 |
{ |
{ |
91 |
QObject::connect(m_ui.ChannelEditPushButton, |
QObject::connect(m_ui.ChannelEditPushButton, |
92 |
SIGNAL(clicked()), |
SIGNAL(clicked()), |
93 |
SLOT(channelEdit())); |
SLOT(channelEdit())); |
94 |
|
QObject::connect(m_ui.FxPushButton, |
95 |
|
SIGNAL(clicked()), |
96 |
|
SLOT(channelFxEdit())); |
97 |
|
|
98 |
|
pMidiActivityTimer = new QTimer(this); |
99 |
|
pMidiActivityTimer->setSingleShot(true); |
100 |
|
QObject::connect( |
101 |
|
pMidiActivityTimer, SIGNAL(timeout()), |
102 |
|
this, SLOT(midiDataCeased()) |
103 |
|
); |
104 |
|
|
105 |
|
#if CONFIG_EVENT_CHANNEL_MIDI |
106 |
|
m_ui.MidiActivityLabel->setPalette(MIDI_OFF_COLOR); |
107 |
|
m_ui.MidiActivityLabel->setAutoFillBackground(true); |
108 |
|
#else |
109 |
|
m_ui.MidiActivityLabel->setText("X"); |
110 |
|
m_ui.MidiActivityLabel->setToolTip("MIDI Activity Disabled"); |
111 |
|
#endif |
112 |
|
|
113 |
|
setSelected(false); |
114 |
} |
} |
115 |
|
|
116 |
ChannelStrip::~ChannelStrip() { |
|
117 |
|
ChannelStrip::~ChannelStrip (void) |
118 |
|
{ |
119 |
|
setSelected(false); |
120 |
|
|
121 |
// Destroy existing channel descriptor. |
// Destroy existing channel descriptor. |
122 |
if (m_pChannel) |
if (m_pChannel) |
123 |
delete m_pChannel; |
delete m_pChannel; |
140 |
while (iter.hasNext()) { |
while (iter.hasNext()) { |
141 |
const QString& sFilename = iter.next().toLocalFile(); |
const QString& sFilename = iter.next().toLocalFile(); |
142 |
if (!sFilename.isEmpty()) { |
if (!sFilename.isEmpty()) { |
143 |
bAccept = qsamplerChannel::isInstrumentFile(sFilename); |
bAccept = Channel::isInstrumentFile(sFilename); |
144 |
break; |
break; |
145 |
} |
} |
146 |
} |
} |
181 |
|
|
182 |
|
|
183 |
// Channel strip setup formal initializer. |
// Channel strip setup formal initializer. |
184 |
void ChannelStrip::setup ( qsamplerChannel *pChannel ) |
void ChannelStrip::setup ( Channel *pChannel ) |
185 |
{ |
{ |
186 |
// Destroy any previous channel descriptor; |
// Destroy any previous channel descriptor; |
187 |
// (remember that once setup we own it!) |
// (remember that once setup we own it!) |
199 |
setAcceptDrops(true); |
setAcceptDrops(true); |
200 |
} |
} |
201 |
|
|
202 |
|
|
203 |
// Channel secriptor accessor. |
// Channel secriptor accessor. |
204 |
qsamplerChannel *ChannelStrip::channel (void) const |
Channel *ChannelStrip::channel (void) const |
205 |
{ |
{ |
206 |
return m_pChannel; |
return m_pChannel; |
207 |
} |
} |
237 |
pal.setColor(QPalette::Background, Qt::black); |
pal.setColor(QPalette::Background, Qt::black); |
238 |
} |
} |
239 |
m_ui.ChannelInfoFrame->setPalette(pal); |
m_ui.ChannelInfoFrame->setPalette(pal); |
240 |
|
m_ui.InstrumentNameTextLabel->setPalette(pal); |
241 |
m_ui.StreamVoiceCountTextLabel->setPalette(pal); |
m_ui.StreamVoiceCountTextLabel->setPalette(pal); |
242 |
} |
} |
243 |
|
|
309 |
m_pChannel->editChannel(); |
m_pChannel->editChannel(); |
310 |
} |
} |
311 |
|
|
312 |
|
bool ChannelStrip::channelFxEdit (void) |
313 |
|
{ |
314 |
|
MainForm *pMainForm = MainForm::getInstance(); |
315 |
|
if (!pMainForm || !channel()) |
316 |
|
return false; |
317 |
|
|
318 |
|
pMainForm->appendMessages(QObject::tr("channel fx sends...")); |
319 |
|
|
320 |
|
bool bResult = false; |
321 |
|
|
322 |
|
#if CONFIG_FXSEND |
323 |
|
ChannelFxForm *pChannelFxForm = |
324 |
|
new ChannelFxForm(channel(), parentWidget()); |
325 |
|
if (pChannelFxForm) { |
326 |
|
//pChannelForm->setup(this); |
327 |
|
bResult = pChannelFxForm->exec(); |
328 |
|
delete pChannelFxForm; |
329 |
|
} |
330 |
|
#else // CONFIG_FXSEND |
331 |
|
QMessageBox::critical(this, |
332 |
|
QSAMPLER_TITLE ": " + tr("Unavailable"), |
333 |
|
tr("Sorry, QSampler was built without FX send support!\n\n" |
334 |
|
"(Make sure you have a recent liblscp when recompiling QSampler)")); |
335 |
|
#endif // CONFIG_FXSEND |
336 |
|
|
337 |
|
return bResult; |
338 |
|
} |
339 |
|
|
340 |
// Channel reset slot. |
// Channel reset slot. |
341 |
bool ChannelStrip::channelReset (void) |
bool ChannelStrip::channelReset (void) |
365 |
|
|
366 |
// Instrument name... |
// Instrument name... |
367 |
if (m_pChannel->instrumentName().isEmpty()) { |
if (m_pChannel->instrumentName().isEmpty()) { |
368 |
if (m_pChannel->instrumentStatus() >= 0) |
if (m_pChannel->instrumentStatus() >= 0) { |
369 |
m_ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::loadingInstrument()); |
m_ui.InstrumentNameTextLabel->setText( |
370 |
else |
' ' + Channel::loadingInstrument()); |
371 |
m_ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::noInstrumentName()); |
} else { |
372 |
} else |
m_ui.InstrumentNameTextLabel->setText( |
373 |
m_ui.InstrumentNameTextLabel->setText(' ' + m_pChannel->instrumentName()); |
' ' + Channel::noInstrumentName()); |
374 |
|
} |
375 |
|
} else { |
376 |
|
m_ui.InstrumentNameTextLabel->setText( |
377 |
|
' ' + m_pChannel->instrumentName()); |
378 |
|
} |
379 |
|
|
380 |
return true; |
return true; |
381 |
} |
} |
416 |
// Update strip caption. |
// Update strip caption. |
417 |
QString sText = m_pChannel->channelName(); |
QString sText = m_pChannel->channelName(); |
418 |
setWindowTitle(sText); |
setWindowTitle(sText); |
419 |
m_ui.ChannelSetupPushButton->setText(sText); |
m_ui.ChannelSetupPushButton->setText('&' + sText); |
420 |
|
|
421 |
// Check if we're up and connected. |
// Check if we're up and connected. |
422 |
MainForm* pMainForm = MainForm::getInstance(); |
MainForm* pMainForm = MainForm::getInstance(); |
427 |
m_pChannel->updateChannelInfo(); |
m_pChannel->updateChannelInfo(); |
428 |
|
|
429 |
// Engine name... |
// Engine name... |
430 |
if (m_pChannel->engineName().isEmpty()) |
if (m_pChannel->engineName().isEmpty()) { |
431 |
m_ui.EngineNameTextLabel->setText(' ' + qsamplerChannel::noEngineName()); |
m_ui.EngineNameTextLabel->setText( |
432 |
else |
' ' + Channel::noEngineName()); |
433 |
m_ui.EngineNameTextLabel->setText(' ' + m_pChannel->engineName()); |
} else { |
434 |
|
m_ui.EngineNameTextLabel->setText( |
435 |
|
' ' + m_pChannel->engineName()); |
436 |
|
} |
437 |
|
|
438 |
// Instrument name... |
// Instrument name... |
439 |
updateInstrumentName(false); |
updateInstrumentName(false); |
455 |
if (iInstrumentStatus < 0) { |
if (iInstrumentStatus < 0) { |
456 |
pal.setColor(QPalette::Foreground, Qt::red); |
pal.setColor(QPalette::Foreground, Qt::red); |
457 |
m_ui.InstrumentStatusTextLabel->setPalette(pal); |
m_ui.InstrumentStatusTextLabel->setPalette(pal); |
458 |
m_ui.InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus)); |
m_ui.InstrumentStatusTextLabel->setText( |
459 |
|
tr("ERR%1").arg(iInstrumentStatus)); |
460 |
m_iErrorCount++; |
m_iErrorCount++; |
461 |
return false; |
return false; |
462 |
} |
} |
464 |
pal.setColor(QPalette::Foreground, |
pal.setColor(QPalette::Foreground, |
465 |
iInstrumentStatus < 100 ? Qt::yellow : Qt::green); |
iInstrumentStatus < 100 ? Qt::yellow : Qt::green); |
466 |
m_ui.InstrumentStatusTextLabel->setPalette(pal); |
m_ui.InstrumentStatusTextLabel->setPalette(pal); |
467 |
m_ui.InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + '%'); |
m_ui.InstrumentStatusTextLabel->setText( |
468 |
|
QString::number(iInstrumentStatus) + '%'); |
469 |
m_iErrorCount = 0; |
m_iErrorCount = 0; |
470 |
|
|
471 |
#ifdef CONFIG_MUTE_SOLO |
#ifdef CONFIG_MUTE_SOLO |
506 |
return false; |
return false; |
507 |
|
|
508 |
// Get current channel voice count. |
// Get current channel voice count. |
509 |
int iVoiceCount = ::lscp_get_channel_voice_count(pMainForm->client(), m_pChannel->channelID()); |
int iVoiceCount = ::lscp_get_channel_voice_count( |
510 |
|
pMainForm->client(), m_pChannel->channelID()); |
511 |
// Get current stream count. |
// Get current stream count. |
512 |
int iStreamCount = ::lscp_get_channel_stream_count(pMainForm->client(), m_pChannel->channelID()); |
int iStreamCount = ::lscp_get_channel_stream_count( |
513 |
|
pMainForm->client(), m_pChannel->channelID()); |
514 |
// Get current channel buffer fill usage. |
// Get current channel buffer fill usage. |
515 |
// As benno has suggested this is the percentage usage |
// As benno has suggested this is the percentage usage |
516 |
// of the least filled buffer stream... |
// of the least filled buffer stream... |
517 |
int iStreamUsage = ::lscp_get_channel_stream_usage(pMainForm->client(), m_pChannel->channelID());; |
int iStreamUsage = ::lscp_get_channel_stream_usage( |
518 |
|
pMainForm->client(), m_pChannel->channelID());; |
519 |
|
|
520 |
// Update the GUI elements... |
// Update the GUI elements... |
521 |
m_ui.StreamUsageProgressBar->setValue(iStreamUsage); |
m_ui.StreamUsageProgressBar->setValue(iStreamUsage); |
522 |
m_ui.StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount)); |
m_ui.StreamVoiceCountTextLabel->setText( |
523 |
|
QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount)); |
524 |
|
|
525 |
// We're clean. |
// We're clean. |
526 |
return true; |
return true; |
549 |
} |
} |
550 |
} |
} |
551 |
|
|
552 |
|
void ChannelStrip::midiArrived() { |
553 |
|
m_ui.MidiActivityLabel->setPalette(MIDI_ON_COLOR); |
554 |
|
pMidiActivityTimer->start(50); |
555 |
|
} |
556 |
|
|
557 |
// Context menu event handler. |
// Context menu event handler. |
558 |
void ChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent ) |
void ChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent ) |
564 |
m_pChannel->contextMenuEvent(pEvent); |
m_pChannel->contextMenuEvent(pEvent); |
565 |
} |
} |
566 |
|
|
567 |
|
void ChannelStrip::midiDataCeased() { |
568 |
|
m_ui.MidiActivityLabel->setPalette(MIDI_OFF_COLOR); |
569 |
|
} |
570 |
|
|
571 |
// Error count hackish accessors. |
// Error count hackish accessors. |
572 |
void ChannelStrip::resetErrorCount (void) |
void ChannelStrip::resetErrorCount (void) |
574 |
m_iErrorCount = 0; |
m_iErrorCount = 0; |
575 |
} |
} |
576 |
|
|
577 |
|
|
578 |
|
// Channel strip activation/selection. |
579 |
|
void ChannelStrip::setSelected ( bool bSelected ) |
580 |
|
{ |
581 |
|
if (bSelected) { |
582 |
|
if (g_pSelectedStrip == this) |
583 |
|
return; |
584 |
|
if (g_pSelectedStrip) |
585 |
|
g_pSelectedStrip->setSelected(false); |
586 |
|
g_pSelectedStrip = this; |
587 |
|
} else { |
588 |
|
if (g_pSelectedStrip == this) |
589 |
|
g_pSelectedStrip = NULL; |
590 |
|
} |
591 |
|
|
592 |
|
QPalette pal; |
593 |
|
if (bSelected) { |
594 |
|
const QColor& color = pal.midlight().color(); |
595 |
|
pal.setColor(QPalette::Background, color.dark(150)); |
596 |
|
pal.setColor(QPalette::Foreground, color.light(150)); |
597 |
|
} |
598 |
|
QWidget::setPalette(pal); |
599 |
|
} |
600 |
|
|
601 |
|
|
602 |
|
bool ChannelStrip::isSelected (void) const |
603 |
|
{ |
604 |
|
return (this == g_pSelectedStrip); |
605 |
|
} |
606 |
|
|
607 |
|
|
608 |
} // namespace QSampler |
} // namespace QSampler |
609 |
|
|
610 |
|
|