--- qsampler/trunk/src/qsamplerMainForm.ui.h 2005/03/14 12:59:27 455 +++ qsampler/trunk/src/qsamplerMainForm.ui.h 2007/01/08 16:52:48 1013 @@ -2,7 +2,7 @@ // // ui.h extension file, included from the uic-generated form implementation. /**************************************************************************** - Copyright (C) 2004-2005, rncbc aka Rui Nuno Capela. All rights reserved. + Copyright (C) 2004-2007, 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 @@ -14,9 +14,9 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *****************************************************************************/ @@ -41,16 +41,20 @@ #include "qsamplerMessages.h" #include "qsamplerChannelStrip.h" +#include "qsamplerInstrumentList.h" +#include "qsamplerInstrumentListForm.h" #include "qsamplerDeviceForm.h" #include "qsamplerOptionsForm.h" -#include "config.h" - #ifdef HAVE_SIGNAL_H #include #endif +#ifdef CONFIG_LIBGIG +#include +#endif + // Timer constant stuff. #define QSAMPLER_TIMER_MSECS 200 @@ -100,14 +104,22 @@ //------------------------------------------------------------------------- // qsamplerMainForm -- Main window form implementation. +// Kind of singleton reference. +qsamplerMainForm *qsamplerMainForm::g_pMainForm = NULL; + + // Kind of constructor. void qsamplerMainForm::init (void) { + // Pseudo-singleton reference setup. + g_pMainForm = this; + // Initialize some pointer references. m_pOptions = NULL; // All child forms are to be created later, not earlier than setup. - m_pMessages = NULL; + m_pMessages = NULL; + m_pInstrumentListForm = NULL; m_pDeviceForm = NULL; // We'll start clean. @@ -184,6 +196,8 @@ // Finally drop any widgets around... if (m_pDeviceForm) delete m_pDeviceForm; + if (m_pInstrumentListForm) + delete m_pInstrumentListForm; if (m_pMessages) delete m_pMessages; if (m_pWorkspace) @@ -202,6 +216,9 @@ // Delete recentfiles menu. if (m_pRecentFilesMenu) delete m_pRecentFilesMenu; + + // Pseudo-singleton reference shut-down. + g_pMainForm = NULL; } @@ -212,18 +229,33 @@ m_pOptions = pOptions; // What style do we create these forms? - WFlags wflags = Qt::WType_TopLevel; + Qt::WFlags wflags = Qt::WStyle_Customize + | Qt::WStyle_NormalBorder + | Qt::WStyle_Title + | Qt::WStyle_SysMenu + | Qt::WStyle_MinMax + | 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); +#ifdef CONFIG_MIDI_INSTRUMENT + m_pInstrumentListForm = new qsamplerInstrumentListForm(this, 0, wflags); + QObject::connect(m_pInstrumentListForm->InstrumentList, + SIGNAL(instrumentsChanged()), + SLOT(sessionDirty())); +#else + viewInstrumentsAction->setEnabled(false); +#endif // Set message defaults... updateMessagesFont(); updateMessagesLimit(); updateMessagesCapture(); // Set the visibility signal. - QObject::connect(m_pMessages, SIGNAL(visibilityChanged(bool)), this, SLOT(stabilizeForm())); + QObject::connect(m_pMessages, + SIGNAL(visibilityChanged(bool)), + SLOT(stabilizeForm())); // Initial decorations toggle state. viewMenubarAction->setOn(m_pOptions->bMenubar); @@ -248,6 +280,7 @@ } // Try to restore old window positioning and initial visibility. m_pOptions->loadWidgetGeometry(this); + m_pOptions->loadWidgetGeometry(m_pInstrumentListForm); m_pOptions->loadWidgetGeometry(m_pDeviceForm); // Final startup stabilization... @@ -287,11 +320,14 @@ ostr << *this; m_pOptions->settings().writeEntry("/Layout/DockWindows", sDockables); // 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(); + m_pOptions->saveWidgetGeometry(m_pDeviceForm); + m_pOptions->saveWidgetGeometry(m_pInstrumentListForm); + m_pOptions->saveWidgetGeometry(this); + // Close popup widgets. + if (m_pInstrumentListForm) + m_pInstrumentListForm->close(); + if (m_pDeviceForm) + m_pDeviceForm->close(); // Stop client and/or server, gracefully. stopServer(); } @@ -344,32 +380,34 @@ if (!decodeDragFiles(pDropEvent, files)) return; - for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) { + 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; + qsamplerChannel *pChannel = new qsamplerChannel(); + 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... + // 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; + delete pChannel; + return; } - // Make that an overall update. - m_iDirtyCount++; - stabilizeForm(); + // Make that an overall update. + m_iDirtyCount++; + stabilizeForm(); } // Otherwise, load an usual session file (LSCP script)... - else if (closeSession(true)) + else if (closeSession(true)) { loadSessionFile(sPath); + break; + } // Make it look responsive...:) QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); } @@ -382,9 +420,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"); + } } } @@ -393,7 +438,7 @@ void qsamplerMainForm::contextMenuEvent( QContextMenuEvent *pEvent ) { stabilizeForm(); - + editMenu->exec(pEvent->globalPos()); } @@ -407,6 +452,7 @@ return m_pOptions; } + // The LSCP client descriptor property. lscp_client_t *qsamplerMainForm::client (void) { @@ -414,6 +460,13 @@ } +// The pseudo-singleton instance accessor. +qsamplerMainForm *qsamplerMainForm::getInstance (void) +{ + return g_pMainForm; +} + + //------------------------------------------------------------------------- // qsamplerMainForm -- Session file stuff. @@ -461,10 +514,10 @@ // Ask for the filename to open... QString sFilename = QFileDialog::getOpenFileName( - m_pOptions->sSessionDir, // Start here. - tr("LSCP Session files") + " (*.lscp)", // Filter (LSCP files) - this, 0, // Parent and name (none) - tr("Open Session") // Caption. + m_pOptions->sSessionDir, // Start here. + tr("LSCP Session files") + " (*.lscp)", // Filter (LSCP files) + this, 0, // Parent and name (none) + QSAMPLER_TITLE ": " + tr("Open Session") // Caption. ); // Have we cancelled? @@ -495,10 +548,10 @@ sFilename = m_pOptions->sSessionDir; // Prompt the guy... sFilename = QFileDialog::getSaveFileName( - sFilename, // Start here. - tr("LSCP Session files") + " (*.lscp)", // Filter (LSCP files) - this, 0, // Parent and name (none) - tr("Save Session") // Caption. + sFilename, // Start here. + tr("LSCP Session files") + " (*.lscp)", // Filter (LSCP files) + this, 0, // Parent and name (none) + QSAMPLER_TITLE ": " + tr("Save Session") // Caption. ); // Have we cancelled it? if (sFilename.isEmpty()) @@ -508,7 +561,8 @@ sFilename += ".lscp"; // Check if already exists... if (sFilename != m_sFilename && QFileInfo(sFilename).exists()) { - if (QMessageBox::warning(this, tr("Warning"), + if (QMessageBox::warning(this, + QSAMPLER_TITLE ": " + tr("Warning"), tr("The file already exists:\n\n" "\"%1\"\n\n" "Do you want to replace it?") @@ -530,7 +584,8 @@ // Are we dirty enough to prompt it? if (m_iDirtyCount > 0) { - switch (QMessageBox::warning(this, tr("Warning"), + switch (QMessageBox::warning(this, + QSAMPLER_TITLE ": " + tr("Warning"), tr("The current session has been changed:\n\n" "\"%1\"\n\n" "Do you want to save the changes?") @@ -583,23 +638,29 @@ return false; } + // Tell the world we'll take some time... + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + // Read the file. + int iLine = 0; int iErrors = 0; QTextStream ts(&file); while (!ts.atEnd()) { // Read the line. - QString sCommand = ts.readLine().simplifyWhiteSpace(); + QString sCommand = ts.readLine().stripWhiteSpace(); + iLine++; // If not empty, nor a comment, call the server... if (!sCommand.isEmpty() && sCommand[0] != '#') { - appendMessagesColor(sCommand, "#996633"); - // Remember that, no matter what, - // all LSCP commands are CR/LF terminated. - sCommand += "\r\n"; - if (::lscp_client_query(m_pClient, sCommand.latin1()) != LSCP_OK) { - appendMessagesClient("lscp_client_query"); - iErrors++; - break; - } + // Remember that, no matter what, + // all LSCP commands are CR/LF terminated. + sCommand += "\r\n"; + if (::lscp_client_query(m_pClient, sCommand.latin1()) != LSCP_OK) { + appendMessagesColor(QString("%1(%2): %3") + .arg(QFileInfo(sFilename).fileName()).arg(iLine) + .arg(sCommand.simplifyWhiteSpace()), "#996633"); + appendMessagesClient("lscp_client_query"); + iErrors++; + } } // Try to make it snappy :) QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); @@ -608,23 +669,26 @@ // Ok. we've read it. file.close(); - // Have we any errors? - if (iErrors > 0) - appendMessagesError(tr("Session could not be loaded\nfrom \"%1\".\n\nSorry.").arg(sFilename)); - // Now we'll try to create (update) the whole GUI session. updateSession(); + // We're fornerly done. + QApplication::restoreOverrideCursor(); + + // 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. stabilizeForm(); return true; @@ -634,6 +698,15 @@ // Save current session to specific file path. bool qsamplerMainForm::saveSessionFile ( const QString& sFilename ) { + if (m_pClient == NULL) + return false; + + // Check whether server is apparently OK... + if (::lscp_get_channels(m_pClient) < 0) { + appendMessagesClient("lscp_get_channels"); + return false; + } + // Open and write into real file. QFile file(sFilename); if (!file.open(IO_WriteOnly | IO_Truncate)) { @@ -641,6 +714,9 @@ return false; } + // Tell the world we'll take some time... + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + // Write the file. int iErrors = 0; QTextStream ts(&file); @@ -657,47 +733,167 @@ << " " << 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 + // will be loaded from a complete initialized server... 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++) { - qsamplerDevice device(m_pClient, qsamplerDevice::Audio, piDeviceIDs[iDevice]); ts << endl; - ts << "# " << device.deviceTypeName() << " " << device.driverName() - << " " << tr("Device") << " " << iDevice << endl; + qsamplerDevice device(qsamplerDevice::Audio, piDeviceIDs[iDevice]); + // Audio device specification... + ts << "# " << device.deviceTypeName() << " " << device.driverName() + << " " << tr("Device") << " " << iDevice << endl; ts << "CREATE AUDIO_OUTPUT_DEVICE " << device.driverName(); - qsamplerDeviceParamMap& params = device.params(); - qsamplerDeviceParamMap::ConstIterator iter; - for (iter = params.begin(); iter != params.end(); ++iter) - ts << " " << iter.key() << "='" << iter.data().value << "'"; + 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); + // 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++) { - qsamplerDevice device(m_pClient, qsamplerDevice::Midi, piDeviceIDs[iDevice]); - ts << "# " << device.deviceTypeName() << " " << device.driverName() - << " " << tr("Device") << " " << iDevice << endl; + ts << endl; + qsamplerDevice device(qsamplerDevice::Midi, piDeviceIDs[iDevice]); + // MIDI device specification... + ts << "# " << device.deviceTypeName() << " " << device.driverName() + << " " << tr("Device") << " " << iDevice << endl; ts << "CREATE MIDI_INPUT_DEVICE " << device.driverName(); - qsamplerDeviceParamMap& params = device.params(); - qsamplerDeviceParamMap::ConstIterator iter; - for (iter = params.begin(); iter != params.end(); ++iter) - ts << " " << iter.key() << "='" << iter.data().value << "'"; + 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); + // Try to keep it snappy :) + QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); } ts << endl; + +#ifdef CONFIG_MIDI_INSTRUMENT + // MIDI instrument mapping... + QMap midiInstrumentMap; + int *piMaps = ::lscp_list_midi_instrument_maps(m_pClient); + for (int iMap = 0; piMaps && piMaps[iMap] >= 0; iMap++) { + int iMidiMap = piMaps[iMap]; + const char *pszMapName + = ::lscp_get_midi_instrument_map_name(m_pClient, iMidiMap); + ts << "# " << tr("MIDI instrument map") << " " << iMap; + if (pszMapName) + ts << " - " << pszMapName; + ts << endl; + ts << "ADD MIDI_INSTRUMENT_MAP"; + if (pszMapName) + ts << " '" << pszMapName << "'"; + ts << endl; + // MIDI instrument mapping... + lscp_midi_instrument_t *pInstrs + = ::lscp_list_midi_instruments(m_pClient, iMidiMap); + for (int iInstr = 0; pInstrs && pInstrs[iInstr].map >= 0; iInstr++) { + lscp_midi_instrument_info_t *pInstrInfo + = ::lscp_get_midi_instrument_info(m_pClient, &pInstrs[iInstr]); + if (pInstrInfo) { + ts << "MAP MIDI_INSTRUMENT " + << iMap << " " + << pInstrs[iInstr].bank << " " + << pInstrs[iInstr].prog << " " + << pInstrInfo->engine_name << " '" + << pInstrInfo->instrument_file << "' " + << pInstrInfo->instrument_nr << " " + << pInstrInfo->volume << " "; + switch (pInstrInfo->load_mode) { + case LSCP_LOAD_PERSISTENT: + ts << "PERSISTENT"; + break; + case LSCP_LOAD_ON_DEMAND_HOLD: + ts << "ON_DEMAND_HOLD"; + break; + case LSCP_LOAD_ON_DEMAND: + case LSCP_LOAD_DEFAULT: + default: + ts << "ON_DEMAND"; + break; + } + if (pInstrInfo->name) + ts << " '" << pInstrInfo->name << "'"; + ts << endl; + } // Check for errors... + else if (::lscp_client_get_errno(m_pClient)) { + appendMessagesClient("lscp_get_midi_instrument_info"); + iErrors++; + } + // Try to keep it snappy :) + QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); + } + ts << endl; + // Check for errors... + if (pInstrs == NULL && ::lscp_client_get_errno(m_pClient)) { + appendMessagesClient("lscp_list_midi_instruments"); + iErrors++; + } + // MIDI strument index/id mapping. + midiInstrumentMap[iMidiMap] = iMap; + } + // Check for errors... + if (piMaps == NULL && ::lscp_client_get_errno(m_pClient)) { + appendMessagesClient("lscp_list_midi_instrument_maps"); + iErrors++; + } +#endif // CONFIG_MIDI_INSTRUMENT + // Sampler channel mapping. QWidgetList wlist = m_pWorkspace->windowList(); for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { @@ -707,22 +903,22 @@ if (pChannel) { ts << "# " << tr("Channel") << " " << iChannel << endl; ts << "ADD CHANNEL" << endl; - 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 (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; } - 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_PORT " << iChannel + << " " << pChannel->midiPort() << endl; ts << "SET CHANNEL MIDI_INPUT_CHANNEL " << iChannel << " "; if (pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL) ts << "ALL"; @@ -730,8 +926,29 @@ 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; + if (pChannel->instrumentStatus() < 100) ts << "# "; + ts << "LOAD INSTRUMENT NON_MODAL '" << pChannel->instrumentFile() << "' " + << pChannel->instrumentNr() << " " << iChannel << endl; + qsamplerChannelRoutingMap::ConstIterator audioRoute; + for (audioRoute = pChannel->audioRouting().begin(); + audioRoute != pChannel->audioRouting().end(); + ++audioRoute) { + ts << "SET CHANNEL AUDIO_OUTPUT_CHANNEL " << iChannel + << " " << audioRoute.key() + << " " << audioRoute.data() << 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; +#ifdef CONFIG_MIDI_INSTRUMENT + if (pChannel->midiMap() >= 0) { + ts << "SET CHANNEL MIDI_INSTRUMENT_MAP " << iChannel + << " " << midiInstrumentMap[pChannel->midiMap()] << endl; + } +#endif ts << endl; } } @@ -742,6 +959,9 @@ // Ok. we've wrote it. file.close(); + // We're fornerly done. + QApplication::restoreOverrideCursor(); + // Have we any errors? if (iErrors > 0) appendMessagesError(tr("Some settings could not be saved\nto \"%1\" session file.\n\nSorry.").arg(sFilename)); @@ -823,21 +1043,27 @@ return; // Ask user whether he/she want's an internal sampler reset... - if (QMessageBox::warning(this, tr("Warning"), + if (QMessageBox::warning(this, + QSAMPLER_TITLE ": " + 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" + "temporary MIDI and Audio disruption.\n\n" "Do you want to reset the sampler engine now?"), tr("Reset"), tr("Cancel")) > 0) return; + // Trye closing the current session, first... + if (!closeSession(true)) + 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; - } + // Do the actual sampler reset... + if (::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.")); @@ -852,17 +1078,18 @@ { 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) { - bRestart = (QMessageBox::warning(this, tr("Warning"), + bRestart = (QMessageBox::warning(this, + QSAMPLER_TITLE ": " + tr("Warning"), 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); } @@ -895,7 +1122,7 @@ return; // Just create the channel instance... - qsamplerChannel *pChannel = new qsamplerChannel(this); + qsamplerChannel *pChannel = new qsamplerChannel(); if (pChannel == NULL) return; @@ -905,7 +1132,7 @@ delete pChannel; return; } - + // And give it to the strip (will own the channel instance, if successful). if (!createChannelStrip(pChannel)) { delete pChannel; @@ -927,14 +1154,15 @@ qsamplerChannelStrip *pChannelStrip = activeChannelStrip(); if (pChannelStrip == NULL) return; - + qsamplerChannel *pChannel = pChannelStrip->channel(); if (pChannel == NULL) return; // Prompt user if he/she's sure about this... if (m_pOptions && m_pOptions->bConfirmRemove) { - if (QMessageBox::warning(this, tr("Warning"), + if (QMessageBox::warning(this, + QSAMPLER_TITLE ": " + tr("Warning"), tr("About to remove channel:\n\n" "%1\n\n" "Are you sure?") @@ -949,7 +1177,7 @@ // Just delete the channel strip. delete pChannelStrip; - + // Do we auto-arrange? if (m_pOptions && m_pOptions->bAutoArrange) channelsArrange(); @@ -993,19 +1221,19 @@ // Reset all sampler channels. void qsamplerMainForm::editResetAllChannels (void) { - if (m_pClient == NULL) - return; + if (m_pClient == NULL) + return; - // Invoque the channel strip procedure, + // 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); + 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); } @@ -1057,23 +1285,41 @@ } +// Show/hide the MIDI instrument list-view form. +void qsamplerMainForm::viewInstruments (void) +{ + if (m_pOptions == NULL) + return; + + if (m_pInstrumentListForm) { + m_pOptions->saveWidgetGeometry(m_pInstrumentListForm); + if (m_pInstrumentListForm->isVisible()) { + m_pInstrumentListForm->hide(); + } else { + m_pInstrumentListForm->show(); + m_pInstrumentListForm->raise(); + m_pInstrumentListForm->setActiveWindow(); + } + } +} + + // Show/hide the device configurator form. void qsamplerMainForm::viewDevices (void) { - if (m_pOptions == NULL) - return; + 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(); - } - } + if (m_pDeviceForm) { + m_pOptions->saveWidgetGeometry(m_pDeviceForm); + if (m_pDeviceForm->isVisible()) { + m_pDeviceForm->hide(); + } else { + m_pDeviceForm->show(); + m_pDeviceForm->raise(); + m_pDeviceForm->setActiveWindow(); + } + } } @@ -1117,7 +1363,8 @@ (!bOldStdoutCapture && m_pOptions->bStdoutCapture) || ( bOldKeepOnTop && !m_pOptions->bKeepOnTop) || (!bOldKeepOnTop && m_pOptions->bKeepOnTop)) { - QMessageBox::information(this, tr("Information"), + QMessageBox::information(this, + QSAMPLER_TITLE ": " + tr("Information"), tr("Some settings may be only effective\n" "next time you start this program."), tr("OK")); updateMessagesCapture(); @@ -1191,7 +1438,7 @@ y += iHeight; } m_pWorkspace->setUpdatesEnabled(true); - + stabilizeForm(); } @@ -1245,11 +1492,27 @@ 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 +#ifndef CONFIG_MIDI_INSTRUMENT + sText += ""; + sText += tr("MIDI instrument mapping 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"; @@ -1274,7 +1537,7 @@ // Update the main application caption... QString sSessionName = sessionName(m_sFilename); if (m_iDirtyCount > 0) - sSessionName += '*'; + sSessionName += " *"; setCaption(tr(QSAMPLER_TITLE " - [%1]").arg(sSessionName)); // Update the main menu state... @@ -1293,7 +1556,13 @@ editResetChannelAction->setEnabled(bHasChannel); editResetAllChannelsAction->setEnabled(bHasChannel); viewMessagesAction->setOn(m_pMessages && m_pMessages->isVisible()); - viewDevicesAction->setOn(m_pDeviceForm && m_pDeviceForm->isVisible()); +#ifdef CONFIG_MIDI_INSTRUMENT + viewInstrumentsAction->setOn(m_pInstrumentListForm + && m_pInstrumentListForm->isVisible()); + viewInstrumentsAction->setEnabled(bHasClient); +#endif + viewDevicesAction->setOn(m_pDeviceForm + && m_pDeviceForm->isVisible()); viewDevicesAction->setEnabled(bHasClient); channelsArrangeAction->setEnabled(bHasChannel); @@ -1329,8 +1598,10 @@ void qsamplerMainForm::channelStripChanged( qsamplerChannelStrip *pChannelStrip ) { // Add this strip to the changed list... - if (m_changedStrips.containsRef(pChannelStrip) == 0) + if (m_changedStrips.containsRef(pChannelStrip) == 0) { m_changedStrips.append(pChannelStrip); + pChannelStrip->resetErrorCount(); + } // Just mark the dirty form. m_iDirtyCount++; @@ -1342,6 +1613,17 @@ // Grab and restore current sampler channels session. void qsamplerMainForm::updateSession (void) { +#ifdef CONFIG_MIDI_INSTRUMENT + // FIXME: Make some room for default instrument maps... + int iMaps = ::lscp_get_midi_instrument_maps(m_pClient); + if (iMaps < 0) + appendMessagesClient("lscp_get_midi_instrument_maps"); + else if (iMaps < 1) { + ::lscp_add_midi_instrument_map(m_pClient, tr("Chromatic").latin1()); + ::lscp_add_midi_instrument_map(m_pClient, tr("Drum Kits").latin1()); + } +#endif + // Retrieve the current channel list. int *piChannelIDs = ::lscp_list_channels(m_pClient); if (piChannelIDs == NULL) { @@ -1349,19 +1631,26 @@ appendMessagesClient("lscp_list_channels"); appendMessagesError(tr("Could not get current list of channels.\n\nSorry.")); } - return; + } else { + // 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(piChannelIDs[iChannel])); + } + m_pWorkspace->setUpdatesEnabled(true); } - // 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); + // Do we auto-arrange? + if (m_pOptions && m_pOptions->bAutoArrange) + channelsArrange(); + + // Remember to refresh devices and instruments... + if (m_pInstrumentListForm) + m_pInstrumentListForm->refreshInstruments(); + if (m_pDeviceForm) + m_pDeviceForm->refreshDevices(); } @@ -1532,7 +1821,11 @@ appendMessagesColor(s.simplifyWhiteSpace(), "#ff0000"); - QMessageBox::critical(this, tr("Error"), s, tr("Cancel")); + // Make it look responsive...:) + QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); + + QMessageBox::critical(this, + QSAMPLER_TITLE ": " + tr("Error"), s, tr("Cancel")); } @@ -1545,6 +1838,9 @@ appendMessagesColor(s + QString(": %1 (errno=%2)") .arg(::lscp_client_get_result(m_pClient)) .arg(::lscp_client_get_errno(m_pClient)), "#996666"); + + // Make it look responsive...:) + QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); } @@ -1572,7 +1868,7 @@ if (m_pOptions->bMessagesLimit) m_pMessages->setMessagesLimit(m_pOptions->iMessagesLimitLines); else - m_pMessages->setMessagesLimit(0); + m_pMessages->setMessagesLimit(-1); } } @@ -1616,7 +1912,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 *))); @@ -1674,7 +1970,7 @@ 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) { @@ -1755,29 +2051,34 @@ } } } - - // Refresh each channel usage, on each period... - if (m_pClient && (m_changedStrips.count() > 0 || m_pOptions->bAutoRefresh)) { - m_iTimerSlot += QSAMPLER_TIMER_MSECS; - 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 (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); + 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 *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); - if (pChannelStrip && pChannelStrip->isVisible()) - pChannelStrip->updateChannelUsage(); - } - } - } + } + // 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())); @@ -1799,7 +2100,8 @@ // Is the server process instance still here? if (m_pServer) { - switch (QMessageBox::warning(this, tr("Warning"), + switch (QMessageBox::warning(this, + QSAMPLER_TITLE ": " + tr("Warning"), tr("Could not start the LinuxSampler server.\n\n" "Maybe it ss already started."), tr("Stop"), tr("Kill"), tr("Cancel"))) { @@ -1958,6 +2260,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(); @@ -1967,11 +2273,13 @@ // Log success here. appendMessages(tr("Client connected.")); - // Hard-notify device configuration form, + // Hard-notify instrumnet and device configuration forms, // if visible, that we're ready... - if (m_pDeviceForm && m_pDeviceForm->isVisible()) - m_pDeviceForm->setClient(m_pClient); - + if (m_pInstrumentListForm) + m_pInstrumentListForm->refreshInstruments(); + if (m_pDeviceForm) + m_pDeviceForm->refreshDevices(); + // Is any session pending to be loaded? if (!m_pOptions->sSessionFile.isEmpty()) { // Just load the prabably startup session... @@ -1992,11 +2300,6 @@ 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...")); @@ -2011,11 +2314,19 @@ // 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; + // Hard-notify instrumnet and device configuration forms, + // if visible, that we're running out... + if (m_pInstrumentListForm) + m_pInstrumentListForm->refreshInstruments(); + if (m_pDeviceForm) + m_pDeviceForm->refreshDevices(); + // Log final here. appendMessages(tr("Client disconnected."));