Audacity 3.2.0
TimeStretching.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 TimeStretching.cpp
7
8 Paul Licameli
9
10**********************************************************************/
11#include "TimeStretching.h"
12#include "BasicUI.h"
13#include "SampleBlock.h"
14#include "Sequence.h"
15#include "TempoChange.h"
16#include "UserException.h"
17#include "WaveClip.h"
18#include <algorithm>
19
21 XO("Pre-processing");
22
24 const WaveTrack &track, double t0, double t1)
25{
26 auto clips = track.Intervals();
27 return std::any_of(clips.begin(), clips.end(), [&](auto pClip) {
28 return pClip->IntersectsPlayRegion(t0, t1) && pClip->HasPitchOrSpeed();
29 });
30}
31
33 std::function<void(const ProgressReporter&)> action,
35{
37 std::move(title), XO("Rendering Clip"));
38}
39
41 const WaveTrack& track, WaveTrack::Interval& interval, double stretchRatio)
42{
43 const auto nextClip =
45 const auto maxEndTime = nextClip != nullptr ?
46 nextClip->Start() :
47 std::numeric_limits<double>::infinity();
48
49 const auto start = interval.Start();
50 const auto end = interval.End();
51
52 const auto expectedEndTime =
53 start + (end - start) * stretchRatio / interval.GetStretchRatio();
54
55 if (expectedEndTime > maxEndTime)
56 return false;
57
58 interval.StretchRightTo(expectedEndTime);
59 return true;
60}
61
64 return [](WaveTrack &track,
65 const std::optional<double> &oldTempo, double newTempo)
66 {
67 for (const auto pClip : track.Intervals())
68 pClip->OnProjectTempoChange(oldTempo, newTempo);
69 };
70}
Toolkit-neutral facade for basic user interface services.
XO("Cut/Copy/Paste")
static const auto title
DEFINE_ATTACHED_VIRTUAL_OVERRIDE(OnWaveTrackProjectTempoChange)
std::function< void(double)> ProgressReporter
Definition: Track.h:48
An AudacityException with no visible message.
Holds a msgid for the translation catalog; may also bind format arguments.
static void WithCancellableProgress(std::function< void(const ProgressReporter &)> action, TranslatableString title, TranslatableString message)
A frequently useful convenience wraps a lambda and may throw this type.
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:238
double GetStretchRatio() const override
Definition: WaveClip.cpp:625
double Start() const override
Definition: WaveClip.cpp:340
double End() const override
Definition: WaveClip.cpp:345
void StretchRightTo(double to)
Sets from the right to the absolute time (if in expected range)
Definition: WaveClip.cpp:588
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
IntervalConstHolder GetNextInterval(const Interval &interval, PlaybackDirection searchDirection) const
Definition: WaveTrack.cpp:173
auto Intervals()
Definition: WaveTrack.h:671
WAVE_TRACK_API const TranslatableString defaultStretchRenderingTitle
WAVE_TRACK_API void WithClipRenderingProgress(std::function< void(const ProgressReporter &)> action, TranslatableString title=defaultStretchRenderingTitle)
WAVE_TRACK_API bool SetClipStretchRatio(const WaveTrack &track, WaveTrack::Interval &interval, double stretchRatio)
WAVE_TRACK_API bool HasPitchOrSpeed(const WaveTrack &track, double t0, double t1)
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
For defining overrides of the method.