From: <sag...@us...> - 2014-02-26 23:40:25
|
Revision: 3781 http://sourceforge.net/p/modplug/code/3781 Author: saga-games Date: 2014-02-26 23:40:15 +0000 (Wed, 26 Feb 2014) Log Message: ----------- [Imp] Sample tab: When zooming into a sample using ctrl-mousewheel, center the zoomed area around the mouse position. [Fix] When recording a plugin's MIDI output, avoid it from being spammed back to exactly the same plugin. Modified Paths: -------------- trunk/OpenMPT/mptrack/AbstractVstEditor.cpp trunk/OpenMPT/mptrack/View_smp.cpp trunk/OpenMPT/mptrack/View_smp.h Modified: trunk/OpenMPT/mptrack/AbstractVstEditor.cpp =================================================================== --- trunk/OpenMPT/mptrack/AbstractVstEditor.cpp 2014-02-26 21:02:25 UTC (rev 3780) +++ trunk/OpenMPT/mptrack/AbstractVstEditor.cpp 2014-02-26 23:40:15 UTC (rev 3781) @@ -99,11 +99,11 @@ } -LRESULT CAbstractVstEditor::OnMidiMsg(WPARAM midiData, LPARAM) -//------------------------------------------------------------ +LRESULT CAbstractVstEditor::OnMidiMsg(WPARAM midiData, LPARAM sender) +//------------------------------------------------------------------- { CModDoc *modDoc = m_VstPlugin.GetModDoc(); - if(modDoc != nullptr) + if(modDoc != nullptr && sender != reinterpret_cast<LPARAM>(&m_VstPlugin)) { if(!CheckInstrument(m_nInstrument)) m_nInstrument = GetBestInstrumentCandidate(); Modified: trunk/OpenMPT/mptrack/View_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_smp.cpp 2014-02-26 21:02:25 UTC (rev 3780) +++ trunk/OpenMPT/mptrack/View_smp.cpp 2014-02-26 23:40:15 UTC (rev 3781) @@ -161,47 +161,61 @@ } -void CViewSample::UpdateScrollSize(const int nZoomOld) -//---------------------------------------------------- +void CViewSample::UpdateScrollSize(int newZoom, bool forceRefresh, SmpLength centeredSample) +//------------------------------------------------------------------------------------------ { CModDoc *pModDoc = GetDocument(); + if(pModDoc == nullptr || (newZoom == m_nZoom && !forceRefresh)) + { + return; + } + const int oldZoom = m_nZoom; + m_nZoom = newZoom; + GetClientRect(&m_rcClient); - if (pModDoc) + const CSoundFile &sndFile = pModDoc->GetrSoundFile(); + SIZE sizePage, sizeLine; + SmpLength dwLen = 0; + + if ((m_nSample > 0) && (m_nSample <= sndFile.GetNumSamples())) { - CPoint pt; - CSoundFile *pSndFile = pModDoc->GetSoundFile(); - SIZE sizePage, sizeLine; - SmpLength dwLen = 0; + const ModSample &sample = sndFile.GetSample(m_nSample); + if (sample.pSample != nullptr) dwLen = sample.nLength; + } + // Compute scroll size in pixels + if (newZoom == 0) // Fit to display + m_sizeTotal.cx = m_rcClient.Width(); + else if(newZoom == 1) // 1:1 + m_sizeTotal.cx = dwLen; + else if(newZoom > 1) // Zoom out + m_sizeTotal.cx = (dwLen + (1 << (newZoom - 1)) - 1) >> (newZoom - 1); + else // Zoom in - here, we don't compute the real number of visible pixels so that the scroll bar doesn't grow unnecessarily long. The scrolling code in OnScrollBy() compensates for this. + m_sizeTotal.cx = dwLen + m_rcClient.Width() - (m_rcClient.Width() >> (-newZoom - 1)); - if ((m_nSample > 0) && (m_nSample <= pSndFile->GetNumSamples())) - { - const ModSample &sample = pSndFile->GetSample(m_nSample); - if (sample.pSample != nullptr) dwLen = sample.nLength; - } - // Compute scroll size in pixels - if (m_nZoom == 0) // Fit to display - m_sizeTotal.cx = m_rcClient.Width(); - else if(m_nZoom == 1) // 1:1 - m_sizeTotal.cx = dwLen; - else if(m_nZoom > 1) // Zoom out - m_sizeTotal.cx = (dwLen + (1 << (m_nZoom - 1)) - 1) >> (m_nZoom - 1); - else // Zoom in - here, we don't compute the real number of visible pixels so that the scroll bar doesn't grow unnecessarily long. The scrolling code in OnScrollBy() compensates for this. - m_sizeTotal.cx = dwLen + m_rcClient.Width() - (m_rcClient.Width() >> (-m_nZoom - 1)); + m_sizeTotal.cy = 1; + sizeLine.cx = (m_rcClient.right / 16) + 1; + if(newZoom < 0) + sizeLine.cx >>= (-newZoom - 1); + sizeLine.cy = 1; + sizePage.cx = sizeLine.cx * 4; + sizePage.cy = 1; - m_sizeTotal.cy = 1; - sizeLine.cx = (m_rcClient.right / 16) + 1; - if(m_nZoom < 0) - sizeLine.cx >>= (-m_nZoom - 1); - sizeLine.cy = 1; - sizePage.cx = sizeLine.cx * 4; - sizePage.cy = 1; + SetScrollSizes(MM_TEXT, m_sizeTotal, sizePage, sizeLine); - SetScrollSizes(MM_TEXT, m_sizeTotal, sizePage, sizeLine); + if(oldZoom != newZoom) // After zoom change, keep the view position. + { + if(centeredSample != SmpLength(-1)) + { + // Center given sample in the view + int scrollToSample = centeredSample >> (std::max(1, newZoom) - 1); + scrollToSample -= (m_rcClient.Width() / 2) >> (-std::min(-1, newZoom) - 1); - if (nZoomOld != m_nZoom) // After zoom change, keep the view position. + Limit(scrollToSample, 0, GetScrollLimit(SB_HORZ)); + SetScrollPos(SB_HORZ, scrollToSample); + } else { - const SmpLength nOldPos = ScrollPosToSamplePos(nZoomOld); + const SmpLength nOldPos = ScrollPosToSamplePos(oldZoom); const float fPosFraction = (dwLen > 0) ? static_cast<float>(nOldPos) / dwLen : 0; SetScrollPos(SB_HORZ, static_cast<int>(fPosFraction * GetScrollLimit(SB_HORZ))); } @@ -284,8 +298,8 @@ } -BOOL CViewSample::SetZoom(int nZoom) -//---------------------------------- +BOOL CViewSample::SetZoom(int nZoom, SmpLength centeredSample) +//------------------------------------------------------------ { if (nZoom == m_nZoom) @@ -293,9 +307,7 @@ if (nZoom > MAX_ZOOM) return FALSE; - const int nZoomOld = m_nZoom; - m_nZoom = nZoom; - UpdateScrollSize(nZoomOld); + UpdateScrollSize(nZoom, true, centeredSample); InvalidateRect(NULL, FALSE); return TRUE; } @@ -1089,7 +1101,7 @@ // Drawing Sample Data ::SelectObject(offScreenDC, CMainFrame::penSample); int smplsize = sample.GetBytesPerSample(); - if (m_nZoom == 1 || m_nZoom < 0 || ((!m_nZoom) && (sample.nLength <= (SmpLength)rect.right))) + if (m_nZoom == 1 || m_nZoom < 0 || ((!m_nZoom) && (sample.nLength <= (SmpLength)rect.Width()))) { // Draw sample data in 1:1 ratio or higher (zoom in) SmpLength len = sample.nLength - nSmpScrollPos; @@ -2581,18 +2593,7 @@ SendCtrlMessage(CTRLMSG_SMP_SETZOOM, zoom); if (zoom) { - SetZoom(zoom); - UpdateScrollSize(); - - // Compute width of new selection and center it in the view - int scrollToSample = (m_dwBeginSel + selLength / 2) >> (std::max(1, zoom) - 1); - scrollToSample -= (m_rcClient.Width() / 2) >> (-std::min(-1, zoom) - 1); - - int minPos, maxPos; - GetScrollRange(SB_HORZ, &minPos, &maxPos); - Limit(scrollToSample, minPos, maxPos); - SetScrollPos(SB_HORZ, scrollToSample); - Invalidate(); + SetZoom(zoom, m_dwBeginSel + selLength / 2); } } @@ -2995,8 +2996,8 @@ } -void CViewSample::DoZoom(int direction) -//------------------------------------- +void CViewSample::DoZoom(int direction, const CPoint &zoomPoint) +//-------------------------------------------------------------- { const CSoundFile &sndFile = GetDocument()->GetrSoundFile(); // zoomOrder: Biggest to smallest zoom order. @@ -3025,10 +3026,23 @@ ASSERT(false); } const ptrdiff_t nPos = std::find(zoomOrder, pZoomOrderEnd, m_nZoom) - zoomOrder; + + int newZoom; if (direction > 0 && nPos > 0) // Zoom in - SendCtrlMessage(CTRLMSG_SMP_SETZOOM, zoomOrder[nPos - 1]); + newZoom = zoomOrder[nPos - 1]; else if (direction < 0 && nPos + 1 < CountOf(zoomOrder)) - SendCtrlMessage(CTRLMSG_SMP_SETZOOM, zoomOrder[nPos + 1]); + newZoom = zoomOrder[nPos + 1]; + else + return; + + if(m_rcClient.PtInRect(zoomPoint)) + { + SetZoom(newZoom, ScreenToSample(zoomPoint.x)); + } else + { + SetZoom(newZoom); + } + SendCtrlMessage(CTRLMSG_SMP_SETZOOM, newZoom); } @@ -3041,7 +3055,8 @@ // the zoom levels in the zoom combobox. if (nFlags == MK_CONTROL && GetDocument()) { - DoZoom(zDelta); + ScreenToClient(&pt); + DoZoom(zDelta, pt); } return CModScrollView::OnMouseWheel(nFlags, zDelta, pt); Modified: trunk/OpenMPT/mptrack/View_smp.h =================================================================== --- trunk/OpenMPT/mptrack/View_smp.h 2014-02-26 21:02:25 UTC (rev 3780) +++ trunk/OpenMPT/mptrack/View_smp.h 2014-02-26 23:40:15 UTC (rev 3781) @@ -57,10 +57,10 @@ DECLARE_SERIAL(CViewSample) protected: - void UpdateScrollSize() {UpdateScrollSize(m_nZoom);} - void UpdateScrollSize(const int nZoomOld); + void UpdateScrollSize() { UpdateScrollSize(m_nZoom, true); } + void UpdateScrollSize(int newZoom, bool forceRefresh, SmpLength centeredSample = SmpLength(-1)); BOOL SetCurrentSample(SAMPLEINDEX nSmp); - BOOL SetZoom(int nZoom); + BOOL SetZoom(int nZoom, SmpLength centeredSample = SmpLength(-1)); int32 SampleToScreen(SmpLength pos) const; SmpLength ScreenToSample(int32 x) const; void PlayNote(ModCommand::NOTE note, const SmpLength nStartPos = 0); @@ -88,7 +88,7 @@ T GetSampleValueFromPoint(const ModSample &smp, const CPoint &point) const; int GetZoomLevel(SmpLength length) const; - void DoZoom(int direction); + void DoZoom(int direction, const CPoint &zoomPoint = CPoint(-1, -1)); bool CanZoomSelection() const; SmpLength ScrollPosToSamplePos() const {return ScrollPosToSamplePos(m_nZoom);} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |