--- qsampler/trunk/src/qsamplerMainForm.ui.h 2005/01/18 11:29:01 341 +++ qsampler/trunk/src/qsamplerMainForm.ui.h 2005/02/20 19:13:33 395 @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -205,9 +206,6 @@ // We got options? m_pOptions = pOptions; - // Set initial instrument name display mode. - qsamplerChannel::setInstrumentNames(m_pOptions->bInstrumentNames); - // Some child forms are to be created right now. m_pMessages = new qsamplerMessages(this); // Set message defaults... @@ -297,28 +295,70 @@ } -// Window drag-n-drop event handlers. -void qsamplerMainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent ) +// Drag'n'drop file handler. +bool qsamplerMainForm::decodeDragFiles ( const QMimeSource *pEvent, QStringList& files ) { - bool bAccept = false; + bool bDecode = false; - if (QTextDrag::canDecode(pDragEnterEvent)) { - QString sUrl; - if (QTextDrag::decode(pDragEnterEvent, sUrl) && m_pClient) - bAccept = QFileInfo(QUrl(sUrl).path()).exists(); + if (QTextDrag::canDecode(pEvent)) { + QString sText; + bDecode = QTextDrag::decode(pEvent, sText); + if (bDecode) { + files = QStringList::split('\n', sText); + for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) + *iter = (*iter).stripWhiteSpace().replace(QRegExp("^file:"), QString::null); + } } - pDragEnterEvent->accept(bAccept); + return bDecode; +} + + +// Window drag-n-drop event handlers. +void qsamplerMainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent ) +{ + QStringList files; + pDragEnterEvent->accept(decodeDragFiles(pDragEnterEvent, files)); } void qsamplerMainForm::dropEvent ( QDropEvent* pDropEvent ) { - if (QTextDrag::canDecode(pDropEvent)) { - QString sUrl; - if (QTextDrag::decode(pDropEvent, sUrl) && closeSession(true)) - loadSessionFile(QUrl(sUrl).path()); - } + QStringList files; + + if (!decodeDragFiles(pDropEvent, files)) + return; + + for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) { + const QString& sPath = QUrl(*iter).path(); + if (qsamplerChannel::isInstrumentFile(sPath)) { + // Try to create a new channel from instrument file... + qsamplerChannel *pChannel = new qsamplerChannel(this); + if (pChannel == NULL) + return; + // Start setting the instrument filename... + pChannel->setInstrument(sPath, 0); + // Before we show it up, may be we'll + // better ask for some initial values? + if (!pChannel->channelSetup(this)) { + delete pChannel; + return; + } + // Finally, give it to a new channel strip... + if (!createChannelStrip(pChannel)) { + delete pChannel; + return; + } + // Make that an overall update. + m_iDirtyCount++; + m_iChangeCount++; + stabilizeForm(); + } // Otherwise, load an usual session file (LSCP script)... + else if (closeSession(true)) + loadSessionFile(sPath); + // Make it look responsive...:) + QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); + } } @@ -383,6 +423,9 @@ if (!closeSession(true)) return false; + // Give us what the server has, right now... + updateSession(); + // Ok increment untitled count. m_iUntitled++; @@ -541,6 +584,7 @@ if (::lscp_client_query(m_pClient, sCommand.latin1()) != LSCP_OK) { appendMessagesClient("lscp_client_query"); iErrors++; + break; } } // Try to make it snappy :) @@ -552,22 +596,10 @@ // Have we any errors? if (iErrors > 0) - appendMessagesError(tr("Some setttings could not be loaded\nfrom \"%1\" session file.\n\nSorry.").arg(sFilename)); + appendMessagesError(tr("Session could not be loaded\nfrom \"%1\".\n\nSorry.").arg(sFilename)); - // Now we'll try to create the whole GUI session. - int *piChannelIDs = ::lscp_list_channels(m_pClient); - if (piChannelIDs == NULL) { - appendMessagesClient("lscp_list_channels"); - appendMessagesError(tr("Could not get current list of channels.\n\nSorry.")); - } - - // Try to (re)create each channel. - m_pWorkspace->setUpdatesEnabled(false); - for (int iChannel = 0; piChannelIDs[iChannel] >= 0; iChannel++) { - createChannelStrip(new qsamplerChannel(this, piChannelIDs[iChannel])); - QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); - } - m_pWorkspace->setUpdatesEnabled(true); + // Now we'll try to create (update) the whole GUI session. + updateSession(); // Save as default session directory. if (m_pOptions) @@ -732,6 +764,9 @@ // Log this. appendMessages(tr("Sampler reset.")); + + // Make it a new session... + newSession(); } @@ -962,8 +997,8 @@ int bOldMessagesLimit = m_pOptions->bMessagesLimit; int iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines; bool bOldCompletePath = m_pOptions->bCompletePath; - int iOldMaxRecentFiles = m_pOptions->iMaxRecentFiles; bool bOldInstrumentNames = m_pOptions->bInstrumentNames; + int iOldMaxRecentFiles = m_pOptions->iMaxRecentFiles; // Load the current setup settings. pOptionsForm->setup(m_pOptions); // Show the setup dialog... @@ -977,13 +1012,13 @@ updateMessagesCapture(); } // Check wheather something immediate has changed. - if (( bOldInstrumentNames && !m_pOptions->bInstrumentNames) || - (!bOldInstrumentNames && m_pOptions->bInstrumentNames)) - qsamplerChannel::setInstrumentNames(m_pOptions->bInstrumentNames); if (( bOldCompletePath && !m_pOptions->bCompletePath) || (!bOldCompletePath && m_pOptions->bCompletePath) || (iOldMaxRecentFiles != m_pOptions->iMaxRecentFiles)) updateRecentFilesMenu(); + if (( bOldInstrumentNames && !m_pOptions->bInstrumentNames) || + (!bOldInstrumentNames && m_pOptions->bInstrumentNames)) + updateInstrumentNames(); if (( bOldDisplayEffect && !m_pOptions->bDisplayEffect) || (!bOldDisplayEffect && m_pOptions->bDisplayEffect)) updateDisplayEffect(); @@ -1094,6 +1129,11 @@ sText += tr("GIG (libgig) file support disabled."); sText += "
"; #endif +#ifndef CONFIG_INSTRUMENT_NAME + sText += ""; + sText += tr("LSCP (liblscp) instrument_name support disabled."); + sText += "
"; +#endif sText += "
\n"; sText += tr("Using") + ": "; sText += ::lscp_client_package(); @@ -1183,6 +1223,32 @@ } +// Grab and restore current sampler channels session. +void qsamplerMainForm::updateSession (void) +{ + // Retrieve the current channel list. + int *piChannelIDs = ::lscp_list_channels(m_pClient); + if (piChannelIDs == NULL) { + if (::lscp_client_get_errno(m_pClient)) { + appendMessagesClient("lscp_list_channels"); + appendMessagesError(tr("Could not get current list of channels.\n\nSorry.")); + } + return; + } + + // Try to (re)create each channel. + m_pWorkspace->setUpdatesEnabled(false); + for (int iChannel = 0; piChannelIDs[iChannel] >= 0; iChannel++) { + // Check if theres already a channel strip for this one... + if (!channelStrip(piChannelIDs[iChannel])) + createChannelStrip(new qsamplerChannel(this, piChannelIDs[iChannel])); + // Make it visibly responsive... + QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); + } + m_pWorkspace->setUpdatesEnabled(true); +} + + // Update the recent files list and menu. void qsamplerMainForm::updateRecentFiles ( const QString& sFilename ) { @@ -1227,6 +1293,24 @@ } +// Force update of the channels instrument names mode. +void qsamplerMainForm::updateInstrumentNames (void) +{ + // Full channel list update... + QWidgetList wlist = m_pWorkspace->windowList(); + if (wlist.isEmpty()) + return; + + m_pWorkspace->setUpdatesEnabled(false); + for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { + qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); + if (pChannelStrip) + pChannelStrip->updateInstrumentName(true); + } + m_pWorkspace->setUpdatesEnabled(true); +} + + // Force update of the channels display font. void qsamplerMainForm::updateDisplayFont (void) { @@ -1404,8 +1488,10 @@ QWidgetList wlist = m_pWorkspace->windowList(); for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); - // y += pChannelStrip->height() + pChannelStrip->parentWidget()->baseSize().height(); - y += pChannelStrip->parentWidget()->frameGeometry().height(); + if (pChannelStrip) { + // y += pChannelStrip->height() + pChannelStrip->parentWidget()->baseSize().height(); + y += pChannelStrip->parentWidget()->frameGeometry().height(); + } } } @@ -1457,12 +1543,33 @@ { QWidgetList wlist = m_pWorkspace->windowList(); if (wlist.isEmpty()) - return 0; + return NULL; return (qsamplerChannelStrip *) wlist.at(iChannel); } +// Retrieve a channel strip by sampler channel id. +qsamplerChannelStrip *qsamplerMainForm::channelStrip ( int iChannelID ) +{ + QWidgetList wlist = m_pWorkspace->windowList(); + if (wlist.isEmpty()) + return NULL; + + for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { + qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); + if (pChannelStrip) { + qsamplerChannel *pChannel = pChannelStrip->channel(); + if (pChannel && pChannel->channelID() == iChannelID) + return pChannelStrip; + } + } + + // Not found. + return NULL; +} + + // Construct the windows menu. void qsamplerMainForm::channelsMenuAboutToShow (void) {