11#ifndef __AUDACITY_WAVETRACK__
12#define __AUDACITY_WAVETRACK__
25#include <wx/longlong.h>
61#define WAVETRACK_MERGE_POINT_TOLERANCE 0.01
73 ) : mWideClip{ wideClip }
74 , mNarrowClip{ narrowClip }
83 bool Intersects(
double t0,
double t1)
const;
98 GetSampleView(
double t0,
double t1,
bool mayThrow)
const;
107 double GetTrimLeft()
const;
108 double GetTrimRight()
const;
111 sampleCount start,
size_t len,
bool mayThrow =
true)
const;
114 sampleCount start,
size_t length,
bool mayThrow)
const;
116 const Sequence &GetSequence()
const;
119 size_t GetAppendBufferLen()
const;
121 int GetColourIndex()
const;
143 ::Channel::GetInterval<WaveChannelInterval>(iInterval); }
145 ::Channel::GetInterval<const WaveChannelInterval>(iInterval); }
147 auto Intervals() { return ::Channel::Intervals<WaveChannelInterval>(); }
149 return ::Channel::Intervals<const WaveChannelInterval>(); }
158 constexpr auto backwards =
false;
160 0, 1, &buffer, start, len, backwards, fill, mayThrow, pNumWithinClips);
200 std::pair<float, float> GetMinMax(
201 double t0,
double t1,
bool mayThrow =
true)
const;
207 float GetRMS(
double t0,
double t1,
bool mayThrow =
true)
const;
210 inline size_t GetBestBlockSize(
sampleCount t)
const;
212 inline size_t GetIdealBlockSize();
215 inline size_t GetMaxBlockSize()
const;
232 Region(
double start_,
double end_) : start(start_),
end(end_) {}
239 return this->start < b.
start;
245 static wxString GetDefaultAudioTrackNamePreference();
262 size_t GetWidth()
const;
265 size_t NChannels()
const override;
268 return this->ChannelGroup::GetChannel<WaveChannel>(
iChannel); }
270 return this->ChannelGroup::GetChannel<const WaveChannel>(
iChannel); }
273 return this->ChannelGroup::Channels<WaveChannel>(); }
275 return this->ChannelGroup::Channels<const WaveChannel>(); }
294 wxString MakeClipCopyName(
const wxString& originalName)
const;
295 wxString MakeNewClipName()
const;
298 using Holder = std::shared_ptr<WaveTrack>;
302 void MoveTo(
double o)
override;
304 bool LinkConsistencyFix(
bool doFix)
override;
307 double GetStartTime()
const override;
309 double GetEndTime()
const override;
319 double GetRate()
const override;
322 void SetRate(
double newRate);
325 float GetGain()
const;
326 void SetGain(
float newGain);
329 float GetPan()
const;
330 void SetPan(
float newPan);
333 float GetChannelGain(
int channel)
const override;
335 int GetWaveColorIndex()
const;
339 void SetWaveColorIndex(
int colorIndex);
358 size_t CountBlocks()
const;
366 const std::function<
void(
size_t)> & progressReport = {});
386 bool keepLink =
true)
const;
402 bool keepLink =
true)
const;
414 void Clear(
double t0,
double t1)
override;
415 void Paste(
double t0,
const Track &src)
override;
426 double t0,
double t1,
const WaveTrack& src,
bool preserve =
true,
427 bool merge =
true,
const TimeWarper* effectWarper =
nullptr,
428 bool clearByTrimming =
false) ;
436 bool preserve =
true,
440 ClearAndPaste(t0, t1, **src.
Any<
const WaveTrack>().begin(),
441 preserve, merge, effectWarper);
444 void Silence(
double t0,
double t1,
ProgressReporter reportProgress)
override;
445 void InsertSilence(
double t,
double len)
override;
450 void Split(
double t0,
double t1) ;
455 void ClearAndAddCutLine(
double t0,
double t1) ;
467 void SplitDelete(
double t0,
double t1) ;
472 double t0,
double t1,
478 void Disjoin(
double t0,
double t1) ;
484 void Trim(
double t0,
double t1) ;
493 void ApplyStretchRatio(
496 void SyncLockAdjust(
double oldT1,
double newT1)
override;
503 bool IsEmpty(
double t0,
double t1)
const;
512 size_t len,
unsigned int stride = 1,
516 void Flush()
override;
518 bool IsLeader()
const override;
523 bool GetMute()
const override;
524 bool GetSolo()
const override;
546 sampleCount* pNumWithinClips =
nullptr)
const override;
558 std::pair<size_t, size_t> GetFloatsCenteredAroundTime(
559 double t,
size_t iChannel,
float* buffer,
size_t numSideSamples,
560 bool mayThrow)
const;
566 GetFloatAtTime(
double t,
size_t iChannel,
float& value,
bool mayThrow)
const;
574 void SetFloatsCenteredAroundTime(
575 double t,
size_t iChannel,
const float* buffer,
size_t numSideSamples,
592 void SetFloatsWithinTimeRange(
593 double t0,
double t1,
size_t iChannel,
594 const std::function<
float(
double sampleTime)>& producer,
610 GetSampleView(
double t0,
double t1,
bool mayThrow =
true)
const;
614 bool HasTrivialEnvelope()
const override;
616 void GetEnvelopeValues(
617 double* buffer,
size_t bufferLen,
double t0,
618 bool backwards)
const override;
625 Envelope* GetEnvelopeAtTime(
double time);
627 const WaveClip* GetClipAtTime(
double time)
const;
628 WaveClip* GetClipAtTime(
double time);
662 size_t GetMaxBlockSize()
const;
663 size_t GetIdealBlockSize();
669 bool HandleXMLTag(
const std::string_view& tag,
const AttributesList& attrs)
override;
670 void HandleXMLEndTag(
const std::string_view& tag)
override;
671 XMLTagHandler *HandleXMLChild(
const std::string_view& tag)
override;
672 void WriteXML(
XMLWriter &xmlFile)
const override;
675 std::optional<TranslatableString> GetErrorOpening()
const override;
687 bool CloseLock() noexcept;
701 const WaveClip* GetLeftmostClip()
const;
702 const WaveClip* GetRightmostClip()
const;
731 return mStack.back().first->get();
743 {
return !( a == b ); }
750 using Pair = std::pair< Iterator, Iterator >;
767 : mIter{ const_cast<
WaveTrack& >( track ) }
774 { ++mIter;
return *
this; }
783 {
return !( a == b ); }
800 void CreateWideClip(
double offset = .0,
const wxString&
name = wxEmptyString);
809 WaveClip* CreateClip(
double offset = .0,
const wxString&
name = wxEmptyString);
826 int GetClipIndex(
const WaveClip* clip)
const;
833 WaveClip *GetClipByIndex(
int index);
837 const WaveClip* GetClipByIndex(
int index)
const;
840 int GetNumClips()
const;
841 int GetNumClips(
double t0,
double t1)
const;
858 void DiscardTrimmed();
865 const std::vector<WaveClip*> &clips,
867 double *allowedAmount =
nullptr
875 CanInsertClip(
const WaveClip& clip,
double& slideBy,
double tolerance)
const;
879 std::shared_ptr<WaveClip> RemoveAndReturnClip(
WaveClip* clip);
887 bool AddClip(
const std::shared_ptr<WaveClip> &clip);
892 bool MergeClips(
int clipidx1,
int clipidx2);
901 void ExpandCutLine(
double cutLinePosition,
902 double* cutlineStart =
nullptr,
double* cutlineEnd =
nullptr);
908 bool RemoveCutLine(
double cutLinePosition);
919 const TypeInfo &GetTypeInfo()
const override;
920 static const TypeInfo &ClassTypeInfo();
928 const std::shared_ptr<WaveClip> &pClip,
929 const std::shared_ptr<WaveClip> &pClip1);
941 void SetName(
const wxString&
name);
942 const wxString& GetName()
const;
944 void SetColorIndex(
int index);
945 int GetColorIndex()
const;
947 void SetPlayStartTime(
double time);
950 bool IntersectsPlayRegion(
double t0,
double t1)
const;
951 bool WithinPlayRegion(
double t)
const;
957 double GetSequenceStartTime()
const;
958 double GetSequenceEndTime()
const;
959 double GetTrimLeft()
const;
960 double GetTrimRight()
const;
963 WideChannelGroupInterval::GetChannel<WaveChannelInterval>(
iChannel); }
965 WideChannelGroupInterval::GetChannel<const WaveChannelInterval>(
iChannel); }
968 WideChannelGroupInterval::Channels<WaveChannelInterval>(); }
971 WideChannelGroupInterval::Channels<const WaveChannelInterval>(); }
973 bool IsPlaceholder()
const;
975 void SetSequenceStartTime(
double t);
980 void SetTrimLeft(
double t);
981 void SetTrimRight(
double t);
982 void ClearLeft(
double t);
983 void ClearRight(
double t);
988 std::shared_ptr<Interval> GetStretchRenderedCopy(
989 const std::function<
void(
double)>& reportProgress,
992 bool StretchRatioEquals(
double value)
const;
995 {
return iChannel == 0 ? mpClip : mpClip1; }
997 {
return iChannel == 0 ? mpClip : mpClip1; }
999 const Envelope& GetEnvelope()
const;
1000 void SetEnvelope(
const Envelope& envelope);
1003 void ForEachClip(
const std::function<
void(
WaveClip&)>& op);
1005 std::shared_ptr<ChannelInterval> DoGetChannel(
size_t iChannel)
override;
1026 auto Intervals() {
return ChannelGroup::Intervals<Interval>(); }
1027 auto Intervals()
const {
return ChannelGroup::Intervals<const Interval>(); }
1033 const WaveClip* FindClipByName(
const wxString&
name)
const;
1035 size_t NIntervals()
const override;
1041 void CopyClipEnvelopes();
1047 double t0,
double t1,
bool addCutLines,
bool split,
1048 bool clearByTrimming =
false);
1057 void ClearAndPasteAtSameTempo(
1058 double t0,
double t1,
const WaveTrack& src,
bool preserve,
bool merge,
1059 const TimeWarper* effectWarper,
bool clearByTrimming);
1060 static void ClearAndPasteOne(
1061 WaveTrack& track,
double t0,
double t1,
double startTime,
double endTime,
1062 const WaveTrack& src,
bool preserve,
bool merge,
1063 const TimeWarper* effectWarper,
bool clearByTrimming);
1066 static void JoinOne(
WaveTrack& track,
double t0,
double t1);
1067 static Holder CopyOne(
const WaveTrack &track,
1068 double t0,
double t1,
bool forClipboard);
1070 size_t iChannel,
size_t nChannels);
1071 static bool ReverseOne(
WaveTrack &track,
1073 static bool ReverseOneClip(
WaveTrack &track,
1075 sampleCount originalEnd,
const ProgressReport &report = {});
1076 void SplitAt(
double t) ;
1077 void ExpandOneCutLine(
double cutLinePosition,
1078 double* cutlineStart,
double* cutlineEnd);
1079 bool MergeOneClipPair(
int clipidx1,
int clipidx2);
1080 void ApplyStretchRatioOnIntervals(
1081 const std::vector<IntervalHolder>& intervals,
1084 void InsertInterval(
const IntervalHolder& interval);
1086 void RemoveInterval(
const IntervalHolder& interval);
1090 ReplaceInterval(
const IntervalHolder& oldOne,
const IntervalHolder& newOne);
1092 std::shared_ptr<WideChannelGroupInterval> DoGetInterval(
size_t iInterval)
1094 std::shared_ptr<::Channel> DoGetChannel(
size_t iChannel)
override;
1097 ChannelGroup &ReallyDoGetChannelGroup()
const override;
1109 mutable int mLegacyRate{ 0 };
1114 void DoSetRate(
double newRate);
1115 void SetClipRates(
double newRate);
1116 void DoOnProjectTempoChange(
1117 const std::optional<double>& oldTempo,
double newTempo)
override;
1124 DuplicateWithOtherTempo(
double newTempo,
WaveTrack*& leader)
const;
1128 bool backwards,
fillFormat fill,
bool mayThrow,
1138 size_t GetFloatsFromTime(
1139 double t,
size_t iChannel,
float* buffer,
size_t numSamples,
1147 void SetFloatsFromTime(
1148 double t,
size_t iChannel,
const float* buffer,
size_t numSamples,
1151 void DoSetPan(
float value);
1152 void DoSetGain(
float value);
1158 void PasteWaveTrack(
double t0,
const WaveTrack &other,
bool merge);
1166 PasteWaveTrackAtSameTempo(
double t0,
const WaveTrack& other,
bool merge);
1167 static void PasteOne(
1169 double insertDuration,
bool merge =
true);
1175 bool RateConsistencyCheck()
const;
1180 bool FormatConsistencyCheck()
const;
1205 assert(&result ==
this);
1212 assert(&result ==
this);
1228#include <unordered_set>
1262 , mpFactory(pFactory)
1269 {
return mpFactory; }
1275 std::shared_ptr<WaveTrack> Create();
std::vector< std::shared_ptr< const ClipInterface > > ClipConstHolders
std::vector< AudioSegmentSampleView > ChannelSampleView
const TranslatableString name
Vector operator*(const Vector &left, const Vector &right)
std::vector< std::vector< AudioSegmentSampleView > > ChannelGroupSampleView
bool operator==(const EffectReverbSettings &a, const EffectReverbSettings &b)
std::shared_ptr< SampleBlockFactory > SampleBlockFactoryPtr
bool operator<(sampleCount a, sampleCount b)
std::function< void(double)> ProgressReporter
std::shared_ptr< TrackList > TrackListHolder
std::shared_ptr< WaveClip > WaveClipHolder
std::vector< WaveClipHolder > WaveClipHolders
std::vector< std::shared_ptr< const WaveClip > > WaveClipConstHolders
std::function< void(SampleBlock &) > BlockVisitor
void VisitBlocks(TrackList &tracks, BlockVisitor visitor, SampleBlockIDSet *pIDs=nullptr)
DECLARE_XML_METHOD_REGISTRY(WAVE_TRACK_API, WaveTrackIORegistry)
WAVE_TRACK_API bool GetEditClipsCanMove()
std::unordered_set< SampleBlockID > SampleBlockIDSet
ENUMERATE_TRACK_TYPE(WaveTrack)
std::pair< double, double > TimeInterval
std::function< void(const SampleBlock &) > BlockInspector
std::vector< WaveClip * > WaveClipPointers
WAVE_TRACK_API StringSetting AudioTrackNameSetting
std::vector< const WaveClip * > WaveClipConstPointers
WAVE_TRACK_API void InspectBlocks(const TrackList &tracks, BlockInspector inspector, SampleBlockIDSet *pIDs=nullptr)
WAVE_TRACK_API BoolSetting EditClipsCanMove
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::Get(track);menu.Check(id, view.GetMultiView());}) :nullptr;}))
bool operator!=(const WaveTrackLocation &a, const WaveTrackLocation &b)
std::vector< Attribute > AttributesList
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Abstraction of a progress dialog with well defined time-to-completion estimate.
This specialization of Setting for bool adds a Toggle method to negate the saved value.
virtual ChannelGroup & DoGetChannelGroup() const =0
Subclass must override.
The intersection of a Channel and a WideChannelGroupInterval.
virtual double GetPlayEndTime() const =0
virtual double GetStretchRatio() const =0
virtual double GetPlayStartTime() const =0
virtual sampleCount TimeToSamples(double time) const =0
virtual sampleCount GetVisibleSampleCount() const =0
Piecewise linear or piecewise exponential function from double to double.
Holds project sample rate.
abstract base class with methods to produce SampleBlock objects
Abstract class allows access to contents of a block of sound samples, serialization as XML,...
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=FillFormat::fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
"narrow" overload fetches first channel only
A WaveTrack contains WaveClip(s). A WaveClip contains a Sequence. A Sequence is primarily an interfac...
Specialization of Setting for strings.
Transforms one point in time to another point. For example, a time stretching effect might use one to...
Abstract base class for an object holding data associated with points on a time axis.
virtual void Paste(double t, const Track &src)=0
Weak precondition allows overrides to replicate one channel into many.
std::shared_ptr< Track > Holder
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
auto Any() -> TrackIterRange< TrackType >
auto GetInterval(size_t iInterval) const
auto GetInterval(size_t iInterval)
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=FillFormat::fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
"narrow" overload fetches from the unique channel
size_t GetIdealBlockSize()
A hint for sizing of well aligned fetches.
size_t GetBestBlockSize(sampleCount t) const
A hint for sizing of well aligned fetches.
size_t GetMaxBlockSize() const
WaveChannelInterval(WaveClip &wideClip, WaveClip &narrowClip, size_t iChannel)
Assume lifetime of this object nests in those of arguments.
const WaveClip & GetNarrowClip() const
const WaveClip & GetClip() const
~WaveChannelInterval() override
size_t GetChannelIndex() const
This allows multiple clips to be a part of one WaveTrack.
AllClipsConstIterator(const WaveTrack &track)
std::pair< Iterator, Iterator > Pair
std::vector< Pair > Stack
WaveClipHolders::iterator Iterator
AllClipsIterator(WaveTrack &track)
std::shared_ptr< const WaveClip > GetClip(size_t iChannel) const
const std::shared_ptr< WaveClip > mpClip1
TODO wide wave tracks: eliminate this.
auto GetChannel(size_t iChannel) const
const std::shared_ptr< WaveClip > mpClip
auto GetChannel(size_t iChannel)
const std::shared_ptr< WaveClip > & GetClip(size_t iChannel)
Used to create or clone a WaveTrack, with appropriate context from the project that will own the trac...
WaveTrackFactory(const WaveTrackFactory &)=delete
const SampleBlockFactoryPtr & GetSampleBlockFactory() const
SampleBlockFactoryPtr mpFactory
WaveTrackFactory & operator=(const WaveTrackFactory &)=delete
WaveTrackFactory(const ProjectRate &rate, const SampleBlockFactoryPtr &pFactory)
const ProjectRate & mRate
A Track that contains audio waveform data.
SampleBlockFactoryPtr mpFactory
std::vector< Region > Regions
auto GetChannel(size_t iChannel) const
void ClearAndPaste(double t0, double t1, const TrackList &src, bool preserve=true, bool merge=true, const TimeWarper *effectWarper=nullptr)
wxCriticalSection mFlushCriticalSection
IteratorRange< AllClipsConstIterator > GetAllClips() const
std::function< bool(double)> ProgressReport
size_t GetIdealBlockSize()
std::shared_ptr< Interval > IntervalHolder
IteratorRange< AllClipsIterator > GetAllClips()
void ApplyStretchRatioOne(double t0, double t1, const ProgressReporter &reportProgress)
const WaveClipConstHolders & GetClips() const
size_t GetMaxBlockSize() const
double mLegacyProjectFileOffset
auto GetChannel(size_t iChannel)
size_t GetBestBlockSize(sampleCount t) const
wxCriticalSection mAppendCriticalSection
std::shared_ptr< const Interval > IntervalConstHolder
bool GetFloats(size_t iChannel, size_t nBuffers, float *const buffers[], sampleCount start, size_t len, bool backwards=false, fillFormat fill=FillFormat::fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
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.
ChannelType
Mutually exclusive channel classifications.
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
std::vector< long > Split(const PluginRegistryVersion ®ver)
double GetRate(const Track &track)
Track & GetTrack(Channel &channel)
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)
static RegisteredToolbarFactory factory
A convenient default parameter for class template Site.
A convenience for use with range-for.
Empty argument passed to some public constructors.
A convenience for defining iterators that return rvalue types, so that they cooperate correctly with ...
Structure to hold region of a wavetrack and a comparison function for sortability.
Region(double start_, double end_)