Audacity 3.2.0
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
WaveClip Class Referencefinal

This allows multiple clips to be a part of one WaveTrack. More...

#include <WaveClip.h>

Inheritance diagram for WaveClip:
[legend]
Collaboration diagram for WaveClip:
[legend]

Classes

struct  Transaction
 Restores state when an update loop over mSequences fails midway. More...
 

Public Types

using Caches = Site< WaveClip, WaveClipListener >
 
- Public Types inherited from ClientData::Site< WaveClip, WaveClipListener >
using DataType = WaveClipListener
 
using DataPointer = UniquePtr< WaveClipListener >
 
using DataFactory = std::function< DataPointer(WaveClip &) >
 Type of function from which RegisteredFactory is constructed; it builds attachments. More...
 
- Public Types inherited from Observer::Publisher< CentShiftChange >
using message_type = CentShiftChange
 
using CallbackReturn = std::conditional_t< true, void, bool >
 
using Callback = std::function< CallbackReturn(const CentShiftChange &) >
 Type of functions that can be connected to the Publisher. More...
 
- Public Types inherited from Observer::Publisher< PitchAndSpeedPresetChange >
using message_type = PitchAndSpeedPresetChange
 
using CallbackReturn = std::conditional_t< true, void, bool >
 
using Callback = std::function< CallbackReturn(const PitchAndSpeedPresetChange &) >
 Type of functions that can be connected to the Publisher. More...
 
- Public Types inherited from Observer::Publisher< StretchRatioChange >
using message_type = StretchRatioChange
 
using CallbackReturn = std::conditional_t< true, void, bool >
 
using Callback = std::function< CallbackReturn(const StretchRatioChange &) >
 Type of functions that can be connected to the Publisher. More...
 
- Public Types inherited from Observer::Publisher< WaveClipDtorCalled >
using message_type = WaveClipDtorCalled
 
using CallbackReturn = std::conditional_t< true, void, bool >
 
using Callback = std::function< CallbackReturn(const WaveClipDtorCalled &) >
 Type of functions that can be connected to the Publisher. More...
 

Public Member Functions

 WaveClip (size_t width, const SampleBlockFactoryPtr &factory, sampleFormat format, int rate, int colourIndex)
 typical constructor More...
 
 WaveClip (const WaveClip &orig, const SampleBlockFactoryPtr &factory, bool copyCutlines)
 
 WaveClip (const WaveClip &orig, const SampleBlockFactoryPtr &factory, bool copyCutlines, double t0, double t1)
 Copy only a range from the given WaveClip. More...
 
virtual ~WaveClip ()
 
bool CheckInvariants () const
 Check invariant conditions on mSequences and mCutlines. More...
 
size_t GetWidth () const override
 
void ConvertToSampleFormat (sampleFormat format, const std::function< void(size_t)> &progressReport={})
 
int GetRate () const override
 
void SetRate (int rate)
 
void SetRawAudioTempo (double tempo)
 
void StretchLeftTo (double to)
 Stretches from left to the absolute time (if in expected range) More...
 
void StretchRightTo (double to)
 Sets from the right to the absolute time (if in expected range) More...
 
void StretchBy (double ratio)
 
double GetStretchRatio () const override
 
bool SetCentShift (int cents)
 
int GetCentShift () const override
 
Observer::Subscription SubscribeToCentShiftChange (std::function< void(int)> cb) override
 
void SetPitchAndSpeedPreset (PitchAndSpeedPreset preset)
 
PitchAndSpeedPreset GetPitchAndSpeedPreset () const override
 
Observer::Subscription SubscribeToPitchAndSpeedPresetChange (std::function< void(PitchAndSpeedPreset)> cb) override
 
void Resample (int rate, BasicUI::ProgressDialog *progress=nullptr)
 
void SetColourIndex (int index)
 
int GetColourIndex () const
 
double GetSequenceStartTime () const noexcept
 
void SetSequenceStartTime (double startTime)
 
double GetSequenceEndTime () const
 
sampleCount GetSequenceStartSample () const
 Returns the index of the first sample of the underlying sequence. More...
 
sampleCount GetSequenceSamplesCount () const
 
double GetPlayStartTime () const noexcept override
 
void SetPlayStartTime (double time)
 
double GetPlayEndTime () const override
 
double GetPlayDuration () const
 
bool IsEmpty () const
 
