11#ifndef __AUDACITY_WAVECLIP__
12#define __AUDACITY_WAVECLIP__
23#include <wx/longlong.h>
82 virtual
void Erase(
size_t index);
102 const Envelope &GetEnvelope()
const;
104 bool Intersects(
double t0,
double t1)
const;
105 double Start()
const;
119 GetSampleView(
double t0,
double t1,
bool mayThrow)
const;
124 bool WithinPlayRegion(
double t)
const;
125 double SamplesToTime(
sampleCount s)
const noexcept;
128 double GetTrimLeft()
const;
129 double GetTrimRight()
const;
132 sampleCount start,
size_t len,
bool mayThrow =
true)
const;
135 sampleCount start,
size_t length,
bool mayThrow)
const;
137 const Sequence &GetSequence()
const;
140 size_t GetAppendBufferLen()
const;
142 const BlockArray *GetSequenceBlockArray()
const;
148 std::pair<float, float>
GetMinMax(
double t0,
double t1,
bool mayThrow)
const;
153 float GetRMS(
double t0,
double t1,
bool mayThrow)
const;
177 sampleCount GetVisibleSampleCount()
const override;
179 double GetPlayStartTime()
const override;
180 double GetPlayEndTime()
const override;
181 double GetPlayDuration()
const;
182 sampleCount TimeToSamples(
double time)
const override;
183 double GetStretchRatio()
const override;
190 {
return !(a == b); }
233 WaveClip, WaveClipListener, ClientData::DeepCopying>,
251 using Attachments = Site<WaveClip, WaveClipListener, ClientData::DeepCopying>;
284 double t0,
double t1);
289 double Start()
const override;
290 double End()
const override;
291 std::shared_ptr<ChannelInterval> DoGetChannel(
size_t iChannel)
override;
296 WideChannelGroupInterval::Channels<Channel>(); }
299 WideChannelGroupInterval::Channels<const Channel>(); }
309 bool CheckInvariants()
const;
315 bool StrongInvariant()
const;
320 void AssertOrRepairStrongInvariant();
332 size_t NChannels()
const override;
335 const std::function<
void(
size_t)> & progressReport = {});
343 void SetRate(
int rate);
344 void SetRawAudioTempo(
double tempo);
352 void StretchBy(
double ratio);
354 double GetStretchRatio()
const override;
358 bool HasEqualPitchAndSpeed(
const WaveClip& other)
const;
366 bool SetCentShift(
int cents);
367 int GetCentShift()
const override;
369 SubscribeToCentShiftChange(std::function<
void(
int)> cb)
const override;
373 SubscribeToPitchAndSpeedPresetChange(
380 double GetSequenceStartTime() const noexcept;
381 void SetSequenceStartTime(
double startTime);
382 double GetSequenceEndTime() const;
391 double GetPlayStartTime() const noexcept override;
392 void SetPlayStartTime(
double time);
396 double GetPlayEndTime() const override;
400 double GetPlayDuration() const;
402 bool IsEmpty() const;
412 sampleCount GetVisibleSampleCount() const override;
415 void SetTrimLeft(
double trim);
417 double GetTrimLeft() const noexcept;
420 void SetTrimRight(
double trim);
422 double GetTrimRight() const noexcept;
425 void TrimLeft(
double deltaTime);
427 void TrimRight(
double deltaTime);
429 void TrimQuarternotesFromRight(
double quarters);
437 void ShiftBy(
double delta) noexcept;
446 bool SplitsPlayRegion(
double t) const;
450 bool WithinPlayRegion(
double t) const;
454 bool BeforePlayRegion(
double t) const;
458 bool AtOrBeforePlayRegion(
double t) const;
462 bool AfterPlayRegion(
double t) const;
467 bool EntirelyWithinPlayRegion(
double t0,
double t1) const;
472 bool PartlyWithinPlayRegion(
double t0,
double t1) const;
477 bool IntersectsPlayRegion(
double t0,
double t1) const;
483 bool CoversEntirePlayRegion(
double t0,
double t1) const;
489 sampleCount CountSamples(
double t0,
double t1) const;
501 bool mayThrow = true) const override;
515 size_t iChannel,
double t0,
double t1,
bool mayThrow = true) const;
524 sampleCount start,
size_t len,
bool mayThrow = true) const;
532 sampleCount start,
size_t len,
bool mayThrow = true) const;
553 Envelope &GetEnvelope() noexcept {
return *mEnvelope; }
557 void SetEnvelope(std::unique_ptr<Envelope> p);
563 const BlockArray* GetSequenceBlockArray(
size_t ii)
const;
572 assert(ii < NChannels());
573 return mSequences[ii].get();
586 std::pair<float, float>
GetMinMax(
size_t ii,
587 double t0,
double t1,
bool mayThrow)
const;
591 float GetRMS(
size_t ii,
double t0,
double t1,
bool mayThrow)
const;
596 void UpdateEnvelopeTrackLen();
601 std::shared_ptr<SampleBlock>
608 std::shared_ptr<SampleBlock>
616 void AppendLegacySharedBlock(
const std::shared_ptr<SampleBlock> &pBlock);
635 size_t len,
unsigned int stride,
656 size_t len,
unsigned int stride,
673 void RepairChannels();
677 void Clear(
double t0,
double t1);
683 void ClearLeft(
double t);
687 void ClearRight(
double t);
695 void ClearAndAddCutLine(
double t0,
double t1);
713 bool Paste(
double t0,
const WaveClip& other);
721 void InsertSilence(
double t,
double len,
double *pEnvelopeValue =
nullptr );
725 void AppendSilence(
double len,
double envelopeValue );
736 bool FindCutLine(
double cutLinePosition,
737 double* cutLineStart =
nullptr,
738 double *cutLineEnd =
nullptr)
const;
749 void OffsetCutLines(
double t0,
double len);
759 bool HandleXMLTag(const
std::string_view& tag, const
AttributesList &attrs) override;
760 void HandleXMLEndTag(const
std::string_view& tag) override;
769 void WriteXML(
size_t ii,
XMLWriter &xmlFile) const;
772 bool GetIsPlaceholder()
const {
return mIsPlaceholder; }
775 void SetName(
const wxString&
name);
776 const wxString& GetName()
const;
780 sampleCount TimeToSamples(
double time)
const override;
781 double SamplesToTime(
sampleCount s)
const noexcept;
800 size_t GetAppendBufferLen(
size_t ii)
const;
813 void DiscardRightChannel();
825 std::shared_ptr<WaveClip> SplitChannels();
845 size_t GetMaxBlockSize()
const;
863 bool copyCutlines, CreateToken token);
867 static void FixSplitCutlines(
870 size_t GreatestAppendBufferLen()
const;
879 bool StretchRatioEquals(
double value) const;
882 std::vector<
std::unique_ptr<
Sequence>> GetEmptySequenceCopies() const;
883 void StretchCutLines(
double ratioChange);
884 double SnapToTrackSample(
double time) const noexcept;
900 double t0,
double t1,
double clip_t0,
double clip_t1) noexcept
902 , t0{ t0 }, t1{ t1 }, clip_t0{ clip_t0 }, clip_t1{ clip_t1 }
907 other.
pClip =
nullptr;
911 void Commit() noexcept { committed =
true; }
917 double t0{}, t1{}, clip_t0{}, clip_t1{};
918 bool committed =
false;
939 bool committed{
false };
944 double mSequenceOffset { 0 };
945 double mTrimLeft { 0 };
946 double mTrimRight { 0 };
950 int mCentShift { 0 };
954 double mClipStretchRatio = 1.;
976 bool mIsPlaceholder {
false };
An audio segment is either a whole clip or the silence between clips. Views allow shared references t...
Abstract class ChannelGroup with two discrete iterable dimensions, channels and intervals; subclasses...
Utility ClientData::Site to register hooks into a host class that attach client data.
std::shared_ptr< SampleBlockFactory > SampleBlockFactoryPtr
AttachedVirtualFunction< struct OnProjectTempoChangeTag, void, ChannelGroup, const std::optional< double > &, double > OnProjectTempoChange
Method to set project tempo on a channel group, defaulting to no-op.
std::function< void(double)> ProgressReporter
std::vector< WaveClipConstHolder > WaveClipConstHolders
std::shared_ptr< const WaveClip > WaveClipConstHolder
std::shared_ptr< WaveClip > WaveClipHolder
CRTP_BASE(WaveClipListenerBase, struct, ClientData::Cloneable< WaveClipListener >)
std::vector< WaveClipHolder > WaveClipHolders
Append(Adapt< My >([](My &table) { return(WaveChannelSubViews::numFactories() > 1) ? std::make_unique< Entry >("MultiView", Entry::CheckItem, OnMultiViewID, XXO("&Multi-view"), POPUP_MENU_FN(OnMultiView), table, [](PopupMenuHandler &handler, wxMenu &menu, int id){ auto &table=static_cast< WaveTrackMenuTable & >(handler);auto &track=table.FindWaveTrack();const auto &view=WaveChannelView::GetFirst(track);menu.Check(id, view.GetMultiView());}) :nullptr;}))
bool operator==(const WaveTrackLocation &a, const WaveTrackLocation &b)
bool operator!=(const WaveTrackLocation &a, const WaveTrackLocation &b)
std::vector< Attribute > AttributesList
Abstraction of a progress dialog with well defined time-to-completion estimate.
The intersection of a Channel and a WideChannelGroupInterval.
Utility to register hooks into a host class that attach client data.
Piecewise linear or piecewise exponential function from double to double.
An object that sends messages to an open-ended list of subscribed callbacks.
A move-only handle representing a connection to a Publisher.
abstract base class with methods to produce SampleBlock objects
Abstract class allows access to contents of a block of sound samples, serialization as XML,...
A WaveTrack contains WaveClip(s). A WaveClip contains a Sequence. A Sequence is primarily an interfac...
Fix consistency of cutlines and envelope after deleting from Sequences.
ClearSequenceFinisher() noexcept=default
const WaveClip & GetClip() const
size_t GetChannelIndex() const
~WaveClipChannel() override
WaveClipChannel(WaveClip &clip, size_t iChannel)
This allows multiple clips to be a part of one WaveTrack.
std::optional< double > mRawAudioTempo
Site< WaveClip, WaveClipListener, ClientData::DeepCopying > Attachments
void SetIsPlaceholder(bool val)
WaveClip(const WaveClip &orig, const SampleBlockFactoryPtr &factory, bool copyCutlines)
std::unique_ptr< Envelope > mEnvelope
Envelope is unique, not per-sequence, and always non-null.
std::optional< double > mProjectTempo
const Envelope & GetEnvelope() const noexcept
int GetRate() const override
int mRate
Sample rate of the raw audio, i.e., before stretching.
const WaveClipHolders & GetCutLines()
Get access to cut lines list.
WaveClip(const WaveClip &)=delete
const Sequence * GetSequence(size_t ii) const
static const char * WaveClip_tag
Sequence * GetSequence(size_t ii)
const WaveClipConstHolders & GetCutLines() const
size_t NumCutLines() const
std::vector< std::unique_ptr< Sequence > > mSequences
A view into an attribute value. The class does not take the ownership of the data.
This class is an interface which should be implemented by classes which wish to be able to load and s...
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Positions or offsets within audio files need a wide type.
WAVE_TRACK_API bool HasPitchOrSpeed(const WaveTrack &track, double t0, double t1)
WAVE_TRACK_API std::pair< float, float > GetMinMax(const WaveChannel &channel, double t0, double t1, bool mayThrow=true)
WAVE_TRACK_API float GetRMS(const WaveChannel &channel, double t0, double t1, bool mayThrow=true)
WAVE_TRACK_API size_t CountBlocks(const WaveTrack &track)
WAVE_TRACK_API sampleCount GetSequenceSamplesCount(const WaveTrack &track)
WAVE_TRACK_API void ExpandCutLine(WaveTrack &track, double cutLinePosition, double *cutlineStart=nullptr, double *cutlineEnd=nullptr)
WAVE_TRACK_API void CloseLock(WaveTrack &track) noexcept
Should be called upon project close. Not balanced by unlocking calls.
WAVE_TRACK_API bool RemoveCutLine(WaveTrack &track, double cutLinePosition)
Remove cut line, without expanding the audio in it.
double GetRate(const Track &track)
void StretchRightTo(WaveTrack::Interval &interval, double t)
void StretchLeftTo(WaveTrack::Interval &interval, double t)
void TrimLeftTo(WaveTrack::Interval &interval, double t)
void TrimRightTo(WaveTrack::Interval &interval, double t)
CentShiftChange(int newValue)
A convenient base class defining abstract virtual Clone() for a given kind of pointer.
const PitchAndSpeedPreset newValue
PitchAndSpeedPresetChange(PitchAndSpeedPreset newValue)
StretchRatioChange(double newValue)
Restores state when an update loop over mSequences fails midway.
std::vector< std::unique_ptr< Sequence > > sequences
virtual void MarkChanged() noexcept=0
virtual void MakeStereo(WaveClipListener &&other, bool aligned)
virtual void Erase(size_t index)
virtual void WriteXMLAttributes(XMLWriter &writer) const
virtual ~WaveClipListener()=0
virtual bool HandleXMLAttribute(const std::string_view &attr, const XMLAttributeValueView &valueView)
virtual void SwapChannels()
Default implementation does nothing.
virtual void Invalidate()=0