mirror of
https://github.com/cookiengineer/audacity
synced 2025-09-19 09:30:52 +02:00
Bug1688: MIDI stretch when select time extends beyond track end...
... The cursor may be the center or the right depending where you pick; both those cases needed fixing.
This commit is contained in:
parent
f2deb1cc43
commit
e86fd3c990
@ -96,11 +96,15 @@ UIHandlePtr StretchHandle::HitTest
|
|||||||
static const double minPeriod = 0.05; // minimum beat period
|
static const double minPeriod = 0.05; // minimum beat period
|
||||||
stretchState.mBeatCenter = { 0, 0 };
|
stretchState.mBeatCenter = { 0, 0 };
|
||||||
|
|
||||||
auto t0 = viewInfo.selectedRegion.t0();
|
auto t0 = GetT0(*pTrack, viewInfo);
|
||||||
|
auto t1 = GetT1(*pTrack, viewInfo);
|
||||||
|
|
||||||
|
if (t0 >= t1)
|
||||||
|
return {};
|
||||||
|
|
||||||
stretchState.mBeat0 = pTrack->NearestBeatTime( t0 );
|
stretchState.mBeat0 = pTrack->NearestBeatTime( t0 );
|
||||||
stretchState.mOrigSel0Quantized = stretchState.mBeat0.first;
|
stretchState.mOrigSel0Quantized = stretchState.mBeat0.first;
|
||||||
|
|
||||||
auto t1 = viewInfo.selectedRegion.t1();
|
|
||||||
stretchState.mBeat1 = pTrack->NearestBeatTime( t1 );
|
stretchState.mBeat1 = pTrack->NearestBeatTime( t1 );
|
||||||
stretchState.mOrigSel1Quantized = stretchState.mBeat1.first;
|
stretchState.mOrigSel1Quantized = stretchState.mBeat1.first;
|
||||||
|
|
||||||
@ -114,6 +118,7 @@ UIHandlePtr StretchHandle::HitTest
|
|||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto selStart = viewInfo.PositionToTime( state.m_x, rect.x );
|
auto selStart = viewInfo.PositionToTime( state.m_x, rect.x );
|
||||||
|
selStart = std::max(t0, std::min(t1, selStart));
|
||||||
stretchState.mBeatCenter = pTrack->NearestBeatTime( selStart );
|
stretchState.mBeatCenter = pTrack->NearestBeatTime( selStart );
|
||||||
bool startNewSelection = true;
|
bool startNewSelection = true;
|
||||||
if ( within( stretchState.mBeat0.second,
|
if ( within( stretchState.mBeat0.second,
|
||||||
@ -262,6 +267,16 @@ UIHandle::Result StretchHandle::Cancel(AudacityProject *pProject)
|
|||||||
return RefreshCode::RefreshNone;
|
return RefreshCode::RefreshNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double StretchHandle::GetT0(const Track &track, const ViewInfo &viewInfo)
|
||||||
|
{
|
||||||
|
return std::max(track.GetStartTime(), viewInfo.selectedRegion.t0());
|
||||||
|
}
|
||||||
|
|
||||||
|
double StretchHandle::GetT1(const Track &track, const ViewInfo &viewInfo)
|
||||||
|
{
|
||||||
|
return std::min(track.GetEndTime(), viewInfo.selectedRegion.t1());
|
||||||
|
}
|
||||||
|
|
||||||
void StretchHandle::Stretch(AudacityProject *pProject, int mouseXCoordinate, int trackLeftEdge,
|
void StretchHandle::Stretch(AudacityProject *pProject, int mouseXCoordinate, int trackLeftEdge,
|
||||||
Track *pTrack)
|
Track *pTrack)
|
||||||
{
|
{
|
||||||
@ -279,8 +294,6 @@ void StretchHandle::Stretch(AudacityProject *pProject, int mouseXCoordinate, int
|
|||||||
double moveto =
|
double moveto =
|
||||||
std::max(0.0, viewInfo.PositionToTime(mouseXCoordinate, trackLeftEdge));
|
std::max(0.0, viewInfo.PositionToTime(mouseXCoordinate, trackLeftEdge));
|
||||||
|
|
||||||
auto t1 = viewInfo.selectedRegion.t1();
|
|
||||||
auto t0 = viewInfo.selectedRegion.t0();
|
|
||||||
double dur, left_dur, right_dur;
|
double dur, left_dur, right_dur;
|
||||||
|
|
||||||
// check to make sure tempo is not higher than 20 beats per second
|
// check to make sure tempo is not higher than 20 beats per second
|
||||||
@ -291,6 +304,8 @@ void StretchHandle::Stretch(AudacityProject *pProject, int mouseXCoordinate, int
|
|||||||
// Take quick exit if so, without changing the selection.
|
// Take quick exit if so, without changing the selection.
|
||||||
switch ( mStretchState.mMode ) {
|
switch ( mStretchState.mMode ) {
|
||||||
case stretchLeft: {
|
case stretchLeft: {
|
||||||
|
auto t0 = viewInfo.selectedRegion.t0();
|
||||||
|
auto t1 = viewInfo.selectedRegion.t1();
|
||||||
dur = t1 - moveto;
|
dur = t1 - moveto;
|
||||||
if (dur < mStretchState.mRightBeats * minPeriod)
|
if (dur < mStretchState.mRightBeats * minPeriod)
|
||||||
return;
|
return;
|
||||||
@ -302,6 +317,8 @@ void StretchHandle::Stretch(AudacityProject *pProject, int mouseXCoordinate, int
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case stretchRight: {
|
case stretchRight: {
|
||||||
|
auto t0 = viewInfo.selectedRegion.t0();
|
||||||
|
auto t1 = viewInfo.selectedRegion.t1();
|
||||||
dur = moveto - t0;
|
dur = moveto - t0;
|
||||||
if (dur < mStretchState.mLeftBeats * minPeriod)
|
if (dur < mStretchState.mLeftBeats * minPeriod)
|
||||||
return;
|
return;
|
||||||
@ -309,10 +326,12 @@ void StretchHandle::Stretch(AudacityProject *pProject, int mouseXCoordinate, int
|
|||||||
( mStretchState.mBeat0, mStretchState.mBeat1, dur );
|
( mStretchState.mBeat0, mStretchState.mBeat1, dur );
|
||||||
viewInfo.selectedRegion.setT1(moveto);
|
viewInfo.selectedRegion.setT1(moveto);
|
||||||
mStretchState.mBeat1.first = moveto;
|
mStretchState.mBeat1.first = moveto;
|
||||||
viewInfo.selectedRegion.setT0(moveto);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case stretchCenter: {
|
case stretchCenter: {
|
||||||
|
auto t0 = GetT0(*mpTrack, viewInfo);
|
||||||
|
auto t1 = GetT1(*mpTrack, viewInfo);
|
||||||
|
moveto = std::max(t0, std::min(t1, moveto));
|
||||||
left_dur = moveto - t0;
|
left_dur = moveto - t0;
|
||||||
right_dur = t1 - moveto;
|
right_dur = t1 - moveto;
|
||||||
if ( left_dur < mStretchState.mLeftBeats * minPeriod ||
|
if ( left_dur < mStretchState.mLeftBeats * minPeriod ||
|
||||||
|
@ -90,6 +90,9 @@ public:
|
|||||||
bool StopsOnKeystroke() override { return true; }
|
bool StopsOnKeystroke() override { return true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static double GetT0(const Track &track, const ViewInfo &viewInfo);
|
||||||
|
static double GetT1(const Track &track, const ViewInfo &viewInfo);
|
||||||
|
|
||||||
void Stretch
|
void Stretch
|
||||||
(AudacityProject *pProject, int mouseXCoordinate, int trackLeftEdge, Track *pTrack);
|
(AudacityProject *pProject, int mouseXCoordinate, int trackLeftEdge, Track *pTrack);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user