Skip to content

Commit

Permalink
Preserve clip selection when changing speed
Browse files Browse the repository at this point in the history
  • Loading branch information
saintmatthieu committed Mar 26, 2024
1 parent 8111a9e commit f3116d6
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/tracks/playabletrack/wavetrack/ui/PitchAndSpeedDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ GetHitClip(AudacityProject& project, const TrackPanelMouseEvent& event)
return {};
}

bool IsExactlySelected(AudacityProject& project, const ClipTimes& clip)
{
auto& viewInfo = ViewInfo::Get(project);
return clip.GetPlayStartTime() == viewInfo.selectedRegion.t0() &&
clip.GetPlayEndTime() == viewInfo.selectedRegion.t1();
}

PitchAndSpeedDialog::PitchShift ToSemitonesAndCents(int oldCents, int newCents)
{
// Rules:
Expand Down Expand Up @@ -385,10 +392,16 @@ bool PitchAndSpeedDialog::SetClipSpeed()
if (!target)
return false;

const auto wasExactlySelected =
IsExactlySelected(mProject, *mLeftClip.lock());

if (!WaveTrackUtilities::SetClipStretchRatio(
*target->track, target->clip, 100 / mClipSpeed))
return false;

if (wasExactlySelected)
WaveClipUtilities::SelectClip(mProject, target->clip);

UpdateHistory(XO("Changed Speed"));

return true;
Expand Down

0 comments on commit f3116d6

Please sign in to comment.