--- qsampler/trunk/src/qsamplerMainForm.ui.h 2005/01/18 13:53:04 344 +++ qsampler/trunk/src/qsamplerMainForm.ui.h 2005/08/19 17:10:16 751 @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -40,6 +41,8 @@ #include "qsamplerMessages.h" #include "qsamplerChannelStrip.h" + +#include "qsamplerDeviceForm.h" #include "qsamplerOptionsForm.h" #include "config.h" @@ -48,6 +51,10 @@ #include #endif +#ifdef CONFIG_LIBGIG +#include +#endif + // Timer constant stuff. #define QSAMPLER_TIMER_MSECS 200 @@ -104,12 +111,12 @@ m_pOptions = NULL; // All child forms are to be created later, not earlier than setup. - m_pMessages = NULL; + m_pMessages = NULL; + m_pDeviceForm = NULL; // We'll start clean. - m_iUntitled = 0; - m_iDirtyCount = 0; - m_iChangeCount = 0; + m_iUntitled = 0; + m_iDirtyCount = 0; m_pServer = NULL; m_pClient = NULL; @@ -138,23 +145,23 @@ pLabel = new QLabel(tr("Connected"), this); pLabel->setAlignment(Qt::AlignLeft); pLabel->setMinimumSize(pLabel->sizeHint()); - m_status[QSAMPLER_STATUS_CLIENT] = pLabel; + m_statusItem[QSAMPLER_STATUS_CLIENT] = pLabel; statusBar()->addWidget(pLabel); // Server address. pLabel = new QLabel(this); pLabel->setAlignment(Qt::AlignLeft); - m_status[QSAMPLER_STATUS_SERVER] = pLabel; + m_statusItem[QSAMPLER_STATUS_SERVER] = pLabel; statusBar()->addWidget(pLabel, 1); // Channel title. pLabel = new QLabel(this); pLabel->setAlignment(Qt::AlignLeft); - m_status[QSAMPLER_STATUS_CHANNEL] = pLabel; + m_statusItem[QSAMPLER_STATUS_CHANNEL] = pLabel; statusBar()->addWidget(pLabel, 2); // Session modification status. pLabel = new QLabel(tr("MOD"), this); pLabel->setAlignment(Qt::AlignHCenter); pLabel->setMinimumSize(pLabel->sizeHint()); - m_status[QSAMPLER_STATUS_SESSION] = pLabel; + m_statusItem[QSAMPLER_STATUS_SESSION] = pLabel; statusBar()->addWidget(pLabel); // Create the recent files sub-menu. @@ -173,29 +180,32 @@ { // Do final processing anyway. processServerExit(); - - // Delete recentfiles menu. - if (m_pRecentFilesMenu) - delete m_pRecentFilesMenu; - // Delete status item labels one by one. - if (m_status[QSAMPLER_STATUS_CLIENT]) - delete m_status[QSAMPLER_STATUS_CLIENT]; - if (m_status[QSAMPLER_STATUS_SERVER]) - delete m_status[QSAMPLER_STATUS_SERVER]; - if (m_status[QSAMPLER_STATUS_CHANNEL]) - delete m_status[QSAMPLER_STATUS_CHANNEL]; - if (m_status[QSAMPLER_STATUS_SESSION]) - delete m_status[QSAMPLER_STATUS_SESSION]; + +#if defined(WIN32) + WSACleanup(); +#endif // Finally drop any widgets around... + if (m_pDeviceForm) + delete m_pDeviceForm; if (m_pMessages) delete m_pMessages; if (m_pWorkspace) delete m_pWorkspace; -#if defined(WIN32) - WSACleanup(); -#endif + // Delete status item labels one by one. + if (m_statusItem[QSAMPLER_STATUS_CLIENT]) + delete m_statusItem[QSAMPLER_STATUS_CLIENT]; + if (m_statusItem[QSAMPLER_STATUS_SERVER]) + delete m_statusItem[QSAMPLER_STATUS_SERVER]; + if (m_statusItem[QSAMPLER_STATUS_CHANNEL]) + delete m_statusItem[QSAMPLER_STATUS_CHANNEL]; + if (m_statusItem[QSAMPLER_STATUS_SESSION]) + delete m_statusItem[QSAMPLER_STATUS_SESSION]; + + // Delete recentfiles menu. + if (m_pRecentFilesMenu) + delete m_pRecentFilesMenu; } @@ -205,8 +215,14 @@ // We got options? m_pOptions = pOptions; + // What style do we create these forms? + WFlags wflags = Qt::WType_TopLevel; + if (m_pOptions->bKeepOnTop) + wflags |= Qt::WStyle_Tool; // Some child forms are to be created right now. m_pMessages = new qsamplerMessages(this); + m_pDeviceForm = new qsamplerDeviceForm(this, 0, wflags); + m_pDeviceForm->setMainForm(this); // An important life immutable! // Set message defaults... updateMessagesFont(); updateMessagesLimit(); @@ -235,8 +251,9 @@ QTextIStream istr(&sDockables); istr >> *this; } - // Try to restore old window positioning. + // Try to restore old window positioning and initial visibility. m_pOptions->loadWidgetGeometry(this); + m_pOptions->loadWidgetGeometry(m_pDeviceForm); // Final startup stabilization... updateRecentFilesMenu(); @@ -274,8 +291,12 @@ QTextOStream ostr(&sDockables); ostr << *this; m_pOptions->settings().writeEntry("/Layout/DockWindows", sDockables); - // And the main windows state. - m_pOptions->saveWidgetGeometry(this); + // And the children, and the main windows state,. + m_pOptions->saveWidgetGeometry(m_pDeviceForm); + m_pOptions->saveWidgetGeometry(this); + // Close popup widgets. + if (m_pDeviceForm) + m_pDeviceForm->close(); // Stop client and/or server, gracefully. stopServer(); } @@ -294,28 +315,69 @@ } -// 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 = 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); + } } @@ -325,9 +387,16 @@ // 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"); + if (pEvent->event() == LSCP_EVENT_CHANNEL_INFO) { + int iChannelID = pEvent->data().toInt(); + qsamplerChannelStrip *pChannelStrip = channelStrip(iChannelID); + if (pChannelStrip) + channelStripChanged(pChannelStrip); + } else { + appendMessagesColor(tr("Notify event: %1 data: %2") + .arg(::lscp_event_to_text(pEvent->event())) + .arg(pEvent->data()), "#996699"); + } } } @@ -336,7 +405,7 @@ void qsamplerMainForm::contextMenuEvent( QContextMenuEvent *pEvent ) { stabilizeForm(); - + editMenu->exec(pEvent->globalPos()); } @@ -380,6 +449,9 @@ if (!closeSession(true)) return false; + // Give us what the server has, right now... + updateSession(); + // Ok increment untitled count. m_iUntitled++; @@ -547,37 +619,24 @@ // Ok. we've read it. file.close(); - // Have we any errors? - if (iErrors > 0) - appendMessagesError(tr("Some setttings could not be loaded\nfrom \"%1\" session file.\n\nSorry.").arg(sFilename)); + // Now we'll try to create (update) the whole GUI session. + updateSession(); - // 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); + // Have we any errors? + if (iErrors > 0) + appendMessagesError(tr("Session loaded with errors\nfrom \"%1\".\n\nSorry.").arg(sFilename)); // Save as default session directory. if (m_pOptions) m_pOptions->sSessionDir = QFileInfo(sFilename).dirPath(true); - // We're not dirty anymore. - m_iDirtyCount = 0; + // We're not dirty anymore, if loaded without errors, + m_iDirtyCount = iErrors; // Stabilize form... m_sFilename = sFilename; updateRecentFiles(sFilename); appendMessages(tr("Open session: \"%1\".").arg(sessionName(m_sFilename))); - + // Make that an overall update. - m_iChangeCount++; stabilizeForm(); return true; } @@ -594,7 +653,7 @@ } // Write the file. - int iErrors = 0; + int iErrors = 0; QTextStream ts(&file); ts << "# " << QSAMPLER_TITLE " - " << tr(QSAMPLER_SUBTITLE) << endl; ts << "# " << tr("Version") @@ -605,31 +664,134 @@ ts << "# " << tr("File") << ": " << QFileInfo(sFilename).fileName() << endl; ts << "# " << tr("Date") - << ": " << QDate::currentDate().toString("MMMM dd yyyy") + << ": " << QDate::currentDate().toString("MMM dd yyyy") << " " << QTime::currentTime().toString("hh:mm:ss") << endl; ts << "#" << endl; ts << endl; + // It is assumed that this new kind of device+session file + // will be loaded from a complete + int *piDeviceIDs; + int iDevice; + ts << "RESET" << endl; + // Audio device mapping. + QMap audioDeviceMap; + piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Audio); + for (iDevice = 0; piDeviceIDs && piDeviceIDs[iDevice] >= 0; iDevice++) { + ts << endl; + qsamplerDevice device(this, qsamplerDevice::Audio, piDeviceIDs[iDevice]); + // Audio device specification... + ts << "# " << device.deviceTypeName() << " " << device.driverName() + << " " << tr("Device") << " " << iDevice << endl; + ts << "CREATE AUDIO_OUTPUT_DEVICE " << device.driverName(); + qsamplerDeviceParamMap::ConstIterator deviceParam; + for (deviceParam = device.params().begin(); + deviceParam != device.params().end(); + ++deviceParam) { + const qsamplerDeviceParam& param = deviceParam.data(); + if (param.value.isEmpty()) ts << "# "; + ts << " " << deviceParam.key() << "='" << param.value << "'"; + } + ts << endl; + // Audio channel parameters... + int iPort = 0; + for (qsamplerDevicePort *pPort = device.ports().first(); + pPort; + pPort = device.ports().next(), ++iPort) { + qsamplerDeviceParamMap::ConstIterator portParam; + for (portParam = pPort->params().begin(); + portParam != pPort->params().end(); + ++portParam) { + const qsamplerDeviceParam& param = portParam.data(); + if (param.fix || param.value.isEmpty()) ts << "# "; + ts << "SET AUDIO_OUTPUT_CHANNEL_PARAMETER " << iDevice + << " " << iPort << " " << portParam.key() + << "='" << param.value << "'" << endl; + } + } + // Audio device index/id mapping. + audioDeviceMap[device.deviceID()] = iDevice; + // Try to keep it snappy :) + QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); + } + // MIDI device mapping. + QMap midiDeviceMap; + piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Midi); + for (iDevice = 0; piDeviceIDs && piDeviceIDs[iDevice] >= 0; iDevice++) { + ts << endl; + qsamplerDevice device(this, qsamplerDevice::Midi, piDeviceIDs[iDevice]); + // MIDI device specification... + ts << "# " << device.deviceTypeName() << " " << device.driverName() + << " " << tr("Device") << " " << iDevice << endl; + ts << "CREATE MIDI_INPUT_DEVICE " << device.driverName(); + qsamplerDeviceParamMap::ConstIterator deviceParam; + for (deviceParam = device.params().begin(); + deviceParam != device.params().end(); + ++deviceParam) { + const qsamplerDeviceParam& param = deviceParam.data(); + if (param.value.isEmpty()) ts << "# "; + ts << " " << deviceParam.key() << "='" << param.value << "'"; + } + ts << endl; + // MIDI port parameters... + int iPort = 0; + for (qsamplerDevicePort *pPort = device.ports().first(); + pPort; + pPort = device.ports().next(), ++iPort) { + qsamplerDeviceParamMap::ConstIterator portParam; + for (portParam = pPort->params().begin(); + portParam != pPort->params().end(); + ++portParam) { + const qsamplerDeviceParam& param = portParam.data(); + if (param.fix || param.value.isEmpty()) ts << "# "; + ts << "SET MIDI_INPUT_PORT_PARAMETER " << iDevice + << " " << iPort << " " << portParam.key() + << "='" << param.value << "'" << endl; + } + } + // MIDI device index/id mapping. + midiDeviceMap[device.deviceID()] = iDevice; + // Try to keep it snappy :) + QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); + } + ts << endl; + // Sampler channel mapping. QWidgetList wlist = m_pWorkspace->windowList(); for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); if (pChannelStrip) { qsamplerChannel *pChannel = pChannelStrip->channel(); if (pChannel) { - int iChannelID = pChannel->channelID(); - ts << "# " << pChannelStrip->caption() << endl; + ts << "# " << tr("Channel") << " " << iChannel << 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 << " "; + if (audioDeviceMap.isEmpty()) { + ts << "SET CHANNEL AUDIO_OUTPUT_TYPE " << iChannel + << " " << pChannel->audioDriver() << endl; + } else { + ts << "SET CHANNEL AUDIO_OUTPUT_DEVICE " << iChannel + << " " << audioDeviceMap[pChannel->audioDevice()] << endl; + } + if (midiDeviceMap.isEmpty()) { + ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannel + << " " << pChannel->midiDriver() << endl; + } else { + ts << "SET CHANNEL MIDI_INPUT_DEVICE " << iChannel + << " " << midiDeviceMap[pChannel->midiDevice()] << 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() << " " << iChannelID << endl; - ts << "LOAD INSTRUMENT NON_MODAL '" << pChannel->instrumentFile() << "' " << pChannel->instrumentNr() << " " << iChannelID << endl; - ts << "SET CHANNEL VOLUME " << iChannelID << " " << pChannel->volume() << 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; + if (pChannel->channelMute()) + ts << "SET CHANNEL MUTE " << iChannel << " 1" << endl; + if (pChannel->channelSolo()) + ts << "SET CHANNEL SOLO " << iChannel << " 1" << endl; ts << endl; } } @@ -658,6 +820,16 @@ } +// Session change receiver slot. +void qsamplerMainForm::sessionDirty (void) +{ + // Just mark the dirty form. + m_iDirtyCount++; + // and update the form status... + stabilizeForm(); +} + + //------------------------------------------------------------------------- // qsamplerMainForm -- File Action slots. @@ -715,7 +887,7 @@ 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" + "temporary MIDI and Audio disruption.\n\n" "Do you want to reset the sampler engine now?"), tr("Reset"), tr("Cancel")) > 0) return; @@ -729,6 +901,9 @@ // Log this. appendMessages(tr("Sampler reset.")); + + // Make it a new session... + newSession(); } @@ -737,9 +912,9 @@ { if (m_pOptions == NULL) return; - + bool bRestart = true; - + // Ask user whether he/she want's a complete restart... // (if we're currently up and running) if (bRestart && m_pClient) { @@ -747,7 +922,7 @@ tr("New settings will be effective after\n" "restarting the client/server connection.\n\n" "Please note that this operation may cause\n" - "temporary MIDI and Audio disruption\n\n" + "temporary MIDI and Audio disruption.\n\n" "Do you want to restart the connection now?"), tr("Restart"), tr("Cancel")) == 0); } @@ -790,7 +965,7 @@ delete pChannel; return; } - + // And give it to the strip (will own the channel instance, if successful). if (!createChannelStrip(pChannel)) { delete pChannel; @@ -799,7 +974,6 @@ // Make that an overall update. m_iDirtyCount++; - m_iChangeCount++; stabilizeForm(); } @@ -813,7 +987,7 @@ qsamplerChannelStrip *pChannelStrip = activeChannelStrip(); if (pChannelStrip == NULL) return; - + qsamplerChannel *pChannel = pChannelStrip->channel(); if (pChannel == NULL) return; @@ -835,7 +1009,7 @@ // Just delete the channel strip. delete pChannelStrip; - + // Do we auto-arrange? if (m_pOptions && m_pOptions->bAutoArrange) channelsArrange(); @@ -871,15 +1045,27 @@ if (pChannelStrip == NULL) return; - qsamplerChannel *pChannel = pChannelStrip->channel(); - if (pChannel == NULL) - return; + // Just invoque the channel strip procedure. + pChannelStrip->channelReset(); +} - // Reset the existing sampler channel. - pChannel->resetChannel(); - // And force a deferred update. - m_iChangeCount++; +// 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); } @@ -931,6 +1117,26 @@ } +// Show/hide the device configurator form. +void qsamplerMainForm::viewDevices (void) +{ + if (m_pOptions == NULL) + return; + + if (m_pDeviceForm) { + m_pOptions->saveWidgetGeometry(m_pDeviceForm); + m_pDeviceForm->setClient(m_pClient); + if (m_pDeviceForm->isVisible()) { + m_pDeviceForm->hide(); + } else { + m_pDeviceForm->show(); + m_pDeviceForm->raise(); + m_pDeviceForm->setActiveWindow(); + } + } +} + + // Show options dialog. void qsamplerMainForm::viewOptions (void) { @@ -955,10 +1161,12 @@ bool bOldDisplayEffect = m_pOptions->bDisplayEffect; int iOldMaxVolume = m_pOptions->iMaxVolume; QString sOldMessagesFont = m_pOptions->sMessagesFont; + bool bOldKeepOnTop = m_pOptions->bKeepOnTop; 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); @@ -966,7 +1174,9 @@ if (pOptionsForm->exec()) { // Warn if something will be only effective on next run. if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) || - (!bOldStdoutCapture && m_pOptions->bStdoutCapture)) { + (!bOldStdoutCapture && m_pOptions->bStdoutCapture) || + ( bOldKeepOnTop && !m_pOptions->bKeepOnTop) || + (!bOldKeepOnTop && m_pOptions->bKeepOnTop)) { QMessageBox::information(this, tr("Information"), tr("Some settings may be only effective\n" "next time you start this program."), tr("OK")); @@ -977,6 +1187,9 @@ (!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(); @@ -1038,7 +1251,7 @@ y += iHeight; } m_pWorkspace->setUpdatesEnabled(true); - + stabilizeForm(); } @@ -1087,11 +1300,27 @@ sText += tr("GIG (libgig) file support disabled."); sText += "
"; #endif +#ifndef CONFIG_INSTRUMENT_NAME + sText += ""; + sText += tr("LSCP (liblscp) instrument_name support disabled."); + sText += "
"; +#endif +#ifndef CONFIG_MUTE_SOLO + sText += ""; + sText += tr("Sampler channel Mute/Solo support disabled."); + sText += "
"; +#endif sText += "
\n"; sText += tr("Using") + ": "; sText += ::lscp_client_package(); sText += " "; sText += ::lscp_client_version(); +#ifdef CONFIG_LIBGIG + sText += ", "; + sText += gig::libraryName().c_str(); + sText += " "; + sText += gig::libraryVersion().c_str(); +#endif sText += "
\n"; sText += "
\n"; sText += tr("Website") + ": " QSAMPLER_WEBSITE "
\n"; @@ -1114,10 +1343,10 @@ 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 *pChannelStrip = activeChannelStrip(); @@ -1133,27 +1362,30 @@ editRemoveChannelAction->setEnabled(bHasChannel); editSetupChannelAction->setEnabled(bHasChannel); editResetChannelAction->setEnabled(bHasChannel); - channelsArrangeAction->setEnabled(bHasChannel); + editResetAllChannelsAction->setEnabled(bHasChannel); viewMessagesAction->setOn(m_pMessages && m_pMessages->isVisible()); + viewDevicesAction->setOn(m_pDeviceForm && m_pDeviceForm->isVisible()); + viewDevicesAction->setEnabled(bHasClient); + channelsArrangeAction->setEnabled(bHasChannel); // Client/Server status... if (bHasClient) { - m_status[QSAMPLER_STATUS_CLIENT]->setText(tr("Connected")); - m_status[QSAMPLER_STATUS_SERVER]->setText(m_pOptions->sServerHost + ":" + QString::number(m_pOptions->iServerPort)); + m_statusItem[QSAMPLER_STATUS_CLIENT]->setText(tr("Connected")); + m_statusItem[QSAMPLER_STATUS_SERVER]->setText(m_pOptions->sServerHost + ":" + QString::number(m_pOptions->iServerPort)); } else { - m_status[QSAMPLER_STATUS_CLIENT]->clear(); - m_status[QSAMPLER_STATUS_SERVER]->clear(); + m_statusItem[QSAMPLER_STATUS_CLIENT]->clear(); + m_statusItem[QSAMPLER_STATUS_SERVER]->clear(); } // Channel status... if (bHasChannel) - m_status[QSAMPLER_STATUS_CHANNEL]->setText(pChannelStrip->caption()); + m_statusItem[QSAMPLER_STATUS_CHANNEL]->setText(pChannelStrip->caption()); else - m_status[QSAMPLER_STATUS_CHANNEL]->clear(); + m_statusItem[QSAMPLER_STATUS_CHANNEL]->clear(); // Session status... if (m_iDirtyCount > 0) - m_status[QSAMPLER_STATUS_SESSION]->setText(tr("MOD")); + m_statusItem[QSAMPLER_STATUS_SESSION]->setText(tr("MOD")); else - m_status[QSAMPLER_STATUS_SESSION]->clear(); + m_statusItem[QSAMPLER_STATUS_SESSION]->clear(); // Recent files menu. m_pRecentFilesMenu->setEnabled(bHasClient && m_pOptions->recentFiles.count() > 0); @@ -1165,10 +1397,14 @@ // Channel change receiver slot. -void qsamplerMainForm::channelStripChanged( qsamplerChannelStrip * ) +void qsamplerMainForm::channelStripChanged( qsamplerChannelStrip *pChannelStrip ) { - // Flag that we're update those channel strips. - m_iChangeCount++; + // Add this strip to the changed list... + if (m_changedStrips.containsRef(pChannelStrip) == 0) { + m_changedStrips.append(pChannelStrip); + pChannelStrip->resetErrorCount(); + } + // Just mark the dirty form. m_iDirtyCount++; // and update the form status... @@ -1176,6 +1412,36 @@ } +// 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); + + // Remember to refresh devices + if (m_pDeviceForm) + m_pDeviceForm->refreshDevices(); +} + + // Update the recent files list and menu. void qsamplerMainForm::updateRecentFiles ( const QString& sFilename ) { @@ -1220,6 +1486,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) { @@ -1365,7 +1649,7 @@ if (m_pOptions->bMessagesLimit) m_pMessages->setMessagesLimit(m_pOptions->iMessagesLimitLines); else - m_pMessages->setMessagesLimit(0); + m_pMessages->setMessagesLimit(-1); } } @@ -1397,8 +1681,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(); + } } } @@ -1407,7 +1693,7 @@ 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 *))); @@ -1432,7 +1718,10 @@ 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; } @@ -1450,12 +1739,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) { @@ -1522,24 +1832,34 @@ } } } - - // Refresh each channel usage, on each period... - if (m_pClient && (m_iChangeCount > 0 || m_pOptions->bAutoRefresh)) { - m_iTimerSlot += QSAMPLER_TIMER_MSECS; - if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime && m_pWorkspace->isUpdatesEnabled()) { - m_iTimerSlot = 0; - m_iChangeCount = 0; - QWidgetList wlist = m_pWorkspace->windowList(); - for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { - qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); - if (pChannelStrip && pChannelStrip->isVisible()) { - // If we can't make it clean, try next time. - if (!pChannelStrip->updateChannelUsage()) - m_iChangeCount++; - } - } - } - } + + if (m_pClient) { + // Update the channel information for each pending strip... + if (m_changedStrips.count() > 0) { + for (qsamplerChannelStrip *pChannelStrip = m_changedStrips.first(); + pChannelStrip; pChannelStrip = m_changedStrips.next()) { + // If successfull, remove from pending list... + if (pChannelStrip->updateChannelInfo()) + m_changedStrips.remove(pChannelStrip); + } + } + // Refresh each channel usage, on each period... + if (m_pOptions->bAutoRefresh) { + m_iTimerSlot += QSAMPLER_TIMER_MSECS; + if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime) { + m_iTimerSlot = 0; + // Update the channel stream usage for each strip... + QWidgetList wlist = m_pWorkspace->windowList(); + for (int iChannel = 0; + iChannel < (int) wlist.count(); iChannel++) { + qsamplerChannelStrip *pChannelStrip + = (qsamplerChannelStrip *) wlist.at(iChannel); + if (pChannelStrip && pChannelStrip->isVisible()) + pChannelStrip->updateChannelUsage(); + } + } + } + } // Register the next timer slot. QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(timerSlot())); @@ -1720,6 +2040,10 @@ ::lscp_client_set_timeout(m_pClient, m_pOptions->iServerTimeout); appendMessages(tr("Client receive timeout is set to %1 msec.").arg(::lscp_client_get_timeout(m_pClient))); + // Subscribe to channel info change notifications... + if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO) != LSCP_OK) + appendMessagesClient("lscp_client_subscribe"); + // We may stop scheduling around. stopSchedule(); @@ -1729,6 +2053,11 @@ // Log success here. appendMessages(tr("Client connected.")); + // Hard-notify device configuration form, + // if visible, that we're ready... + if (m_pDeviceForm && m_pDeviceForm->isVisible()) + m_pDeviceForm->setClient(m_pClient); + // Is any session pending to be loaded? if (!m_pOptions->sSessionFile.isEmpty()) { // Just load the prabably startup session... @@ -1749,6 +2078,11 @@ if (m_pClient == NULL) return; + // Hard-notify device configuration form, + // if visible, that we're running out... + if (m_pDeviceForm && m_pDeviceForm->isVisible()) + m_pDeviceForm->setClient(NULL); + // Log prepare here. appendMessages(tr("Client disconnecting...")); @@ -1763,9 +2097,10 @@ // channels from the back-end server. m_iDirtyCount = 0; closeSession(false); - + // Close us as a client... - lscp_client_destroy(m_pClient); + ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO); + ::lscp_client_destroy(m_pClient); m_pClient = NULL; // Log final here.