--- qsampler/trunk/src/qsamplerMainForm.ui.h 2005/02/18 10:28:45 391 +++ qsampler/trunk/src/qsamplerMainForm.ui.h 2005/02/23 13:47:47 404 @@ -108,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; @@ -317,9 +316,8 @@ // Window drag-n-drop event handlers. void qsamplerMainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent ) { - QStringList files; - - pDragEnterEvent->accept(decodeDragFiles(pDragEnterEvent, files)); + QStringList files; + pDragEnterEvent->accept(decodeDragFiles(pDragEnterEvent, files)); } @@ -352,7 +350,6 @@ } // Make that an overall update. m_iDirtyCount++; - m_iChangeCount++; stabilizeForm(); } // Otherwise, load an usual session file (LSCP script)... else if (closeSession(true)) @@ -424,6 +421,9 @@ if (!closeSession(true)) return false; + // Give us what the server has, right now... + updateSession(); + // Ok increment untitled count. m_iUntitled++; @@ -596,20 +596,8 @@ if (iErrors > 0) appendMessagesError(tr("Session could not be loaded\nfrom \"%1\".\n\nSorry.").arg(sFilename)); - // Now we'll try to create the whole GUI session. - 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); - } + // Now we'll try to create (update) the whole GUI session. + updateSession(); // Save as default session directory. if (m_pOptions) @@ -622,7 +610,6 @@ appendMessages(tr("Open session: \"%1\".").arg(sessionName(m_sFilename))); // Make that an overall update. - m_iChangeCount++; stabilizeForm(); return true; } @@ -774,6 +761,9 @@ // Log this. appendMessages(tr("Sampler reset.")); + + // Make it a new session... + newSession(); } @@ -844,7 +834,6 @@ // Make that an overall update. m_iDirtyCount++; - m_iChangeCount++; stabilizeForm(); } @@ -916,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(); +// Reset all sampler channels. +void qsamplerMainForm::editResetAllChannels (void) +{ + if (m_pClient == NULL) + return; - // And force a deferred update. - m_iChangeCount++; + // 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); } @@ -1187,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()); @@ -1219,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... @@ -1230,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 ) { @@ -1469,8 +1499,10 @@ 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(); + } } } @@ -1504,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; } @@ -1522,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) { @@ -1596,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(); } } }