Audacity 3.2.0
Functions
WaveClipUtilities.cpp File Reference
#include "WaveClipUtilities.h"
#include "SampleCount.h"
#include <algorithm>
#include <cassert>
#include <cmath>
#include "PitchAndSpeedDialog.h"
#include "ProjectAudioIO.h"
#include "ProjectHistory.h"
#include "ProjectWindows.h"
#include "UndoManager.h"
#include "ViewInfo.h"
#include "WaveTrack.h"
Include dependency graph for WaveClipUtilities.cpp:

Go to the source code of this file.

Functions

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)
 
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 ShowClipPitchAndSpeedDialog (AudacityProject &project, WaveTrack &track, WaveTrack::Interval &interval, std::optional< PitchAndSpeedDialogFocus > focus)
 

Function Documentation

◆ fillWhere()

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

Definition at line 69 of file WaveClipUtilities.cpp.

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

References anonymous_namespace{ClipSegmentTest.cpp}::sampleRate.

Referenced by WaveClipSpectrumCache::GetSpectrogram(), and WaveClipWaveformCache::GetWaveDisplay().

Here is the caller graph for this function:

◆ findCorrection()

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 
)

Definition at line 26 of file WaveClipUtilities.cpp.

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

References anonymous_namespace{ClipSegmentTest.cpp}::sampleRate.

Referenced by WaveClipSpectrumCache::GetSpectrogram(), and WaveClipWaveformCache::GetWaveDisplay().

Here is the caller graph for this function:

◆ GetWaveClipMenuItems()

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

Definition at line 81 of file WaveClipUtilities.cpp.

82{
83 return {
84 { L"Cut", XO("Cut") },
85 { L"Copy", XO("Copy") },
86 { L"Paste", XO("Paste") },
87 {},
88 { L"Split", XO("Split Clip") },
89 { L"Join", XO("Join Clips") },
90 { L"TrackMute", XO("Mute/Unmute Track") },
91 {},
92 { L"RenameClip", XO("Rename Clip...") },
93 { L"ChangePitchAndSpeed", XO("Pitch and Speed...") },
94 { L"RenderPitchAndSpeed", XO("Render Pitch and Speed") },
95 };
96 ;
97}
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 PushClipSpeedChangedUndoState ( AudacityProject project,
double  speedInPercent 
)

Definition at line 99 of file WaveClipUtilities.cpp.

101{
103 /* i18n-hint: This is about changing the clip playback speed, speed is in
104 percent */
105 XO("Changed Clip Speed to %.01f%%").Format(speedInPercent),
106 /* i18n-hint: This is about changing the clip playback speed, speed is in
107 percent */
108 XO("Changed Speed to %.01f%%").Format(speedInPercent),
110}
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:

◆ ShowClipPitchAndSpeedDialog()

void ShowClipPitchAndSpeedDialog ( AudacityProject project,
WaveTrack track,
WaveTrack::Interval interval,
std::optional< PitchAndSpeedDialogFocus focus 
)

Definition at line 112 of file WaveClipUtilities.cpp.

115{
117 ProjectAudioIO::Get(project).IsAudioActive(), track, interval,
118 &GetProjectFrame(project), focus);
119 if (wxID_OK == dlg.ShowModal())
121 XO("Changed Pitch and Speed"), XO("Changed Pitch and Speed"),
123}
AUDACITY_DLL_API wxFrame & GetProjectFrame(AudacityProject &project)
Get the top-level window associated with the project (as a wxFrame only, when you do not need to use ...
static ProjectAudioIO & Get(AudacityProject &project)

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

Referenced by WaveTrackAffordanceControls::StartEditSelectedClipSpeed().

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