Audacity 3.2.0
Functions
WaveClipUIUtilities Namespace Reference

Functions

AUDACITY_DLL_API void findCorrection (const std::vector< sampleCount > &oldWhere, size_t oldLen, size_t newLen, double t0, double sampleRate, double stretchRatio, double samplesPerPixel, int &oldX0, double &correction)
 
AUDACITY_DLL_API void fillWhere (std::vector< sampleCount > &where, size_t len, bool addBias, double correction, double t0, double sampleRate, double stretchRatio, double samplesPerPixel)
 
std::vector< CommonTrackPanelCell::MenuItemGetWaveClipMenuItems ()
 
void PushClipSpeedChangedUndoState (AudacityProject &project, double speedInPercent)
 
void SelectClip (AudacityProject &project, const WaveTrack::Interval &clip)
 

Function Documentation

◆ fillWhere()

void WaveClipUIUtilities::fillWhere ( std::vector< sampleCount > &  where,
size_t  len,
bool  addBias,
double  correction,
double  t0,
double  sampleRate,
double  stretchRatio,
double  samplesPerPixel 
)

Definition at line 66 of file WaveClipUIUtilities.cpp.

69{
70 // Be careful to make the first value non-negative
71 const auto bias = addBias ? .5 : 0.;
72 const double w0 = 0.5 + correction + bias + t0 * sampleRate / stretchRatio;
73 where[0] = sampleCount(std::max(0.0, floor(w0)));
74 for (decltype(len) x = 1; x < len + 1; x++)
75 where[x] = sampleCount(floor(w0 + double(x) * samplesPerPixel));
76}
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19

References anonymous_namespace{ClipSegmentTest.cpp}::sampleRate.

Referenced by WaveClipSpectrumCache::GetSpectrogram().

Here is the caller graph for this function:

◆ findCorrection()

void WaveClipUIUtilities::findCorrection ( const std::vector< sampleCount > &  oldWhere,
size_t  oldLen,
size_t  newLen,
double  t0,
double  sampleRate,
double  stretchRatio,
double  samplesPerPixel,
int &  oldX0,
double &  correction 
)

Definition at line 23 of file WaveClipUIUtilities.cpp.

27{
28 // Mitigate the accumulation of location errors
29 // in copies of copies of ... of caches.
30 // Look at the loop that populates "where" below to understand this.
31
32 // Find the sample position that is the origin in the old cache.
33 const double oldWhere0 = oldWhere[1].as_double() - samplesPerPixel;
34 const double oldWhereLast = oldWhere0 + oldLen * samplesPerPixel;
35 // Find the length in samples of the old cache.
36 const double denom = oldWhereLast - oldWhere0;
37
38 // What sample would go in where[0] with no correction?
39 const double guessWhere0 = t0 * sampleRate / stretchRatio;
40
41 if ( // Skip if old and NEW are disjoint:
42 oldWhereLast <= guessWhere0 ||
43 guessWhere0 + newLen * samplesPerPixel <= oldWhere0 ||
44 // Skip unless denom rounds off to at least 1.
45 denom < 0.5)
46 {
47 // The computation of oldX0 in the other branch
48 // may underflow and the assertion would be violated.
49 oldX0 = oldLen;
50 correction = 0.0;
51 }
52 else
53 {
54 // What integer position in the old cache array does that map to?
55 // (even if it is out of bounds)
56 oldX0 = floor(0.5 + oldLen * (guessWhere0 - oldWhere0) / denom);
57 // What sample count would the old cache have put there?
58 const double where0 = oldWhere0 + double(oldX0) * samplesPerPixel;
59 // What correction is needed to align the NEW cache with the old?
60 const double correction0 = where0 - guessWhere0;
61 correction = std::clamp(correction0, -samplesPerPixel, samplesPerPixel);
62 assert(correction == correction0);
63 }
64}

References anonymous_namespace{ClipSegmentTest.cpp}::sampleRate.

Referenced by WaveClipSpectrumCache::GetSpectrogram().

Here is the caller graph for this function:

◆ GetWaveClipMenuItems()

std::vector< CommonTrackPanelCell::MenuItem > WaveClipUIUtilities::GetWaveClipMenuItems ( )

Definition at line 79 of file WaveClipUIUtilities.cpp.

80{
81 return {
82 { L"Cut", XO("Cut") },
83 { L"Copy", XO("Copy") },
84 { L"Paste", XO("Paste") },
85 {},
86 { L"Split", XO("Split Clip") },
87 { L"Join", XO("Join Clips") },
88 { L"TrackMute", XO("Mute/Unmute Track") },
89 {},
90 { L"RenameClip", XO("Rename Clip...") },
91 { L"ChangePitchAndSpeed", XO("Pitch and Speed...") },
92 { L"RenderPitchAndSpeed", XO("Render Pitch and Speed") },
93 };
94 ;
95}
XO("Cut/Copy/Paste")

References XO().

Referenced by WaveChannelSubView::GetMenuItems(), and WaveTrackAffordanceControls::GetMenuItems().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PushClipSpeedChangedUndoState()

void WaveClipUIUtilities::PushClipSpeedChangedUndoState ( AudacityProject project,
double  speedInPercent 
)

Definition at line 97 of file WaveClipUIUtilities.cpp.

99{
101 /* i18n-hint: This is about changing the clip playback speed, speed is in
102 percent */
103 XO("Changed Clip Speed to %.01f%%").Format(speedInPercent),
104 /* i18n-hint: This is about changing the clip playback speed, speed is in
105 percent */
106 XO("Changed Speed to %.01f%%").Format(speedInPercent),
108}
const auto project
Abstract base class used in importing a file.
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)

References CONSOLIDATE, ProjectHistory::Get(), project, ProjectHistory::PushState(), and XO().

Referenced by AdjustClipBorder::Finish().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SelectClip()

void WaveClipUIUtilities::SelectClip ( AudacityProject project,
const WaveTrack::Interval clip 
)

Definition at line 110 of file WaveClipUIUtilities.cpp.

112{
113 auto& viewInfo = ViewInfo::Get(project);
114 viewInfo.selectedRegion.setTimes(
115 clip.GetPlayStartTime(), clip.GetPlayEndTime());
116}
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
double GetPlayStartTime() const noexcept override
Definition: WaveClip.cpp:1762
double GetPlayEndTime() const override
Definition: WaveClip.cpp:1772

References ViewInfo::Get(), WaveClip::GetPlayEndTime(), WaveClip::GetPlayStartTime(), and project.

Referenced by ClipPitchAndSpeedButtonHandle::DoRelease(), WaveTrackAffordanceControls::OnRenderClipStretching(), and PitchAndSpeedDialog::SetClipSpeed().

Here is the call graph for this function:
Here is the caller graph for this function: