--- qsampler/trunk/src/qsamplerMainForm.ui.h 2004/11/17 12:40:25 297 +++ qsampler/trunk/src/qsamplerMainForm.ui.h 2005/03/02 16:23:10 418 @@ -2,7 +2,7 @@ // // ui.h extension file, included from the uic-generated form implementation. /**************************************************************************** - Copyright (C) 2004, rncbc aka Rui Nuno Capela. All rights reserved. + Copyright (C) 2004-2005, rncbc aka Rui Nuno Capela. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -44,6 +45,9 @@ #include "config.h" +#ifdef HAVE_SIGNAL_H +#include +#endif // Timer constant stuff. #define QSAMPLER_TIMER_MSECS 200 @@ -104,9 +108,8 @@ m_pMessages = NULL; // We'll start clean. - m_iUntitled = 0; - m_iDirtyCount = 0; - m_iChangeCount = 0; + m_iUntitled = 0; + m_iDirtyCount = 0; m_pServer = NULL; m_pClient = NULL; @@ -116,6 +119,11 @@ m_iTimerSlot = 0; +#ifdef HAVE_SIGNAL_H + // Set to ignore any fatal "Broken pipe" signals. + ::signal(SIGPIPE, SIG_IGN); +#endif + // Make it an MDI workspace. m_pWorkspace = new QWorkspace(this); m_pWorkspace->setScrollBarsEnabled(true); @@ -165,10 +173,17 @@ { // Do final processing anyway. processServerExit(); - - // Delete recentfiles menu. - if (m_pRecentFilesMenu) - delete m_pRecentFilesMenu; + +#if defined(WIN32) + WSACleanup(); +#endif + + // Finally drop any widgets around... + if (m_pMessages) + delete m_pMessages; + if (m_pWorkspace) + delete m_pWorkspace; + // Delete status item labels one by one. if (m_status[QSAMPLER_STATUS_CLIENT]) delete m_status[QSAMPLER_STATUS_CLIENT]; @@ -179,15 +194,9 @@ if (m_status[QSAMPLER_STATUS_SESSION]) delete m_status[QSAMPLER_STATUS_SESSION]; - // Finally drop any widgets around... - if (m_pMessages) - delete m_pMessages; - if (m_pWorkspace) - delete m_pWorkspace; - -#if defined(WIN32) - WSACleanup(); -#endif + // Delete recentfiles menu. + if (m_pRecentFilesMenu) + delete m_pRecentFilesMenu; } @@ -286,28 +295,69 @@ } -// Window drag-n-drop event handlers. -void qsamplerMainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent ) +// Drag'n'drop file handler. +bool qsamplerMainForm::decodeDragFiles ( const QMimeSource *pEvent, QStringList& files ) { - bool bAccept = false; + bool bDecode = false; - if (QTextDrag::canDecode(pDragEnterEvent)) { - QString sUrl; - if (QTextDrag::decode(pDragEnterEvent, sUrl) && m_pClient) - bAccept = QFileInfo(QUrl(sUrl).path()).exists(); + if (QTextDrag::canDecode(pEvent)) { + QString sText; + bDecode = QTextDrag::decode(pEvent, sText); + if (bDecode) { + files = QStringList::split('\n', sText); + for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) + *iter = QUrl((*iter).stripWhiteSpace().replace(QRegExp("^file:"), QString::null)).path(); + } } - pDragEnterEvent->accept(bAccept); + return bDecode; +} + + +// Window drag-n-drop event handlers. +void qsamplerMainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent ) +{ + QStringList files; + pDragEnterEvent->accept(decodeDragFiles(pDragEnterEvent, files)); } void qsamplerMainForm::dropEvent ( QDropEvent* pDropEvent ) { - if (QTextDrag::canDecode(pDropEvent)) { - QString sUrl; - if (QTextDrag::decode(pDropEvent, sUrl) && closeSession(true)) - loadSessionFile(QUrl(sUrl).path()); - } + QStringList files; + + if (!decodeDragFiles(pDropEvent, files)) + return; + + for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) { + const QString& sPath = *iter; + if (qsamplerChannel::isInstrumentFile(sPath)) { + // Try to create a new channel from instrument file... + qsamplerChannel *pChannel = new qsamplerChannel(this); + if (pChannel == NULL) + return; + // Start setting the instrument filename... + pChannel->setInstrument(sPath, 0); + // Before we show it up, may be we'll + // better ask for some initial values? + if (!pChannel->channelSetup(this)) { + delete pChannel; + return; + } + // Finally, give it to a new channel strip... + if (!createChannelStrip(pChannel)) { + delete pChannel; + return; + } + // Make that an overall update. + m_iDirtyCount++; + stabilizeForm(); + } // Otherwise, load an usual session file (LSCP script)... + else if (closeSession(true)) + loadSessionFile(sPath); + // Make it look responsive...:) + QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); + } } @@ -372,6 +422,9 @@ if (!closeSession(true)) return false; + // Give us what the server has, right now... + updateSession(); + // Ok increment untitled count. m_iUntitled++; @@ -530,6 +583,7 @@ if (::lscp_client_query(m_pClient, sCommand.latin1()) != LSCP_OK) { appendMessagesClient("lscp_client_query"); iErrors++; + break; } } // Try to make it snappy :) @@ -541,22 +595,10 @@ // Have we any errors? if (iErrors > 0) - appendMessagesError(tr("Some setttings could not be loaded\nfrom \"%1\" session file.\n\nSorry.").arg(sFilename)); + appendMessagesError(tr("Session could not be loaded\nfrom \"%1\".\n\nSorry.").arg(sFilename)); - // Now we'll try to create the whole GUI session. - int iChannels = ::lscp_get_channels(m_pClient); - if (iChannels < 0) { - appendMessagesClient("lscp_get_channels"); - appendMessagesError(tr("Could not get current number of channels.\n\nSorry.")); - } - - // Try to (re)create each channel. - m_pWorkspace->setUpdatesEnabled(false); - for (int iChannelID = 0; iChannelID < iChannels; iChannelID++) { - createChannelStrip(iChannelID); - QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); - } - m_pWorkspace->setUpdatesEnabled(true); + // Now we'll try to create (update) the whole GUI session. + updateSession(); // Save as default session directory. if (m_pOptions) @@ -567,6 +609,8 @@ m_sFilename = sFilename; updateRecentFiles(sFilename); appendMessages(tr("Open session: \"%1\".").arg(sessionName(m_sFilename))); + + // Make that an overall update. stabilizeForm(); return true; } @@ -604,21 +648,20 @@ if (pChannelStrip) { qsamplerChannel *pChannel = pChannelStrip->channel(); if (pChannel) { - int iChannelID = pChannel->channelID(); - ts << "# " << pChannelStrip->caption() << endl; + ts << "# Channel " << iChannel << endl; ts << "ADD CHANNEL" << endl; - ts << "SET CHANNEL AUDIO_OUTPUT_TYPE " << iChannelID << " " << pChannel->audioDriver() << endl; - ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannelID << " " << pChannel->midiDriver() << endl; - ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannelID << " " << pChannel->midiPort() << endl; - ts << "SET CHANNEL MIDI_INPUT_CHANNEL " << iChannelID << " "; - if (pChannel->midiChannel() > 0) - ts << pChannel->midiChannel(); - else + ts << "SET CHANNEL AUDIO_OUTPUT_TYPE " << iChannel << " " << pChannel->audioDriver() << endl; + ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannel << " " << pChannel->midiDriver() << endl; + // ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannel << " " << pChannel->midiPort() << endl; + ts << "SET CHANNEL MIDI_INPUT_CHANNEL " << iChannel << " "; + if (pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL) ts << "ALL"; + else + ts << pChannel->midiChannel(); ts << endl; - ts << "LOAD ENGINE " << pChannel->engineName() << " " << iChannelID << endl; - ts << "LOAD INSTRUMENT NON_MODAL '" << pChannel->instrumentFile() << "' " << pChannel->instrumentNr() << " " << iChannelID << endl; - ts << "SET CHANNEL VOLUME " << iChannelID << " " << pChannel->volume() << endl; + ts << "LOAD ENGINE " << pChannel->engineName() << " " << iChannel << endl; + ts << "LOAD INSTRUMENT NON_MODAL '" << pChannel->instrumentFile() << "' " << pChannel->instrumentNr() << " " << iChannel << endl; + ts << "SET CHANNEL VOLUME " << iChannel << " " << pChannel->volume() << endl; ts << endl; } } @@ -718,6 +761,9 @@ // Log this. appendMessages(tr("Sampler reset.")); + + // Make it a new session... + newSession(); } @@ -768,9 +814,27 @@ if (m_pClient == NULL) return; - // Just create the channel strip, - // by giving an invalid channel id. - createChannelStrip(-1); + // Just create the channel instance... + qsamplerChannel *pChannel = new qsamplerChannel(this); + if (pChannel == NULL) + return; + + // Before we show it up, may be we'll + // better ask for some initial values? + if (!pChannel->channelSetup(this)) { + delete pChannel; + return; + } + + // And give it to the strip (will own the channel instance, if successful). + if (!createChannelStrip(pChannel)) { + delete pChannel; + return; + } + + // Make that an overall update. + m_iDirtyCount++; + stabilizeForm(); } @@ -841,15 +905,27 @@ if (pChannelStrip == NULL) return; - qsamplerChannel *pChannel = pChannelStrip->channel(); - if (pChannel == NULL) - return; + // Just invoque the channel strip procedure. + pChannelStrip->channelReset(); +} - // Reset the existing sampler channel. - pChannel->resetChannel(); - // Refresh channel strip info. - pChannelStrip->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); } @@ -929,6 +1005,7 @@ 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); @@ -947,6 +1024,9 @@ (!bOldCompletePath && m_pOptions->bCompletePath) || (iOldMaxRecentFiles != m_pOptions->iMaxRecentFiles)) updateRecentFilesMenu(); + if (( bOldInstrumentNames && !m_pOptions->bInstrumentNames) || + (!bOldInstrumentNames && m_pOptions->bInstrumentNames)) + updateInstrumentNames(); if (( bOldDisplayEffect && !m_pOptions->bDisplayEffect) || (!bOldDisplayEffect && m_pOptions->bDisplayEffect)) updateDisplayEffect(); @@ -1057,6 +1137,11 @@ sText += tr("GIG (libgig) file support disabled."); sText += "
"; #endif +#ifndef CONFIG_INSTRUMENT_NAME + sText += ""; + sText += tr("LSCP (liblscp) instrument_name support disabled."); + sText += "
"; +#endif sText += "
\n"; sText += tr("Using") + ": "; sText += ::lscp_client_package(); @@ -1084,10 +1169,10 @@ void qsamplerMainForm::stabilizeForm (void) { // Update the main application caption... - QString sSessioName = sessionName(m_sFilename); + QString sSessionName = sessionName(m_sFilename); if (m_iDirtyCount > 0) - sSessioName += '*'; - setCaption(tr(QSAMPLER_TITLE " - [%1]").arg(sSessioName)); + sSessionName += '*'; + setCaption(tr(QSAMPLER_TITLE " - [%1]").arg(sSessionName)); // Update the main menu state... qsamplerChannelStrip *pChannelStrip = activeChannelStrip(); @@ -1103,6 +1188,7 @@ editRemoveChannelAction->setEnabled(bHasChannel); editSetupChannelAction->setEnabled(bHasChannel); editResetChannelAction->setEnabled(bHasChannel); + editResetAllChannelsAction->setEnabled(bHasChannel); channelsArrangeAction->setEnabled(bHasChannel); viewMessagesAction->setOn(m_pMessages && m_pMessages->isVisible()); @@ -1135,10 +1221,12 @@ // Channel change receiver slot. -void qsamplerMainForm::channelStripChanged( qsamplerChannelStrip * ) +void qsamplerMainForm::channelStripChanged( qsamplerChannelStrip *pChannelStrip ) { - // Flag that we're update those channel strips. - m_iChangeCount++; + // Add this strip to the changed list... + if (m_changedStrips.containsRef(pChannelStrip) == 0) + m_changedStrips.append(pChannelStrip); + // Just mark the dirty form. m_iDirtyCount++; // and update the form status... @@ -1146,6 +1234,32 @@ } +// Grab and restore current sampler channels session. +void qsamplerMainForm::updateSession (void) +{ + // Retrieve the current channel list. + int *piChannelIDs = ::lscp_list_channels(m_pClient); + if (piChannelIDs == NULL) { + if (::lscp_client_get_errno(m_pClient)) { + appendMessagesClient("lscp_list_channels"); + appendMessagesError(tr("Could not get current list of channels.\n\nSorry.")); + } + return; + } + + // Try to (re)create each channel. + m_pWorkspace->setUpdatesEnabled(false); + for (int iChannel = 0; piChannelIDs[iChannel] >= 0; iChannel++) { + // Check if theres already a channel strip for this one... + if (!channelStrip(piChannelIDs[iChannel])) + createChannelStrip(new qsamplerChannel(this, piChannelIDs[iChannel])); + // Make it visibly responsive... + QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); + } + m_pWorkspace->setUpdatesEnabled(true); +} + + // Update the recent files list and menu. void qsamplerMainForm::updateRecentFiles ( const QString& sFilename ) { @@ -1190,6 +1304,24 @@ } +// Force update of the channels instrument names mode. +void qsamplerMainForm::updateInstrumentNames (void) +{ + // Full channel list update... + QWidgetList wlist = m_pWorkspace->windowList(); + if (wlist.isEmpty()) + return; + + m_pWorkspace->setUpdatesEnabled(false); + for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { + qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); + if (pChannelStrip) + pChannelStrip->updateInstrumentName(true); + } + m_pWorkspace->setUpdatesEnabled(true); +} + + // Force update of the channels display font. void qsamplerMainForm::updateDisplayFont (void) { @@ -1355,9 +1487,9 @@ // qsamplerMainForm -- MDI channel strip management. // The channel strip creation executive. -qsamplerChannelStrip *qsamplerMainForm::createChannelStrip ( int iChannelID ) +qsamplerChannelStrip *qsamplerMainForm::createChannelStrip ( qsamplerChannel *pChannel ) { - if (m_pClient == NULL) + if (m_pClient == NULL || pChannel == NULL) return NULL; // Prepare for auto-arrange? @@ -1367,25 +1499,22 @@ QWidgetList wlist = m_pWorkspace->windowList(); for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); - // y += pChannelStrip->height() + pChannelStrip->parentWidget()->baseSize().height(); - y += pChannelStrip->parentWidget()->frameGeometry().height(); + if (pChannelStrip) { + // y += pChannelStrip->height() + pChannelStrip->parentWidget()->baseSize().height(); + y += pChannelStrip->parentWidget()->frameGeometry().height(); + } } } // Add a new channel itema... WFlags wflags = Qt::WStyle_Customize | Qt::WStyle_Tool | Qt::WStyle_Title | Qt::WStyle_NoBorder; pChannelStrip = new qsamplerChannelStrip(m_pWorkspace, 0, wflags); - // Actual channel setup. - pChannelStrip->setup(this, iChannelID); - QObject::connect(pChannelStrip, SIGNAL(channelChanged(qsamplerChannelStrip *)), this, SLOT(channelStripChanged(qsamplerChannelStrip *))); - // Before we show it up, may be we'll - // better ask for some initial values? - if (iChannelID < 0 && !pChannelStrip->channelSetup()) { - // No luck, bail out... - delete pChannelStrip; + if (pChannelStrip == NULL) return NULL; - } - + + // Actual channel strip setup... + pChannelStrip->setup(pChannel); + QObject::connect(pChannelStrip, SIGNAL(channelChanged(qsamplerChannelStrip *)), this, SLOT(channelStripChanged(qsamplerChannelStrip *))); // Set some initial aesthetic options... if (m_pOptions) { // Background display effect... @@ -1407,7 +1536,10 @@ int iHeight = pChannelStrip->parentWidget()->frameGeometry().height(); pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight); } - + + // This is pretty new, so we'll watch for it closely. + channelStripChanged(pChannelStrip); + // Return our successful reference... return pChannelStrip; } @@ -1425,12 +1557,33 @@ { QWidgetList wlist = m_pWorkspace->windowList(); if (wlist.isEmpty()) - return 0; + return NULL; return (qsamplerChannelStrip *) wlist.at(iChannel); } +// Retrieve a channel strip by sampler channel id. +qsamplerChannelStrip *qsamplerMainForm::channelStrip ( int iChannelID ) +{ + QWidgetList wlist = m_pWorkspace->windowList(); + if (wlist.isEmpty()) + return NULL; + + for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { + qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); + if (pChannelStrip) { + qsamplerChannel *pChannel = pChannelStrip->channel(); + if (pChannel && pChannel->channelID() == iChannelID) + return pChannelStrip; + } + } + + // Not found. + return NULL; +} + + // Construct the windows menu. void qsamplerMainForm::channelsMenuAboutToShow (void) { @@ -1499,19 +1652,24 @@ } // Refresh each channel usage, on each period... - if (m_pClient && (m_iChangeCount > 0 || m_pOptions->bAutoRefresh)) { + 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; - m_iChangeCount = 0; + // Update the channel information for each pending strip... + for (qsamplerChannelStrip *pChannelStrip = m_changedStrips.first(); + pChannelStrip; + pChannelStrip = m_changedStrips.next()) { + // If successfull, remove from pending list... + if (pChannelStrip->updateChannelInfo()) + m_changedStrips.remove(pChannelStrip); + } + // Update the channel stream usage for each strip... QWidgetList wlist = m_pWorkspace->windowList(); for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); - if (pChannelStrip && pChannelStrip->isVisible()) { - // If we can't make it clean, try next time. - if (!pChannelStrip->updateChannelUsage()) - m_iChangeCount++; - } + if (pChannelStrip && pChannelStrip->isVisible()) + pChannelStrip->updateChannelUsage(); } } }