--- qsampler/trunk/src/qsamplerMainForm.ui.h 2004/06/09 20:24:48 119 +++ qsampler/trunk/src/qsamplerMainForm.ui.h 2005/03/02 16:23:10 418 @@ -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 @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -36,6 +37,7 @@ #include "qsamplerAbout.h" #include "qsamplerOptions.h" +#include "qsamplerChannel.h" #include "qsamplerMessages.h" #include "qsamplerChannelStrip.h" @@ -43,6 +45,9 @@ #include "config.h" +#ifdef HAVE_SIGNAL_H +#include +#endif // Timer constant stuff. #define QSAMPLER_TIMER_MSECS 200 @@ -54,10 +59,42 @@ #define QSAMPLER_STATUS_SESSION 3 // Current session modification state. +// All winsock apps needs this. #if defined(WIN32) static WSADATA _wsaData; #endif + +//------------------------------------------------------------------------- +// qsamplerCustomEvent -- specialty for callback comunication. + +#define QSAMPLER_CUSTOM_EVENT 1000 + +class qsamplerCustomEvent : public QCustomEvent +{ +public: + + // Constructor. + qsamplerCustomEvent(lscp_event_t event, const char *pchData, int cchData) + : QCustomEvent(QSAMPLER_CUSTOM_EVENT) + { + m_event = event; + m_data.setLatin1(pchData, cchData); + } + + // Accessors. + lscp_event_t event() { return m_event; } + QString& data() { return m_data; } + +private: + + // The proper event type. + lscp_event_t m_event; + // The event data as a string. + QString m_data; +}; + + //------------------------------------------------------------------------- // qsamplerMainForm -- Main window form implementation. @@ -71,7 +108,7 @@ m_pMessages = NULL; // We'll start clean. - m_iUntitled = 0; + m_iUntitled = 0; m_iDirtyCount = 0; m_pServer = NULL; @@ -82,6 +119,11 @@ m_iTimerSlot = 0; +#ifdef HAVE_SIGNAL_H + // Set to ignore any fatal "Broken pipe" signals. + ::signal(SIGPIPE, SIG_IGN); +#endif + // Make it an MDI workspace. m_pWorkspace = new QWorkspace(this); m_pWorkspace->setScrollBarsEnabled(true); @@ -131,10 +173,17 @@ { // Do final processing anyway. processServerExit(); - - // Delete recentfiles menu. - if (m_pRecentFilesMenu) - delete m_pRecentFilesMenu; + +#if defined(WIN32) + WSACleanup(); +#endif + + // Finally drop any widgets around... + if (m_pMessages) + delete m_pMessages; + if (m_pWorkspace) + delete m_pWorkspace; + // Delete status item labels one by one. if (m_status[QSAMPLER_STATUS_CLIENT]) delete m_status[QSAMPLER_STATUS_CLIENT]; @@ -145,15 +194,9 @@ if (m_status[QSAMPLER_STATUS_SESSION]) delete m_status[QSAMPLER_STATUS_SESSION]; - // Finally drop any widgets around... - if (m_pMessages) - delete m_pMessages; - if (m_pWorkspace) - delete m_pWorkspace; - -#if defined(WIN32) - WSACleanup(); -#endif + // Delete recentfiles menu. + if (m_pRecentFilesMenu) + delete m_pRecentFilesMenu; } @@ -252,30 +295,94 @@ } -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 = QUrl((*iter).stripWhiteSpace().replace(QRegExp("^file:"), QString::null)).path(); + } } - 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 = *iter; + 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++; + stabilizeForm(); + } // Otherwise, load an usual session file (LSCP script)... + else if (closeSession(true)) + loadSessionFile(sPath); + // Make it look responsive...:) + QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); + } +} + + +// Custome event handler. +void qsamplerMainForm::customEvent ( QCustomEvent *pCustomEvent ) +{ + // For the time being, just pump it to messages. + if (pCustomEvent->type() == QSAMPLER_CUSTOM_EVENT) { + qsamplerCustomEvent *pEvent = (qsamplerCustomEvent *) pCustomEvent; + appendMessagesColor(tr("Notify event: %1 data: %2") + .arg(::lscp_event_to_text(pEvent->event())) + .arg(pEvent->data()), "#996699"); } } +// Context menu event handler. +void qsamplerMainForm::contextMenuEvent( QContextMenuEvent *pEvent ) +{ + stabilizeForm(); + + editMenu->exec(pEvent->globalPos()); +} + + //------------------------------------------------------------------------- // qsamplerMainForm -- Brainless public property accessors. @@ -315,6 +422,9 @@ if (!closeSession(true)) return false; + // Give us what the server has, right now... + updateSession(); + // Ok increment untitled count. m_iUntitled++; @@ -428,10 +538,13 @@ m_pWorkspace->setUpdatesEnabled(false); QWidgetList wlist = m_pWorkspace->windowList(); for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { - qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel); - if (bForce && ::lscp_remove_channel(m_pClient, pChannel->channelID()) != LSCP_OK) - appendMessagesClient("lscp_remove_channel"); - delete pChannel; + qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); + if (pChannelStrip) { + qsamplerChannel *pChannel = pChannelStrip->channel(); + if (bForce && pChannel) + pChannel->removeChannel(); + delete pChannelStrip; + } } m_pWorkspace->setUpdatesEnabled(true); // We're now clean, for sure. @@ -470,6 +583,7 @@ if (::lscp_client_query(m_pClient, sCommand.latin1()) != LSCP_OK) { appendMessagesClient("lscp_client_query"); iErrors++; + break; } } // Try to make it snappy :) @@ -481,22 +595,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 iChannels = ::lscp_get_channels(m_pClient); - if (iChannels < 0) { - appendMessagesClient("lscp_get_channels"); - appendMessagesError(tr("Could not get current number of channels.\n\nSorry.")); - } - - // Try to (re)create each channel. - m_pWorkspace->setUpdatesEnabled(false); - for (int iChannelID = 0; iChannelID < iChannels; iChannelID++) { - createChannel(iChannelID, false); - 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) @@ -507,6 +609,8 @@ m_sFilename = sFilename; updateRecentFiles(sFilename); appendMessages(tr("Open session: \"%1\".").arg(sessionName(m_sFilename))); + + // Make that an overall update. stabilizeForm(); return true; } @@ -540,18 +644,27 @@ ts << endl; QWidgetList wlist = m_pWorkspace->windowList(); for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { - qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel); - int iChannelID = pChannel->channelID(); - ts << "# " << pChannel->caption() << endl; - ts << "ADD CHANNEL" << endl; - ts << "SET CHANNEL AUDIO_OUTPUT_TYPE " << iChannelID << " " << pChannel->audioDriver() << endl; - ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannelID << " " << pChannel->midiDriver() << endl; - // ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannelID << " " << pChannel->midiPort() << endl; - ts << "SET CHANNEL MIDI_INPUT_CHANNEL " << iChannelID << " " << pChannel->midiChannel() << endl; - ts << "LOAD ENGINE " << pChannel->engineName() << " " << iChannelID << endl; - ts << "LOAD INSTRUMENT " << pChannel->instrumentFile() << " " << pChannel->instrumentNr() << " " << iChannelID << endl; - ts << "SET CHANNEL VOLUME " << iChannelID << " " << pChannel->volume() << endl; - ts << endl; + qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); + if (pChannelStrip) { + qsamplerChannel *pChannel = pChannelStrip->channel(); + if (pChannel) { + ts << "# Channel " << iChannel << endl; + ts << "ADD CHANNEL" << endl; + ts << "SET CHANNEL AUDIO_OUTPUT_TYPE " << iChannel << " " << pChannel->audioDriver() << endl; + ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannel << " " << pChannel->midiDriver() << endl; + // ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannel << " " << pChannel->midiPort() << endl; + ts << "SET CHANNEL MIDI_INPUT_CHANNEL " << iChannel << " "; + if (pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL) + ts << "ALL"; + else + ts << pChannel->midiChannel(); + ts << endl; + ts << "LOAD ENGINE " << pChannel->engineName() << " " << iChannel << endl; + ts << "LOAD INSTRUMENT NON_MODAL '" << pChannel->instrumentFile() << "' " << pChannel->instrumentNr() << " " << iChannel << endl; + ts << "SET CHANNEL VOLUME " << iChannel << " " << pChannel->volume() << endl; + ts << endl; + } + } // Try to keep it snappy :) QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); } @@ -623,6 +736,37 @@ } +// Reset the sampler instance. +void qsamplerMainForm::fileReset (void) +{ + if (m_pClient == NULL) + return; + + // Ask user whether he/she want's an internal sampler reset... + if (QMessageBox::warning(this, tr("Warning"), + tr("Resetting the sampler instance will close\n" + "all device and channel configurations.\n\n" + "Please note that this operation may cause\n" + "temporary MIDI and Audio disruption\n\n" + "Do you want to reset the sampler engine now?"), + tr("Reset"), tr("Cancel")) > 0) + return; + + // Just do the reset, after closing down current session... + if (closeSession(true) && ::lscp_reset_sampler(m_pClient) != LSCP_OK) { + appendMessagesClient("lscp_reset_sampler"); + appendMessagesError(tr("Could not reset sampler instance.\n\nSorry.")); + return; + } + + // Log this. + appendMessages(tr("Sampler reset.")); + + // Make it a new session... + newSession(); +} + + // Restart the client/server instance. void qsamplerMainForm::fileRestart (void) { @@ -670,23 +814,26 @@ if (m_pClient == NULL) return; - // Create the new sampler channel. - int iChannelID = ::lscp_add_channel(m_pClient); - if (iChannelID < 0) { - appendMessagesClient("lscp_add_channel"); - appendMessagesError(tr("Could not create the new channel.\n\nSorry.")); + // Just create the channel instance... + qsamplerChannel *pChannel = new qsamplerChannel(this); + if (pChannel == NULL) return; - } - - // Log this happening. - appendMessages(tr("Channel %1 created.").arg(iChannelID)); - // Just create the channel strip with given id. - createChannel(iChannelID, true); + // Before we show it up, may be we'll + // better ask for some initial values? + if (!pChannel->channelSetup(this)) { + delete pChannel; + return; + } + + // And give it to the strip (will own the channel instance, if successful). + if (!createChannelStrip(pChannel)) { + delete pChannel; + return; + } - // We'll be dirty, for sure... + // Make that an overall update. m_iDirtyCount++; - // Stabilize form anyway. stabilizeForm(); } @@ -697,7 +844,11 @@ if (m_pClient == NULL) return; - qsamplerChannelStrip *pChannel = activeChannel(); + qsamplerChannelStrip *pChannelStrip = activeChannelStrip(); + if (pChannelStrip == NULL) + return; + + qsamplerChannel *pChannel = pChannelStrip->channel(); if (pChannel == NULL) return; @@ -707,23 +858,18 @@ tr("About to remove channel:\n\n" "%1\n\n" "Are you sure?") - .arg(pChannel->caption()), + .arg(pChannelStrip->caption()), tr("OK"), tr("Cancel")) > 0) return; } // Remove the existing sampler channel. - if (::lscp_remove_channel(m_pClient, pChannel->channelID()) != LSCP_OK) { - appendMessagesClient("lscp_remove_channel"); - appendMessagesError(tr("Could not remove channel.\n\nSorry.")); + if (!pChannel->removeChannel()) return; - } - // Log this happening. - appendMessages(tr("Channel %1 removed.").arg(pChannel->channelID())); - // Just delete the channel strip. - delete pChannel; + delete pChannelStrip; + // Do we auto-arrange? if (m_pOptions && m_pOptions->bAutoArrange) channelsArrange(); @@ -740,12 +886,12 @@ if (m_pClient == NULL) return; - qsamplerChannelStrip *pChannel = activeChannel(); - if (pChannel == NULL) + qsamplerChannelStrip *pChannelStrip = activeChannelStrip(); + if (pChannelStrip == NULL) return; // Just invoque the channel strip procedure. - pChannel->channelSetup(); + pChannelStrip->channelSetup(); } @@ -755,22 +901,31 @@ if (m_pClient == NULL) return; - qsamplerChannelStrip *pChannel = activeChannel(); - if (pChannel == NULL) + qsamplerChannelStrip *pChannelStrip = activeChannelStrip(); + if (pChannelStrip == NULL) return; - // Remove the existing sampler channel. - if (::lscp_reset_channel(m_pClient, pChannel->channelID()) != LSCP_OK) { - appendMessagesClient("lscp_reset_channel"); - appendMessagesError(tr("Could not reset channel.\n\nSorry.")); - return; - } + // Just invoque the channel strip procedure. + pChannelStrip->channelReset(); +} - // Log this. - appendMessages(tr("Channel %1 reset.").arg(pChannel->channelID())); - // Refresh channel strip info. - pChannel->updateChannelInfo(); +// Reset all sampler channels. +void qsamplerMainForm::editResetAllChannels (void) +{ + if (m_pClient == NULL) + return; + + // Invoque the channel strip procedure, + // for all channels out there... + m_pWorkspace->setUpdatesEnabled(false); + QWidgetList wlist = m_pWorkspace->windowList(); + for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { + qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); + if (pChannelStrip) + pChannelStrip->channelReset(); + } + m_pWorkspace->setUpdatesEnabled(true); } @@ -831,9 +986,9 @@ qsamplerOptionsForm *pOptionsForm = new qsamplerOptionsForm(this); if (pOptionsForm) { // Check out some initial nullities(tm)... - qsamplerChannelStrip *pChannel = activeChannel(); - if (m_pOptions->sDisplayFont.isEmpty() && pChannel) - m_pOptions->sDisplayFont = pChannel->displayFont().toString(); + qsamplerChannelStrip *pChannelStrip = activeChannelStrip(); + if (m_pOptions->sDisplayFont.isEmpty() && pChannelStrip) + m_pOptions->sDisplayFont = pChannelStrip->displayFont().toString(); if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages) m_pOptions->sMessagesFont = m_pMessages->messagesFont().toString(); // To track down deferred or immediate changes. @@ -843,12 +998,14 @@ bool bOldServerStart = m_pOptions->bServerStart; QString sOldServerCmdLine = m_pOptions->sServerCmdLine; QString sOldDisplayFont = m_pOptions->sDisplayFont; + bool bOldDisplayEffect = m_pOptions->bDisplayEffect; int iOldMaxVolume = m_pOptions->iMaxVolume; QString sOldMessagesFont = m_pOptions->sMessagesFont; bool bOldStdoutCapture = m_pOptions->bStdoutCapture; int bOldMessagesLimit = m_pOptions->bMessagesLimit; int iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines; bool bOldCompletePath = m_pOptions->bCompletePath; + bool bOldInstrumentNames = m_pOptions->bInstrumentNames; int iOldMaxRecentFiles = m_pOptions->iMaxRecentFiles; // Load the current setup settings. pOptionsForm->setup(m_pOptions); @@ -867,6 +1024,12 @@ (!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(); if (sOldDisplayFont != m_pOptions->sDisplayFont) updateDisplayFont(); if (iOldMaxVolume != m_pOptions->iMaxVolume) @@ -909,19 +1072,19 @@ m_pWorkspace->setUpdatesEnabled(false); int y = 0; for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { - qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel); - /* if (pChannel->testWState(WState_Maximized | WState_Minimized)) { + qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); + /* if (pChannelStrip->testWState(WState_Maximized | WState_Minimized)) { // Prevent flicker... - pChannel->hide(); - pChannel->showNormal(); + pChannelStrip->hide(); + pChannelStrip->showNormal(); } */ - pChannel->adjustSize(); + pChannelStrip->adjustSize(); int iWidth = m_pWorkspace->width(); - if (iWidth < pChannel->width()) - iWidth = pChannel->width(); - // int iHeight = pChannel->height() + pChannel->parentWidget()->baseSize().height(); - int iHeight = pChannel->parentWidget()->frameGeometry().height(); - pChannel->parentWidget()->setGeometry(0, y, iWidth, iHeight); + if (iWidth < pChannelStrip->width()) + iWidth = pChannelStrip->width(); + // int iHeight = pChannelStrip->height() + pChannelStrip->parentWidget()->baseSize().height(); + int iHeight = pChannelStrip->parentWidget()->frameGeometry().height(); + pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight); y += iHeight; } m_pWorkspace->setUpdatesEnabled(true); @@ -969,6 +1132,16 @@ sText += tr("Debugging option enabled."); sText += "
"; #endif +#ifndef CONFIG_LIBGIG + sText += ""; + 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(); @@ -996,24 +1169,26 @@ void qsamplerMainForm::stabilizeForm (void) { // Update the main application caption... - QString sSessioName = sessionName(m_sFilename); + QString sSessionName = sessionName(m_sFilename); if (m_iDirtyCount > 0) - sSessioName += '*'; - setCaption(tr(QSAMPLER_TITLE " - [%1]").arg(sSessioName)); + sSessionName += '*'; + setCaption(tr(QSAMPLER_TITLE " - [%1]").arg(sSessionName)); // Update the main menu state... - qsamplerChannelStrip *pChannel = activeChannel(); + qsamplerChannelStrip *pChannelStrip = activeChannelStrip(); bool bHasClient = (m_pOptions != NULL && m_pClient != NULL); - bool bHasChannel = (bHasClient && pChannel != NULL); + bool bHasChannel = (bHasClient && pChannelStrip != NULL); fileNewAction->setEnabled(bHasClient); fileOpenAction->setEnabled(bHasClient); fileSaveAction->setEnabled(bHasClient && m_iDirtyCount > 0); fileSaveAsAction->setEnabled(bHasClient); + fileResetAction->setEnabled(bHasClient); fileRestartAction->setEnabled(bHasClient || m_pServer == NULL); editAddChannelAction->setEnabled(bHasClient); editRemoveChannelAction->setEnabled(bHasChannel); editSetupChannelAction->setEnabled(bHasChannel); editResetChannelAction->setEnabled(bHasChannel); + editResetAllChannelsAction->setEnabled(bHasChannel); channelsArrangeAction->setEnabled(bHasChannel); viewMessagesAction->setOn(m_pMessages && m_pMessages->isVisible()); @@ -1027,7 +1202,7 @@ } // Channel status... if (bHasChannel) - m_status[QSAMPLER_STATUS_CHANNEL]->setText(pChannel->caption()); + m_status[QSAMPLER_STATUS_CHANNEL]->setText(pChannelStrip->caption()); else m_status[QSAMPLER_STATUS_CHANNEL]->clear(); // Session status... @@ -1046,8 +1221,12 @@ // Channel change receiver slot. -void qsamplerMainForm::channelChanged( qsamplerChannelStrip * ) +void qsamplerMainForm::channelStripChanged( qsamplerChannelStrip *pChannelStrip ) { + // Add this strip to the changed list... + if (m_changedStrips.containsRef(pChannelStrip) == 0) + m_changedStrips.append(pChannelStrip); + // Just mark the dirty form. m_iDirtyCount++; // and update the form status... @@ -1055,6 +1234,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 ) { @@ -1099,6 +1304,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) { @@ -1120,8 +1343,31 @@ m_pWorkspace->setUpdatesEnabled(false); for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { - qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel); - pChannel->setDisplayFont(font); + qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); + if (pChannelStrip) + pChannelStrip->setDisplayFont(font); + } + m_pWorkspace->setUpdatesEnabled(true); +} + + +// Update channel strips background effect. +void qsamplerMainForm::updateDisplayEffect (void) +{ + QPixmap pm; + if (m_pOptions->bDisplayEffect) + pm = QPixmap::fromMimeSource("displaybg1.png"); + + // 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->setDisplayBackground(pm); } m_pWorkspace->setUpdatesEnabled(true); } @@ -1140,8 +1386,9 @@ m_pWorkspace->setUpdatesEnabled(false); for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { - qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel); - pChannel->setMaxVolume(m_pOptions->iMaxVolume); + qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); + if (pChannelStrip) + pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume); } m_pWorkspace->setUpdatesEnabled(true); } @@ -1240,68 +1487,103 @@ // qsamplerMainForm -- MDI channel strip management. // The channel strip creation executive. -void qsamplerMainForm::createChannel ( int iChannelID, bool bPrompt ) +qsamplerChannelStrip *qsamplerMainForm::createChannelStrip ( qsamplerChannel *pChannel ) { - if (m_pClient == NULL) - return; + if (m_pClient == NULL || pChannel == NULL) + return NULL; // Prepare for auto-arrange? - qsamplerChannelStrip *pChannel = NULL; + qsamplerChannelStrip *pChannelStrip = NULL; int y = 0; if (m_pOptions && m_pOptions->bAutoArrange) { QWidgetList wlist = m_pWorkspace->windowList(); for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { - pChannel = (qsamplerChannelStrip *) wlist.at(iChannel); - // y += pChannel->height() + pChannel->parentWidget()->baseSize().height(); - y += pChannel->parentWidget()->frameGeometry().height(); + pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); + if (pChannelStrip) { + // y += pChannelStrip->height() + pChannelStrip->parentWidget()->baseSize().height(); + y += pChannelStrip->parentWidget()->frameGeometry().height(); + } } } // Add a new channel itema... WFlags wflags = Qt::WStyle_Customize | Qt::WStyle_Tool | Qt::WStyle_Title | Qt::WStyle_NoBorder; - pChannel = new qsamplerChannelStrip(m_pWorkspace, 0, wflags); - pChannel->setMaxVolume(m_pOptions->iMaxVolume); - pChannel->setup(this, iChannelID); - // We'll need a display font. - QFont font; - if (m_pOptions && font.fromString(m_pOptions->sDisplayFont)) - pChannel->setDisplayFont(font); - // Track channel setup changes. - QObject::connect(pChannel, SIGNAL(channelChanged(qsamplerChannelStrip *)), this, SLOT(channelChanged(qsamplerChannelStrip *))); - // Before we show it up, may be we'll - // better ask for some initial values? - if (bPrompt) - pChannel->channelSetup(); + pChannelStrip = new qsamplerChannelStrip(m_pWorkspace, 0, wflags); + if (pChannelStrip == NULL) + return NULL; + + // Actual channel strip setup... + pChannelStrip->setup(pChannel); + QObject::connect(pChannelStrip, SIGNAL(channelChanged(qsamplerChannelStrip *)), this, SLOT(channelStripChanged(qsamplerChannelStrip *))); + // Set some initial aesthetic options... + if (m_pOptions) { + // Background display effect... + pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect); + // We'll need a display font. + QFont font; + if (font.fromString(m_pOptions->sDisplayFont)) + pChannelStrip->setDisplayFont(font); + // Maximum allowed volume setting. + pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume); + } + // Now we show up us to the world. - pChannel->show(); + pChannelStrip->show(); // Only then, we'll auto-arrange... if (m_pOptions && m_pOptions->bAutoArrange) { int iWidth = m_pWorkspace->width(); // int iHeight = pChannel->height() + pChannel->parentWidget()->baseSize().height(); - int iHeight = pChannel->parentWidget()->frameGeometry().height(); - pChannel->parentWidget()->setGeometry(0, y, iWidth, iHeight); + int iHeight = pChannelStrip->parentWidget()->frameGeometry().height(); + pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight); } + + // This is pretty new, so we'll watch for it closely. + channelStripChanged(pChannelStrip); + + // Return our successful reference... + return pChannelStrip; } // Retrieve the active channel strip. -qsamplerChannelStrip *qsamplerMainForm::activeChannel (void) +qsamplerChannelStrip *qsamplerMainForm::activeChannelStrip (void) { return (qsamplerChannelStrip *) m_pWorkspace->activeWindow(); } // Retrieve a channel strip by index. -qsamplerChannelStrip *qsamplerMainForm::channelAt ( int iChannel ) +qsamplerChannelStrip *qsamplerMainForm::channelStripAt ( int iChannel ) { 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) { @@ -1313,10 +1595,12 @@ if (!wlist.isEmpty()) { channelsMenu->insertSeparator(); for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { - qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel); - int iItemID = channelsMenu->insertItem(pChannel->caption(), this, SLOT(channelsMenuActivated(int))); - channelsMenu->setItemParameter(iItemID, iChannel); - channelsMenu->setItemChecked(iItemID, activeChannel() == pChannel); + qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); + if (pChannelStrip) { + int iItemID = channelsMenu->insertItem(pChannelStrip->caption(), this, SLOT(channelsMenuActivated(int))); + channelsMenu->setItemParameter(iItemID, iChannel); + channelsMenu->setItemChecked(iItemID, activeChannelStrip() == pChannelStrip); + } } } } @@ -1325,10 +1609,10 @@ // Windows menu activation slot void qsamplerMainForm::channelsMenuActivated ( int iChannel ) { - qsamplerChannelStrip *pChannel = channelAt(iChannel); - if (pChannel) - pChannel->showNormal(); - pChannel->setFocus(); + qsamplerChannelStrip *pChannelStrip = channelStripAt(iChannel); + if (pChannelStrip) + pChannelStrip->showNormal(); + pChannelStrip->setFocus(); } @@ -1368,15 +1652,24 @@ } // Refresh each channel usage, on each period... - if (m_pClient && m_pOptions->bAutoRefresh && m_pWorkspace->isUpdatesEnabled()) { + if (m_pClient && (m_changedStrips.count() > 0 || m_pOptions->bAutoRefresh)) { m_iTimerSlot += QSAMPLER_TIMER_MSECS; - if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime) { + if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime && m_pWorkspace->isUpdatesEnabled()) { m_iTimerSlot = 0; + // Update the channel information for each pending strip... + for (qsamplerChannelStrip *pChannelStrip = m_changedStrips.first(); + pChannelStrip; + pChannelStrip = m_changedStrips.next()) { + // If successfull, remove from pending list... + if (pChannelStrip->updateChannelInfo()) + m_changedStrips.remove(pChannelStrip); + } + // Update the channel stream usage for each strip... QWidgetList wlist = m_pWorkspace->windowList(); for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { - qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel); - if (pChannel->isVisible()) - pChannel->updateChannelUsage(); + qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); + if (pChannelStrip && pChannelStrip->isVisible()) + pChannelStrip->updateChannelUsage(); } } } @@ -1462,12 +1755,16 @@ // And try to stop server. if (m_pServer) { appendMessages(tr("Server is stopping...")); - if (m_pServer->isRunning()) { + if (m_pServer->isRunning()) m_pServer->tryTerminate(); - return; - } } + // Give it some time to terminate gracefully and stabilize... + QTime t; + t.start(); + while (t.elapsed() < QSAMPLER_TIMER_MSECS) + QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); + // Do final processing anyway. processServerExit(); } @@ -1509,22 +1806,17 @@ //------------------------------------------------------------------------- // qsamplerMainForm -- Client stuff. - // The LSCP client callback procedure. -lscp_status_t qsampler_client_callback ( lscp_client_t *pClient, const char *pchBuffer, int cchBuffer, void *pvData ) +lscp_status_t qsampler_client_callback ( lscp_client_t */*pClient*/, lscp_event_t event, const char *pchData, int cchData, void *pvData ) { qsamplerMainForm *pMainForm = (qsamplerMainForm *) pvData; if (pMainForm == NULL) return LSCP_FAILED; - char *pszBuffer = (char *) malloc(cchBuffer + 1); - if (pszBuffer == NULL) - return LSCP_FAILED; - - memcpy(pszBuffer, pchBuffer, cchBuffer); - pszBuffer[cchBuffer] = (char) 0; - pMainForm->appendMessagesColor(pszBuffer, "#996699"); - free(pszBuffer); + // ATTN: DO NOT EVER call any GUI code here, + // as this is run under some other thread context. + // A custom event must be posted here... + QApplication::postEvent(pMainForm, new qsamplerCustomEvent(event, pchData, cchData)); return LSCP_OK; }