From: <sag...@us...> - 2011-09-27 16:42:12
|
Revision: 1059 http://modplug.svn.sourceforge.net/modplug/?rev=1059&view=rev Author: saga-games Date: 2011-09-27 16:42:05 +0000 (Tue, 27 Sep 2011) Log Message: ----------- [Fix] Sample Editor: Deleting some sample data adjusted loop points, but not sustain points. Modified Paths: -------------- trunk/OpenMPT/mptrack/View_smp.cpp trunk/OpenMPT/mptrack/View_smp.h Modified: trunk/OpenMPT/mptrack/View_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_smp.cpp 2011-09-25 22:22:38 UTC (rev 1058) +++ trunk/OpenMPT/mptrack/View_smp.cpp 2011-09-27 16:42:05 UTC (rev 1059) @@ -1720,6 +1720,41 @@ } +// Update loop points after deleting a sample selection +void CViewSample::AdjustLoopPoints(UINT &loopStart, UINT &loopEnd, UINT length) const +//----------------------------------------------------------------------------------- +{ + if(m_dwBeginSel < loopStart && m_dwEndSel < loopStart) + { + // cut part is before loop start + loopStart -= m_dwEndSel - m_dwBeginSel; + loopEnd -= m_dwEndSel - m_dwBeginSel; + } + else if(m_dwBeginSel < loopStart && m_dwEndSel < loopEnd) + { + // cut part is partly before loop start + loopStart = m_dwBeginSel; + loopEnd -= m_dwEndSel - m_dwBeginSel; + } + else if(m_dwBeginSel >= loopStart && m_dwEndSel < loopEnd) + { + // cut part is in the loop + loopEnd -= m_dwEndSel - m_dwBeginSel; + } + else if(m_dwBeginSel >= loopStart && m_dwBeginSel < loopEnd && m_dwEndSel > loopEnd) + { + // cut part is partly before loop end + loopEnd = m_dwBeginSel; + } + + if(loopEnd > length) loopEnd = length; + if(loopStart + 4 >= loopEnd) + { + loopStart = loopEnd = 0; + } +} + + void CViewSample::OnEditDelete() //------------------------------ { @@ -1774,35 +1809,19 @@ } len = sample.nLength; - // adjust loop points (could need some optimization) - if(m_dwBeginSel < sample.nLoopStart && m_dwEndSel < sample.nLoopStart) + + // adjust loop points + AdjustLoopPoints(sample.nLoopStart, sample.nLoopEnd, len); + AdjustLoopPoints(sample.nSustainStart, sample.nSustainEnd, len); + + if(sample.nLoopEnd == 0) { - // cut part is before loop start - sample.nLoopStart -= m_dwEndSel - m_dwBeginSel; - sample.nLoopEnd -= m_dwEndSel - m_dwBeginSel; + sample.uFlags &= ~(CHN_LOOP | CHN_PINGPONGLOOP); } - else if(m_dwBeginSel < sample.nLoopStart && m_dwEndSel < sample.nLoopEnd) - { - // cut part is partly before loop start - sample.nLoopStart = m_dwBeginSel; - sample.nLoopEnd -= m_dwEndSel - m_dwBeginSel; - } - else if(m_dwBeginSel >= sample.nLoopStart && m_dwEndSel < sample.nLoopEnd) - { - // cut part is in the loop - sample.nLoopEnd -= m_dwEndSel - m_dwBeginSel; - } - else if(m_dwBeginSel >= sample.nLoopStart && m_dwBeginSel < sample.nLoopEnd && m_dwEndSel > sample.nLoopEnd) - { - // cut part is partly before loop end - sample.nLoopEnd = m_dwBeginSel; - } - if (sample.nLoopEnd > len) sample.nLoopEnd = len; - if (sample.nLoopStart + 4 >= sample.nLoopEnd) + if(sample.nSustainEnd == 0) { - sample.nLoopStart = sample.nLoopEnd = 0; - sample.uFlags &= ~CHN_LOOP; + sample.uFlags &= ~(CHN_SUSTAINLOOP | CHN_PINGPONGSUSTAIN); } } SetCurSel(0, 0); @@ -1844,7 +1863,7 @@ dwMemSize += sizeof(WAVEFILEHEADER) + sizeof(WAVEFORMATHEADER) + sizeof(WAVEDATAHEADER) + sizeof(WAVEEXTRAHEADER) + sizeof(WAVESAMPLERINFO); // For name + fname - dwMemSize += 32*2; + dwMemSize += 32 * 2; BeginWaitCursor(); if ((pMainFrm->OpenClipboard()) && ((hCpy = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, dwMemSize))!=NULL)) { @@ -1866,16 +1885,16 @@ } pfmt->channels = (sample.uFlags & CHN_STEREO) ? (WORD)2 : (WORD)1; pfmt->bitspersample = (sample.uFlags & CHN_16BIT) ? (WORD)16 : (WORD)8; - pfmt->samplesize = pfmt->channels*pfmt->bitspersample/8; + pfmt->samplesize = pfmt->channels * pfmt->bitspersample / 8; pfmt->bytessec = pfmt->freqHz*pfmt->samplesize; pdata->id_data = IFFID_data; pdata->length = dwSmpLen; phdr->filesize += pdata->length; - LPBYTE psamples = p+sizeof(WAVEFILEHEADER)+sizeof(WAVEFORMATHEADER)+sizeof(WAVEDATAHEADER); + LPBYTE psamples = p + sizeof(WAVEFILEHEADER) + sizeof(WAVEFORMATHEADER) + sizeof(WAVEDATAHEADER); memcpy(psamples, sample.pSample+dwSmpOffset, dwSmpLen); if (pfmt->bitspersample == 8) { - for (UINT i=0; i<dwSmpLen; i++) psamples[i] += 0x80; + for (UINT i = 0; i < dwSmpLen; i++) psamples[i] += 0x80; } if (bExtra) { Modified: trunk/OpenMPT/mptrack/View_smp.h =================================================================== --- trunk/OpenMPT/mptrack/View_smp.h 2011-09-25 22:22:38 UTC (rev 1058) +++ trunk/OpenMPT/mptrack/View_smp.h 2011-09-27 16:42:05 UTC (rev 1059) @@ -30,7 +30,7 @@ CViewSample(); DECLARE_SERIAL(CViewSample) -public: +protected: void UpdateScrollSize() {UpdateScrollSize(m_nZoom);} void UpdateScrollSize(const UINT nZoomOld); BOOL SetCurrentSample(SAMPLEINDEX nSmp); @@ -69,6 +69,8 @@ UINT ScrollPosToSamplePos() const {return ScrollPosToSamplePos(m_nZoom);} UINT ScrollPosToSamplePos(UINT nZoom) const {return (nZoom > 0) ? (m_nScrollPos << (nZoom - 1)) : 0;} + void AdjustLoopPoints(UINT &loopStart, UINT &loopEnd, UINT length) const; + public: //{{AFX_VIRTUAL(CViewSample) virtual void OnDraw(CDC *); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |