--- qsampler/trunk/src/qsamplerMainForm.ui.h 2004/09/29 13:12:45 264 +++ qsampler/trunk/src/qsamplerMainForm.ui.h 2005/02/17 17:27:59 388 @@ -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,8 +108,9 @@ m_pMessages = NULL; // We'll start clean. - m_iUntitled = 0; - m_iDirtyCount = 0; + m_iUntitled = 0; + m_iDirtyCount = 0; + m_iChangeCount = 0; m_pServer = NULL; m_pClient = NULL; @@ -115,6 +120,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); @@ -285,27 +295,61 @@ } -// 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 = (*iter).stripWhiteSpace().replace(QRegExp("^file:"), QString::null); + } } - 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)) { + for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) { + const QString& sPath = QUrl(*iter).path(); + 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; + } + // Make that an overall update. + m_iDirtyCount++; + m_iChangeCount++; + stabilizeForm(); + } // Otherwise, load an usual session file (LSCP script)... + else if (closeSession(true)) + loadSessionFile(sPath); + } } } @@ -487,8 +531,8 @@ qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); if (pChannelStrip) { qsamplerChannel *pChannel = pChannelStrip->channel(); - if (bForce && pChannel && ::lscp_remove_channel(m_pClient, pChannel->channelID()) != LSCP_OK) - appendMessagesClient("lscp_remove_channel"); + if (bForce && pChannel) + pChannel->removeChannel(); delete pChannelStrip; } } @@ -529,6 +573,7 @@ if (::lscp_client_query(m_pClient, sCommand.latin1()) != LSCP_OK) { appendMessagesClient("lscp_client_query"); iErrors++; + break; } } // Try to make it snappy :) @@ -540,22 +585,22 @@ // Have we any errors? if (iErrors > 0) - appendMessagesError(tr("Some setttings could not be loaded\nfrom \"%1\" session file.\n\nSorry.").arg(sFilename)); + appendMessagesError(tr("Session could not be loaded\nfrom \"%1\".\n\nSorry.").arg(sFilename)); // Now we'll try to create the whole GUI session. - int iChannels = ::lscp_get_channels(m_pClient); - if (iChannels < 0) { - appendMessagesClient("lscp_get_channels"); - appendMessagesError(tr("Could not get current number of channels.\n\nSorry.")); - } - - // Try to (re)create each channel. - m_pWorkspace->setUpdatesEnabled(false); - for (int iChannelID = 0; iChannelID < iChannels; iChannelID++) { - createChannel(iChannelID, false); - QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); - } - m_pWorkspace->setUpdatesEnabled(true); + int *piChannelIDs = ::lscp_list_channels(m_pClient); + if (piChannelIDs == NULL) { + appendMessagesClient("lscp_list_channels"); + appendMessagesError(tr("Could not get current list of channels.\n\nSorry.")); + } else { + // Try to (re)create each channel. + m_pWorkspace->setUpdatesEnabled(false); + for (int iChannel = 0; piChannelIDs[iChannel] >= 0; iChannel++) { + createChannelStrip(new qsamplerChannel(this, piChannelIDs[iChannel])); + QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); + } + m_pWorkspace->setUpdatesEnabled(true); + } // Save as default session directory. if (m_pOptions) @@ -566,6 +611,9 @@ m_sFilename = sFilename; updateRecentFiles(sFilename); appendMessages(tr("Open session: \"%1\".").arg(sessionName(m_sFilename))); + + // Make that an overall update. + m_iChangeCount++; stabilizeForm(); return true; } @@ -610,10 +658,10 @@ 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 + 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; @@ -767,23 +815,27 @@ if (m_pClient == NULL) return; - // Create the new sampler channel. - int iChannelID = ::lscp_add_channel(m_pClient); - if (iChannelID < 0) { - appendMessagesClient("lscp_add_channel"); - appendMessagesError(tr("Could not create the new channel.\n\nSorry.")); + // Just create the channel instance... + qsamplerChannel *pChannel = new qsamplerChannel(this); + if (pChannel == NULL) return; - } - // Log this happening. - appendMessages(tr("Channel %1 created.").arg(iChannelID)); - - // Just create the channel strip with given id. - createChannel(iChannelID, true); + // Before we show it up, may be we'll + // better ask for some initial values? + if (!pChannel->channelSetup(this)) { + delete pChannel; + return; + } + + // And give it to the strip (will own the channel instance, if successful). + if (!createChannelStrip(pChannel)) { + delete pChannel; + return; + } - // We'll be dirty, for sure... + // Make that an overall update. m_iDirtyCount++; - // Stabilize form anyway. + m_iChangeCount++; stabilizeForm(); } @@ -814,17 +866,12 @@ } // 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(); @@ -846,7 +893,7 @@ return; // Just invoque the channel strip procedure. - pChannelStrip->showChannelSetup(false); + pChannelStrip->channelSetup(); } @@ -864,18 +911,11 @@ if (pChannel == 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; - } - - // Log this. - appendMessages(tr("Channel %1 reset.").arg(pChannel->channelID())); + // Reset the existing sampler channel. + pChannel->resetChannel(); - // Refresh channel strip info. - pChannelStrip->updateChannelInfo(); + // And force a deferred update. + m_iChangeCount++; } @@ -948,12 +988,14 @@ bool bOldServerStart = m_pOptions->bServerStart; QString sOldServerCmdLine = m_pOptions->sServerCmdLine; QString sOldDisplayFont = m_pOptions->sDisplayFont; + bool bOldDisplayEffect = m_pOptions->bDisplayEffect; int iOldMaxVolume = m_pOptions->iMaxVolume; QString sOldMessagesFont = m_pOptions->sMessagesFont; bool bOldStdoutCapture = m_pOptions->bStdoutCapture; int bOldMessagesLimit = m_pOptions->bMessagesLimit; int iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines; bool bOldCompletePath = m_pOptions->bCompletePath; + bool bOldInstrumentNames = m_pOptions->bInstrumentNames; int iOldMaxRecentFiles = m_pOptions->iMaxRecentFiles; // Load the current setup settings. pOptionsForm->setup(m_pOptions); @@ -972,6 +1014,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) @@ -1079,6 +1127,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(); @@ -1159,6 +1212,8 @@ // Channel change receiver slot. void qsamplerMainForm::channelStripChanged( qsamplerChannelStrip * ) { + // Flag that we're update those channel strips. + m_iChangeCount++; // Just mark the dirty form. m_iDirtyCount++; // and update the form status... @@ -1210,6 +1265,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) { @@ -1239,6 +1312,28 @@ } +// 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); +} + + // Force update of the channels maximum volume setting. void qsamplerMainForm::updateMaxVolume (void) { @@ -1353,10 +1448,10 @@ // 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 *pChannelStrip = NULL; @@ -1373,18 +1468,24 @@ // 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); - pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume); - pChannelStrip->setup(this, iChannelID); - // We'll need a display font. - QFont font; - if (m_pOptions && font.fromString(m_pOptions->sDisplayFont)) - pChannelStrip->setDisplayFont(font); - // Track channel setup changes. + if (pChannelStrip == NULL) + return NULL; + + // Actual channel strip setup... + pChannelStrip->setup(pChannel); 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 (bPrompt) - pChannelStrip->showChannelSetup(true); + // 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. pChannelStrip->show(); // Only then, we'll auto-arrange... @@ -1394,6 +1495,9 @@ int iHeight = pChannelStrip->parentWidget()->frameGeometry().height(); pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight); } + + // Return our successful reference... + return pChannelStrip; } @@ -1483,15 +1587,19 @@ } // Refresh each channel usage, on each period... - if (m_pClient && m_pOptions->bAutoRefresh && m_pWorkspace->isUpdatesEnabled()) { + if (m_pClient && (m_iChangeCount > 0 || m_pOptions->bAutoRefresh)) { m_iTimerSlot += QSAMPLER_TIMER_MSECS; - if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime) { + if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime && m_pWorkspace->isUpdatesEnabled()) { m_iTimerSlot = 0; + m_iChangeCount = 0; QWidgetList wlist = m_pWorkspace->windowList(); for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); - if (pChannelStrip && pChannelStrip->isVisible()) - pChannelStrip->updateChannelUsage(); + if (pChannelStrip && pChannelStrip->isVisible()) { + // If we can't make it clean, try next time. + if (!pChannelStrip->updateChannelUsage()) + m_iChangeCount++; + } } } }