11#ifndef __AUDACITY_WAVETRACK__
12#define __AUDACITY_WAVETRACK__
26#include <wx/longlong.h>
67#define WAVETRACK_MERGE_POINT_TOLERANCE 0.01
107 sampleCount* pNumWithinClips =
nullptr)
const override;
111 double GetRate()
const override;
114 double* buffer,
size_t bufferLen,
double t0,
115 bool backwards)
const override;
120 std::shared_ptr<WaveClipChannel>
GetInterval(
size_t iInterval);
121 std::shared_ptr<const WaveClipChannel>
GetInterval(
size_t iInterval)
const;
133 constexpr auto backwards =
false;
135 0, 1, &buffer, start, len, backwards, fill, mayThrow, pNumWithinClips);
173 start, len, effectiveFormat);
187 inline size_t GetBestBlockSize(
sampleCount t)
const;
189 inline size_t GetIdealBlockSize();
192 inline size_t GetMaxBlockSize()
const;
219 Region(
double start_,
double end_) : start(start_),
end(end_) {}
226 return this->start < b.
start;
232 static wxString GetDefaultAudioTrackNamePreference();
247 using Holder = std::shared_ptr<WaveTrack>;
254 {
return mpFactory; }
259 return this->ChannelGroup::GetChannel<WaveChannel>(
iChannel); }
261 return this->ChannelGroup::GetChannel<const WaveChannel>(
iChannel); }
264 return this->ChannelGroup::Channels<WaveChannel>(); }
266 return this->ChannelGroup::Channels<const WaveChannel>(); }
274 std::ptrdiff_t FindClip(
const Interval &clip);
276 void RemoveClip(std::ptrdiff_t distance);
282 wxString MakeClipCopyName(
const wxString& originalName)
const;
283 wxString MakeNewClipName()
const;
289 void MoveTo(
double o)
override;
290 void ShiftBy(
double t0,
double delta)
override;
292 bool LinkConsistencyFix(
bool doFix)
override;
307 double GetRate()
const override;
312 void SetRate(
double newRate);
315 float GetVolume()
const;
316 void SetVolume(
float newVolume);
319 float GetPan()
const;
320 void SetPan(
float newPan);
330 const std::function<
void(
size_t)> & progressReport = {});
346 Holder EmptyCopy(
size_t nChannels,
366 Holder MonoToStereo();
372 std::vector<Holder> SplitChannels();
381 Track::Holder Copy(
double t0,
double t1,
bool forClipboard =
true)
384 void Clear(
double t0,
double t1)
override;
385 void Paste(
double t0,
const Track &src)
override;
394 double t0,
double t1,
const WaveTrack& src,
bool preserve =
true,
395 bool merge =
true,
const TimeWarper* effectWarper =
nullptr,
396 bool clearByTrimming =
false) ;
398 void Silence(
double t0,
double t1,
ProgressReporter reportProgress)
override;
399 void InsertSilence(
double t,
double len)
override;
401 void Split(
double t0,
double t1);
403 std::pair<IntervalHolder, IntervalHolder> SplitAt(
double t);
408 void ClearAndAddCutLine(
double t0,
double t1) ;
413 Holder SplitCut(
double t0,
double t1) ;
416 void SplitDelete(
double t0,
double t1) ;
418 double t0,
double t1,
421 void Disjoin(
double t0,
double t1) ;
424 void Trim(
double t0,
double t1) ;
433 void ApplyPitchAndSpeed(
436 void SyncLockAdjust(
double oldT1,
double newT1)
override;
443 bool IsEmpty(
double t0,
double t1)
const;
453 size_t len,
unsigned int stride = 1,
457 void Flush()
override;
459 void RepairChannels()
override;
464 bool GetMute()
const override;
465 bool GetSolo()
const override;
487 sampleCount* pNumWithinClips =
nullptr)
const override;
501 GetSampleView(
double t0,
double t1,
bool mayThrow =
true)
const;
508 double* buffer,
size_t bufferLen,
double t0,
509 bool backwards)
const override;
518 size_t GetMaxBlockSize()
const;
519 size_t GetIdealBlockSize();
525 bool HandleXMLTag(
const std::string_view& tag,
const AttributesList& attrs)
override;
526 void HandleXMLEndTag(
const std::string_view& tag)
override;
527 XMLTagHandler *HandleXMLChild(
const std::string_view& tag)
override;
528 void WriteXML(
XMLWriter &xmlFile)
const override;
531 std::optional<TranslatableString> GetErrorOpening()
const override;
559 CreateClip(
double offset = .0,
const wxString&
name = wxEmptyString,
560 const Interval *pToCopy =
nullptr,
bool copyCutlines =
true);
568 IntervalHolder CopyClip(
const Interval &toCopy,
bool copyCutlines);
571 void CopyWholeClip(
const Interval &clip,
double t0,
bool forClipboard);
572 void CopyPartOfClip(
const Interval &clip,
573 double t0,
double t1,
bool forClipboard);
574 void FinishCopy(
double t0,
double t1,
bool forClipboard);
590 double offset = .0,
const wxString&
name = wxEmptyString)
const;
608 int GetNumClips()
const;
614 IntervalConstHolders SortedIntervalArray()
const;
621 const std::vector<Interval*> &movingClips,
623 double *allowedAmount =
nullptr
631 CanInsertClip(
const Interval& clip,
double& slideBy,
double tolerance)
const;
636 bool MergeClips(
int clipidx1,
int clipidx2);
646 [[nodiscard]]
bool SetFloats(
const float *
const *buffers,
656 const TypeInfo &GetTypeInfo()
const override;
657 static const TypeInfo &ClassTypeInfo();
671 auto Intervals() {
return ChannelGroup::Intervals<Interval>(); }
672 auto Intervals()
const {
return ChannelGroup::Intervals<const Interval>(); }
679 bool newClip,
bool allowEmpty =
false);
686 bool HasClipNamed(
const wxString&
name)
const;
705 bool newClip,
bool backup,
bool allowEmpty);
712 void MergeChannelAttachments(
WaveTrack &&other);
715 void EraseChannelAttachments(
size_t index);
719 int GetClipIndex(
const Interval &clip)
const;
724 double t0,
double t1,
bool addCutLines,
bool split,
725 bool clearByTrimming =
false);
735 void ClearAndPasteAtSameTempo(
736 double t0,
double t1,
const WaveTrack& src,
bool preserve,
bool merge,
737 const TimeWarper* effectWarper,
bool clearByTrimming);
744 double* cutlineStart,
double* cutlineEnd);
745 void ApplyPitchAndSpeedOnIntervals(
746 const std::vector<IntervalHolder>& intervals,
756 std::shared_ptr<WideChannelGroupInterval> DoGetInterval(
size_t iInterval)
758 std::shared_ptr<::Channel> DoGetChannel(
size_t iChannel)
override;
778 mutable int mLegacyRate{ 0 };
783 void DoSetRate(
double newRate);
784 [[nodiscard]] Holder DuplicateWithOtherTempo(
double newTempo)
const;
788 bool backwards,
fillFormat fill,
bool mayThrow,
791 void DoSetPan(
float value);
792 void DoSetVolume(
float value);
797 void PasteWaveTrack(
double t0,
const WaveTrack &other,
bool merge);
805 PasteWaveTrackAtSameTempo(
double t0,
const WaveTrack& other,
bool merge);
808 bool RateConsistencyCheck()
const;
811 bool FormatConsistencyCheck()
const;
827 void ZipClips(
bool mustAlign =
true);
834 double mLegacyProjectFileOffset{ 0 };
882 , mpFactory(pFactory)
889 {
return mpFactory; }
895 std::shared_ptr<WaveTrack> Create();
940 std::shared_ptr<WaveTrack> DoCreate(
std::vector< std::shared_ptr< const ClipInterface > > ClipConstHolders
std::vector< AudioSegmentSampleView > ChannelSampleView
std::vector< std::vector< AudioSegmentSampleView > > ChannelGroupSampleView
std::shared_ptr< SampleBlockFactory > SampleBlockFactoryPtr
bool operator<(sampleCount a, sampleCount b)
ResultType Join(const ContainerType< ResultType, Rest... > &container, const SeparatorType &separator)
std::function< void(double)> ProgressReporter
std::shared_ptr< TrackList > TrackListHolder
std::vector< WaveClipConstHolder > WaveClipConstHolders
std::shared_ptr< const WaveClip > WaveClipConstHolder
std::shared_ptr< WaveClip > WaveClipHolder
std::vector< WaveClipHolder > WaveClipHolders
DECLARE_XML_METHOD_REGISTRY(WAVE_TRACK_API, WaveTrackIORegistry)
WAVE_TRACK_API bool GetEditClipsCanMove()
ENUMERATE_TRACK_TYPE(WaveTrack)
std::pair< double, double > TimeInterval
std::vector< WaveClip * > WaveClipPointers
WAVE_TRACK_API StringSetting AudioTrackNameSetting
std::vector< const WaveClip * > WaveClipConstPointers
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::GetFirst(track);menu.Check(id, view.GetMultiView());}) :nullptr;}))
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.
size_t NIntervals() const
Report the number of intervals.
std::shared_ptr< IntervalType > GetInterval(size_t iInterval)
Retrieve an interval, cast to the given type.
IteratorRange< IntervalIterator< IntervalType > > Intervals()
Get range of intervals with mutative access.
virtual ChannelGroup & DoGetChannelGroup() const =0
Subclass must override.
Piecewise linear or piecewise exponential function from double to double.
An object that sends messages to an open-ended list of subscribed callbacks.
Holds project sample rate.
abstract base class with methods to produce SampleBlock objects
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...
bool SetFloats(const float *buffer, sampleCount start, size_t len, sampleFormat effectiveFormat=widestSampleFormat)
Random-access assignment of a range of samples.
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.
ChannelGroup & DoGetChannelGroup() const override
Subclass must override.
size_t GetBestBlockSize(sampleCount t) const
A hint for sizing of well aligned fetches.
sampleFormat GetSampleFormat() const
size_t GetMaxBlockSize() const
WaveClipChannel(WaveClip &clip, size_t iChannel)
This allows multiple clips to be a part of one WaveTrack.
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
wxCriticalSection mFlushCriticalSection
sampleFormat GetSampleFormat() const override
void ExpandOneCutLine(double cutLinePosition, double *cutlineStart, double *cutlineEnd)
size_t GetIdealBlockSize()
std::shared_ptr< Interval > IntervalHolder
static const char * WaveTrack_tag
const SampleBlockFactoryPtr & GetSampleBlockFactory() const
std::vector< IntervalHolder > IntervalHolders
std::optional< WaveChannel > mRightChannel
may be null
void ApplyPitchAndSpeedOne(double t0, double t1, const ProgressReporter &reportProgress)
std::vector< IntervalConstHolder > IntervalConstHolders
static void JoinOne(WaveTrack &track, double t0, double t1)
size_t GetMaxBlockSize() const
auto GetChannel(size_t iChannel)
size_t GetBestBlockSize(sampleCount t) const
std::shared_ptr< WaveTrack > Holder
wxCriticalSection mAppendCriticalSection
std::shared_ptr< const Interval > IntervalConstHolder
virtual bool HasTrivialEnvelope() const =0
virtual double GetStartTime() const =0
virtual void GetEnvelopeValues(double *buffer, size_t bufferLen, double t0, bool backwards) const =0
virtual sampleFormat WidestEffectiveFormat() const =0
virtual bool DoGet(size_t iChannel, size_t nBuffers, const samplePtr buffers[], sampleFormat format, sampleCount start, size_t len, bool backward, fillFormat fill=FillFormat::fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const =0
virtual double GetEndTime() const =0
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
virtual float GetChannelVolume(int channel) const =0
virtual size_t NChannels() const =0
A constant property.
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.
WAVE_TRACK_API ClipPointer GetIntervalAtTime(WaveChannel &channel, double t)
WAVE_TRACK_API ClipPointer GetClipAtTime(WaveChannel &channel, double time)
WAVE_TRACK_API ClipPointers SortedClipArray(WaveChannel &channel)
Get clips sorted by play start time.
std::vector< IntervalHolder > IntervalHolders
std::shared_ptr< WaveTrack::Interval > IntervalHolder
std::shared_ptr< const WaveTrack::Interval > IntervalConstHolder
std::vector< long > Split(const PluginRegistryVersion ®ver)
double GetRate(const Track &track)
Track & GetTrack(Channel &channel)
const char * end(const char *str) noexcept
virtual ChannelType GetChannelType() const =0
Classify this channel.
A convenient default parameter for class template Site.
A convenience for use with range-for.
Structure to hold region of a wavetrack and a comparison function for sortability.
Region(double start_, double end_)
@ Deserialized
being read from project file
@ New
newly created and empty
@ Inserted
(partly) copied from another clip, or moved from a track
enum WaveTrackMessage::Type type