sampleCount GetPlayStartSample () const
 Real start time of the clip, quantized to raw sample rate (track's rate) More...
 
sampleCount GetPlayEndSample () const
 Real end time of the clip, quantized to raw sample rate (track's rate) More...
 
sampleCount GetVisibleSampleCount () const override
 
void SetTrimLeft (double trim)
 Sets the play start offset in seconds from the beginning of the underlying sequence. More...
 
double GetTrimLeft () const noexcept
 Returns the play start offset in seconds from the beginning of the underlying sequence. More...
 
void SetTrimRight (double trim)
 Sets the play end offset in seconds from the ending of the underlying sequence. More...
 
double GetTrimRight () const noexcept
 Returns the play end offset in seconds from the ending of the underlying sequence. More...
 
void TrimLeft (double deltaTime)
 Moves play start position by deltaTime. More...
 
void TrimRight (double deltaTime)
 Moves play end position by deltaTime. More...
 
void TrimQuarternotesFromRight (double quarters)
 Same as TrimRight, but expressed as quarter notes. More...
 
void TrimLeftTo (double to)
 Sets the the left trimming to the absolute time (if that is in bounds) More...
 
void TrimRightTo (double to)
 Sets the the right trimming to the absolute time (if that is in bounds) More...
 
void ShiftBy (double delta) noexcept
 
bool SplitsPlayRegion (double t) const
 [ < t and t < ), such that if the track were split at t, it would split this clip in two of lengths > 0. More...
 
bool WithinPlayRegion (double t) const
 t ∈ [...) More...
 
bool BeforePlayRegion (double t) const
 t < [ More...
 
bool AtOrBeforePlayRegion (double t) const
 t <= [ More...
 
bool AfterPlayRegion (double t) const
 ) <= t More...
 
bool EntirelyWithinPlayRegion (double t0, double t1) const
 t0 and t1 both ∈ [...) More...
 
bool PartlyWithinPlayRegion (double t0, double t1) const
 t0 xor t1 ∈ [...) More...
 
bool IntersectsPlayRegion (double t0, double t1) const
 [t0, t1) ∩ [...) != ∅ More...
 
bool CoversEntirePlayRegion (double t0, double t1) const
 t0 <= [ and ) <= t1, such that removing [t0, t1) from the track deletes this clip. More...
 
sampleCount CountSamples (double t0, double t1) const
 
AudioSegmentSampleView GetSampleView (size_t iChannel, sampleCount start, size_t length, bool mayThrow=true) const override
 Request up to length samples. The actual number of samples available from the returned view is queried through AudioSegmentSampleView::GetSampleCount(). More...
 
AudioSegmentSampleView GetSampleView (size_t iChannel, double t0, double t1, bool mayThrow=true) const
 Request interval samples within [t0, t1). t0 and t1 are truncated to the clip's play start and end. Stretching influences the number of samples fitting into [t0, t1), i.e., half as many for twice as large a stretch ratio, due to a larger spacing of the raw samples. The actual number of samples available from the returned view is queried through AudioSegmentSampleView::GetSampleCount(). More...
 
bool GetSamples (size_t ii, samplePtr buffer, sampleFormat format, sampleCount start, size_t len, bool mayThrow=true) const
 Get samples from one channel. More...
 
bool GetSamples (samplePtr buffers[], sampleFormat format, sampleCount start, size_t len, bool mayThrow=true) const
 Get (non-interleaved) samples from all channels. More...
 
void SetSamples (size_t ii, constSamplePtr buffer, sampleFormat format, sampleCount start, size_t len, sampleFormat effectiveFormat)
 
bool GetFloatAtTime (double t, size_t iChannel, float &value, bool mayThrow) const
 
EnvelopeGetEnvelope ()
 
const EnvelopeGetEnvelope () const
 
void SetEnvelope (std::unique_ptr< Envelope > p)
 
BlockArrayGetSequenceBlockArray (size_t ii)
 
const BlockArrayGetSequenceBlockArray (size_t ii) const
 
SequenceGetSequence (size_t ii)
 
const SequenceGetSequence (size_t ii) const
 
void MarkChanged ()
 
std::pair< float, float > GetMinMax (size_t ii, double t0, double t1, bool mayThrow) const
 
float GetRMS (size_t ii, double t0, double t1, bool mayThrow) const
 
void UpdateEnvelopeTrackLen ()
 
std::shared_ptr< SampleBlockAppendNewBlock (constSamplePtr buffer, sampleFormat format, size_t len)
 
void AppendSharedBlock (const std::shared_ptr< SampleBlock > &pBlock)
 
bool Append (constSamplePtr buffers[], sampleFormat format, size_t len, unsigned int stride, sampleFormat effectiveFormat)
 
void Flush ()
 Flush must be called after last Append. More...
 
void Clear (double t0, double t1)
 
void ClearLeft (double t)
 
void ClearRight (double t)
 
void ClearAndAddCutLine (double t0, double t1)
 
bool Paste (double t0, const WaveClip &other)
 
void InsertSilence (double t, double len, double *pEnvelopeValue=nullptr)
 
void AppendSilence (double len, double envelopeValue)
 
WaveClipHoldersGetCutLines ()
 Get access to cut lines list. More...
 
const WaveClipConstHoldersGetCutLines () const
 
size_t NumCutLines () const
 
bool FindCutLine (double cutLinePosition, double *cutLineStart=NULL, double *cutLineEnd=NULL) const
 
void ExpandCutLine (double cutLinePosition)
 
bool RemoveCutLine (double cutLinePosition)
 Remove cut line, without expanding the audio in it. More...
 
void OffsetCutLines (double t0, double len)
 Offset cutlines right to time 't0' by time amount 'len'. More...
 
void CloseLock () noexcept
 Should be called upon project close. Not balanced by unlocking calls. More...
 
bool HandleXMLTag (const std::string_view &tag, const AttributesList &attrs) override
 
void HandleXMLEndTag (const std::string_view &tag) override
 
XMLTagHandlerHandleXMLChild (const std::string_view &tag) override
 
void WriteXML (XMLWriter &xmlFile) const
 
bool GetIsPlaceholder () const
 
void SetIsPlaceholder (bool val)
 
bool SharesBoundaryWithNextClip (const WaveClip *next) const
 
void SetName (const wxString &name)
 
const wxString & GetName () const
 
sampleCount TimeToSamples (double time) const override
 
double SamplesToTime (sampleCount s) const noexcept
 
void SetSilence (sampleCount offset, sampleCount length)
 Silences the 'length' amount of samples starting from 'offset'(relative to the play start) More...
 
constSamplePtr GetAppendBuffer (size_t ii) const
 Get one channel of the append buffer. More...
 
size_t GetAppendBufferLen () const
 
void OnProjectTempoChange (const std::optional< double > &oldTempo, double newTempo)
 
bool HasEqualPitchAndSpeed (const WaveClip &other) const
 
bool HasPitchOrSpeed () const
 
void SetFloatsFromTime (double t, size_t iChannel, const float *buffer, size_t numSamples, sampleFormat effectiveFormat)
 Considers buffer as audio starting at TimeToSamples(t) (relative to clip play start time) and with equal stretch ratio. Samples at intersecting indices are then copied, leaving non-intersecting clip samples untouched. E.g., buffer: [a b c d e] clip : [x y z] result: [d e z]. More...
 
void SetFloatsCenteredAroundTime (double t, size_t iChannel, const float *buffer, size_t numSideSamples, sampleFormat effectiveFormat)
 Same as SetFloatsFromTime, but with buffer starting at TimeToSamples(t0 - SamplesToTime(numSideSamples)). [buffer, buffer + 2 * numSizeSamples + 1) is assumed to be a valid span of addresses. More...
 
void SetFloatAtTime (double t, size_t iChannel, float value, sampleFormat effectiveFormat)
 
- Public Member Functions inherited from ClipInterface
 ~ClipInterface () override
 
virtual AudioSegmentSampleView GetSampleView (size_t iChannel, sampleCount start, size_t length, bool mayThrow=true) const =0
 
virtual size_t GetWidth () const =0
 
virtual int GetCentShift () const =0
 
virtual Observer::Subscription SubscribeToCentShiftChange (std::function< void(int)> cb)=0
 
virtual PitchAndSpeedPreset GetPitchAndSpeedPreset () const =0
 
virtual Observer::Subscription SubscribeToPitchAndSpeedPresetChange (std::function< void(PitchAndSpeedPreset)> cb)=0
 
- Public Member Functions inherited from ClipTimes
virtual ~ClipTimes ()
 
virtual sampleCount GetVisibleSampleCount () const =0
 
virtual int GetRate () const =0
 
virtual double GetPlayStartTime () const =0
 
virtual double GetPlayEndTime () const =0
 
virtual sampleCount TimeToSamples (double time) const =0
 
virtual double GetStretchRatio () const =0
 
- Public Member Functions inherited from XMLTagHandler
 XMLTagHandler ()
 
virtual ~XMLTagHandler ()
 
virtual bool HandleXMLTag (const std::string_view &tag, const AttributesList &attrs)=0
 
virtual void HandleXMLEndTag (const std::string_view &WXUNUSED(tag))
 
virtual void HandleXMLContent (const std::string_view &WXUNUSED(content))
 
virtual XMLTagHandlerHandleXMLChild (const std::string_view &tag)=0
 
void ReadXMLEndTag (const char *tag)
 
void ReadXMLContent (const char *s, int len)
 
XMLTagHandlerReadXMLChild (const char *tag)
 
- Public Member Functions inherited from ClientData::Site< WaveClip, WaveClipListener >
 ~Site ()
 
 Site ()
 
 Site (const Site &other)
 
 Site (Site &&other)
 
Siteoperator= (const Site &other)
 
Siteoperator= (Site &&other)
 
size_t size () const
 How many attachment pointers are in the Site. More...
 
Subclass & Get (const RegisteredFactory &key)
 Get reference to an attachment, creating on demand if not present, down-cast it to Subclass. More...
 
auto Get (const RegisteredFactory &key) const -> std::enable_if_t< std::is_const< Subclass >::value, Subclass & >
 Get reference to an attachment, creating on demand if not present, down-cast it to Subclass. More...
 
Subclass * Find (const RegisteredFactory &key)
 Get a (bare) pointer to an attachment, or null, down-cast it to Subclass *; will not create on demand. More...
 
auto Find (const RegisteredFactory &key) const -> std::enable_if_t< std::is_const< Subclass >::value, Subclass * >
 Get a (bare) pointer to an attachment, or null, down-cast it to Subclass *; will not create on demand. More...
 
void Assign (const RegisteredFactory &key, ReplacementPointer &&replacement)
 Reassign Site's pointer to ClientData. More...
 
- Public Member Functions inherited from Observer::Publisher< CentShiftChange >
 Publisher (ExceptionPolicy *pPolicy=nullptr, Alloc a={})
 Constructor supporting type-erased custom allocation/deletion. More...
 
 Publisher (Publisher &&)=default
 
Publisheroperator= (Publisher &&)=default
 
Subscription Subscribe (Callback callback)
 Connect a callback to the Publisher; later-connected are called earlier. More...
 
Subscription Subscribe (Object &obj, Return(Object::*callback)(Args...))
 Overload of Subscribe takes an object and pointer-to-member-function. More...
 
- Public Member Functions inherited from Observer::Publisher< PitchAndSpeedPresetChange >
 Publisher (ExceptionPolicy *pPolicy=nullptr, Alloc a={})
 Constructor supporting type-erased custom allocation/deletion. More...
 
 Publisher (Publisher &&)=default
 
Publisheroperator= (Publisher &&)=default
 
Subscription Subscribe (Callback callback)
 Connect a callback to the Publisher; later-connected are called earlier. More...
 
Subscription Subscribe (Object &obj, Return(Object::*callback)(Args...))
 Overload of Subscribe takes an object and pointer-to-member-function. More...
 
- Public Member Functions inherited from Observer::Publisher< StretchRatioChange >
 Publisher (ExceptionPolicy *pPolicy=nullptr, Alloc a={})
 Constructor supporting type-erased custom allocation/deletion. More...
 
 Publisher (Publisher &&)=default
 
Publisheroperator= (Publisher &&)=default
 
Subscription Subscribe (Callback callback)
 Connect a callback to the Publisher; later-connected are called earlier. More...
 
Subscription Subscribe (Object &obj, Return(Object::*callback)(Args...))
 Overload of Subscribe takes an object and pointer-to-member-function. More...
 
- Public Member Functions inherited from Observer::Publisher< WaveClipDtorCalled >
 Publisher (ExceptionPolicy *pPolicy=nullptr, Alloc a={})
 Constructor supporting type-erased custom allocation/deletion. More...
 
 Publisher (Publisher &&)=default
 
Publisheroperator= (Publisher &&)=default
 
Subscription Subscribe (Callback callback)
 Connect a callback to the Publisher; later-connected are called earlier. More...
 
Subscription Subscribe (Object &obj, Return(Object::*callback)(Args...))
 Overload of Subscribe takes an object and pointer-to-member-function. More...
 

Private Member Functions

 WaveClip (const WaveClip &)=delete
 
WaveClipoperator= (const WaveClip &)=delete
 
sampleCount TimeToSequenceSamples (double t) const
 
bool StretchRatioEquals (double value) const
 
sampleCount GetNumSamples () const
 
SampleFormats GetSampleFormats () const
 
const SampleBlockFactoryPtrGetFactory ()
 
std::vector< std::unique_ptr< Sequence > > GetEmptySequenceCopies () const
 
void StretchCutLines (double ratioChange)
 
double SnapToTrackSample (double time) const noexcept
 
void ClearSequence (double t0, double t1)
 

Private Attributes

PitchAndSpeedPreset mPitchAndSpeedPreset { PitchAndSpeedPreset::Default }
 
int mCentShift { 0 }
 
double mClipStretchRatio = 1.
 
std::optional< double > mRawAudioTempo
 
std::optional< double > mProjectTempo
 
int mRate
 Sample rate of the raw audio, i.e., before stretching. More...
 
int mColourIndex
 
std::vector< std::unique_ptr< Sequence > > mSequences
 
std::unique_ptr< EnvelopemEnvelope
 Envelope is unique, not per-sequence. More...
 
WaveClipHolders mCutLines {}
 
bool mIsPlaceholder { false }
 
wxString mName
 
double mSequenceOffset { 0 }
 
double mTrimLeft { 0 }
 
double mTrimRight { 0 }
 

Additional Inherited Members

- Static Public Member Functions inherited from ClientData::Site< WaveClip, WaveClipListener >
static size_t numFactories ()
 How many static factories have been registered with this specialization of Site. More...
 
- Static Public Attributes inherited from Observer::Publisher< CentShiftChange >
static constexpr bool notifies_all
 
- Static Public Attributes inherited from Observer::Publisher< PitchAndSpeedPresetChange >
static constexpr bool notifies_all
 
- Static Public Attributes inherited from Observer::Publisher< StretchRatioChange >
static constexpr bool notifies_all
 
- Static Public Attributes inherited from Observer::Publisher< WaveClipDtorCalled >
static constexpr bool notifies_all
 
- Protected Member Functions inherited from ClientData::Site< WaveClip, WaveClipListener >
void ForEach (const Function &function)
 Invoke function on each ClientData object that has been created in this. More...
 
void ForEach (const Function &function) const
 Invoke function on each ClientData object that has been created in this. More...
 
WaveClipListenerFindIf (const Function &function)
 Return pointer to first attachment in this that is not null and satisfies a predicate, or nullptr. More...
 
const WaveClipListenerFindIf (const Function &function) const
 Return pointer to first attachment in this that is not null and satisfies a predicate, or nullptr. More...
 
void BuildAll ()
 For each RegisteredFactory, if the corresponding attachment is absent in this, build and store it. More...
 
- Protected Member Functions inherited from Observer::Publisher< CentShiftChange >
CallbackReturn Publish (const CentShiftChange &message)
 Send a message to connected callbacks. More...
 
- Protected Member Functions inherited from Observer::Publisher< PitchAndSpeedPresetChange >
CallbackReturn Publish (const PitchAndSpeedPresetChange &message)
 Send a message to connected callbacks. More...
 
- Protected Member Functions inherited from Observer::Publisher< StretchRatioChange >
CallbackReturn Publish (const StretchRatioChange &message)
 Send a message to connected callbacks. More...
 
- Protected Member Functions inherited from Observer::Publisher< WaveClipDtorCalled >
CallbackReturn Publish (const WaveClipDtorCalled &message)
 Send a message to connected callbacks. More...
 

Detailed Description

This allows multiple clips to be a part of one WaveTrack.

Definition at line 130 of file WaveClip.h.

Member Typedef Documentation

◆ Caches

Definition at line 147 of file WaveClip.h.

Constructor & Destructor Documentation

◆ WaveClip() [1/4]

WaveClip::WaveClip ( const WaveClip )
privatedelete

◆ WaveClip() [2/4]

WaveClip::WaveClip ( size_t  width,
const SampleBlockFactoryPtr factory,
sampleFormat  format,
int  rate,
int  colourIndex 
)

typical constructor

Parameters
widthhow many sequences
Precondition
width > 0
Postcondition
GetWidth() == width

Definition at line 40 of file WaveClip.cpp.

43{
44 assert(width > 0);
45 mRate = rate;
46 mColourIndex = colourIndex;
47 mSequences.resize(width);
48 for (auto &pSequence : mSequences)
49 pSequence = std::make_unique<Sequence>(factory,
51
52 mEnvelope = std::make_unique<Envelope>(true, 1e-7, 2.0, 1.0);
53 assert(CheckInvariants());
54}
@ narrowestSampleFormat
Two synonyms for previous values that might change if more values were added.
Two sample formats, remembering format of original source and describing stored format.
Definition: SampleFormat.h:79
bool CheckInvariants() const
Check invariant conditions on mSequences and mCutlines.
Definition: WaveClip.cpp:1559
std::unique_ptr< Envelope > mEnvelope
Envelope is unique, not per-sequence.
Definition: WaveClip.h:685
int mRate
Sample rate of the raw audio, i.e., before stretching.
Definition: WaveClip.h:673
int mColourIndex
Definition: WaveClip.h:674
std::vector< std::unique_ptr< Sequence > > mSequences
Definition: WaveClip.h:683
static RegisteredToolbarFactory factory

References CheckInvariants(), cloud::factory, anonymous_namespace{ExportPCM.cpp}::format, mColourIndex, mEnvelope, mRate, mSequences, and narrowestSampleFormat.

Here is the call graph for this function:

◆ WaveClip() [3/4]

WaveClip::WaveClip ( const WaveClip orig,
const SampleBlockFactoryPtr factory,
bool  copyCutlines 
)

essentially a copy constructor - but you must pass in the current sample block factory, because we might be copying from one project to another

Postcondition
GetWidth() == orig.GetWidth()

Definition at line 56 of file WaveClip.cpp.

59 : mCentShift { orig.mCentShift }
64{
65 // essentially a copy constructor - but you must pass in the
66 // current sample block factory, because we might be copying
67 // from one project to another
68
70 mTrimLeft = orig.mTrimLeft;
72 mRate = orig.mRate;
74 mSequences.reserve(orig.GetWidth());
75 for (auto &pSequence : orig.mSequences)
76 mSequences.push_back(
77 std::make_unique<Sequence>(*pSequence, factory));
78
79 mEnvelope = std::make_unique<Envelope>(*orig.mEnvelope);
80
81 mName = orig.mName;
82
83 if (copyCutlines)
84 for (const auto &clip: orig.mCutLines)
85 mCutLines.push_back(std::make_shared<WaveClip>(*clip, factory, true));
86
88
89 assert(GetWidth() == orig.GetWidth());
90 assert(CheckInvariants());
91}
PitchAndSpeedPreset mPitchAndSpeedPreset
Definition: WaveClip.h:663
std::optional< double > mRawAudioTempo
Definition: WaveClip.h:669
bool mIsPlaceholder
Definition: WaveClip.h:695
int mCentShift
Definition: WaveClip.h:664
double mTrimRight
Definition: WaveClip.h:660
std::optional< double > mProjectTempo
Definition: WaveClip.h:670
wxString mName
Definition: WaveClip.h:698
bool GetIsPlaceholder() const
Definition: WaveClip.h:599
double mSequenceOffset
Definition: WaveClip.h:658
double mTrimLeft
Definition: WaveClip.h:659
WaveClipHolders mCutLines
Definition: WaveClip.h:692
size_t GetWidth() const override
Definition: WaveClip.cpp:167
double mClipStretchRatio
Definition: WaveClip.h:668

References CheckInvariants(), cloud::factory, GetIsPlaceholder(), GetWidth(), mColourIndex, mCutLines, mEnvelope, mIsPlaceholder, mName, mRate, mSequenceOffset, mSequences, mTrimLeft, and mTrimRight.

Here is the call graph for this function:

◆ WaveClip() [4/4]

WaveClip::WaveClip ( const WaveClip orig,
const SampleBlockFactoryPtr factory,
bool  copyCutlines,
double  t0,
double  t1 
)

Copy only a range from the given WaveClip.

Precondition
CountSamples(t1, t0) > 0
Postcondition
GetWidth() == orig.GetWidth()

Definition at line 93 of file WaveClip.cpp.

96 : mCentShift { orig.mCentShift }
100{
101 assert(orig.CountSamples(t0, t1) > 0);
102
104
105 //Adjust trim values to sample-boundary
106 if(t0 > orig.GetPlayStartTime()) {
107 const auto s0 = orig.TimeToSamples(t0 - orig.GetSequenceStartTime());
108 mTrimLeft = orig.SamplesToTime(s0);
109
110 }
111 else
112 mTrimLeft = orig.mTrimLeft;
113
114 if(t1 < orig.GetPlayEndTime())
115 {
116 const auto s1 = orig.TimeToSamples(orig.GetSequenceEndTime() - t1);
117 mTrimRight = orig.SamplesToTime(s1);
118 }
119 else
120 mTrimRight = orig.mTrimRight;
121
122 mRate = orig.mRate;
124
126
127 mSequences.reserve(orig.GetWidth());
128 for (auto &pSequence : orig.mSequences)
129 mSequences.push_back(
130 std::make_unique<Sequence>(*pSequence, factory));
131
132 mEnvelope = std::make_unique<Envelope>(*orig.mEnvelope);
133
134 if (copyCutlines)
135 for (const auto &cutline : orig.mCutLines)
136 mCutLines.push_back(
137 std::make_shared<WaveClip>(*cutline, factory, true));
138
139 assert(GetWidth() == orig.GetWidth());
140 assert(CheckInvariants());
141}
double GetSequenceStartTime() const noexcept
Definition: WaveClip.cpp:1453
sampleCount TimeToSamples(double time) const override
Definition: WaveClip.cpp:1313
double GetPlayStartTime() const noexcept override
Definition: WaveClip.cpp:1343
sampleCount CountSamples(double t0, double t1) const
Definition: WaveClip.cpp:1537
double GetPlayEndTime() const override
Definition: WaveClip.cpp:1353
double SamplesToTime(sampleCount s) const noexcept
Definition: WaveClip.cpp:1318
double GetSequenceEndTime() const
Definition: WaveClip.cpp:1466

References CheckInvariants(), CountSamples(), cloud::factory, GetIsPlaceholder(), GetPlayEndTime(), GetPlayStartTime(), GetSequenceEndTime(), GetSequenceStartTime(), GetWidth(), mColourIndex, mCutLines, mEnvelope, mIsPlaceholder, mRate, mSequenceOffset, mSequences, mTrimLeft, mTrimRight, SamplesToTime(), and TimeToSamples().

Here is the call graph for this function:

◆ ~WaveClip()

WaveClip::~WaveClip ( )
virtual

Definition at line 144 of file WaveClip.cpp.

145{
147}
CallbackReturn Publish(const Message &message)
Send a message to connected callbacks.
Definition: Observer.h:207

References Observer::Publisher< Message, NotifyAll >::Publish().

Here is the call graph for this function:

Member Function Documentation

◆ AfterPlayRegion()

bool WaveClip::AfterPlayRegion ( double  t) const

) <= t

Definition at line 1532 of file WaveClip.cpp.

1533{
1534 return GetPlayEndTime() <= t;
1535}

References GetPlayEndTime().

Here is the call graph for this function:

◆ Append()

bool WaveClip::Append ( constSamplePtr  buffers[],
sampleFormat  format,
size_t  len,
unsigned int  stride,
sampleFormat  effectiveFormat 
)

Append (non-interleaved) samples to all channels You must call Flush after the last Append

Returns
true if at least one complete block was created assume as many buffers available as GetWidth() In case of failure or exceptions, the clip contents are unchanged but un-flushed data are lost
Parameters
effectiveFormatMake the effective format of the data at least the minumum of this value and `format`. (Maybe wider, if merging with preexistent data.) If the data are later narrowed from stored format, but not narrower than the effective, then no dithering will occur.

Definition at line 533 of file WaveClip.cpp.

535{
536 Finally Do{ [this]{ assert(CheckInvariants()); } };
537
538 // There is not a transaction to enforce consistency of lengths of sequences
539 // (And there is as yet always just one sequence).
540
541 //wxLogDebug(wxT("Append: len=%lli"), (long long) len);
542
543 size_t ii = 0;
544 bool appended = false;
545 for (auto &pSequence : mSequences)
546 appended =
547 pSequence->Append(buffers[ii++], format, len, stride, effectiveFormat)
548 || appended;
549
550 // use No-fail-guarantee
552 MarkChanged();
553
554 return appended;
555}
void MarkChanged()
Definition: WaveClip.cpp:437
void UpdateEnvelopeTrackLen()
Definition: WaveClip.cpp:506
"finally" as in The C++ Programming Language, 4th ed., p. 358 Useful for defining ad-hoc RAII actions...
Definition: MemoryX.h:172

References CheckInvariants(), anonymous_namespace{ExportPCM.cpp}::format, MarkChanged(), mSequences, and UpdateEnvelopeTrackLen().

Here is the call graph for this function:

◆ AppendNewBlock()

std::shared_ptr< SampleBlock > WaveClip::AppendNewBlock ( constSamplePtr  buffer,
sampleFormat  format,
size_t  len 
)

For use in importing pre-version-3 projects to preserve sharing of blocks; no dithering applied

Precondition
GetWidth() == 1
Exception safety guarantee:
Strong

Definition at line 516 of file WaveClip.cpp.

517{
518 // This is a special use function for legacy files only and this assertion
519 // does not need to be relaxed
520 assert(GetWidth() == 1);
521 return mSequences[0]->AppendNewBlock( buffer, format, len );
522}

References anonymous_namespace{ExportPCM.cpp}::format, GetWidth(), and mSequences.

Here is the call graph for this function:

◆ AppendSharedBlock()

void WaveClip::AppendSharedBlock ( const std::shared_ptr< SampleBlock > &  pBlock)

For use in importing pre-version-3 projects to preserve sharing of blocks

Precondition
GetWidth() == 1
Exception safety guarantee:
Strong

Definition at line 525 of file WaveClip.cpp.

526{
527 // This is a special use function for legacy files only and this assertion
528 // does not need to be relaxed
529 assert(GetWidth() == 1);
530 mSequences[0]->AppendSharedBlock( pBlock );
531}

References GetWidth(), and mSequences.

Here is the call graph for this function:

◆ AppendSilence()

void WaveClip::AppendSilence ( double  len,
double  envelopeValue 
)

Insert silence at the end, and causes the envelope to ramp linearly to the given value

Exception safety guarantee:
Strong

Definition at line 880 of file WaveClip.cpp.

881{
882 auto t = GetPlayEndTime();
883 InsertSilence( t, len, &envelopeValue );
884}
void InsertSilence(double t, double len, double *pEnvelopeValue=nullptr)
Definition: WaveClip.cpp:836

References GetPlayEndTime(), and InsertSilence().

Here is the call graph for this function:

◆ AtOrBeforePlayRegion()

bool WaveClip::AtOrBeforePlayRegion ( double  t) const

t <= [

Definition at line 1527 of file WaveClip.cpp.

1528{
1529 return t <= GetPlayStartTime();
1530}

References GetPlayStartTime().

Here is the call graph for this function:

◆ BeforePlayRegion()

bool WaveClip::BeforePlayRegion ( double  t) const

t < [

Definition at line 1522 of file WaveClip.cpp.

1523{
1524 return t < GetPlayStartTime();
1525}

References GetPlayStartTime().

Referenced by EntirelyWithinPlayRegion().

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

◆ CheckInvariants()

bool WaveClip::CheckInvariants ( ) const

Check invariant conditions on mSequences and mCutlines.

Definition at line 1559 of file WaveClip.cpp.

1560{
1561 const auto width = GetWidth();
1562 auto iter = mSequences.begin(),
1563 end = mSequences.end();
1564 // There must be at least one pointer
1565 if (iter != end) {
1566 // All pointers mut be non-null
1567 auto &pFirst = *iter++;
1568 if (pFirst) {
1569 // All sequences must have the sample formats, and sample block factory
1570 return
1571 std::all_of(iter, end, [&](decltype(pFirst) pSequence) {
1572 return pSequence &&
1573 pSequence->GetSampleFormats() == pFirst->GetSampleFormats() &&
1574 pSequence->GetFactory() == pFirst->GetFactory();
1575 }) &&
1576 // All cut lines are non-null, satisfy the invariants, and match width
1577 std::all_of(mCutLines.begin(), mCutLines.end(),
1578 [width](const WaveClipHolder &pCutLine) {
1579 return pCutLine && pCutLine->GetWidth() == width &&
1580 pCutLine->CheckInvariants();
1581 });
1582 }
1583 }
1584 return false;
1585}
std::shared_ptr< WaveClip > WaveClipHolder
Definition: WaveClip.h:45
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159

References PackedArray::end(), GetWidth(), mCutLines, and mSequences.

Referenced by Append(), ClearAndAddCutLine(), HandleXMLEndTag(), Paste(), and WaveClip().

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

◆ Clear()

void WaveClip::Clear ( double  t0,
double  t1 
)

This name is consistent with WaveTrack::Clear. It performs a "Cut" operation (but without putting the cut audio to the clipboard)

Exception safety guarantee:
Strong

Definition at line 887 of file WaveClip.cpp.

888{
889 auto st0 = t0;
890 auto st1 = t1;
891 auto offset = .0;
892 if (st0 <= GetPlayStartTime())
893 {
894 offset = (t0 - GetPlayStartTime()) + GetTrimLeft();
895 st0 = GetSequenceStartTime();
896
897 SetTrimLeft(.0);
898 }
899 if (st1 >= GetPlayEndTime())
900 {
901 st1 = GetSequenceEndTime();
902 SetTrimRight(.0);
903 }
904 ClearSequence(st0, st1);
905
906 if (offset != .0)
907 ShiftBy(offset);
908}
void ShiftBy(double delta) noexcept
Definition: WaveClip.cpp:1479
double GetTrimLeft() const noexcept
Returns the play start offset in seconds from the beginning of the underlying sequence.
Definition: WaveClip.cpp:1396
void SetTrimRight(double trim)
Sets the play end offset in seconds from the ending of the underlying sequence.
Definition: WaveClip.cpp:1401
void ClearSequence(double t0, double t1)
Definition: WaveClip.cpp:929
void SetTrimLeft(double trim)
Sets the play start offset in seconds from the beginning of the underlying sequence.
Definition: WaveClip.cpp:1391

References ClearSequence(), GetPlayEndTime(), GetPlayStartTime(), GetSequenceEndTime(), GetSequenceStartTime(), GetTrimLeft(), SetTrimLeft(), SetTrimRight(), and ShiftBy().

Here is the call graph for this function:

◆ ClearAndAddCutLine()

void WaveClip::ClearAndAddCutLine ( double  t0,
double  t1 
)

Clear, and add cut line that starts at t0 and contains everything until t1 if there is at least one clip sample between t0 and t1, noop otherwise.

Exception safety guarantee:
Weak – This WaveClip remains destructible in case of AudacityException. But some cutlines may be deleted

Definition at line 992 of file WaveClip.cpp.

993{
994 if (t0 > GetPlayEndTime() || t1 < GetPlayStartTime() || CountSamples(t0, t1) == 0)
995 return; // no samples to remove
996
997 Transaction transaction{ *this };
998
999 const double clip_t0 = std::max( t0, GetPlayStartTime() );
1000 const double clip_t1 = std::min( t1, GetPlayEndTime() );
1001
1002 auto newClip = std::make_shared<WaveClip>(
1003 *this, GetFactory(), true, clip_t0, clip_t1);
1004 if(t1 < GetPlayEndTime())
1005 {
1006 newClip->ClearSequence(t1, newClip->GetSequenceEndTime());
1007 newClip->SetTrimRight(.0);
1008 }
1009 if(t0 > GetPlayStartTime())
1010 {
1011 newClip->ClearSequence(newClip->GetSequenceStartTime(), t0);
1012 newClip->SetTrimLeft(.0);
1013 }
1014
1015 newClip->SetSequenceStartTime( clip_t0 - GetSequenceStartTime() );
1016
1017 // Remove cutlines from this clip that were in the selection, shift
1018 // left those that were after the selection
1019 // May DELETE as we iterate, so don't use range-for
1020 for (auto it = mCutLines.begin(); it != mCutLines.end();)
1021 {
1022 WaveClip* clip = it->get();
1023 double cutlinePosition = GetSequenceStartTime() + clip->GetSequenceStartTime();
1024 if (cutlinePosition >= t0 && cutlinePosition <= t1)
1025 it = mCutLines.erase(it);
1026 else
1027 {
1028 if (cutlinePosition >= t1)
1029 {
1030 clip->ShiftBy(clip_t0 - clip_t1);
1031 }
1032 ++it;
1033 }
1034 }
1035
1036 // Clear actual audio data
1037 auto s0 = TimeToSequenceSamples(t0);
1038 auto s1 = TimeToSequenceSamples(t1);
1039
1040 // use Weak-guarantee
1041 for (auto &pSequence : mSequences)
1042 pSequence->Delete(s0, s1-s0);
1043
1044 // Collapse envelope
1045 auto sampleTime = 1.0 / GetRate();
1046 GetEnvelope()->CollapseRegion( t0, t1, sampleTime );
1047
1048 transaction.Commit();
1049 MarkChanged();
1050
1051 mCutLines.push_back(std::move(newClip));
1052
1053 // New cutline was copied from this so will have correct width
1054 assert(CheckInvariants());
1055}
int min(int a, int b)
void CollapseRegion(double t0, double t1, double sampleDur)
Definition: Envelope.cpp:378
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:138
sampleCount TimeToSequenceSamples(double t) const
Definition: WaveClip.cpp:1550
int GetRate() const override
Definition: WaveClip.h:191
Envelope * GetEnvelope()
Definition: WaveClip.h:441
const SampleBlockFactoryPtr & GetFactory()
Definition: WaveClip.cpp:415

References CheckInvariants(), Envelope::CollapseRegion(), CountSamples(), GetEnvelope(), GetFactory(), GetPlayEndTime(), GetPlayStartTime(), GetRate(), GetSequenceStartTime(), MarkChanged(), mCutLines, min(), mSequences, ShiftBy(), and TimeToSequenceSamples().

Here is the call graph for this function:

◆ ClearLeft()

void WaveClip::ClearLeft ( double  t)

Removes samples starting from the left boundary of the clip till t, if it's inside the play region. Also removes trimmed (hidden) data, if present. Changes offset to make remaining samples stay at their old place. Destructive operation.

Definition at line 910 of file WaveClip.cpp.

911{
912 if (t > GetPlayStartTime() && t < GetPlayEndTime())
913 {
915 SetTrimLeft(.0);
917 }
918}
void SetSequenceStartTime(double startTime)
Definition: WaveClip.cpp:1460

References ClearSequence(), GetPlayEndTime(), GetPlayStartTime(), GetSequenceStartTime(), SetSequenceStartTime(), and SetTrimLeft().

Here is the call graph for this function:

◆ ClearRight()

void WaveClip::ClearRight ( double  t)

Removes samples starting from t (if it's inside the clip), till the right boundary. Also removes trimmed (hidden) data, if present. Destructive operation.

Definition at line 920 of file WaveClip.cpp.

921{
922 if (t > GetPlayStartTime() && t < GetPlayEndTime())
923 {
925 SetTrimRight(.0);
926 }
927}

References ClearSequence(), GetPlayEndTime(), GetPlayStartTime(), GetSequenceEndTime(), and SetTrimRight().

Here is the call graph for this function:

◆ ClearSequence()

void WaveClip::ClearSequence ( double  t0,
double  t1 
)
private

This name is consistent with WaveTrack::Clear. It performs a "Cut" operation (but without putting the cut audio to the clipboard)

Definition at line 929 of file WaveClip.cpp.

930{
931 Transaction transaction{ *this };
932
933 auto clip_t0 = std::max(t0, GetSequenceStartTime());
934 auto clip_t1 = std::min(t1, GetSequenceEndTime());
935
936 auto s0 = TimeToSequenceSamples(clip_t0);
937 auto s1 = TimeToSequenceSamples(clip_t1);
938
939 if (s0 != s1)
940 {
941 // use Strong-guarantee
942 for (auto &pSequence : mSequences)
943 pSequence->Delete(s0, s1 - s0);
944
945 // use No-fail-guarantee in the remaining
946
947 // msmeyer
948 //
949 // Delete all cutlines that are within the given area, if any.
950 //
951 // Note that when cutlines are active, two functions are used:
952 // Clear() and ClearAndAddCutLine(). ClearAndAddCutLine() is called
953 // whenever the user directly calls a command that removes some audio, e.g.
954 // "Cut" or "Clear" from the menu. This command takes care about recursive
955 // preserving of cutlines within clips. Clear() is called when internal
956 // operations want to remove audio. In the latter case, it is the right
957 // thing to just remove all cutlines within the area.
958 //
959
960 // May DELETE as we iterate, so don't use range-for
961 for (auto it = mCutLines.begin(); it != mCutLines.end();)
962 {
963 WaveClip* clip = it->get();
964 double cutlinePosition = GetSequenceStartTime() + clip->GetSequenceStartTime();
965 if (cutlinePosition >= t0 && cutlinePosition <= t1)
966 {
967 // This cutline is within the area, DELETE it
968 it = mCutLines.erase(it);
969 }
970 else
971 {
972 if (cutlinePosition >= t1)
973 {
974 clip->ShiftBy(clip_t0 - clip_t1);
975 }
976 ++it;
977 }
978 }
979
980 // Collapse envelope
981 auto sampleTime = 1.0 / GetRate();
982 GetEnvelope()->CollapseRegion(t0, t1, sampleTime);
983 }
984
985 transaction.Commit();
986 MarkChanged();
987}

References Envelope::CollapseRegion(), GetEnvelope(), GetRate(), GetSequenceEndTime(), GetSequenceStartTime(), MarkChanged(), mCutLines, min(), mSequences, ShiftBy(), and TimeToSequenceSamples().

Referenced by Clear(), ClearLeft(), ClearRight(), InsertSilence(), and Paste().

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

◆ CloseLock()

void WaveClip::CloseLock ( )
noexcept

Should be called upon project close. Not balanced by unlocking calls.

Exception safety guarantee:
No-fail

Definition at line 1138 of file WaveClip.cpp.

1139{
1140 // Don't need a Transaction for noexcept operations
1141 for (auto &pSequence : mSequences)
1142 pSequence->CloseLock();
1143 for (const auto &cutline: mCutLines)
1144 cutline->CloseLock();
1145}

References mCutLines, and mSequences.

◆ ConvertToSampleFormat()

void WaveClip::ConvertToSampleFormat ( sampleFormat  format,
const std::function< void(size_t)> &  progressReport = {} 
)

Definition at line 484 of file WaveClip.cpp.

486{
487 // Note: it is not necessary to do this recursively to cutlines.
488 // They get converted as needed when they are expanded.
489
490 Transaction transaction{ *this };
491
492 auto bChanged = mSequences[0]->ConvertToSampleFormat(format, progressReport);
493 for (size_t ii = 1, width = GetWidth(); ii < width; ++ii) {
494 bool alsoChanged =
495 mSequences[ii]->ConvertToSampleFormat(format, progressReport);
496 // Class invariant implies:
497 assert(bChanged == alsoChanged);
498 }
499 if (bChanged)
500 MarkChanged();
501
502 transaction.Commit();
503}

References anonymous_namespace{ExportPCM.cpp}::format, GetWidth(), MarkChanged(), and mSequences.

Here is the call graph for this function:

◆ CountSamples()

sampleCount WaveClip::CountSamples ( double  t0,
double  t1 
) const

Counts number of samples within t0 and t1 region. t0 and t1 are rounded to the nearest clip sample boundary, i.e. relative to clips start time offset.

Returns
Number of samples within t0 and t1 if t1 > t0, 0 otherwise

Definition at line 1537 of file WaveClip.cpp.

1538{
1539 if(t0 < t1)
1540 {
1541 t0 = std::max(t0, GetPlayStartTime());
1542 t1 = std::min(t1, GetPlayEndTime());
1543 const auto s0 = TimeToSamples(t0 - GetPlayStartTime());
1544 const auto s1 = TimeToSamples(t1 - GetPlayStartTime());
1545 return s1 - s0;
1546 }
1547 return { 0 };
1548}

References GetPlayEndTime(), GetPlayStartTime(), min(), and TimeToSamples().

Referenced by ClearAndAddCutLine(), and WaveClip().

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

◆ CoversEntirePlayRegion()

bool WaveClip::CoversEntirePlayRegion ( double  t0,
double  t1 
) const

t0 <= [ and ) <= t1, such that removing [t0, t1) from the track deletes this clip.

Precondition
t0 <= t1

Definition at line 1516 of file WaveClip.cpp.

1517{
1518 assert(t0 <= t1);
1519 return t0 <= GetPlayStartTime() && GetPlayEndTime() <= t1;
1520}

References GetPlayEndTime(), and GetPlayStartTime().

Here is the call graph for this function:

◆ EntirelyWithinPlayRegion()

bool WaveClip::EntirelyWithinPlayRegion ( double  t0,
double  t1 
) const

t0 and t1 both ∈ [...)

Precondition
t0 <= t1

Definition at line 1494 of file WaveClip.cpp.

1495{
1496 assert(t0 <= t1);
1497 // t1 is the open end of the interval, hence it's ok if it's equal to the
1498 // open end of the play region.
1499 return !BeforePlayRegion(t0) && t1 <= GetPlayEndTime();
1500}
bool BeforePlayRegion(double t) const
t < [
Definition: WaveClip.cpp:1522

References BeforePlayRegion(), and GetPlayEndTime().

Here is the call graph for this function:

◆ ExpandCutLine()

void WaveClip::ExpandCutLine ( double  cutLinePosition)

Expand cut line (that is, re-insert audio, then DELETE audio saved in cut line). Returns true if a cut line could be found and successfully expanded, false otherwise

Exception safety guarantee:
Strong

Definition at line 1078 of file WaveClip.cpp.

1079{
1080 auto end = mCutLines.end();
1081 auto it = std::find_if( mCutLines.begin(), end,
1082 [&](const WaveClipHolder &cutline) {
1083 return fabs(GetSequenceStartTime() + cutline->GetSequenceStartTime() - cutLinePosition) < 0.0001;
1084 } );
1085
1086 if ( it != end ) {
1087 auto *cutline = it->get();
1088 // assume Strong-guarantee from Paste
1089
1090 // Envelope::Paste takes offset into account, WaveClip::Paste doesn't!
1091 // Do this to get the right result:
1092 cutline->mEnvelope->SetOffset(0);
1093 bool success = Paste(
1094 GetSequenceStartTime() + cutline->GetSequenceStartTime(), *cutline);
1095 assert(success); // class invariant promises cutlines have correct width
1096
1097 // Now erase the cutline,
1098 // but be careful to find it again, because Paste above may
1099 // have modified the array of cutlines (if our cutline contained
1100 // another cutline!), invalidating the iterator we had.
1101 end = mCutLines.end();
1102 it = std::find_if(mCutLines.begin(), end,
1103 [=](const WaveClipHolder &p) { return p.get() == cutline; });
1104 if (it != end)
1105 mCutLines.erase(it); // deletes cutline!
1106 else {
1107 wxASSERT(false);
1108 }
1109 }
1110}
bool Paste(double t0, const WaveClip &other)
Definition: WaveClip.cpp:728

References PackedArray::end(), GetSequenceStartTime(), mCutLines, and Paste().

Here is the call graph for this function:

◆ FindCutLine()

bool WaveClip::FindCutLine ( double  cutLinePosition,
double *  cutLineStart = NULL,
double *  cutLineEnd = NULL 
) const

Find cut line at (approximately) this position. Returns true and fills in cutLineStart and cutLineEnd (if specified) if a cut line at this position could be found. Return false otherwise.

Definition at line 1057 of file WaveClip.cpp.

1060{
1061 for (const auto &cutline: mCutLines)
1062 {
1063 if (fabs(GetSequenceStartTime() + cutline->GetSequenceStartTime() - cutLinePosition) < 0.0001)
1064 {
1065 auto startTime = GetSequenceStartTime() + cutline->GetSequenceStartTime();
1066 if (cutlineStart)
1067 *cutlineStart = startTime;
1068 if (cutlineEnd)
1069 *cutlineEnd = startTime + cutline->SamplesToTime(cutline->GetVisibleSampleCount());
1070 return true;
1071 }
1072 }
1073
1074 return false;
1075}

References GetSequenceStartTime(), and mCutLines.

Here is the call graph for this function:

◆ Flush()

void WaveClip::Flush ( )

Flush must be called after last Append.

In case of exceptions, the clip contents are unchanged but un-flushed data are lost

Definition at line 557 of file WaveClip.cpp.

558{
559 //wxLogDebug(wxT("WaveClip::Flush"));
560 //wxLogDebug(wxT(" mAppendBufferLen=%lli"), (long long) mAppendBufferLen);
561 //wxLogDebug(wxT(" previous sample count %lli"), (long long) mSequence->GetNumSamples());
562
563 if (GetAppendBufferLen() > 0) {
564
565 Transaction transaction{ *this };
566
567 for (auto &pSequence : mSequences)
568 pSequence->Flush();
569
570 transaction.Commit();
571
572 // No-fail operations
574 MarkChanged();
575 }
576
577 //wxLogDebug(wxT("now sample count %lli"), (long long) mSequence->GetNumSamples());
578}
size_t GetAppendBufferLen() const
Definition: WaveClip.cpp:270

References WaveClip::Transaction::Commit(), GetAppendBufferLen(), MarkChanged(), mSequences, and UpdateEnvelopeTrackLen().

Referenced by WaveTrack::FlushOne(), and Resample().

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

◆ GetAppendBuffer()

constSamplePtr WaveClip::GetAppendBuffer ( size_t  ii) const

Get one channel of the append buffer.

Parameters
iiidentifies the channel
Precondition
ii < GetWidth()

Definition at line 431 of file WaveClip.cpp.

432{
433 assert(ii < GetWidth());
434 return mSequences[ii]->GetAppendBuffer();
435}

References GetWidth(), and mSequences.

Referenced by WaveChannelInterval::GetAppendBuffer().

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

◆ GetAppendBufferLen()

size_t WaveClip::GetAppendBufferLen ( ) const

Definition at line 270 of file WaveClip.cpp.

271{
272 // All append buffers have equal lengths by class invariant
273 return mSequences[0]->GetAppendBufferLen();
274}

References mSequences.

Referenced by Flush(), WaveChannelInterval::GetAppendBufferLen(), and GetPlayEndTime().

Here is the caller graph for this function:

◆ GetCentShift()

int WaveClip::GetCentShift ( ) const
overridevirtual

Implements ClipInterface.

Definition at line 365 of file WaveClip.cpp.

366{
367 return mCentShift;
368}

References mCentShift.

Referenced by anonymous_namespace{PitchAndSpeedDialog.cpp}::GetClipShift(), HasEqualPitchAndSpeed(), and HasPitchOrSpeed().

Here is the caller graph for this function:

◆ GetColourIndex()

int WaveClip::GetColourIndex ( ) const
inline

Definition at line 233 of file WaveClip.h.

233{ return mColourIndex; }

Referenced by WaveChannelInterval::GetColourIndex().

Here is the caller graph for this function:

◆ GetCutLines() [1/2]

WaveClipHolders & WaveClip::GetCutLines ( )
inline

Get access to cut lines list.

Definition at line 562 of file WaveClip.h.

562{ return mCutLines; }

◆ GetCutLines() [2/2]

const WaveClipConstHolders & WaveClip::GetCutLines ( ) const
inline

Definition at line 563 of file WaveClip.h.

564 { return reinterpret_cast< const WaveClipConstHolders& >( mCutLines ); }
std::vector< std::shared_ptr< const WaveClip > > WaveClipConstHolders
Definition: WaveClip.h:47

◆ GetEmptySequenceCopies()

std::vector< std::unique_ptr< Sequence > > WaveClip::GetEmptySequenceCopies ( ) const
private

Definition at line 421 of file WaveClip.cpp.

422{
423 decltype(mSequences) newSequences;
424 newSequences.reserve(mSequences.size());
425 for (auto& pSequence : mSequences)
426 newSequences.push_back(std::make_unique<Sequence>(
427 pSequence->GetFactory(), pSequence->GetSampleFormats()));
428 return newSequences;
429}

References mSequences.

Referenced by Resample().

Here is the caller graph for this function:

◆ GetEnvelope() [1/2]

Envelope * WaveClip::GetEnvelope ( )
inline

Definition at line 441 of file WaveClip.h.

441{ return mEnvelope.get(); }

Referenced by ClearAndAddCutLine(), ClearSequence(), WaveChannelInterval::GetEnvelope(), WaveTrack::GetEnvelopeAtTime(), AUPImportFileHandle::HandleEnvelope(), WaveTrack::HandleXMLChild(), and InsertSilence().

Here is the caller graph for this function:

◆ GetEnvelope() [2/2]

const Envelope * WaveClip::GetEnvelope ( ) const
inline

Definition at line 442 of file WaveClip.h.

442{ return mEnvelope.get(); }

◆ GetFactory()

const SampleBlockFactoryPtr & WaveClip::GetFactory ( )
private

Definition at line 415 of file WaveClip.cpp.

416{
417 // All sequences have the same factory by class invariant
418 return mSequences[0]->GetFactory();
419}

References mSequences.

Referenced by ClearAndAddCutLine(), Paste(), and WaveClip::Transaction::Transaction().

Here is the caller graph for this function:

◆ GetFloatAtTime()

bool WaveClip::GetFloatAtTime ( double  t,
size_t  iChannel,
float &  value,
bool  mayThrow 
) const
Parameters
trelative to clip start sample

Definition at line 204 of file WaveClip.cpp.

206{
207 if (!WithinPlayRegion(t))
208 return false;
209 const auto start = TimeToSamples(t);
210 return GetSamples(
211 iChannel, reinterpret_cast<samplePtr>(&value), floatSample, start, 1u,
212 mayThrow);
213}
char * samplePtr
Definition: SampleFormat.h:57
bool WithinPlayRegion(double t) const
t ∈ [...)
Definition: WaveClip.cpp:1489
bool GetSamples(size_t ii, samplePtr buffer, sampleFormat format, sampleCount start, size_t len, bool mayThrow=true) const
Get samples from one channel.
Definition: WaveClip.cpp:172

References floatSample, GetSamples(), anonymous_namespace{StretchingSequenceIntegrationTest.cpp}::iChannel, TimeToSamples(), and WithinPlayRegion().

Here is the call graph for this function:

◆ GetIsPlaceholder()

bool WaveClip::GetIsPlaceholder ( ) const
inline

Definition at line 599 of file WaveClip.h.

599{ return mIsPlaceholder; }

Referenced by WaveClip().

Here is the caller graph for this function:

◆ GetMinMax()

std::pair< float, float > WaveClip::GetMinMax ( size_t  ii,
double  t0,
double  t1,
bool  mayThrow 
) const

Getting high-level data for one channel for screen display and clipping calculations and Contrast

Parameters
iiidentifies the channel
Precondition
ii < GetWidth()

Definition at line 442 of file WaveClip.cpp.

444{
445 assert(ii < GetWidth());
446 t0 = std::max(t0, GetPlayStartTime());
447 t1 = std::min(t1, GetPlayEndTime());
448 if (t0 > t1) {
449 if (mayThrow)
451 return {
452 0.f, // harmless, but unused since Sequence::GetMinMax does not use these values
453 0.f // harmless, but unused since Sequence::GetMinMax does not use these values
454 };
455 }
456
457 if (t0 == t1)
458 return{ 0.f, 0.f };
459
460 auto s0 = TimeToSequenceSamples(t0);
461 auto s1 = TimeToSequenceSamples(t1);
462
463 return mSequences[ii]->GetMinMax(s0, s1 - s0, mayThrow);
464}
#define THROW_INCONSISTENCY_EXCEPTION
Throw InconsistencyException, using C++ preprocessor to identify the source code location.

References GetPlayEndTime(), GetPlayStartTime(), GetWidth(), min(), mSequences, THROW_INCONSISTENCY_EXCEPTION, and TimeToSequenceSamples().

Here is the call graph for this function:

◆ GetName()

const wxString & WaveClip::GetName ( ) const

Definition at line 1308 of file WaveClip.cpp.

1309{
1310 return mName;
1311}

References mName.

◆ GetNumSamples()

sampleCount WaveClip::GetNumSamples ( ) const
private

Definition at line 403 of file WaveClip.cpp.

404{
405 // All sequences have equal lengths by class invariant
406 return mSequences[0]->GetNumSamples();
407}

References mSequences.

Referenced by GetPlayEndTime(), GetSampleView(), GetSequenceEndTime(), GetSequenceSamplesCount(), GetVisibleSampleCount(), Resample(), SetRate(), TimeToSequenceSamples(), and UpdateEnvelopeTrackLen().

Here is the caller graph for this function:

◆ GetPitchAndSpeedPreset()

PitchAndSpeedPreset WaveClip::GetPitchAndSpeedPreset ( ) const
overridevirtual

Implements ClipInterface.

Definition at line 1185 of file WaveClip.cpp.

1186{
1187 return mPitchAndSpeedPreset;
1188}

References mPitchAndSpeedPreset.

◆ GetPlayDuration()

double WaveClip::GetPlayDuration ( ) const

Always a multiple of the track's sample period, whether the clip is stretched or not.

Definition at line 1365 of file WaveClip.cpp.

1366{
1367 return GetPlayEndTime() - GetPlayStartTime();
1368}

References GetPlayEndTime(), and GetPlayStartTime().

Referenced by anonymous_namespace{WaveTrack.cpp}::GetSampleAccessArgs(), and IsEmpty().

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

◆ GetPlayEndSample()

sampleCount WaveClip::GetPlayEndSample ( ) const

Real end time of the clip, quantized to raw sample rate (track's rate)

Definition at line 1380 of file WaveClip.cpp.

1381{
1382 return sampleCount { GetPlayEndTime() * mRate + 0.5 };
1383}
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19

References GetPlayEndTime(), and mRate.

Referenced by WaveTrack::ReverseOne().

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

◆ GetPlayEndTime()

double WaveClip::GetPlayEndTime ( ) const
overridevirtual

Open-end of play region. Always a multiple of the track's sample period, whether the clip is stretched or not.

Implements ClipTimes.

Definition at line 1353 of file WaveClip.cpp.

1354{
1355 const auto numSamples = GetNumSamples();
1356 double maxLen = mSequenceOffset +
1357 ((numSamples + GetAppendBufferLen()).as_double()) *
1359 mTrimRight;
1360 // JS: calculated value is not the length;
1361 // it is a maximum value and can be negative; no clipping to 0
1362 return SnapToTrackSample(maxLen);
1363}
double GetStretchRatio() const override
Definition: WaveClip.cpp:356
double SnapToTrackSample(double time) const noexcept
Definition: WaveClip.cpp:1323
sampleCount GetNumSamples() const
Definition: WaveClip.cpp:403

References GetAppendBufferLen(), GetNumSamples(), GetStretchRatio(), mRate, mSequenceOffset, mTrimRight, and SnapToTrackSample().

Referenced by AUPImportFileHandle::AddSilence(), AfterPlayRegion(), AppendSilence(), WaveTrack::CanInsertClip(), Clear(), ClearAndAddCutLine(), WaveTrack::ClearAndPasteOne(), ClearLeft(), ClearRight(), CountSamples(), CoversEntirePlayRegion(), WaveChannelInterval::End(), EntirelyWithinPlayRegion(), WaveTrack::GetAdjacentClip(), GetMinMax(), GetPlayDuration(), GetPlayEndSample(), WaveChannelInterval::GetPlayEndTime(), InsertSilence(), IntersectsPlayRegion(), WaveTrackUtils::IsClipSelected(), WaveTrack::MergeOneClipPair(), Paste(), WaveTrack::PasteOne(), SplitsPlayRegion(), StretchLeftTo(), StretchRightTo(), TrimLeftTo(), WaveClip(), and WithinPlayRegion().

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

◆ GetPlayStartSample()

sampleCount WaveClip::GetPlayStartSample ( ) const

Real start time of the clip, quantized to raw sample rate (track's rate)

Definition at line 1375 of file WaveClip.cpp.

1376{
1377 return sampleCount { GetPlayStartTime() * mRate + 0.5 };
1378}

References GetPlayStartTime(), and mRate.

Referenced by WaveTrack::ReverseOne().

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

◆ GetPlayStartTime()

double WaveClip::GetPlayStartTime ( ) const
overridevirtualnoexcept

Closed-begin of play region. Always a multiple of the track's sample period, whether the clip is stretched or not.

Implements ClipTimes.

Definition at line 1343 of file WaveClip.cpp.

1344{
1346}

References mSequenceOffset, mTrimLeft, and SnapToTrackSample().

Referenced by AtOrBeforePlayRegion(), BeforePlayRegion(), WaveTrack::CanInsertClip(), Clear(), ClearAndAddCutLine(), WaveTrack::ClearAndPasteOne(), ClearLeft(), ClearRight(), CountSamples(), CoversEntirePlayRegion(), WaveTrack::GetAdjacentClip(), GetMinMax(), GetPlayDuration(), GetPlayStartSample(), WaveChannelInterval::GetPlayStartTime(), anonymous_namespace{WaveTrack.cpp}::GetSampleAccessArgs(), InsertSilence(), IntersectsPlayRegion(), WaveTrackUtils::IsClipSelected(), WaveTrack::JoinOne(), Paste(), WaveTrack::PasteOne(), WaveTrack::RightmostOrNewClip(), anonymous_namespace{SampleHandle.cpp}::SampleResolutionTest(), SharesBoundaryWithNextClip(), SplitsPlayRegion(), WaveChannelInterval::Start(), StretchBy(), StretchLeftTo(), StretchRightTo(), TrimRightTo(), WaveClip(), and WithinPlayRegion().

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

◆ GetRate()

int WaveClip::GetRate ( ) const
inlineoverridevirtual

Implements ClipTimes.

Definition at line 191 of file WaveClip.h.

192 {
193 return mRate;
194 }

Referenced by ClearAndAddCutLine(), ClearSequence(), WaveChannelInterval::GetRate(), anonymous_namespace{WaveTrack.cpp}::GetSampleAccessArgs(), InsertSilence(), Paste(), anonymous_namespace{SampleHandle.cpp}::SampleResolutionTest(), SharesBoundaryWithNextClip(), TrimQuarternotesFromRight(), and UpdateEnvelopeTrackLen().

Here is the caller graph for this function:

◆ GetRMS()

float WaveClip::GetRMS ( size_t  ii,
double  t0,
double  t1,
bool  mayThrow 
) const

Getting high-level data for one channel for screen display and clipping calculations and Contrast

Parameters
iiidentifies the channel
Precondition
ii < GetWidth()

Definition at line 466 of file WaveClip.cpp.

467{
468 assert(ii < GetWidth());
469 if (t0 > t1) {
470 if (mayThrow)
472 return 0.f;
473 }
474
475 if (t0 == t1)
476 return 0.f;
477
478 auto s0 = TimeToSequenceSamples(t0);
479 auto s1 = TimeToSequenceSamples(t1);
480
481 return mSequences[ii]->GetRMS(s0, s1-s0, mayThrow);
482}

References GetWidth(), mSequences, THROW_INCONSISTENCY_EXCEPTION, and TimeToSequenceSamples().

Here is the call graph for this function:

◆ GetSampleFormats()

SampleFormats WaveClip::GetSampleFormats ( ) const
private

Definition at line 409 of file WaveClip.cpp.

410{
411 // All sequences have the same formats by class invariant
412 return mSequences[0]->GetSampleFormats();
413}

References mSequences.

Referenced by Paste().

Here is the caller graph for this function:

◆ GetSamples() [1/2]

bool WaveClip::GetSamples ( samplePtr  buffers[],
sampleFormat  format,
sampleCount  start,
size_t  len,
bool  mayThrow = true 
) const

Get (non-interleaved) samples from all channels.

assume as many buffers available as GetWidth()

Parameters
startrelative to clip play start sample

Definition at line 181 of file WaveClip.cpp.

183{
184 bool result = true;
185 for (size_t ii = 0, width = GetWidth(); result && ii < width; ++ii)
186 result = GetSamples(ii, buffers[ii], format, start, len, mayThrow);
187 return result;
188}

References anonymous_namespace{ExportPCM.cpp}::format, GetSamples(), and GetWidth().

Here is the call graph for this function:

◆ GetSamples() [2/2]

bool WaveClip::GetSamples ( size_t  ii,
samplePtr  buffer,
sampleFormat  format,
sampleCount  start,
size_t  len,
bool  mayThrow = true 
) const

Get samples from one channel.

Parameters
iiidentifies the channel
startrelative to clip play start sample
Precondition
ii < GetWidth()

Definition at line 172 of file WaveClip.cpp.

175{
176 assert(ii < GetWidth());
177 return mSequences[ii]
178 ->Get(buffer, format, start + TimeToSamples(mTrimLeft), len, mayThrow);
179}

References anonymous_namespace{ExportPCM.cpp}::format, GetWidth(), mSequences, mTrimLeft, and TimeToSamples().

Referenced by GetFloatAtTime(), WaveChannelInterval::GetSamples(), and GetSamples().

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

◆ GetSampleView() [1/2]

AudioSegmentSampleView WaveClip::GetSampleView ( size_t  iChannel,
double  t0,
double  t1,
bool  mayThrow = true 
) const

Request interval samples within [t0, t1). t0 and t1 are truncated to the clip's play start and end. Stretching influences the number of samples fitting into [t0, t1), i.e., half as many for twice as large a stretch ratio, due to a larger spacing of the raw samples. The actual number of samples available from the returned view is queried through AudioSegmentSampleView::GetSampleCount().

Precondition
iChannel < GetWidth()
stretched samples in [t0, t1) can be counted in a size_t

Definition at line 157 of file WaveClip.cpp.

159{
160 assert(iChannel < GetWidth());
161 const auto start = TimeToSamples(std::max(0., t0));
162 const auto length =
163 (std::min(GetNumSamples(), TimeToSamples(t1)) - start).as_size_t();
164 return GetSampleView(iChannel, start, length, mayThrow);
165}
AudioSegmentSampleView GetSampleView(size_t iChannel, sampleCount start, size_t length, bool mayThrow=true) const override
Request up to length samples. The actual number of samples available from the returned view is querie...
Definition: WaveClip.cpp:149

References GetNumSamples(), GetSampleView(), GetWidth(), anonymous_namespace{StretchingSequenceIntegrationTest.cpp}::iChannel, min(), and TimeToSamples().

Here is the call graph for this function:

◆ GetSampleView() [2/2]

AudioSegmentSampleView WaveClip::GetSampleView ( size_t  iChannel,
sampleCount  start,
size_t  length,
bool  mayThrow = true 
) const
overridevirtual

Request up to length samples. The actual number of samples available from the returned view is queried through AudioSegmentSampleView::GetSampleCount().

Parameters
startindex of first clip sample from play start
Precondition
iChannel < GetWidth()

Implements ClipInterface.

Definition at line 149 of file WaveClip.cpp.

151{
152 assert(ii < GetWidth());
153 return mSequences[ii]->GetFloatSampleView(
154 start + TimeToSamples(mTrimLeft), length, mayThrow);
155}

References GetWidth(), mSequences, mTrimLeft, and TimeToSamples().

Referenced by WaveChannelInterval::GetSampleView(), and GetSampleView().

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

◆ GetSequence() [1/2]

Sequence * WaveClip::GetSequence ( size_t  ii)
inline

Get low-level access to a sequence. Whenever possible, don't use this, but use more high-level functions inside WaveClip (or add them if you think they are useful for general use)

Precondition
ii < GetWidth()

Definition at line 461 of file WaveClip.h.

461 {
462 assert(ii < GetWidth());
463 return mSequences[ii].get();
464 }

Referenced by WaveTrack::GetIdealBlockSize(), WaveChannelInterval::GetSequence(), and WaveTrack::HandleXMLChild().

Here is the caller graph for this function:

◆ GetSequence() [2/2]

const Sequence * WaveClip::GetSequence ( size_t  ii) const
inline

Get low-level access to a sequence. Whenever possible, don't use this, but use more high-level functions inside WaveClip (or add them if you think they are useful for general use)

Precondition
ii < GetWidth()

Definition at line 468 of file WaveClip.h.

468{ return mSequences[ii].get(); }

◆ GetSequenceBlockArray() [1/2]

BlockArray * WaveClip::GetSequenceBlockArray ( size_t  ii)
Parameters
iiidentifies the channel
Precondition
ii < GetWidth()

Definition at line 258 of file WaveClip.cpp.

259{
260 assert(ii < GetWidth());
261 return &mSequences[ii]->GetBlockArray();
262}

References GetWidth(), and mSequences.

Here is the call graph for this function:

◆ GetSequenceBlockArray() [2/2]

const BlockArray * WaveClip::GetSequenceBlockArray ( size_t  ii) const

Parameters
iiidentifies the channel
Precondition
ii < GetWidth()

Definition at line 264 of file WaveClip.cpp.

265{
266 assert(ii < GetWidth());
267 return &mSequences[ii]->GetBlockArray();
268}

References GetWidth(), and mSequences.

Here is the call graph for this function:

◆ GetSequenceEndTime()

double WaveClip::GetSequenceEndTime ( ) const

Definition at line 1466 of file WaveClip.cpp.

1467{
1468 const auto numSamples = GetNumSamples();
1469 double maxLen = GetSequenceStartTime() +
1470 numSamples.as_double() * GetStretchRatio() / mRate;
1471 return maxLen;
1472}

References GetNumSamples(), GetSequenceStartTime(), GetStretchRatio(), and mRate.

Referenced by Clear(), ClearRight(), ClearSequence(), InsertSilence(), Paste(), TimeToSequenceSamples(), TrimRightTo(), and WaveClip().

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

◆ GetSequenceSamplesCount()

sampleCount WaveClip::GetSequenceSamplesCount ( ) const

Returns the total number of samples in all underlying sequences (but not counting the cutlines)

Definition at line 1338 of file WaveClip.cpp.

1339{
1340 return GetNumSamples() * GetWidth();
1341}

References GetNumSamples(), and GetWidth().

Referenced by Paste().

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

◆ GetSequenceStartSample()

sampleCount WaveClip::GetSequenceStartSample ( ) const

Returns the index of the first sample of the underlying sequence.

Definition at line 1474 of file WaveClip.cpp.

1475{
1477}

References mSequenceOffset, and TimeToSamples().

Here is the call graph for this function:

◆ GetSequenceStartTime()

double WaveClip::GetSequenceStartTime ( ) const
noexcept

Definition at line 1453 of file WaveClip.cpp.

1454{
1455 // JS: mSequenceOffset is the minimum value and it is returned; no clipping to 0
1456 // Do we need to `SnapToTrackSample` before returning?
1457 return mSequenceOffset;
1458}

References mSequenceOffset.

Referenced by Clear(), ClearAndAddCutLine(), WaveTrack::ClearAndPasteOne(), ClearLeft(), ClearSequence(), ExpandCutLine(), FindCutLine(), GetSequenceEndTime(), InsertSilence(), OffsetCutLines(), Paste(), RemoveCutLine(), SetRate(), TimeToSequenceSamples(), and WaveClip().

Here is the caller graph for this function:

◆ GetStretchRatio()

double WaveClip::GetStretchRatio ( ) const
overridevirtual

Implements ClipTimes.

Definition at line 356 of file WaveClip.cpp.

357{
358 const auto dstSrcRatio =
359 mProjectTempo.has_value() && mRawAudioTempo.has_value() ?
361 1.0;
362 return mClipStretchRatio * dstSrcRatio;
363}

References mClipStretchRatio, mProjectTempo, and mRawAudioTempo.

Referenced by GetPlayEndTime(), anonymous_namespace{WaveTrack.cpp}::GetSampleAccessArgs(), GetSequenceEndTime(), WaveChannelInterval::GetStretchRatio(), HasEqualPitchAndSpeed(), OnProjectTempoChange(), Paste(), anonymous_namespace{SampleHandle.cpp}::SampleResolutionTest(), SetRate(), SharesBoundaryWithNextClip(), StretchBy(), StretchLeftTo(), StretchRatioEquals(), TimeToSamples(), TrimQuarternotesFromRight(), and UpdateEnvelopeTrackLen().

Here is the caller graph for this function:

◆ GetTrimLeft()

double WaveClip::GetTrimLeft ( ) const
noexcept

Returns the play start offset in seconds from the beginning of the underlying sequence.

Definition at line 1396 of file WaveClip.cpp.

1397{
1398 return mTrimLeft;
1399}

References mTrimLeft.

Referenced by Clear(), WaveTrack::ClearAndPasteOne(), WaveChannelInterval::GetTrimLeft(), and Paste().

Here is the caller graph for this function:

◆ GetTrimRight()

double WaveClip::GetTrimRight ( ) const
noexcept

Returns the play end offset in seconds from the ending of the underlying sequence.

Definition at line 1406 of file WaveClip.cpp.

1407{
1408 return mTrimRight;
1409}

References mTrimRight.

Referenced by WaveTrack::ClearAndPasteOne(), WaveChannelInterval::GetTrimRight(), and Paste().

Here is the caller graph for this function:

◆ GetVisibleSampleCount()

sampleCount WaveClip::GetVisibleSampleCount ( ) const
overridevirtual

Returns a number of raw samples, not accounting for stretching.

Implements ClipTimes.

Definition at line 1385 of file WaveClip.cpp.

1386{
1387 return GetNumSamples()
1389}

References GetNumSamples(), mTrimLeft, mTrimRight, and TimeToSamples().

Referenced by anonymous_namespace{WaveTrack.cpp}::GetSampleAccessArgs(), WaveChannelInterval::GetVisibleSampleCount(), SetFloatsFromTime(), and SharesBoundaryWithNextClip().

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

◆ GetWidth()

size_t WaveClip::GetWidth ( ) const
overridevirtual

How many Sequences the clip contains. Set at construction time; changes only if increased by deserialization

Implements ClipInterface.

Definition at line 167 of file WaveClip.cpp.

168{
169 return mSequences.size();
170}

References mSequences.

Referenced by AppendNewBlock(), AppendSharedBlock(), CheckInvariants(), WaveTrack::ClearAndPasteOne(), ConvertToSampleFormat(), GetAppendBuffer(), GetMinMax(), GetRMS(), GetSamples(), GetSampleView(), GetSequenceBlockArray(), GetSequenceSamplesCount(), Paste(), SetSamples(), and WaveClip().

Here is the caller graph for this function:

◆ HandleXMLChild()

XMLTagHandler * WaveClip::HandleXMLChild ( const std::string_view &  tag)
overridevirtual

Implements XMLTagHandler.

Definition at line 668 of file WaveClip.cpp.

669{
670 auto &pFirst = mSequences[0];
671 if (tag == "sequence") {
672 mSequences.push_back(std::make_unique<Sequence>(
673 pFirst->GetFactory(), pFirst->GetSampleFormats()));
674 return mSequences.back().get();
675 }
676 else if (tag == "envelope")
677 return mEnvelope.get();
678 else if (tag == "waveclip")
679 {
680 // Nested wave clips are cut lines
681 auto format = pFirst->GetSampleFormats().Stored();
682 // The format is not stored in WaveClip itself but passed to
683 // Sequence::Sequence; but then the Sequence will deserialize format
684 // again
685 mCutLines.push_back(
686 std::make_shared<WaveClip>(
687 // Make only one channel now, but recursive deserialization
688 // increases the width later
689 1, pFirst->GetFactory(),
690 format, mRate, 0 /*colourindex*/));
691 return mCutLines.back().get();
692 }
693 else
694 return NULL;
695}

References anonymous_namespace{ExportPCM.cpp}::format, mCutLines, mEnvelope, mRate, and mSequences.

Referenced by AUPImportFileHandle::HandleSequence(), and AUPImportFileHandle::HandleWaveClip().

Here is the caller graph for this function:

◆ HandleXMLEndTag()

void WaveClip::HandleXMLEndTag ( const std::string_view &  tag)
override

Definition at line 654 of file WaveClip.cpp.

655{
656 // All blocks were deserialized into new sequences; remove the one made
657 // by the constructor which remains empty.
658 mSequences.erase(mSequences.begin());
659 mSequences.shrink_to_fit();
660 if (tag == "waveclip")
662 // A proof of this assertion assumes that nothing has happened since
663 // construction of this, besides calls to the other deserialization
664 // functions
665 assert(CheckInvariants());
666}

References CheckInvariants(), mSequences, and UpdateEnvelopeTrackLen().

Referenced by WaveTrack::HandleXMLEndTag().

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

◆ HandleXMLTag()

bool WaveClip::HandleXMLTag ( const std::string_view &  tag,
const AttributesList attrs 
)
overridevirtual

Implements XMLTagHandler.

Definition at line 580 of file WaveClip.cpp.

581{
582 if (tag == "waveclip")
583 {
584 double dblValue;
585 long longValue;
586 for (auto pair : attrs)
587 {
588 auto attr = pair.first;
589 auto value = pair.second;
590
591 if (attr == "offset")
592 {
593 if (!value.TryGet(dblValue))
594 return false;
595 SetSequenceStartTime(dblValue);
596 }
597 else if (attr == "trimLeft")
598 {
599 if (!value.TryGet(dblValue))
600 return false;
601 SetTrimLeft(dblValue);
602 }
603 else if (attr == "trimRight")
604 {
605 if (!value.TryGet(dblValue))
606 return false;
607 SetTrimRight(dblValue);
608 }
609 else if (attr == "centShift")
610 {
611 if (!value.TryGet(dblValue))
612 return false;
613 mCentShift = dblValue;
614 }
615 else if (attr == "pitchAndSpeedPreset")
616 {
617 if (!value.TryGet(longValue))
618 return false;
619 mPitchAndSpeedPreset = static_cast<PitchAndSpeedPreset>(longValue);
620 }
621 else if (attr == "rawAudioTempo")
622 {
623 if (!value.TryGet(dblValue))
624 return false;
625 if (dblValue == 0)
626 mRawAudioTempo.reset();
627 else
628 mRawAudioTempo = dblValue;
629 }
630 else if (attr == "clipStretchRatio")
631 {
632 if (!value.TryGet(dblValue))
633 return false;
634 mClipStretchRatio = dblValue;
635 }
636 else if (attr == "name")
637 {
638 if(value.IsStringView())
639 SetName(value.ToWString());
640 }
641 else if (attr == "colorindex")
642 {
643 if (!value.TryGet(longValue))
644 return false;
645 SetColourIndex(longValue);
646 }
647 }
648 return true;
649 }
650
651 return false;
652}
PitchAndSpeedPreset
Definition: ClipInterface.h:40
void SetName(const wxString &name)
Definition: WaveClip.cpp:1303
void SetColourIndex(int index)
Definition: WaveClip.h:232

References mCentShift, mClipStretchRatio, mPitchAndSpeedPreset, mRawAudioTempo, SetColourIndex(), SetName(), SetSequenceStartTime(), SetTrimLeft(), and SetTrimRight().

Here is the call graph for this function:

◆ HasEqualPitchAndSpeed()

bool WaveClip::HasEqualPitchAndSpeed ( const WaveClip other) const

Checks for stretch-ratio equality, accounting for rounding errors.

Definition at line 386 of file WaveClip.cpp.

387{
388 return StretchRatioEquals(other.GetStretchRatio()) &&
389 GetCentShift() == other.GetCentShift();
390}
int GetCentShift() const override
Definition: WaveClip.cpp:365
bool StretchRatioEquals(double value) const
Definition: WaveClip.cpp:397

References GetCentShift(), GetStretchRatio(), and StretchRatioEquals().

Referenced by WaveTrack::ClearAndPasteOne(), and WaveTrack::MergeOneClipPair().

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

◆ HasPitchOrSpeed()

bool WaveClip::HasPitchOrSpeed ( ) const

Definition at line 392 of file WaveClip.cpp.

393{
394 return !StretchRatioEquals(1.0) || GetCentShift() != 0;
395}

References GetCentShift(), and StretchRatioEquals().

Here is the call graph for this function:

◆ InsertSilence()

void WaveClip::InsertSilence ( double  t,
double  len,
double *  pEnvelopeValue = nullptr 
)

Insert silence - note that this is an efficient operation for large amounts of silence

Exception safety guarantee:
Strong

Definition at line 836 of file WaveClip.cpp.

837{
838 Transaction transaction{ *this };
839
840 if (t == GetPlayStartTime() && t > GetSequenceStartTime())
842 else if (t == GetPlayEndTime() && t < GetSequenceEndTime()) {
844 SetTrimRight(.0);
845 }
846
847 const auto s0 = TimeToSequenceSamples(t);
848 const auto slen = TimeToSamples(len);
849
850 // use Strong-guarantee
851 for (auto &pSequence : mSequences)
852 pSequence->InsertSilence(s0, slen);
853
854 transaction.Commit();
855
856 // use No-fail-guarantee
857 OffsetCutLines(t, len);
858
859 const auto sampleTime = 1.0 / GetRate();
860 auto pEnvelope = GetEnvelope();
861 if ( pEnvelopeValue ) {
862
863 // Preserve limit value at the end
864 auto oldLen = pEnvelope->GetTrackLen();
865 auto newLen = oldLen + len;
866 pEnvelope->Cap( sampleTime );
867
868 // Ramp across the silence to the given value
869 pEnvelope->SetTrackLen( newLen, sampleTime );
870 pEnvelope->InsertOrReplace
871 ( pEnvelope->GetOffset() + newLen, *pEnvelopeValue );
872 }
873 else
874 pEnvelope->InsertSpace( t, len );
875
876 MarkChanged();
877}
void OffsetCutLines(double t0, double len)
Offset cutlines right to time 't0' by time amount 'len'.
Definition: WaveClip.cpp:1129

References ClearSequence(), GetEnvelope(), GetPlayEndTime(), GetPlayStartTime(), GetRate(), GetSequenceEndTime(), GetSequenceStartTime(), MarkChanged(), mSequences, OffsetCutLines(), SetTrimRight(), TimeToSamples(), and TimeToSequenceSamples().

Referenced by AUPImportFileHandle::AddSilence(), and AppendSilence().

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

◆ IntersectsPlayRegion()

bool WaveClip::IntersectsPlayRegion ( double  t0,
double  t1 
) const

[t0, t1) ∩ [...) != ∅

Precondition
t0 <= t1

Definition at line 1508 of file WaveClip.cpp.

1509{
1510 assert(t0 <= t1);
1511 // t1 is the open end of the interval, so it must be excluded from the closed
1512 // begin of the play region.
1513 return t0 < GetPlayEndTime() && GetPlayStartTime() < t1;
1514}

References GetPlayEndTime(), and GetPlayStartTime().

Referenced by WaveChannelInterval::Intersects().

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

◆ IsEmpty()

bool WaveClip::IsEmpty ( ) const

Definition at line 1370 of file WaveClip.cpp.

1371{
1372 return std::floor(GetPlayDuration() * mRate + 0.5) < 2.0;
1373}
double GetPlayDuration() const
Definition: WaveClip.cpp:1365

References GetPlayDuration(), and mRate.

Here is the call graph for this function:

◆ MarkChanged()

void WaveClip::MarkChanged ( )

WaveTrack calls this whenever data in the wave clip changes. It is called automatically when WaveClip has a chance to know that something has changed, like when member functions SetSamples() etc. are called.

Exception safety guarantee:
No-fail

Definition at line 437 of file WaveClip.cpp.

438{
439 Caches::ForEach( std::mem_fn( &WaveClipListener::MarkChanged ) );
440}
virtual void MarkChanged()=0

References WaveClipListener::MarkChanged().

Referenced by Append(), ClearAndAddCutLine(), ClearSequence(), ConvertToSampleFormat(), Flush(), InsertSilence(), Paste(), SetRate(), SetSamples(), and SetSilence().

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

◆ NumCutLines()

size_t WaveClip::NumCutLines ( ) const
inline

Definition at line 565 of file WaveClip.h.

565{ return mCutLines.size(); }

◆ OffsetCutLines()

void WaveClip::OffsetCutLines ( double  t0,
double  len 
)

Offset cutlines right to time 't0' by time amount 'len'.

Exception safety guarantee:
No-fail

Definition at line 1129 of file WaveClip.cpp.

1130{
1131 for (const auto &cutLine : mCutLines)
1132 {
1133 if (GetSequenceStartTime() + cutLine->GetSequenceStartTime() >= t0)
1134 cutLine->ShiftBy(len);
1135 }
1136}

References GetSequenceStartTime(), and mCutLines.

Referenced by InsertSilence(), and Paste().

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

◆ OnProjectTempoChange()

void WaveClip::OnProjectTempoChange ( const std::optional< double > &  oldTempo,
double  newTempo 
)

Definition at line 276 of file WaveClip.cpp.

278{
279 if (!mRawAudioTempo.has_value())
280 // When we have tempo detection ready (either by header-file
281 // read-up or signal analysis) we can use something smarter than that. In
282 // the meantime, use the tempo of the project when the clip is created as
283 // source tempo.
284 mRawAudioTempo = oldTempo.value_or(newTempo);
285
286 if (oldTempo.has_value())
287 {
288 const auto ratioChange = *oldTempo / newTempo;
289 mSequenceOffset *= ratioChange;
290 mTrimLeft *= ratioChange;
291 mTrimRight *= ratioChange;
292 StretchCutLines(ratioChange);
293 mEnvelope->RescaleTimesBy(ratioChange);
294 }
295 mProjectTempo = newTempo;
298}
void StretchCutLines(double ratioChange)
Definition: WaveClip.cpp:344

References GetStretchRatio(), mEnvelope, mProjectTempo, mRawAudioTempo, mSequenceOffset, mTrimLeft, mTrimRight, Observer::Publisher< Message, NotifyAll >::Publish(), and StretchCutLines().

Here is the call graph for this function:

◆ operator=()

WaveClip & WaveClip::operator= ( const WaveClip )
privatedelete

◆ PartlyWithinPlayRegion()

bool WaveClip::PartlyWithinPlayRegion ( double  t0,
double  t1 
) const

t0 xor t1 ∈ [...)

Precondition
t0 <= t1

Definition at line 1502 of file WaveClip.cpp.

1503{
1504 assert(t0 <= t1);
1505 return WithinPlayRegion(t0) != WithinPlayRegion(t1);
1506}

References WithinPlayRegion().

Here is the call graph for this function:

◆ Paste()

bool WaveClip::Paste ( double  t0,
const WaveClip other 
)
Returns
true and succeed if and only if this->GetWidth() == other.GetWidth() and either this is empty or this->GetStretchRatio() == other.GetStretchRatio().
Exception safety guarantee:
Strong

Definition at line 728 of file WaveClip.cpp.

729{
730 if (GetWidth() != other.GetWidth())
731 return false;
732
733 if (GetSequenceSamplesCount() == 0)
734 {
735 // Empty clip: we're flexible and adopt the other's stretching.
739 }
740 else if (GetStretchRatio() != other.GetStretchRatio())
741 return false;
742
743 Finally Do{ [this]{ assert(CheckInvariants()); } };
744
745 Transaction transaction{ *this };
746
747 const bool clipNeedsResampling = other.mRate != mRate;
748 const bool clipNeedsNewFormat =
750 std::shared_ptr<WaveClip> newClip;
751
752 t0 = std::clamp(t0, GetPlayStartTime(), GetPlayEndTime());
753
754 //seems like edge cases cannot happen, see WaveTrack::PasteWaveTrack
755 auto &factory = GetFactory();
756 if (t0 == GetPlayStartTime())
757 {
759 SetTrimLeft(other.GetTrimLeft());
760
761 auto copy = std::make_shared<WaveClip>(other, factory, true);
762 copy->ClearSequence(copy->GetPlayEndTime(), copy->GetSequenceEndTime());
763 newClip = std::move(copy);
764 }
765 else if (t0 == GetPlayEndTime())
766 {
768 SetTrimRight(other.GetTrimRight());
769
770 auto copy = std::make_shared<WaveClip>(other, factory, true);
771 copy->ClearSequence(copy->GetSequenceStartTime(), copy->GetPlayStartTime());
772 newClip = std::move(copy);
773 }
774 else
775 {
776 newClip = std::make_shared<WaveClip>(other, factory, true);
777 newClip->ClearSequence(newClip->GetPlayEndTime(), newClip->GetSequenceEndTime());
778 newClip->ClearSequence(newClip->GetSequenceStartTime(), newClip->GetPlayStartTime());
779 newClip->SetTrimLeft(0);
780 newClip->SetTrimRight(0);
781 }
782
783 if (clipNeedsResampling || clipNeedsNewFormat)
784 {
785 auto copy = std::make_shared<WaveClip>(*newClip.get(), factory, true);
786
787 if (clipNeedsResampling)
788 // The other clip's rate is different from ours, so resample
789 copy->Resample(mRate);
790
791 if (clipNeedsNewFormat)
792 // Force sample formats to match.
793 copy->ConvertToSampleFormat(GetSampleFormats().Stored());
794 newClip = std::move(copy);
795 }
796
797 // Paste cut lines contained in pasted clip
798 WaveClipHolders newCutlines;
799 for (const auto &cutline: newClip->mCutLines)
800 {
801 auto cutlineCopy = std::make_shared<WaveClip>(*cutline, factory,
802 // Recursively copy cutlines of cutlines. They don't need
803 // their offsets adjusted.
804 true);
805 cutlineCopy->ShiftBy(t0 - GetSequenceStartTime());
806 newCutlines.push_back(std::move(cutlineCopy));
807 }
808
810
811 // Because newClip was made above as a copy of (a copy of) other
812 assert(other.GetWidth() == newClip->GetWidth());
813 // And other has the same width as this, so this loop is safe
814 // Assume Strong-guarantee from Sequence::Paste
815 for (size_t ii = 0, width = GetWidth(); ii < width; ++ii)
816 mSequences[ii]->Paste(s0, newClip->mSequences[ii].get());
817
818 transaction.Commit();
819
820 // Assume No-fail-guarantee in the remaining
821 MarkChanged();
822 const auto sampleTime = 1.0 / GetRate();
823 const auto timeOffsetInEnvelope =
825 mEnvelope->PasteEnvelope(
826 timeOffsetInEnvelope, newClip->mEnvelope.get(), sampleTime);
827 OffsetCutLines(t0, newClip->GetPlayEndTime() - newClip->GetPlayStartTime());
828
829 for (auto &holder : newCutlines)
830 mCutLines.push_back(std::move(holder));
831
832 return true;
833}
std::vector< WaveClipHolder > WaveClipHolders
Definition: WaveClip.h:46
sampleFormat Stored() const
Definition: SampleFormat.h:91
double GetTrimRight() const noexcept
Returns the play end offset in seconds from the ending of the underlying sequence.
Definition: WaveClip.cpp:1406
SampleFormats GetSampleFormats() const
Definition: WaveClip.cpp:409
sampleCount GetSequenceSamplesCount() const
Definition: WaveClip.cpp:1338
double as_double() const
Definition: SampleCount.h:46
void copy(const T *src, T *dst, int32_t n)
Definition: VectorOps.h:40

References sampleCount::as_double(), CheckInvariants(), ClearSequence(), staffpad::vo::copy(), cloud::factory, GetFactory(), GetPlayEndTime(), GetPlayStartTime(), GetRate(), GetSampleFormats(), GetSequenceEndTime(), GetSequenceSamplesCount(), GetSequenceStartTime(), GetStretchRatio(), GetTrimLeft(), GetTrimRight(), GetWidth(), MarkChanged(), mClipStretchRatio, mCutLines, mEnvelope, mProjectTempo, mRate, mRawAudioTempo, mSequences, OffsetCutLines(), Paste(), SetTrimLeft(), SetTrimRight(), SampleFormats::Stored(), and TimeToSequenceSamples().

Referenced by WaveTrack::ClearAndPasteOne(), ExpandCutLine(), WaveTrack::MergeOneClipPair(), Paste(), and WaveTrack::PasteOne().

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

◆ RemoveCutLine()

bool WaveClip::RemoveCutLine ( double  cutLinePosition)

Remove cut line, without expanding the audio in it.

Definition at line 1112 of file WaveClip.cpp.

1113{
1114 for (auto it = mCutLines.begin(); it != mCutLines.end(); ++it)
1115 {
1116 const auto &cutline = *it;
1117 //std::numeric_limits<double>::epsilon() or (1.0 / static_cast<double>(mRate))?
1118 if (fabs(GetSequenceStartTime() + cutline->GetSequenceStartTime() - cutLinePosition) < 0.0001)
1119 {
1120 mCutLines.erase(it); // deletes cutline!
1121 return true;
1122 }
1123 }
1124
1125 return false;
1126}

References GetSequenceStartTime(), and mCutLines.

Here is the call graph for this function:

◆ Resample()

void WaveClip::Resample ( int  rate,
BasicUI::ProgressDialog progress = nullptr 
)
Exception safety guarantee:
Strong

We want to keep going as long as we have something to feed the resampler with OR as long as the resampler spews out samples (which could continue for a few iterations after we stop feeding it)

Definition at line 1191 of file WaveClip.cpp.

1192{
1193 // Note: it is not necessary to do this recursively to cutlines.
1194 // They get resampled as needed when they are expanded.
1195
1196 if (rate == mRate)
1197 return; // Nothing to do
1198
1199 // This function does its own RAII without a Transaction
1200
1201 double factor = (double)rate / (double)mRate;
1202 ::Resample resample(true, factor, factor); // constant rate resampling
1203
1204 const size_t bufsize = 65536;
1205 Floats inBuffer{ bufsize };
1206 Floats outBuffer{ bufsize };
1207 sampleCount pos = 0;
1208 bool error = false;
1209 int outGenerated = 0;
1210 const auto numSamples = GetNumSamples();
1211
1212 // These sequences are appended to below
1213 auto newSequences = GetEmptySequenceCopies();
1214
1220 while (pos < numSamples || outGenerated > 0) {
1221 const auto inLen = limitSampleBufferSize( bufsize, numSamples - pos );
1222
1223 bool isLast = ((pos + inLen) == numSamples);
1224
1225 auto ppNewSequence = newSequences.begin();
1226 std::optional<std::pair<size_t, size_t>> results{};
1227 for (auto &pSequence : mSequences) {
1228 auto &pNewSequence = *ppNewSequence++;
1229 if (!pSequence->Get((samplePtr)inBuffer.get(), floatSample, pos, inLen, true))
1230 {
1231 error = true;
1232 break;
1233 }
1234
1235 // Expect the same results for all channels, or else fail
1236 auto newResults = resample.Process(factor, inBuffer.get(), inLen,
1237 isLast, outBuffer.get(), bufsize);
1238 if (!results)
1239 results.emplace(newResults);
1240 else if (*results != newResults) {
1241 error = true;
1242 break;
1243 }
1244
1245 outGenerated = results->second;
1246 if (outGenerated < 0) {
1247 error = true;
1248 break;
1249 }
1250
1251 pNewSequence->Append((samplePtr)outBuffer.get(), floatSample,
1252 outGenerated, 1,
1253 widestSampleFormat /* computed samples need dither */
1254 );
1255 }
1256 if (results)
1257 pos += results->first;
1258
1259 if (progress)
1260 {
1261 auto updateResult = progress->Poll(
1262 pos.as_long_long(),
1263 numSamples.as_long_long()
1264 );
1265 error = (updateResult != BasicUI::ProgressResult::Success);
1266 if (error)
1267 throw UserException{};
1268 }
1269 }
1270
1271 if (error)
1274 XO("Resampling failed."),
1275 XO("Warning"),
1276 "Error:_Resampling"
1277 };
1278 else
1279 {
1280 // Use No-fail-guarantee in these steps
1281 mSequences = move(newSequences);
1282 mRate = rate;
1283 Flush();
1284 Caches::ForEach( std::mem_fn( &WaveClipListener::Invalidate ) );
1285 }
1286}
@ Internal
Indicates internal failure from Audacity.
XO("Cut/Copy/Paste")
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
virtual ProgressResult Poll(unsigned long long numerator, unsigned long long denominator, const TranslatableString &message={})=0
Update the bar and poll for clicks. Call only on the main thread.
Interface to libsoxr.
Definition: Resample.h:27
A MessageBoxException that shows a given, unvarying string.
Can be thrown when user cancels operations, as with a progress dialog. Delayed handler does nothing.
Definition: UserException.h:17
std::vector< std::unique_ptr< Sequence > > GetEmptySequenceCopies() const
Definition: WaveClip.cpp:421
void Flush()
Flush must be called after last Append.
Definition: WaveClip.cpp:557
virtual void Invalidate()=0

References sampleCount::as_long_long(), floatSample, Flush(), GetEmptySequenceCopies(), GetNumSamples(), Internal, WaveClipListener::Invalidate(), limitSampleBufferSize(), mRate, mSequences, BasicUI::ProgressDialog::Poll(), Resample::Process(), BasicUI::Success, widestSampleFormat, and XO().

Here is the call graph for this function:

◆ SamplesToTime()

double WaveClip::SamplesToTime ( sampleCount  s) const
noexcept

Definition at line 1318 of file WaveClip.cpp.

1319{
1320 return s.as_double() * GetStretchRatio() / mRate;
1321}

Referenced by anonymous_namespace{WaveTrack.cpp}::RoundToNearestClipSample(), SetFloatsCenteredAroundTime(), SetRate(), and WaveClip().

Here is the caller graph for this function:

◆ SetCentShift()

bool WaveClip::SetCentShift ( int  cents)

Definition at line 1167 of file WaveClip.cpp.

1168{
1169 if (
1172 return false;
1173 mCentShift = cents;
1175 return true;
1176}
static constexpr auto MaxCents
static constexpr auto MinCents

References TimeAndPitchInterface::MaxCents, mCentShift, TimeAndPitchInterface::MinCents, and Observer::Publisher< Message, NotifyAll >::Publish().

Here is the call graph for this function:

◆ SetColourIndex()

void WaveClip::SetColourIndex ( int  index)
inline

Definition at line 232 of file WaveClip.h.

232{ mColourIndex = index; }

Referenced by HandleXMLTag().

Here is the caller graph for this function:

◆ SetEnvelope()

void WaveClip::SetEnvelope ( std::unique_ptr< Envelope p)

Definition at line 253 of file WaveClip.cpp.

254{
255 mEnvelope = move(p);
256}

References mEnvelope.

◆ SetFloatAtTime()

void WaveClip::SetFloatAtTime ( double  t,
size_t  iChannel,
float  value,
sampleFormat  effectiveFormat 
)

Definition at line 247 of file WaveClip.cpp.

249{
250 SetFloatsCenteredAroundTime(t, iChannel, &value, 0u, effectiveFormat);
251}
void SetFloatsCenteredAroundTime(double t, size_t iChannel, const float *buffer, size_t numSideSamples, sampleFormat effectiveFormat)
Same as SetFloatsFromTime, but with buffer starting at TimeToSamples(t0 - SamplesToTime(numSideSample...
Definition: WaveClip.cpp:238

References anonymous_namespace{StretchingSequenceIntegrationTest.cpp}::iChannel, and SetFloatsCenteredAroundTime().

Here is the call graph for this function:

◆ SetFloatsCenteredAroundTime()

void WaveClip::SetFloatsCenteredAroundTime ( double  t,
size_t  iChannel,
const float *  buffer,
size_t  numSideSamples,
sampleFormat  effectiveFormat 
)

Same as SetFloatsFromTime, but with buffer starting at TimeToSamples(t0 - SamplesToTime(numSideSamples)). [buffer, buffer + 2 * numSizeSamples + 1) is assumed to be a valid span of addresses.

Definition at line 238 of file WaveClip.cpp.

241{
243 t - SamplesToTime(numSideSamples), iChannel, buffer,
244 2 * numSideSamples + 1, effectiveFormat);
245}
void SetFloatsFromTime(double t, size_t iChannel, const float *buffer, size_t numSamples, sampleFormat effectiveFormat)
Considers buffer as audio starting at TimeToSamples(t) (relative to clip play start time) and with eq...
Definition: WaveClip.cpp:215

References anonymous_namespace{StretchingSequenceIntegrationTest.cpp}::iChannel, SamplesToTime(), and SetFloatsFromTime().

Referenced by SetFloatAtTime().

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

◆ SetFloatsFromTime()

void WaveClip::SetFloatsFromTime ( double  t,
size_t  iChannel,
const float *  buffer,
size_t  numSamples,
sampleFormat  effectiveFormat 
)

Considers buffer as audio starting at TimeToSamples(t) (relative to clip play start time) and with equal stretch ratio. Samples at intersecting indices are then copied, leaving non-intersecting clip samples untouched. E.g., buffer: [a b c d e] clip : [x y z] result: [d e z].

Succeed with out-of-bounds requests, only changing what is in bounds.

Definition at line 215 of file WaveClip.cpp.

218{
219 const auto maybeNegativeStart = TimeToSamples(t);
220 const auto maybeOutOfBoundEnd = maybeNegativeStart + numFloats;
221 const auto effectiveStart = std::max(sampleCount { 0 }, maybeNegativeStart);
222 const auto effectiveEnd =
223 std::min(GetVisibleSampleCount(), maybeOutOfBoundEnd);
224 if (effectiveStart >= effectiveEnd)
225 return;
226 // Cannot be greater than `numFloats` -> safe cast
227 const auto effectiveLen = (effectiveEnd - effectiveStart).as_size_t();
228 // Cannot be greater than `numFloats` -> safe cast
229 const auto numLeadingZeros =
230 (effectiveStart - maybeNegativeStart).as_size_t();
231 const auto offsetBuffer =
232 reinterpret_cast<const char*>(buffer + numLeadingZeros);
234 iChannel, offsetBuffer, floatSample, effectiveStart, effectiveLen,
235 effectiveFormat);
236}
sampleCount GetVisibleSampleCount() const override
Definition: WaveClip.cpp:1385
void SetSamples(size_t ii, constSamplePtr buffer, sampleFormat format, sampleCount start, size_t len, sampleFormat effectiveFormat)
Definition: WaveClip.cpp:191

References floatSample, GetVisibleSampleCount(), anonymous_namespace{StretchingSequenceIntegrationTest.cpp}::iChannel, min(), SetSamples(), and TimeToSamples().

Referenced by SetFloatsCenteredAroundTime().

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

◆ SetIsPlaceholder()

void WaveClip::SetIsPlaceholder ( bool  val)
inline

Definition at line 600 of file WaveClip.h.

600{ mIsPlaceholder = val; }

◆ SetName()

void WaveClip::SetName ( const wxString &  name)

Definition at line 1303 of file WaveClip.cpp.

1304{
1305 mName = name;
1306}
const TranslatableString name
Definition: Distortion.cpp:76

References mName, and name.

Referenced by HandleXMLTag().

Here is the caller graph for this function:

◆ SetPitchAndSpeedPreset()

void WaveClip::SetPitchAndSpeedPreset ( PitchAndSpeedPreset  preset)

Definition at line 1178 of file WaveClip.cpp.

References mPitchAndSpeedPreset, preset, and Observer::Publisher< Message, NotifyAll >::Publish().

Here is the call graph for this function:

◆ SetPlayStartTime()

void WaveClip::SetPlayStartTime ( double  time)

Definition at line 1348 of file WaveClip.cpp.

1349{
1351}

References mTrimLeft, and SetSequenceStartTime().

Here is the call graph for this function:

◆ SetRate()

void WaveClip::SetRate ( int  rate)

Definition at line 1147 of file WaveClip.cpp.

1148{
1149 const auto trimLeftSampleNum = TimeToSamples(mTrimLeft);
1150 const auto trimRightSampleNum = TimeToSamples(mTrimRight);
1151 auto ratio = static_cast<double>(mRate) / rate;
1152 mRate = rate;
1153 mTrimLeft = SamplesToTime(trimLeftSampleNum);
1154 mTrimRight = SamplesToTime(trimRightSampleNum);
1155 const auto newLength =
1157 mEnvelope->RescaleTimes(newLength);
1158 MarkChanged();
1160}

References sampleCount::as_double(), GetNumSamples(), GetSequenceStartTime(), GetStretchRatio(), MarkChanged(), mEnvelope, mRate, mTrimLeft, mTrimRight, SamplesToTime(), SetSequenceStartTime(), and TimeToSamples().

Here is the call graph for this function:

◆ SetRawAudioTempo()

void WaveClip::SetRawAudioTempo ( double  tempo)

Definition at line 1162 of file WaveClip.cpp.

1163{
1164 mRawAudioTempo = tempo;
1165}

References mRawAudioTempo.

◆ SetSamples()

void WaveClip::SetSamples ( size_t  ii,
constSamplePtr  buffer,
sampleFormat  format,
sampleCount  start,
size_t  len,
sampleFormat  effectiveFormat 
)
Parameters
iiidentifies the channel
Precondition
ii < GetWidth()
Parameters
startrelative to clip play start sample
Exception safety guarantee:
Strong
Parameters
effectiveFormatMake the effective format of the data at least the minumum of this value and `format`. (Maybe wider, if merging with preexistent data.) If the data are later narrowed from stored format, but not narrower than the effective, then no dithering will occur.

Definition at line 191 of file WaveClip.cpp.

194{
195 assert(ii < GetWidth());
196 // use Strong-guarantee
197 mSequences[ii]->SetSamples(buffer, format,
198 start + TimeToSamples(mTrimLeft), len, effectiveFormat);
199
200 // use No-fail-guarantee
201 MarkChanged();
202}

References anonymous_namespace{ExportPCM.cpp}::format, GetWidth(), MarkChanged(), mSequences, mTrimLeft, and TimeToSamples().

Referenced by SetFloatsFromTime().

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

◆ SetSequenceStartTime()

void WaveClip::SetSequenceStartTime ( double  startTime)

Definition at line 1460 of file WaveClip.cpp.

1461{
1462 mSequenceOffset = startTime;
1463 mEnvelope->SetOffset(startTime);
1464}

References mEnvelope, and mSequenceOffset.

Referenced by WaveTrack::ClearAndPasteOne(), ClearLeft(), WaveTrack::HandleXMLChild(), HandleXMLTag(), SetPlayStartTime(), and SetRate().

Here is the caller graph for this function:

◆ SetSilence()

void WaveClip::SetSilence ( sampleCount  offset,
sampleCount  length 
)

Silences the 'length' amount of samples starting from 'offset'(relative to the play start)

Definition at line 1328 of file WaveClip.cpp.

1329{
1330 const auto start = TimeToSamples(mTrimLeft) + offset;
1331 Transaction transaction{ *this };
1332 for (auto &pSequence : mSequences)
1333 pSequence->SetSilence(start, length);
1334 transaction.Commit();
1335 MarkChanged();
1336}

References WaveClip::Transaction::Commit(), MarkChanged(), mSequences, mTrimLeft, and TimeToSamples().

Here is the call graph for this function:

◆ SetTrimLeft()

void WaveClip::SetTrimLeft ( double  trim)

Sets the play start offset in seconds from the beginning of the underlying sequence.

Definition at line 1391 of file WaveClip.cpp.

1392{
1393 mTrimLeft = std::max(.0, trim);
1394}

References mTrimLeft.

Referenced by Clear(), WaveTrack::ClearAndPasteOne(), ClearLeft(), HandleXMLTag(), Paste(), and TrimLeft().

Here is the caller graph for this function:

◆ SetTrimRight()

void WaveClip::SetTrimRight ( double  trim)

Sets the play end offset in seconds from the ending of the underlying sequence.

Definition at line 1401 of file WaveClip.cpp.

1402{
1403 mTrimRight = std::max(.0, trim);
1404}

References mTrimRight.

Referenced by Clear(), WaveTrack::ClearAndPasteOne(), ClearRight(), HandleXMLTag(), InsertSilence(), Paste(), and TrimRight().

Here is the caller graph for this function:

◆ SharesBoundaryWithNextClip()

bool WaveClip::SharesBoundaryWithNextClip ( const WaveClip next) const

Definition at line 1292 of file WaveClip.cpp.

1293{
1294 double endThis = GetRate() * GetPlayStartTime() +
1296 double startNext = next->GetRate() * next->GetPlayStartTime();
1297
1298 // given that a double has about 15 significant digits, using a criterion
1299 // of half a sample should be safe in all normal usage.
1300 return fabs(startNext - endThis) < 0.5;
1301}

References sampleCount::as_double(), GetPlayStartTime(), GetRate(), GetStretchRatio(), and GetVisibleSampleCount().

Here is the call graph for this function:

◆ ShiftBy()

void WaveClip::ShiftBy ( double  delta)
noexcept
Exception safety guarantee:
No-fail

Definition at line 1479 of file WaveClip.cpp.

1480{
1482}

Referenced by Clear(), ClearAndAddCutLine(), WaveTrack::ClearAndPasteOne(), ClearSequence(), and WaveTrack::CopyOne().

Here is the caller graph for this function:

◆ SnapToTrackSample()

double WaveClip::SnapToTrackSample ( double  time) const
privatenoexcept

Definition at line 1323 of file WaveClip.cpp.

1324{
1325 return std::round(t * mRate) / mRate;
1326}
fastfloat_really_inline void round(adjusted_mantissa &am, callback cb) noexcept
Definition: fast_float.h:2512

References fast_float::round().

Referenced by GetPlayEndTime(), GetPlayStartTime(), TrimLeftTo(), and TrimRightTo().

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

◆ SplitsPlayRegion()

bool WaveClip::SplitsPlayRegion ( double  t) const

[ < t and t < ), such that if the track were split at t, it would split this clip in two of lengths > 0.

The play region is an open-closed interval, [...), where "[ = GetPlayStartTime()", and ") = GetPlayEndTime()."

Definition at line 1484 of file WaveClip.cpp.

1485{
1486 return GetPlayStartTime() < t && t < GetPlayEndTime();
1487}

References GetPlayEndTime(), and GetPlayStartTime().

Referenced by WaveTrack::ApplyPitchAndSpeed().

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

◆ StretchBy()

void WaveClip::StretchBy ( double  ratio)

Definition at line 330 of file WaveClip.cpp.

331{
332 const auto pst = GetPlayStartTime();
333 mSequenceOffset = pst - mTrimLeft * ratio;
334 mTrimLeft *= ratio;
335 mTrimRight *= ratio;
336 mClipStretchRatio *= ratio;
337 mEnvelope->SetOffset(mSequenceOffset);
338 mEnvelope->RescaleTimesBy(ratio);
339 StretchCutLines(ratio);
342}

References GetPlayStartTime(), GetStretchRatio(), mClipStretchRatio, mEnvelope, mSequenceOffset, mTrimLeft, mTrimRight, Observer::Publisher< Message, NotifyAll >::Publish(), and StretchCutLines().

Referenced by StretchRightTo().

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

◆ StretchCutLines()

void WaveClip::StretchCutLines ( double  ratioChange)
private

Definition at line 344 of file WaveClip.cpp.

345{
346 for (const auto& cutline : mCutLines)
347 {
348 cutline->mSequenceOffset *= ratioChange;
349 cutline->mTrimLeft *= ratioChange;
350 cutline->mTrimRight *= ratioChange;
351 cutline->mClipStretchRatio *= ratioChange;
352 cutline->mEnvelope->RescaleTimesBy(ratioChange);
353 }
354}

References mCutLines.

Referenced by OnProjectTempoChange(), StretchBy(), and StretchLeftTo().

Here is the caller graph for this function:

◆ StretchLeftTo()

void WaveClip::StretchLeftTo ( double  to)

Stretches from left to the absolute time (if in expected range)

Definition at line 300 of file WaveClip.cpp.

301{
302 const auto pet = GetPlayEndTime();
303 if (to >= pet)
304 return;
305 const auto oldPlayDuration = pet - GetPlayStartTime();
306 const auto newPlayDuration = pet - to;
307 const auto ratioChange = newPlayDuration / oldPlayDuration;
308 mSequenceOffset = pet - (pet - mSequenceOffset) * ratioChange;
309 mTrimLeft *= ratioChange;
310 mTrimRight *= ratioChange;
311 mClipStretchRatio *= ratioChange;
312 mEnvelope->SetOffset(mSequenceOffset);
313 mEnvelope->RescaleTimesBy(ratioChange);
314 StretchCutLines(ratioChange);
317}

References GetPlayEndTime(), GetPlayStartTime(), GetStretchRatio(), mClipStretchRatio, mEnvelope, mSequenceOffset, mTrimLeft, mTrimRight, Observer::Publisher< Message, NotifyAll >::Publish(), and StretchCutLines().

Here is the call graph for this function:

◆ StretchRatioEquals()

bool WaveClip::StretchRatioEquals ( double  value) const
private

Definition at line 397 of file WaveClip.cpp.

398{
400 1 + GetStretchRatio() - value);
401}
static bool IsPassThroughMode(double stretchRatio)

References GetStretchRatio(), and TimeAndPitchInterface::IsPassThroughMode().

Referenced by HasEqualPitchAndSpeed(), and HasPitchOrSpeed().

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

◆ StretchRightTo()

void WaveClip::StretchRightTo ( double  to)

Sets from the right to the absolute time (if in expected range)

Definition at line 319 of file WaveClip.cpp.

320{
321 const auto pst = GetPlayStartTime();
322 if (to <= pst)
323 return;
324 const auto oldPlayDuration = GetPlayEndTime() - pst;
325 const auto newPlayDuration = to - pst;
326 const auto ratioChange = newPlayDuration / oldPlayDuration;
327 StretchBy(ratioChange);
328}
void StretchBy(double ratio)
Definition: WaveClip.cpp:330

References GetPlayEndTime(), GetPlayStartTime(), and StretchBy().

Here is the call graph for this function:

◆ SubscribeToCentShiftChange()

Observer::Subscription WaveClip::SubscribeToCentShiftChange ( std::function< void(int)>  cb)
overridevirtual

Implements ClipInterface.

Definition at line 371 of file WaveClip.cpp.

372{
374 [cb](const CentShiftChange& cents) { cb(cents.newValue); });
375}
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
Definition: Observer.h:199
const int newValue
Definition: WaveClip.h:105

References CentShiftChange::newValue, and Observer::Publisher< Message, NotifyAll >::Subscribe().

Here is the call graph for this function:

◆ SubscribeToPitchAndSpeedPresetChange()

Observer::Subscription WaveClip::SubscribeToPitchAndSpeedPresetChange ( std::function< void(PitchAndSpeedPreset)>  cb)
overridevirtual

Implements ClipInterface.

Definition at line 377 of file WaveClip.cpp.

379{
381 [cb](const PitchAndSpeedPresetChange& formant) {
382 cb(formant.newValue);
383 });
384}
const PitchAndSpeedPreset newValue
Definition: WaveClip.h:114

References PitchAndSpeedPresetChange::newValue, and Observer::Publisher< Message, NotifyAll >::Subscribe().

Here is the call graph for this function:

◆ TimeToSamples()

sampleCount WaveClip::TimeToSamples ( double  time) const
overridevirtual

Implements ClipTimes.

Definition at line 1313 of file WaveClip.cpp.

1314{
1315 return sampleCount(floor(time * mRate / GetStretchRatio() + 0.5));
1316}

References GetStretchRatio(), and mRate.

Referenced by CountSamples(), GetFloatAtTime(), GetSamples(), GetSampleView(), GetSequenceStartSample(), GetVisibleSampleCount(), InsertSilence(), SetFloatsFromTime(), SetRate(), SetSamples(), SetSilence(), WaveChannelInterval::TimeToSamples(), TimeToSequenceSamples(), and WaveClip().

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

◆ TimeToSequenceSamples()

sampleCount WaveClip::TimeToSequenceSamples ( double  t) const
private

Definition at line 1550 of file WaveClip.cpp.

1551{
1552 if (t < GetSequenceStartTime())
1553 return 0;
1554 else if (t > GetSequenceEndTime())
1555 return GetNumSamples();
1556 return TimeToSamples(t - GetSequenceStartTime());
1557}

References GetNumSamples(), GetSequenceEndTime(), GetSequenceStartTime(), and TimeToSamples().

Referenced by ClearAndAddCutLine(), ClearSequence(), GetMinMax(), GetRMS(), InsertSilence(), and Paste().

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

◆ TrimLeft()

void WaveClip::TrimLeft ( double  deltaTime)

Moves play start position by deltaTime.

Definition at line 1411 of file WaveClip.cpp.

1412{
1413 SetTrimLeft(mTrimLeft + deltaTime);
1414}

References mTrimLeft, and SetTrimLeft().

Here is the call graph for this function:

◆ TrimLeftTo()

void WaveClip::TrimLeftTo ( double  to)

Sets the the left trimming to the absolute time (if that is in bounds)

Definition at line 1440 of file WaveClip.cpp.

1441{
1442 mTrimLeft =
1445}

References GetPlayEndTime(), mSequenceOffset, mTrimLeft, and SnapToTrackSample().

Here is the call graph for this function:

◆ TrimQuarternotesFromRight()

void WaveClip::TrimQuarternotesFromRight ( double  quarters)

Same as TrimRight, but expressed as quarter notes.

Definition at line 1421 of file WaveClip.cpp.

1422{
1423 assert(mRawAudioTempo.has_value());
1424 if (!mRawAudioTempo.has_value())
1425 return;
1426 const auto secondsPerQuarter = 60 * GetStretchRatio() / *mRawAudioTempo;
1427 // MH https://github.com/audacity/audacity/issues/5878: Clip boundaries are
1428 // quantized to the sample period. Music durations aren't, though.
1429 // `quarters` was probably chosen such that the clip ends exactly at some
1430 // musical grid snapping point. However, if we right-trim by `quarters`,
1431 // the clip's play end time might be rounded up to the next sample period,
1432 // overlapping the next snapping point on the musical grid. We don't want
1433 // this, or it would disturb music producers who want to horizontally
1434 // duplicate loops.
1435 const auto quantizedTrim =
1436 std::ceil(quarters * secondsPerQuarter * GetRate()) / GetRate();
1437 TrimRight(quantizedTrim);
1438}
void TrimRight(double deltaTime)
Moves play end position by deltaTime.
Definition: WaveClip.cpp:1416

References GetRate(), GetStretchRatio(), mRawAudioTempo, and TrimRight().

Here is the call graph for this function:

◆ TrimRight()

void WaveClip::TrimRight ( double  deltaTime)

Moves play end position by deltaTime.

Definition at line 1416 of file WaveClip.cpp.

1417{
1418 SetTrimRight(mTrimRight + deltaTime);
1419}

References mTrimRight, and SetTrimRight().

Referenced by TrimQuarternotesFromRight().

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

◆ TrimRightTo()

void WaveClip::TrimRightTo ( double  to)

Sets the the right trimming to the absolute time (if that is in bounds)

Definition at line 1447 of file WaveClip.cpp.

1448{
1449 const auto endTime = SnapToTrackSample(GetSequenceEndTime());
1450 mTrimRight = endTime - std::clamp(to, GetPlayStartTime(), endTime);
1451}

References GetPlayStartTime(), GetSequenceEndTime(), mTrimRight, and SnapToTrackSample().

Here is the call graph for this function:

◆ UpdateEnvelopeTrackLen()

void WaveClip::UpdateEnvelopeTrackLen ( )

Whenever you do an operation to the sequence that will change the number of samples (that is, the length of the clip), you will want to call this function to tell the envelope about it.

Exception safety guarantee:
No-fail

Definition at line 506 of file WaveClip.cpp.

507{
508 // The envelope time points account for stretching.
509 const auto len = GetNumSamples().as_double() * GetStretchRatio() / mRate;
510 if (len != mEnvelope->GetTrackLen())
511 mEnvelope->SetTrackLen(len, 1.0 / GetRate());
512}

References sampleCount::as_double(), GetNumSamples(), GetRate(), GetStretchRatio(), mEnvelope, and mRate.

Referenced by Append(), Flush(), and HandleXMLEndTag().

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

◆ WithinPlayRegion()

bool WaveClip::WithinPlayRegion ( double  t) const

t ∈ [...)

Definition at line 1489 of file WaveClip.cpp.

1490{
1491 return GetPlayStartTime() <= t && t < GetPlayEndTime();
1492}

References GetPlayEndTime(), and GetPlayStartTime().

Referenced by GetFloatAtTime(), and PartlyWithinPlayRegion().

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

◆ WriteXML()

void WaveClip::WriteXML ( XMLWriter xmlFile) const

Definition at line 697 of file WaveClip.cpp.

699{
700 if (GetSequenceSamplesCount() <= 0)
701 // Oops, I'm empty? How did that happen? Anyway, I do nothing but causing
702 // problems, don't save me.
703 return;
704
705 xmlFile.StartTag(wxT("waveclip"));
706 xmlFile.WriteAttr(wxT("offset"), mSequenceOffset, 8);
707 xmlFile.WriteAttr(wxT("trimLeft"), mTrimLeft, 8);
708 xmlFile.WriteAttr(wxT("trimRight"), mTrimRight, 8);
709 xmlFile.WriteAttr(wxT("centShift"), mCentShift);
710 xmlFile.WriteAttr(
711 wxT("pitchAndSpeedPreset"), static_cast<long>(mPitchAndSpeedPreset));
712 xmlFile.WriteAttr(wxT("rawAudioTempo"), mRawAudioTempo.value_or(0.), 8);
713 xmlFile.WriteAttr(wxT("clipStretchRatio"), mClipStretchRatio, 8);
714 xmlFile.WriteAttr(wxT("name"), mName);
715 xmlFile.WriteAttr(wxT("colorindex"), mColourIndex );
716
717 for (auto &pSequence : mSequences)
718 pSequence->WriteXML(xmlFile);
719 mEnvelope->WriteXML(xmlFile);
720
721 for (const auto &clip: mCutLines)
722 clip->WriteXML(xmlFile);
723
724 xmlFile.EndTag(wxT("waveclip"));
725}
wxT("CloseDown"))
virtual void StartTag(const wxString &name)
Definition: XMLWriter.cpp:79
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:36
virtual void EndTag(const wxString &name)
Definition: XMLWriter.cpp:102

References wxT().

Here is the call graph for this function:

Member Data Documentation

◆ mCentShift

int WaveClip::mCentShift { 0 }
private

Definition at line 664 of file WaveClip.h.

Referenced by GetCentShift(), HandleXMLTag(), and SetCentShift().

◆ mClipStretchRatio

double WaveClip::mClipStretchRatio = 1.
private

Definition at line 668 of file WaveClip.h.

Referenced by GetStretchRatio(), HandleXMLTag(), Paste(), StretchBy(), and StretchLeftTo().

◆ mColourIndex

int WaveClip::mColourIndex
private

Definition at line 674 of file WaveClip.h.

Referenced by WaveClip().

◆ mCutLines

WaveClipHolders WaveClip::mCutLines {}
private

Cut Lines are nothing more than ordinary wave clips, with the offset relative to the start of the clip.

Invariant
all are non-null

Definition at line 692 of file WaveClip.h.

Referenced by CheckInvariants(), ClearAndAddCutLine(), ClearSequence(), CloseLock(), ExpandCutLine(), FindCutLine(), HandleXMLChild(), OffsetCutLines(), Paste(), RemoveCutLine(), StretchCutLines(), and WaveClip().

◆ mEnvelope

std::unique_ptr<Envelope> WaveClip::mEnvelope
private

◆ mIsPlaceholder

bool WaveClip::mIsPlaceholder { false }
private

Definition at line 695 of file WaveClip.h.

Referenced by WaveClip().

◆ mName

wxString WaveClip::mName
private

Definition at line 698 of file WaveClip.h.

Referenced by GetName(), SetName(), and WaveClip().

◆ mPitchAndSpeedPreset

PitchAndSpeedPreset WaveClip::mPitchAndSpeedPreset { PitchAndSpeedPreset::Default }
private

Definition at line 663 of file WaveClip.h.

Referenced by GetPitchAndSpeedPreset(), HandleXMLTag(), and SetPitchAndSpeedPreset().

◆ mProjectTempo

std::optional<double> WaveClip::mProjectTempo
private

Definition at line 670 of file WaveClip.h.

Referenced by GetStretchRatio(), OnProjectTempoChange(), and Paste().

◆ mRate

int WaveClip::mRate
private

Sample rate of the raw audio, i.e., before stretching.

Definition at line 673 of file WaveClip.h.

Referenced by GetPlayEndSample(), GetPlayEndTime(), GetPlayStartSample(), GetSequenceEndTime(), HandleXMLChild(), IsEmpty(), Paste(), Resample(), SetRate(), TimeToSamples(), UpdateEnvelopeTrackLen(), and WaveClip().

◆ mRawAudioTempo

std::optional<double> WaveClip::mRawAudioTempo
private

◆ mSequenceOffset

double WaveClip::mSequenceOffset { 0 }
private

Real-time durations, i.e., stretching the clip modifies these.

Definition at line 658 of file WaveClip.h.

Referenced by GetPlayEndTime(), GetPlayStartTime(), GetSequenceStartSample(), GetSequenceStartTime(), OnProjectTempoChange(), SetSequenceStartTime(), StretchBy(), StretchLeftTo(), TrimLeftTo(), and WaveClip().

◆ mSequences

std::vector<std::unique_ptr<Sequence> > WaveClip::mSequences
private

◆ mTrimLeft

double WaveClip::mTrimLeft { 0 }
private

◆ mTrimRight

double WaveClip::mTrimRight { 0 }
private

The documentation for this class was generated from the following files: