--- qsampler/trunk/src/qsamplerChannelStrip.ui.h 2004/11/17 15:41:58 299 +++ qsampler/trunk/src/qsamplerChannelStrip.ui.h 2005/02/20 19:13:33 395 @@ -2,7 +2,7 @@ // // ui.h extension file, included from the uic-generated form implementation. /**************************************************************************** - Copyright (C) 2004, rncbc aka Rui Nuno Capela. All rights reserved. + Copyright (C) 2004-2005, rncbc aka Rui Nuno Capela. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -34,14 +35,18 @@ #include "config.h" +// Channel status/usage usage limit control. +#define QSAMPLER_ERROR_LIMIT 3 +#define QSAMPLER_ERROR_CYCLE 33 + // Kind of constructor. void qsamplerChannelStrip::init (void) { // Initialize locals. - m_pMainForm = NULL; m_pChannel = NULL; m_iDirtyChange = 0; + m_iErrorCount = 0; // Try to restore normal window positioning. adjustSize(); @@ -58,26 +63,68 @@ } +// Drag'n'drop file handler. +bool qsamplerChannelStrip::decodeDragFile ( const QMimeSource *pEvent, QString& sInstrumentFile ) +{ + if (m_pChannel == NULL) + return false; + + if (QTextDrag::canDecode(pEvent)) { + QString sText; + if (QTextDrag::decode(pEvent, sText)) { + QStringList files = QStringList::split('\n', sText); + for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) { + *iter = (*iter).stripWhiteSpace().replace(QRegExp("^file:"), QString::null); + if (qsamplerChannel::isInstrumentFile(*iter)) { + sInstrumentFile = *iter; + return true; + } + } + } + } + // Fail. + return false; +} + + +// Window drag-n-drop event handlers. +void qsamplerChannelStrip::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent ) +{ + QString sInstrumentFile; + pDragEnterEvent->accept(decodeDragFile(pDragEnterEvent, sInstrumentFile)); +} + + +void qsamplerChannelStrip::dropEvent ( QDropEvent* pDropEvent ) +{ + QString sInstrumentFile; + + if (decodeDragFile(pDropEvent, sInstrumentFile)) { + // Go and set the dropped instrument filename... + m_pChannel->setInstrument(sInstrumentFile, 0); + // Open up the channel dialog. + channelSetup(); + } +} + + // Channel strip setup formal initializer. -void qsamplerChannelStrip::setup ( qsamplerMainForm *pMainForm, int iChannelID ) +void qsamplerChannelStrip::setup ( qsamplerChannel *pChannel ) { - // Set main form reference. - m_pMainForm = pMainForm; - - // Destroy any previous channel descriptor. + // Destroy any previous channel descriptor; + // (remember that once setup we own it!) if (m_pChannel) delete m_pChannel; - // Create a new one... - m_pChannel = new qsamplerChannel(pMainForm); - // And set appropriate settings. - if (m_pChannel && iChannelID >= 0) { - m_pChannel->setChannelID(iChannelID); - m_iDirtyChange = 0; - } + // Set the new one... + m_pChannel = pChannel; // Stabilize this around. updateChannelInfo(); + + // We'll accept drops from now on... + if (m_pChannel) + setAcceptDrops(true); } // Channel secriptor accessor. @@ -131,22 +178,50 @@ } +// Maximum volume slider accessors. +void qsamplerChannelStrip::setMaxVolume ( int iMaxVolume ) +{ + m_iDirtyChange++; + VolumeSlider->setRange(0, iMaxVolume); + VolumeSpinBox->setRange(0, iMaxVolume); + m_iDirtyChange--; +} + + // Channel setup dialog slot. bool qsamplerChannelStrip::channelSetup (void) { - bool bResult = false; + // Invoke the channel setup dialog. + bool bResult = m_pChannel->channelSetup(this); - qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(this); - if (pChannelForm) { - pChannelForm->setup(m_pChannel); - bResult = pChannelForm->exec(); - delete pChannelForm; - } + if (bResult) { + // Reset the error/cycle. + m_iErrorCount = 0; + // Notify that thie channel has changed. + emit channelChanged(this); + } - if (bResult) - emit channelChanged(this); + return bResult; +} + + +// Update the channel instrument name. +bool qsamplerChannelStrip::updateInstrumentName ( bool bForce ) +{ + if (m_pChannel == NULL) + return false; - return bResult; + // Do we refersh the actual name? + if (bForce) + m_pChannel->updateInstrumentName(); + + // Instrument name... + if (m_pChannel->instrumentName().isEmpty()) + InstrumentNameTextLabel->setText(' ' + qsamplerChannel::noInstrumentName()); + else + InstrumentNameTextLabel->setText(' ' + m_pChannel->instrumentName()); + + return true; } @@ -168,20 +243,14 @@ // Read actual channel information. m_pChannel->updateChannelInfo(); - // Set some proper display values. - const QString sIndent = " "; - // Engine name... if (m_pChannel->engineName().isEmpty()) - EngineNameTextLabel->setText(sIndent + tr("(No engine)")); + EngineNameTextLabel->setText(' ' + qsamplerChannel::noEngineName()); else - EngineNameTextLabel->setText(sIndent + m_pChannel->engineName()); + EngineNameTextLabel->setText(' ' + m_pChannel->engineName()); - // Instrument name... - if (m_pChannel->instrumentFile().isEmpty()) - InstrumentNameTextLabel->setText(sIndent + tr("(No instrument)")); - else - InstrumentNameTextLabel->setText(sIndent + qsamplerChannel::getInstrumentName(m_pChannel->instrumentFile(), m_pChannel->instrumentNr())); + // Instrument name... + updateInstrumentName(false); // Instrument status... int iInstrumentStatus = m_pChannel->instrumentStatus(); @@ -246,17 +315,33 @@ if (m_pChannel->client() == NULL) return false; - // Conditionally update whole channel status info. - if (m_pChannel->instrumentStatus() >= 0 && m_pChannel->instrumentStatus() < 100) { - updateChannelInfo(); - // Once we get a complete instrument load, try a implied reset channel.... - if (m_pChannel->instrumentStatus() == 100) - m_pChannel->resetChannel(); - } - // Leave, if we still have an erroneus or incomplete instrument load. - if (m_pChannel->instrumentStatus() < 100) - return false; - + // Check for error limit/recycle... + if (m_iErrorCount > QSAMPLER_ERROR_LIMIT) + m_iErrorCount -= QSAMPLER_ERROR_CYCLE; + if (m_iErrorCount < 0) { + m_iErrorCount++; + return false; + } + + // Update whole channel status info, + // if instrument load is still pending... + if (m_pChannel->instrumentStatus() < 100) { + // grab the whole sampler channel data... + updateChannelInfo(); + // Check (updated) status again... + int iInstrumentStatus = m_pChannel->instrumentStatus(); + if (iInstrumentStatus < 100) { + if (iInstrumentStatus < 0) + m_iErrorCount++; + return false; + } + // Once we get a complete instrument load, + // we'll try an implied channel reset... + m_pChannel->resetChannel(); + // Reset error count. + m_iErrorCount = 0; + } + // Get current channel voice count. int iVoiceCount = ::lscp_get_channel_voice_count(m_pChannel->client(), m_pChannel->channelID()); // Get current stream count. @@ -301,21 +386,11 @@ // Context menu event handler. void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent ) { - if (m_pMainForm == NULL) + if (m_pChannel == NULL) return; - // We'll just show up the main form's edit menu. - m_pMainForm->contextMenuEvent(pEvent); -} - - -// Maximum volume slider accessors. -void qsamplerChannelStrip::setMaxVolume ( int iMaxVolume ) -{ - m_iDirtyChange++; - VolumeSlider->setRange(0, iMaxVolume); - VolumeSpinBox->setRange(0, iMaxVolume); - m_iDirtyChange--; + // We'll just show up the main form's edit menu (thru qsamplerChannel). + m_pChannel->contextMenuEvent(pEvent); }