--- qsampler/trunk/src/qsamplerMainForm.ui.h 2004/10/06 15:42:59 267 +++ qsampler/trunk/src/qsamplerMainForm.ui.h 2004/11/17 13:05:42 298 @@ -104,8 +104,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; @@ -487,8 +488,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; } } @@ -552,7 +553,7 @@ // Try to (re)create each channel. m_pWorkspace->setUpdatesEnabled(false); for (int iChannelID = 0; iChannelID < iChannels; iChannelID++) { - createChannel(iChannelID, false); + createChannelStrip(iChannelID); QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); } m_pWorkspace->setUpdatesEnabled(true); @@ -767,24 +768,9 @@ 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.")); - 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... - m_iDirtyCount++; - // Stabilize form anyway. - stabilizeForm(); + // Just create the channel strip, + // by giving an invalid channel id. + createChannelStrip(-1); } @@ -814,15 +800,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 +827,7 @@ return; // Just invoque the channel strip procedure. - pChannelStrip->showChannelSetup(false); + pChannelStrip->channelSetup(); } @@ -865,18 +845,13 @@ 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++; } @@ -1164,6 +1139,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 +1357,10 @@ // qsamplerMainForm -- MDI channel strip management. // The channel strip creation executive. -void qsamplerMainForm::createChannel ( int iChannelID, bool bPrompt ) +qsamplerChannelStrip *qsamplerMainForm::createChannelStrip ( int iChannelID ) { if (m_pClient == NULL) - return; + return NULL; // Prepare for auto-arrange? qsamplerChannelStrip *pChannelStrip = NULL; @@ -1400,6 +1377,17 @@ // 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; + return NULL; + } + // Set some initial aesthetic options... if (m_pOptions) { // Background display effect... @@ -1411,13 +1399,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 +1409,9 @@ int iHeight = pChannelStrip->parentWidget()->frameGeometry().height(); pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight); } + + // Return our successful reference... + return pChannelStrip; } @@ -1516,15 +1501,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++; + } } } }