--- qsampler/trunk/src/qsamplerMainForm.ui.h 2004/06/09 20:24:48 119 +++ qsampler/trunk/src/qsamplerMainForm.ui.h 2007/01/12 21:21:16 1025 @@ -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-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. *****************************************************************************/ @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -36,13 +37,23 @@ #include "qsamplerAbout.h" #include "qsamplerOptions.h" +#include "qsamplerChannel.h" #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 @@ -54,24 +65,65 @@ #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. +// 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_pInstrumentListForm = NULL; + m_pDeviceForm = NULL; // We'll start clean. - m_iUntitled = 0; + m_iUntitled = 0; m_iDirtyCount = 0; m_pServer = NULL; @@ -82,11 +134,18 @@ 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); - // Set the activation connection. - QObject::connect(m_pWorkspace, SIGNAL(windowActivated(QWidget *)), this, SLOT(stabilizeForm())); + // Set the activation connection. + QObject::connect(m_pWorkspace, + SIGNAL(windowActivated(QWidget *)), + SLOT(stabilizeForm())); // Make it shine :-) setCentralWidget(m_pWorkspace); @@ -96,23 +155,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. @@ -131,29 +190,37 @@ { // 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_pInstrumentListForm) + delete m_pInstrumentListForm; 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; + + // Pseudo-singleton reference shut-down. + g_pMainForm = NULL; } @@ -163,14 +230,34 @@ // We got options? m_pOptions = pOptions; + // What style do we create these forms? + 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); @@ -193,8 +280,10 @@ 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_pInstrumentListForm); + m_pOptions->loadWidgetGeometry(m_pDeviceForm); // Final startup stabilization... updateRecentFilesMenu(); @@ -232,8 +321,15 @@ 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(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(); } @@ -252,30 +348,103 @@ } -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(); + 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); + break; + } + // 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; + 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"); + } } } +// Context menu event handler. +void qsamplerMainForm::contextMenuEvent( QContextMenuEvent *pEvent ) +{ + stabilizeForm(); + + editMenu->exec(pEvent->globalPos()); +} + + //------------------------------------------------------------------------- // qsamplerMainForm -- Brainless public property accessors. @@ -285,6 +454,7 @@ return m_pOptions; } + // The LSCP client descriptor property. lscp_client_t *qsamplerMainForm::client (void) { @@ -292,6 +462,13 @@ } +// The pseudo-singleton instance accessor. +qsamplerMainForm *qsamplerMainForm::getInstance (void) +{ + return g_pMainForm; +} + + //------------------------------------------------------------------------- // qsamplerMainForm -- Session file stuff. @@ -315,6 +492,9 @@ if (!closeSession(true)) return false; + // Give us what the server has, right now... + updateSession(); + // Ok increment untitled count. m_iUntitled++; @@ -336,10 +516,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? @@ -370,10 +550,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()) @@ -383,7 +563,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?") @@ -405,7 +586,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?") @@ -428,10 +610,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. @@ -455,22 +640,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++; - } + // 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); @@ -479,34 +671,27 @@ // 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 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); + // 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; } @@ -515,6 +700,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)) { @@ -522,8 +716,11 @@ return false; } + // Tell the world we'll take some time... + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + // Write the file. - int iErrors = 0; + int iErrors = 0; QTextStream ts(&file); ts << "# " << QSAMPLER_TITLE " - " << tr(QSAMPLER_SUBTITLE) << endl; ts << "# " << tr("Version") @@ -534,24 +731,261 @@ 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 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++) { + ts << 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::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(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; + +#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++) { - 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 + = static_cast (wlist.at(iChannel)); + if (pChannelStrip) { + qsamplerChannel *pChannel = pChannelStrip->channel(); + 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 (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() << " " << iChannel << 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 +#ifdef CONFIG_FXSEND + int iChannelID = pChannel->channelID(); + int *piFxSends = ::lscp_list_fxsends(m_pClient, iChannelID); + for (int iFxSend = 0; + piFxSends && piFxSends[iFxSend] >= 0; + iFxSend++) { + lscp_fxsend_info_t *pFxSendInfo = ::lscp_get_fxsend_info( + m_pClient, iChannelID, piFxSends[iFxSend]); + if (pFxSendInfo) { + ts << "CREATE FX_SEND " << iChannel + << " " << pFxSendInfo->midi_controller; + if (pFxSendInfo->name) + ts << " '" << pFxSendInfo->name << "'"; + ts << endl; + int *piRouting = pFxSendInfo->audio_routing; + for (int iAudioSrc = 0; + piRouting && piRouting[iAudioSrc] >= 0; + iAudioSrc++) { + ts << "SET FX_SEND AUDIO_OUTPUT_CHANNEL " + << iChannel + << " " << iFxSend + << " " << iAudioSrc + << " " << piRouting[iAudioSrc] << endl; + } + } // Check for errors... + else if (::lscp_client_get_errno(m_pClient)) { + appendMessagesClient("lscp_get_fxsend_info"); + iErrors++; + } + } +#endif + ts << endl; + } + } // Try to keep it snappy :) QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); } @@ -559,6 +993,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)); @@ -577,6 +1014,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. @@ -623,22 +1070,60 @@ } +// 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, + 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" + "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... + // 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.")); + + // Make it a new session... + newSession(); +} + + // Restart the client/server instance. void qsamplerMainForm::fileRestart (void) { 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); } @@ -670,23 +1155,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(); + if (pChannel == NULL) return; - } - // Log this happening. - appendMessages(tr("Channel %1 created.").arg(iChannelID)); + // Before we show it up, may be we'll + // better ask for some initial values? + if (!pChannel->channelSetup(this)) { + delete pChannel; + return; + } - // Just create the channel strip with given id. - createChannel(iChannelID, true); + // 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,33 +1185,33 @@ if (m_pClient == NULL) return; - qsamplerChannelStrip *pChannel = activeChannel(); + 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?") - .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 +1228,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 +1243,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); } @@ -822,6 +1319,44 @@ } +// 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_pDeviceForm) { + m_pOptions->saveWidgetGeometry(m_pDeviceForm); + if (m_pDeviceForm->isVisible()) { + m_pDeviceForm->hide(); + } else { + m_pDeviceForm->show(); + m_pDeviceForm->raise(); + m_pDeviceForm->setActiveWindow(); + } + } +} + + // Show options dialog. void qsamplerMainForm::viewOptions (void) { @@ -831,9 +1366,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 +1378,15 @@ 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 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); @@ -856,8 +1394,11 @@ if (pOptionsForm->exec()) { // Warn if something will be only effective on next run. if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) || - (!bOldStdoutCapture && m_pOptions->bStdoutCapture)) { - QMessageBox::information(this, tr("Information"), + (!bOldStdoutCapture && m_pOptions->bStdoutCapture) || + ( bOldKeepOnTop && !m_pOptions->bKeepOnTop) || + (!bOldKeepOnTop && m_pOptions->bKeepOnTop)) { + QMessageBox::information(this, + QSAMPLER_TITLE ": " + tr("Information"), tr("Some settings may be only effective\n" "next time you start this program."), tr("OK")); updateMessagesCapture(); @@ -867,6 +1408,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,23 +1456,23 @@ 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); - + stabilizeForm(); } @@ -969,11 +1516,47 @@ 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 +#ifndef CONFIG_MUTE_SOLO + sText += ""; + sText += tr("Sampler channel Mute/Solo support disabled."); + sText += "
"; +#endif +#ifndef CONFIG_AUDIO_ROUTING + sText += ""; + sText += tr("LSCP (liblscp) audio_routing support disabled."); + sText += "
"; +#endif +#ifndef CONFIG_FXSEND + sText += ""; + sText += tr("Sampler channel Effect Sends 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"; @@ -996,45 +1579,55 @@ 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); - channelsArrangeAction->setEnabled(bHasChannel); + editResetAllChannelsAction->setEnabled(bHasChannel); viewMessagesAction->setOn(m_pMessages && m_pMessages->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); // 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(pChannel->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); @@ -1046,8 +1639,14 @@ // 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); + pChannelStrip->resetErrorCount(); + } + // Just mark the dirty form. m_iDirtyCount++; // and update the form status... @@ -1055,6 +1654,50 @@ } +// 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) { + if (::lscp_client_get_errno(m_pClient)) { + appendMessagesClient("lscp_list_channels"); + appendMessagesError(tr("Could not get current list of channels.\n\nSorry.")); + } + } 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); + } + + // 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(); +} + + // Update the recent files list and menu. void qsamplerMainForm::updateRecentFiles ( const QString& sFilename ) { @@ -1099,6 +1742,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 +1781,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 +1824,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); } @@ -1180,7 +1865,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")); } @@ -1193,6 +1882,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); } @@ -1220,7 +1912,7 @@ if (m_pOptions->bMessagesLimit) m_pMessages->setMessagesLimit(m_pOptions->iMessagesLimitLines); else - m_pMessages->setMessagesLimit(0); + m_pMessages->setMessagesLimit(-1); } } @@ -1240,68 +1932,105 @@ // 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 *)), + 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 +2042,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 +2056,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(); } @@ -1366,20 +2097,34 @@ } } } - - // Refresh each channel usage, on each period... - if (m_pClient && m_pOptions->bAutoRefresh && m_pWorkspace->isUpdatesEnabled()) { - m_iTimerSlot += QSAMPLER_TIMER_MSECS; - if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime) { - m_iTimerSlot = 0; - 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(); - } - } - } + + 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())); @@ -1401,7 +2146,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"))) { @@ -1422,13 +2168,20 @@ m_pServer = new QProcess(this); // Setup stdout/stderr capture... - //if (m_pOptions->bStdoutCapture) { - m_pServer->setCommunication(QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr); - QObject::connect(m_pServer, SIGNAL(readyReadStdout()), this, SLOT(readServerStdout())); - QObject::connect(m_pServer, SIGNAL(readyReadStderr()), this, SLOT(readServerStdout())); - //} - // The unforgiveable signal communication... - QObject::connect(m_pServer, SIGNAL(processExited()), this, SLOT(processServerExit())); + // if (m_pOptions->bStdoutCapture) { + m_pServer->setCommunication( + QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr); + QObject::connect(m_pServer, + SIGNAL(readyReadStdout()), + SLOT(readServerStdout())); + QObject::connect(m_pServer, + SIGNAL(readyReadStderr()), + SLOT(readServerStdout())); + // } + // The unforgiveable signal communication... + QObject::connect(m_pServer, + SIGNAL(processExited()), + SLOT(processServerExit())); // Build process arguments... m_pServer->setArguments(QStringList::split(' ', m_pOptions->sServerCmdLine)); @@ -1462,12 +2215,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 +2266,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; } @@ -1561,6 +2313,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(); @@ -1570,6 +2326,13 @@ // Log success here. appendMessages(tr("Client connected.")); + // Hard-notify instrumnet and device configuration forms, + // if visible, that we're ready... + 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... @@ -1604,11 +2367,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."));