Skip to content

Commit 6933ab2

Browse files
committed
Merged revision(s) 22591-22593 from trunk/OpenMPT:
[Imp] MO3: Import dummy command W (XM). ........ [Imp] Pressing Ctrl while moving loop points or clicking loop start/end spin buttons now moves the loop, keeping the loop length constant. ........ [Ref] Remove unused variable. ........ git-svn-id: https://source.openmpt.org/svn/openmpt/branches/OpenMPT-1.31@22594 56274372-70c3-4bfc-bfc3-4c3a0b034d27
1 parent 8cc9032 commit 6933ab2

File tree

7 files changed

+266
-167
lines changed

7 files changed

+266
-167
lines changed

mptrack/Ctrl_smp.cpp

Lines changed: 36 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -2938,99 +2938,29 @@ void CCtrlSamples::OnSustainPointsChanged()
29382938
}
29392939

29402940

2941-
#define SMPLOOP_ACCURACY 7 // 5%
2942-
#define BIDILOOP_ACCURACY 2 // 5%
2943-
2944-
2945-
bool MPT_LoopCheck(int sstart0, int sstart1, int send0, int send1)
2946-
{
2947-
int dse0 = send0 - sstart0;
2948-
if ((dse0 < -SMPLOOP_ACCURACY) || (dse0 > SMPLOOP_ACCURACY)) return false;
2949-
int dse1 = send1 - sstart1;
2950-
if ((dse1 < -SMPLOOP_ACCURACY) || (dse1 > SMPLOOP_ACCURACY)) return false;
2951-
int dstart = sstart1 - sstart0;
2952-
int dend = send1 - send0;
2953-
if (!dstart) dstart = dend >> 7;
2954-
if (!dend) dend = dstart >> 7;
2955-
if ((dstart ^ dend) < 0) return false;
2956-
int delta = dend - dstart;
2957-
return ((delta > -SMPLOOP_ACCURACY) && (delta < SMPLOOP_ACCURACY));
2958-
}
2959-
2960-
2961-
bool MPT_BidiEndCheck(int spos0, int spos1, int spos2)
2962-
{
2963-
int delta0 = spos1 - spos0;
2964-
int delta1 = spos2 - spos1;
2965-
int delta2 = spos2 - spos0;
2966-
if (!delta0) delta0 = delta1 >> 7;
2967-
if (!delta1) delta1 = delta0 >> 7;
2968-
if ((delta1 ^ delta0) < 0) return false;
2969-
return ((delta0 >= -1) && (delta0 <= 0) && (delta1 >= -1) && (delta1 <= 0) && (delta2 >= -1) && (delta2 <= 0));
2970-
}
2971-
2972-
2973-
bool MPT_BidiStartCheck(int spos0, int spos1, int spos2)
2974-
{
2975-
int delta1 = spos1 - spos0;
2976-
int delta0 = spos2 - spos1;
2977-
int delta2 = spos2 - spos0;
2978-
if (!delta0) delta0 = delta1 >> 7;
2979-
if (!delta1) delta1 = delta0 >> 7;
2980-
if ((delta1 ^ delta0) < 0) return false;
2981-
return ((delta0 >= -1) && (delta0 <= 0) && (delta1 > -1) && (delta1 <= 0) && (delta2 >= -1) && (delta2 <= 0));
2982-
}
2983-
2984-
2985-
29862941
void CCtrlSamples::OnVScroll(UINT nCode, UINT, CScrollBar *scrollBar)
29872942
{
2988-
TCHAR s[256];
2943+
TCHAR s[32];
29892944
if(IsLocked()) return;
29902945
ModSample &sample = m_sndFile.GetSample(m_nSample);
2991-
const uint8 *pSample = mpt::byte_cast<const uint8 *>(sample.sampleb());
2992-
const uint32 inc = sample.GetBytesPerSample();
2993-
SmpLength i;
2994-
int pos;
2946+
const bool moveLoop = CMainFrame::GetInputHandler()->CtrlPressed();
29952947
bool redraw = false;
29962948
static CScrollBar *lastScrollbar = nullptr;
29972949

29982950
LockControls();
2999-
if ((!sample.nLength) || (!pSample)) goto NoSample;
3000-
if (sample.uFlags[CHN_16BIT])
3001-
{
3002-
pSample++;
3003-
}
30042951
// Loop Start
3005-
if ((pos = m_SpinLoopStart.GetPos32()) != 0 && sample.nLoopEnd > 0)
2952+
if(int pos = m_SpinLoopStart.GetPos32(); pos != 0 && sample.nLoopEnd > 0 && sample.HasSampleData())
30062953
{
3007-
bool bOk = false;
3008-
const uint8 *p = pSample + sample.nLoopStart * inc;
3009-
int find0 = (int)pSample[sample.nLoopEnd*inc-inc];
3010-
int find1 = (int)pSample[sample.nLoopEnd*inc];
3011-
// Find Next LoopStart Point
3012-
if (pos > 0)
3013-
{
3014-
for (i = sample.nLoopStart + 1; i + 16 < sample.nLoopEnd; i++)
3015-
{
3016-
p += inc;
3017-
bOk = sample.uFlags[CHN_PINGPONGLOOP] ? MPT_BidiStartCheck(p[0], p[inc], p[inc*2]) : MPT_LoopCheck(find0, find1, p[0], p[inc]);
3018-
if (bOk) break;
3019-
}
3020-
} else
3021-
// Find Prev LoopStart Point
2954+
if(SmpLength i = SampleEdit::FindLoopStart(sample, false, pos > 0, moveLoop); i < sample.nLength)
30222955
{
3023-
for (i = sample.nLoopStart; i; )
2956+
if(!m_startedEdit && lastScrollbar != scrollBar)
2957+
PrepareUndo(moveLoop ? "Move Loop" : "Set Loop Start");
2958+
if(moveLoop)
30242959
{
3025-
i--;
3026-
p -= inc;
3027-
bOk = sample.uFlags[CHN_PINGPONGLOOP] ? MPT_BidiStartCheck(p[0], p[inc], p[inc*2]) : MPT_LoopCheck(find0, find1, p[0], p[inc]);
3028-
if (bOk) break;
2960+
sample.nLoopEnd = i + (sample.nLoopEnd - sample.nLoopStart);
2961+
wsprintf(s, _T("%u"), sample.nLoopEnd);
2962+
m_EditLoopEnd.SetWindowText(s);
30292963
}
3030-
}
3031-
if (bOk)
3032-
{
3033-
if(!m_startedEdit && lastScrollbar != scrollBar) PrepareUndo("Set Loop Start");
30342964
sample.nLoopStart = i;
30352965
wsprintf(s, _T("%u"), sample.nLoopStart);
30362966
m_EditLoopStart.SetWindowText(s);
@@ -3040,34 +2970,18 @@ void CCtrlSamples::OnVScroll(UINT nCode, UINT, CScrollBar *scrollBar)
30402970
m_SpinLoopStart.SetPos(0);
30412971
}
30422972
// Loop End
3043-
if ((pos = m_SpinLoopEnd.GetPos32()) != 0)
2973+
if(int pos = m_SpinLoopEnd.GetPos32(); pos != 0 && sample.HasSampleData())
30442974
{
3045-
bool bOk = false;
3046-
const uint8 *p = pSample + sample.nLoopEnd * inc;
3047-
int find0 = (int)pSample[sample.nLoopStart*inc];
3048-
int find1 = (int)pSample[sample.nLoopStart*inc+inc];
3049-
// Find Next LoopEnd Point
3050-
if (pos > 0)
3051-
{
3052-
for (i = sample.nLoopEnd + 1; i <= sample.nLength; i++, p += inc)
3053-
{
3054-
bOk = sample.uFlags[CHN_PINGPONGLOOP] ? MPT_BidiEndCheck(p[0], p[inc], p[inc*2]) : MPT_LoopCheck(find0, find1, p[0], p[inc]);
3055-
if (bOk) break;
3056-
}
3057-
} else
3058-
// Find Prev LoopEnd Point
2975+
if(SmpLength i = SampleEdit::FindLoopEnd(sample, false, pos > 0, moveLoop); i > 0)
30592976
{
3060-
for (i = sample.nLoopEnd; i > sample.nLoopStart + 16; )
2977+
if(!m_startedEdit && lastScrollbar != scrollBar)
2978+
PrepareUndo(moveLoop ? "Move Loop" : "Set Loop End");
2979+
if(moveLoop)
30612980
{
3062-
i--;
3063-
p -= inc;
3064-
bOk = sample.uFlags[CHN_PINGPONGLOOP] ? MPT_BidiEndCheck(p[0], p[inc], p[inc*2]) : MPT_LoopCheck(find0, find1, p[0], p[inc]);
3065-
if (bOk) break;
2981+
sample.nLoopStart = i - (sample.nLoopEnd - sample.nLoopStart);
2982+
wsprintf(s, _T("%u"), sample.nLoopStart);
2983+
m_EditLoopStart.SetWindowText(s);
30662984
}
3067-
}
3068-
if (bOk)
3069-
{
3070-
if(!m_startedEdit && lastScrollbar != scrollBar) PrepareUndo("Set Loop End");
30712985
sample.nLoopEnd = i;
30722986
wsprintf(s, _T("%u"), sample.nLoopEnd);
30732987
m_EditLoopEnd.SetWindowText(s);
@@ -3077,35 +2991,18 @@ void CCtrlSamples::OnVScroll(UINT nCode, UINT, CScrollBar *scrollBar)
30772991
m_SpinLoopEnd.SetPos(0);
30782992
}
30792993
// Sustain Loop Start
3080-
if ((pos = m_SpinSustainStart.GetPos32()) != 0 && sample.nSustainEnd > 0)
2994+
if(int pos = m_SpinSustainStart.GetPos32(); pos != 0 && sample.nSustainEnd > 0 && sample.HasSampleData())
30812995
{
3082-
bool bOk = false;
3083-
const uint8 *p = pSample + sample.nSustainStart * inc;
3084-
int find0 = (int)pSample[sample.nSustainEnd*inc-inc];
3085-
int find1 = (int)pSample[sample.nSustainEnd*inc];
3086-
// Find Next Sustain LoopStart Point
3087-
if (pos > 0)
3088-
{
3089-
for (i = sample.nSustainStart + 1; i + 16 < sample.nSustainEnd; i++)
3090-
{
3091-
p += inc;
3092-
bOk = sample.uFlags[CHN_PINGPONGSUSTAIN] ? MPT_BidiStartCheck(p[0], p[inc], p[inc*2]) : MPT_LoopCheck(find0, find1, p[0], p[inc]);
3093-
if (bOk) break;
3094-
}
3095-
} else
3096-
// Find Prev Sustain LoopStart Point
2996+
if(SmpLength i = SampleEdit::FindLoopStart(sample, true, pos > 0, moveLoop); i < sample.nLength)
30972997
{
3098-
for (i = sample.nSustainStart; i; )
2998+
if(!m_startedEdit && lastScrollbar != scrollBar)
2999+
PrepareUndo(moveLoop ? "Move Sustain Loop" : "Set Sustain Loop Start");
3000+
if(moveLoop)
30993001
{
3100-
i--;
3101-
p -= inc;
3102-
bOk = sample.uFlags[CHN_PINGPONGSUSTAIN] ? MPT_BidiStartCheck(p[0], p[inc], p[inc*2]) : MPT_LoopCheck(find0, find1, p[0], p[inc]);
3103-
if (bOk) break;
3002+
sample.nSustainEnd = i + (sample.nSustainEnd - sample.nSustainStart);
3003+
wsprintf(s, _T("%u"), sample.nSustainEnd);
3004+
m_EditSustainEnd.SetWindowText(s);
31043005
}
3105-
}
3106-
if (bOk)
3107-
{
3108-
if(!m_startedEdit && lastScrollbar != scrollBar) PrepareUndo("Set Sustain Loop Start");
31093006
sample.nSustainStart = i;
31103007
wsprintf(s, _T("%u"), sample.nSustainStart);
31113008
m_EditSustainStart.SetWindowText(s);
@@ -3115,34 +3012,18 @@ void CCtrlSamples::OnVScroll(UINT nCode, UINT, CScrollBar *scrollBar)
31153012
m_SpinSustainStart.SetPos(0);
31163013
}
31173014
// Sustain Loop End
3118-
if ((pos = m_SpinSustainEnd.GetPos32()) != 0)
3015+
if(int pos = m_SpinSustainEnd.GetPos32(); pos != 0 && sample.HasSampleData())
31193016
{
3120-
bool bOk = false;
3121-
const uint8 *p = pSample + sample.nSustainEnd * inc;
3122-
int find0 = (int)pSample[sample.nSustainStart*inc];
3123-
int find1 = (int)pSample[sample.nSustainStart*inc+inc];
3124-
// Find Next LoopEnd Point
3125-
if (pos > 0)
3126-
{
3127-
for (i = sample.nSustainEnd + 1; i + 1 < sample.nLength; i++, p += inc)
3128-
{
3129-
bOk = sample.uFlags[CHN_PINGPONGSUSTAIN] ? MPT_BidiEndCheck(p[0], p[inc], p[inc*2]) : MPT_LoopCheck(find0, find1, p[0], p[inc]);
3130-
if (bOk) break;
3131-
}
3132-
} else
3133-
// Find Prev LoopEnd Point
3017+
if(SmpLength i = SampleEdit::FindLoopEnd(sample, true, pos > 0, moveLoop); i > 0)
31343018
{
3135-
for (i = sample.nSustainEnd; i > sample.nSustainStart + 16; )
3019+
if(!m_startedEdit && lastScrollbar != scrollBar)
3020+
PrepareUndo(moveLoop ? "Move Sustain Loop" : "Set Sustain Loop End");
3021+
if(moveLoop)
31363022
{
3137-
i--;
3138-
p -= inc;
3139-
bOk = sample.uFlags[CHN_PINGPONGSUSTAIN] ? MPT_BidiEndCheck(p[0], p[inc], p[inc*2]) : MPT_LoopCheck(find0, find1, p[0], p[inc]);
3140-
if (bOk) break;
3023+
sample.nSustainStart = i - (sample.nSustainEnd - sample.nSustainStart);
3024+
wsprintf(s, _T("%u"), sample.nSustainStart);
3025+
m_EditSustainStart.SetWindowText(s);
31413026
}
3142-
}
3143-
if (bOk)
3144-
{
3145-
if(!m_startedEdit && lastScrollbar != scrollBar) PrepareUndo("Set Sustain Loop End");
31463027
sample.nSustainEnd = i;
31473028
wsprintf(s, _T("%u"), sample.nSustainEnd);
31483029
m_EditSustainEnd.SetWindowText(s);
@@ -3151,9 +3032,8 @@ void CCtrlSamples::OnVScroll(UINT nCode, UINT, CScrollBar *scrollBar)
31513032
}
31523033
m_SpinSustainEnd.SetPos(0);
31533034
}
3154-
NoSample:
31553035
// FineTune / C-5 Speed
3156-
if ((pos = m_SpinFineTune.GetPos32()) != 0)
3036+
if(int pos = m_SpinFineTune.GetPos32(); pos != 0)
31573037
{
31583038
if(!m_startedEdit && lastScrollbar != scrollBar)
31593039
PrepareUndo("Finetune");
@@ -3366,8 +3246,7 @@ void CCtrlSamples::OnXFade()
33663246
CSampleXFadeDlg dlg(this, sample);
33673247
if(dlg.DoModal() == IDOK)
33683248
{
3369-
const SmpLength loopStart = dlg.m_useSustainLoop ? sample.nSustainStart: sample.nLoopStart;
3370-
const SmpLength loopEnd = dlg.m_useSustainLoop ? sample.nSustainEnd: sample.nLoopEnd;
3249+
const auto [loopStart, loopEnd] = dlg.m_useSustainLoop ? sample.GetSustainLoop() : sample.GetLoop();
33713250
const SmpLength maxSamples = std::min({ sample.nLength, loopStart, loopEnd / 2 });
33723251
SmpLength fadeSamples = dlg.PercentToSamples(dlg.m_fadeLength);
33733252
LimitMax(fadeSamples, maxSamples);

mptrack/View_smp.cpp

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,9 +1857,11 @@ void CViewSample::OnMouseMove(UINT flags, CPoint point)
18571857
m_startDragValue = ScreenToSample(point.x);
18581858
}
18591859

1860+
const bool moveLoop = (flags & MK_CONTROL);
18601861
bool update = false;
18611862
SmpLength *updateLoopPoint = nullptr;
18621863
const char *updateLoopDesc = nullptr;
1864+
SmpLength loopLength = 0;
18631865
switch(m_dragItem)
18641866
{
18651867
case HitTestItem::SelectionStart:
@@ -1872,28 +1874,50 @@ void CViewSample::OnMouseMove(UINT flags, CPoint point)
18721874
}
18731875
break;
18741876
case HitTestItem::LoopStart:
1875-
if(x < sample.nLoopEnd)
1877+
if(moveLoop)
1878+
{
1879+
updateLoopPoint = &sample.nLoopStart;
1880+
updateLoopDesc = "Move Loop";
1881+
loopLength = sample.nLoopEnd - sample.nLoopStart;
1882+
} else if(x < sample.nLoopEnd)
18761883
{
18771884
updateLoopPoint = &sample.nLoopStart;
18781885
updateLoopDesc = "Set Loop Start";
18791886
}
18801887
break;
18811888
case HitTestItem::LoopEnd:
1882-
if(x > sample.nLoopStart)
1889+
if(moveLoop)
1890+
{
1891+
updateLoopPoint = &sample.nLoopStart;
1892+
updateLoopDesc = "Move Loop";
1893+
loopLength = sample.nLoopEnd - sample.nLoopStart;
1894+
x = (x > loopLength) ? x - loopLength : 0;
1895+
} else if(x > sample.nLoopStart)
18831896
{
18841897
updateLoopPoint = &sample.nLoopEnd;
18851898
updateLoopDesc = "Set Loop End";
18861899
}
18871900
break;
18881901
case HitTestItem::SustainStart:
1889-
if(x < sample.nSustainEnd)
1902+
if(moveLoop)
1903+
{
1904+
updateLoopPoint = &sample.nSustainStart;
1905+
updateLoopDesc = "Move Sustain Loop";
1906+
loopLength = sample.nSustainEnd - sample.nSustainStart;
1907+
} else if(x < sample.nSustainEnd)
18901908
{
18911909
updateLoopPoint = &sample.nSustainStart;
18921910
updateLoopDesc = "Set Sustain Start";
18931911
}
18941912
break;
18951913
case HitTestItem::SustainEnd:
1896-
if(x > sample.nSustainStart)
1914+
if(moveLoop)
1915+
{
1916+
updateLoopPoint = &sample.nSustainStart;
1917+
updateLoopDesc = "Move Loop";
1918+
loopLength = sample.nSustainEnd - sample.nSustainStart;
1919+
x = (x > loopLength) ? x - loopLength : 0;
1920+
} else if(x > sample.nSustainStart)
18971921
{
18981922
updateLoopPoint = &sample.nSustainEnd;
18991923
updateLoopDesc = "Set Sustain End";
@@ -1909,13 +1933,20 @@ void CViewSample::OnMouseMove(UINT flags, CPoint point)
19091933
break;
19101934
}
19111935

1936+
if(loopLength)
1937+
LimitMax(x, sample.nLength - loopLength);
1938+
19121939
if(updateLoopPoint && updateLoopDesc && *updateLoopPoint != x)
19131940
{
19141941
if(!m_dragPreparedUndo)
19151942
pModDoc->GetSampleUndo().PrepareUndo(m_nSample, sundo_none, updateLoopDesc);
19161943
m_dragPreparedUndo = true;
19171944
update = true;
19181945
*updateLoopPoint = x;
1946+
if(loopLength && updateLoopPoint == &sample.nLoopStart)
1947+
sample.nLoopEnd = sample.nLoopStart + loopLength;
1948+
else if(loopLength && updateLoopPoint == &sample.nSustainStart)
1949+
sample.nSustainEnd = sample.nSustainStart + loopLength;
19191950
sample.PrecomputeLoops(sndFile, true);
19201951
SetModified(SampleHint().Info(), true, false);
19211952
}
@@ -2050,7 +2081,7 @@ void CViewSample::OnLButtonDown(UINT flags, CPoint point)
20502081
} else
20512082
{
20522083
// ctrl + click = play from cursor pos
2053-
if(flags & MK_CONTROL)
2084+
if((flags & MK_CONTROL) && point.y >= m_timelineHeight)
20542085
PlayNote(NOTE_MIDDLEC, ScreenToSample(point.x));
20552086
}
20562087
}

soundlib/Load_mo3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ bool CSoundFile::ReadMO3(FileReader &file, ModLoadingFlags loadFlags)
10161016
CMD_PORTAMENTOUP, CMD_TREMOR, CMD_RETRIG, CMD_FINEVIBRATO,
10171017
CMD_CHANNELVOLUME, CMD_CHANNELVOLSLIDE, CMD_PANNINGSLIDE, CMD_S3MCMDEX,
10181018
CMD_TEMPO, CMD_GLOBALVOLSLIDE, CMD_PANBRELLO, CMD_MIDI,
1019-
CMD_NONE,/*FineVolSld*/ CMD_NONE,/*PortaDown*/ CMD_NONE, /*PortaUp*/ CMD_NONE,
1019+
CMD_NONE,/*FineVolSld*/ CMD_NONE,/*PortaDown*/ CMD_NONE, /*PortaUp*/ CMD_DUMMY,
10201020
CMD_NONE,/*ITVolCol*/ CMD_XPARAM, CMD_SMOOTHMIDI, CMD_DELAYCUT,
10211021
CMD_FINETUNE, CMD_FINETUNE_SMOOTH,
10221022
};

soundlib/ModSample.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ struct ModSample
144144
void SetLoop(SmpLength start, SmpLength end, bool enable, bool pingpong, CSoundFile &sndFile);
145145
// Set sustain loop points and update loop wrap-around buffer
146146
void SetSustainLoop(SmpLength start, SmpLength end, bool enable, bool pingpong, CSoundFile &sndFile);
147+
// Retrieve the normal loop points
148+
std::pair<SmpLength, SmpLength> GetLoop() const noexcept { return std::make_pair(nLoopStart, nLoopEnd); }
149+
// Retrieve the sustain loop points
150+
std::pair<SmpLength, SmpLength> GetSustainLoop() const noexcept { return std::make_pair(nSustainStart, nSustainEnd); }
147151
// Update loop wrap-around buffer
148152
void PrecomputeLoops(CSoundFile &sndFile, bool updateChannels = true);
149153

soundlib/modsmp_ctrl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,7 @@ static void XFadeSampleImpl(const T *srcIn, const T *srcOut, T *output, const Sm
177177
bool XFadeSample(ModSample &smp, SmpLength fadeLength, int fadeLaw, bool afterloopFade, bool useSustainLoop, CSoundFile &sndFile)
178178
{
179179
if(!smp.HasSampleData()) return false;
180-
const SmpLength loopStart = useSustainLoop ? smp.nSustainStart : smp.nLoopStart;
181-
const SmpLength loopEnd = useSustainLoop ? smp.nSustainEnd : smp.nLoopEnd;
180+
const auto [loopStart, loopEnd] = useSustainLoop ? smp.GetSustainLoop() : smp.GetLoop();
182181

183182
if(loopEnd <= loopStart || loopEnd > smp.nLength) return false;
184183
if(loopStart < fadeLength) return false;

0 commit comments

Comments
 (0)