--- qsampler/trunk/src/qsamplerMainForm.ui.h 2004/10/06 15:42:59 267 +++ qsampler/trunk/src/qsamplerMainForm.ui.h 2005/01/18 11:29:01 341 @@ -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 @@ -44,6 +44,9 @@ #include "config.h" +#ifdef HAVE_SIGNAL_H +#include +#endif // Timer constant stuff. #define QSAMPLER_TIMER_MSECS 200 @@ -104,8 +107,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 +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); @@ -196,6 +205,9 @@ // We got options? m_pOptions = pOptions; + // Set initial instrument name display mode. + qsamplerChannel::setInstrumentNames(m_pOptions->bInstrumentNames); + // Some child forms are to be created right now. m_pMessages = new qsamplerMessages(this); // Set message defaults... @@ -487,8 +499,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; } } @@ -543,16 +555,16 @@ appendMessagesError(tr("Some setttings could not be loaded\nfrom \"%1\" session file.\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.")); + int *piChannelIDs = ::lscp_list_channels(m_pClient); + if (piChannelIDs == NULL) { + appendMessagesClient("lscp_list_channels"); + appendMessagesError(tr("Could not get current list of channels.\n\nSorry.")); } // Try to (re)create each channel. m_pWorkspace->setUpdatesEnabled(false); - for (int iChannelID = 0; iChannelID < iChannels; iChannelID++) { - createChannel(iChannelID, false); + for (int iChannel = 0; piChannelIDs[iChannel] >= 0; iChannel++) { + createChannelStrip(new qsamplerChannel(this, piChannelIDs[iChannel])); QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); } m_pWorkspace->setUpdatesEnabled(true); @@ -566,6 +578,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 +625,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 +782,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; + + // 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; } - // Log this happening. - appendMessages(tr("Channel %1 created.").arg(iChannelID)); - - // Just create the channel strip with given id. - createChannel(iChannelID, true); - - // We'll be dirty, for sure... + // Make that an overall update. m_iDirtyCount++; - // Stabilize form anyway. + m_iChangeCount++; stabilizeForm(); } @@ -814,15 +833,9 @@ } // 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 pChannelStrip; @@ -847,7 +860,7 @@ return; // Just invoque the channel strip procedure. - pChannelStrip->showChannelSetup(false); + pChannelStrip->channelSetup(); } @@ -865,18 +878,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++; } @@ -957,6 +963,7 @@ int iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines; bool bOldCompletePath = m_pOptions->bCompletePath; int iOldMaxRecentFiles = m_pOptions->iMaxRecentFiles; + bool bOldInstrumentNames = m_pOptions->bInstrumentNames; // Load the current setup settings. pOptionsForm->setup(m_pOptions); // Show the setup dialog... @@ -970,6 +977,9 @@ updateMessagesCapture(); } // Check wheather something immediate has changed. + if (( bOldInstrumentNames && !m_pOptions->bInstrumentNames) || + (!bOldInstrumentNames && m_pOptions->bInstrumentNames)) + qsamplerChannel::setInstrumentNames(m_pOptions->bInstrumentNames); if (( bOldCompletePath && !m_pOptions->bCompletePath) || (!bOldCompletePath && m_pOptions->bCompletePath) || (iOldMaxRecentFiles != m_pOptions->iMaxRecentFiles)) @@ -1164,6 +1174,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... @@ -1380,10 +1392,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; @@ -1400,6 +1412,12 @@ // 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); + 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... @@ -1411,13 +1429,7 @@ // Maximum allowed volume setting. pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume); } - // 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 (bPrompt) - pChannelStrip->showChannelSetup(true); + // Now we show up us to the world. pChannelStrip->show(); // Only then, we'll auto-arrange... @@ -1427,6 +1439,9 @@ int iHeight = pChannelStrip->parentWidget()->frameGeometry().height(); pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight); } + + // Return our successful reference... + return pChannelStrip; } @@ -1516,15 +1531,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++; + } } } }