Audacity 3.2.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends | List of all members
WaveTrack Class Referencefinal

A Track that contains audio waveform data. More...

#include <WaveTrack.h>

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

Classes

class  AllClipsConstIterator
 
class  AllClipsIterator
 
class  IntervalData
 
struct  Region
 Structure to hold region of a wavetrack and a comparison function for sortability. More...
 

Public Types

using Regions = std::vector< Region >
 
typedef WaveTrackLocation Location
 
using Holder = std::shared_ptr< WaveTrack >
 
- Public Types inherited from Track
enum class  LinkType : int { None = 0 , Group = 2 , Aligned }
 For two tracks describes the type of the linkage. More...
 
enum  ChannelType { LeftChannel = 0 , RightChannel = 1 , MonoChannel = 2 }
 
using ChannelGroupAttachments = ClientData::Site< ChannelGroupData, ClientData::Cloneable<>, ClientData::DeepCopying >
 Hosting of objects attached by higher level code. More...
 
using AttachedObjects = ::AttachedTrackObjects
 Alias for my base type. More...
 
using IntervalData = TrackIntervalData
 
using Interval = TrackInterval
 
using Intervals = std::vector< Interval >
 
using ConstInterval = ConstTrackInterval
 
using ConstIntervals = std::vector< ConstInterval >
 
using Holder = std::shared_ptr< Track >
 
template<typename R = void>
using Continuation = std::function< R() >
 Type of arguments passed as optional second parameter to TypeSwitch() cases. More...
 
using Fallthrough = Continuation<>
 Type of arguments passed as optional second parameter to TypeSwitch<void>() cases. More...
 
- Public Types inherited from ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >
using DataType = ClientData
 
using DataPointer = Pointer< ClientData >
 
using DataFactory = std::function< DataPointer(Host &) >
 Type of function from which RegisteredFactory is constructed; it builds attachments. More...
 

Public Member Functions

 WaveTrack (const SampleBlockFactoryPtr &pFactory, sampleFormat format, double rate)
 
 WaveTrack (const WaveTrack &orig)
 
void Reinit (const WaveTrack &orig)
 
virtual ~WaveTrack ()
 
double GetOffset () const override
 
void SetOffset (double o) override
 
ChannelType GetChannelIgnoringPan () const override
 
ChannelType GetChannel () const override
 
virtual void SetPanFromChannelType () override
 
bool LinkConsistencyFix (bool doFix, bool completeList) override
 Check consistency of channel groups, and maybe fix it. More...
 
double GetStartTime () const override
 Get the time at which the first clip in the track starts. More...
 
double GetEndTime () const override
 Get the time at which the last clip in the track ends, plus recorded stuff. More...
 
double GetRate () const override
 
void SetRate (double newRate)
 
float GetGain () const
 
void SetGain (float newGain)
 
float GetPan () const
 
void SetPan (float newPan) override
 
float GetChannelGain (int channel) const override
 Takes gain and pan into account. More...
 
float GetOldChannelGain (int channel) const override
 
void SetOldChannelGain (int channel, float gain) override
 
int GetWaveColorIndex () const
 
void SetWaveColorIndex (int colorIndex)
 
sampleCount GetPlaySamplesCount () const
 
sampleCount GetSequenceSamplesCount () const
 
sampleFormat GetSampleFormat () const override
 
void ConvertToSampleFormat (sampleFormat format, const std::function< void(size_t)> &progressReport={})
 
const SpectrogramSettingsGetSpectrogramSettings () const
 
SpectrogramSettingsGetSpectrogramSettings ()
 
SpectrogramSettingsGetIndependentSpectrogramSettings ()
 
void SetSpectrogramSettings (std::unique_ptr< SpectrogramSettings > &&pSettings)
 
const WaveformSettingsGetWaveformSettings () const
 
WaveformSettingsGetWaveformSettings ()
 
void SetWaveformSettings (std::unique_ptr< WaveformSettings > &&pSettings)
 
void UseSpectralPrefs (bool bUse=true)
 
Track::Holder Cut (double t0, double t1) override
 
Holder EmptyCopy (const SampleBlockFactoryPtr &pFactory={}) const
 
Track::Holder Copy (double t0, double t1, bool forClipboard=true) const override
 
Track::Holder CopyNonconst (double t0, double t1)
 
void Clear (double t0, double t1) override
 
void Paste (double t0, const Track *src) override
 
void ClearAndPaste (double t0, double t1, const Track *src, bool preserve=true, bool merge=true, const TimeWarper *effectWarper=NULL)
 
void Silence (double t0, double t1) override
 
void InsertSilence (double t, double len) override
 
void SplitAt (double t)
 
void Split (double t0, double t1)
 
void ClearAndAddCutLine (double t0, double t1)
 
Track::Holder SplitCut (double t0, double t1)
 
void SplitDelete (double t0, double t1)
 
void Join (double t0, double t1)
 
void Disjoin (double t0, double t1)
 
void Trim (double t0, double t1)
 
void HandleClear (double t0, double t1, bool addCutLines, bool split)
 
void SyncLockAdjust (double oldT1, double newT1) override
 
bool IsEmpty (double t0, double t1) const
 Returns true if there are no WaveClips in the specified region. More...
 
bool Append (constSamplePtr buffer, sampleFormat format, size_t len, unsigned int stride=1) override
 
void Flush () override
 
bool Get (samplePtr buffer, sampleFormat format, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const override
 
void Set (constSamplePtr buffer, sampleFormat format, sampleCount start, size_t len)
 
void GetEnvelopeValues (double *buffer, size_t bufferLen, double t0) const override
 Fetch envelope values corresponding to uniformly separated sample times starting at the given time. More...
 
std::pair< float, float > GetMinMax (double t0, double t1, bool mayThrow=true) const
 
float GetRMS (double t0, double t1, bool mayThrow=true) const
 
SequenceGetSequenceAtTime (double time)
 
EnvelopeGetEnvelopeAtTime (double time)
 
WaveClipGetClipAtSample (sampleCount sample)
 
WaveClipGetClipAtTime (double time)
 
sampleCount GetBlockStart (sampleCount t) const override
 This returns a possibly large or negative value. More...
 
size_t GetBestBlockSize (sampleCount t) const override
 This returns a nonnegative number of samples meant to size a memory buffer. More...
 
size_t GetMaxBlockSize () const override
 This returns a nonnegative number of samples meant to size a memory buffer. More...
 
size_t GetIdealBlockSize ()
 
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 override
 
bool GetErrorOpening () override
 
bool CloseLock ()
 
WaveClipHoldersGetClips ()
 
const WaveClipConstHoldersGetClips () const
 
IteratorRange< AllClipsIteratorGetAllClips ()
 
IteratorRange< AllClipsConstIteratorGetAllClips () const
 
WaveClipCreateClip (double offset=.0, const wxString &name=wxEmptyString)
 
WaveClipNewestOrNewClip ()
 Get access to the most recently added clip, or create a clip, if there is not already one. THIS IS NOT NECESSARILY RIGHTMOST. More...
 
WaveClipRightmostOrNewClip ()
 Get access to the last (rightmost) clip, or create a clip, if there is not already one. More...
 
int GetClipIndex (const WaveClip *clip) const
 
WaveClipGetClipByIndex (int index)
 
const WaveClipGetClipByIndex (int index) const
 
int GetNumClips () const
 
WaveClipPointers SortedClipArray ()
 
WaveClipConstPointers SortedClipArray () const
 
bool CanOffsetClips (const std::vector< WaveClip * > &clips, double amount, double *allowedAmount=nullptr)
 Decide whether the clips could be offset (and inserted) together without overlapping other clips. More...
 
bool CanInsertClip (WaveClip *clip, double &slideBy, double &tolerance) const
 
std::shared_ptr< WaveClipRemoveAndReturnClip (WaveClip *clip)
 
bool AddClip (const std::shared_ptr< WaveClip > &clip)
 Append a clip to the track; which must have the same block factory as this track; return success. More...
 
void MergeClips (int clipidx1, int clipidx2)
 
void UpdateLocationsCache () const
 
const std::vector< Location > & GetCachedLocations () const
 
void ExpandCutLine (double cutLinePosition, double *cutlineStart=NULL, double *cutlineEnd=NULL)
 
bool RemoveCutLine (double cutLinePosition)
 
void Merge (const Track &orig) override
 
void Resample (int rate, BasicUI::ProgressDialog *progress=NULL)
 
const TypeInfoGetTypeInfo () const override
 
int GetLastScaleType () const
 
void SetLastScaleType () const
 
int GetLastdBRange () const
 
void SetLastdBRange () const
 
void GetDisplayBounds (float *min, float *max) const
 
void SetDisplayBounds (float min, float max) const
 
void GetSpectrumBounds (float *min, float *max) const
 
void SetSpectrumBounds (float min, float max) const
 
int ZeroLevelYCoordinate (wxRect rect) const
 
Track::Holder PasteInto (AudacityProject &) const override
 Find or create the destination track for a paste, maybe in a different project. More...
 
ConstIntervals GetIntervals () const override
 Report times on the track where important intervals begin and end, for UI to snap to. More...
 
Intervals GetIntervals () override
 
const WaveClipFindClipByName (const wxString &name) const
 Returns nullptr if clip with such name was not found. More...
 
- Public Member Functions inherited from WritableSampleTrack
 ~WritableSampleTrack () override
 
const TypeInfoGetTypeInfo () const override
 
virtual void SetOldChannelGain (int channel, float gain)=0
 
virtual bool Append (constSamplePtr buffer, sampleFormat format, size_t len, unsigned int stride=1)=0
 Append the sample data to the track. You must call Flush() after the last Append. More...
 
virtual void Flush ()=0
 Flush must be called after last Append. More...
 
- Public Member Functions inherited from SampleTrack
 ~SampleTrack () override
 
const TypeInfoGetTypeInfo () const override
 
virtual sampleFormat GetSampleFormat () const =0
 
virtual ChannelType GetChannelIgnoringPan () const =0
 
virtual float GetOldChannelGain (int channel) const =0
 
virtual double GetRate () const =0
 
virtual void GetEnvelopeValues (double *buffer, size_t bufferLen, double t0) const =0
 Fetch envelope values corresponding to uniformly separated sample times starting at the given time. More...
 
virtual float GetChannelGain (int channel) const =0
 Takes gain and pan into account. More...
 
virtual size_t GetBestBlockSize (sampleCount t) const =0
 This returns a nonnegative number of samples meant to size a memory buffer. More...
 
virtual size_t GetMaxBlockSize () const =0
 This returns a nonnegative number of samples meant to size a memory buffer. More...
 
virtual sampleCount GetBlockStart (sampleCount t) const =0
 This returns a possibly large or negative value. More...
 
bool GetFloats (float *buffer, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
 Retrieve samples from a track in floating-point format, regardless of the storage format. More...
 
virtual bool Get (samplePtr buffer, sampleFormat format, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const =0
 Retrieve samples from a track in a specified format. More...
 
sampleCount TimeToLongSamples (double t0) const
 Convert correctly between an (absolute) time in seconds and a number of samples. More...
 
double LongSamplesToTime (sampleCount pos) const
 Convert correctly between a number of samples and an (absolute) time in seconds. More...
 
- Public Member Functions inherited from PlayableTrack
 PlayableTrack ()
 
 PlayableTrack (const PlayableTrack &orig)
 
bool GetMute () const
 
bool GetSolo () const
 
bool GetNotMute () const
 
bool GetNotSolo () const
 
void SetMute (bool m)
 
void SetSolo (bool s)
 
void Init (const PlayableTrack &init)
 
void Merge (const Track &init) override
 
void WriteXMLAttributes (XMLWriter &xmlFile) const
 
bool HandleXMLAttribute (const std::string_view &attr, const XMLAttributeValueView &value)
 
- Public Member Functions inherited from AudioTrack
 AudioTrack ()
 
 AudioTrack (const Track &orig)
 
void WriteXMLAttributes (XMLWriter &WXUNUSED(xmlFile)) const
 
bool HandleXMLAttribute (const std::string_view &, const XMLAttributeValueView &)
 
- Public Member Functions inherited from Track
TrackId GetId () const
 
template<typename Subclass = Track>
std::shared_ptr< Subclass > SharedPointer ()
 
template<typename Subclass = const Track>
auto SharedPointer () const -> std::enable_if_t< std::is_const_v< Subclass >, std::shared_ptr< Subclass > >
 
std::shared_ptr< TrackSubstitutePendingChangedTrack ()
 
std::shared_ptr< const TrackSubstitutePendingChangedTrack () const
 
std::shared_ptr< const TrackSubstituteOriginalTrack () const
 
virtual const TypeInfoGetTypeInfo () const =0
 
virtual const TypeNamesGetTypeNames () const
 
virtual bool SupportsBasicEditing () const
 Whether this track type implements cut-copy-paste; by default, true. More...
 
virtual Holder PasteInto (AudacityProject &) const =0
 Find or create the destination track for a paste, maybe in a different project. More...
 
virtual ConstIntervals GetIntervals () const
 Report times on the track where important intervals begin and end, for UI to snap to. More...
 
virtual Intervals GetIntervals ()
 
int GetIndex () const
 
void SetIndex (int index)
 
virtual bool LinkConsistencyFix (bool doFix=true, bool completeList=true)
 Check consistency of channel groups, and maybe fix it. More...
 
bool LinkConsistencyCheck (bool completeList)
 Do the non-mutating part of consistency fix only and return status. More...
 
bool HasOwner () const
 
std::shared_ptr< TrackListGetOwner () const
 
LinkType GetLinkType () const noexcept
 
bool IsAlignedWithLeader () const
 Returns true if the leader track has link type LinkType::Aligned. More...
 
ChannelGroupDataGetGroupData ()
 
const ChannelGroupDataGetGroupData () const
 
 Track ()
 
 Track (const Track &orig)
 
virtual ~Track ()
 
void Init (const Track &orig)
 
virtual Holder Duplicate () const
 
virtual void Merge (const Track &orig)
 
wxString GetName () const
 
void SetName (const wxString &n)
 
bool GetSelected () const
 
virtual void SetSelected (bool s)
 
void EnsureVisible (bool modifyState=false)
 
virtual ChannelType GetChannel () const
 
virtual double GetOffset () const =0
 
void Offset (double t)
 
virtual void SetOffset (double o)
 
virtual void SetPan (float)
 
virtual void SetPanFromChannelType ()
 
virtual Holder Cut (double WXUNUSED(t0), double WXUNUSED(t1))=0
 
virtual Holder Copy (double WXUNUSED(t0), double WXUNUSED(t1), bool forClipboard=true) const =0
 
virtual void Clear (double WXUNUSED(t0), double WXUNUSED(t1))=0
 
virtual void Paste (double WXUNUSED(t), const Track *WXUNUSED(src))=0
 
virtual void SyncLockAdjust (double oldT1, double newT1)
 
virtual void Silence (double WXUNUSED(t0), double WXUNUSED(t1))=0
 
virtual void InsertSilence (double WXUNUSED(t), double WXUNUSED(len))=0
 
bool SameKindAs (const Track &track) const
 
template<typename R = void, typename ... Functions>
TypeSwitch (const Functions &...functions)
 Use this function rather than testing track type explicitly and making down-casts. More...
 
template<typename R = void, typename ... Functions>
TypeSwitch (const Functions &...functions) const
 Use this function rather than testing track type explicitly and making down-casts. More...
 
virtual void WriteXML (XMLWriter &xmlFile) const =0
 
virtual bool GetErrorOpening ()
 
virtual double GetStartTime () const =0
 
virtual double GetEndTime () const =0
 
void Notify (int code=-1)
 
bool Any () const
 
bool IsSelected () const
 
bool IsLeader () const
 
bool IsSelectedLeader () const
 
void AdjustPositions ()
 
void WriteCommonXMLAttributes (XMLWriter &xmlFile, bool includeNameAndSelected=true) const
 
bool HandleCommonXMLAttribute (const std::string_view &attr, const XMLAttributeValueView &valueView)
 
- 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< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >
 ~Site ()
 
 Site ()
 
 Site (const Site &other)
 
Siteoperator= (const Site &other)
 
 Site (Site &&other)
 
Siteoperator= (Site &&other)
 
size_t size () const
 How many attachment pointers are in the Site. More...
 
template<typename Subclass = ClientData>
Subclass & Get (const RegisteredFactory &key)
 Get reference to an attachment, creating on demand if not present, down-cast it to Subclass. More...
 
template<typename Subclass = const ClientData>
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...
 
template<typename Subclass = ClientData>
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...
 
template<typename Subclass = const ClientData>
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...
 
template<typename ReplacementPointer >
void Assign (const RegisteredFactory &key, ReplacementPointer &&replacement)
 Reassign Site's pointer to ClientData. More...
 

Static Public Member Functions

static wxString GetDefaultAudioTrackNamePreference ()
 
static WaveTrackNew (AudacityProject &project)
 
static const TypeInfoClassTypeInfo ()
 
- Static Public Member Functions inherited from WritableSampleTrack
static const TypeInfoClassTypeInfo ()
 
- Static Public Member Functions inherited from SampleTrack
static const TypeInfoClassTypeInfo ()
 
- Static Public Member Functions inherited from PlayableTrack
static const TypeInfoClassTypeInfo ()
 
- Static Public Member Functions inherited from AudioTrack
static const TypeInfoClassTypeInfo ()
 
- Static Public Member Functions inherited from Track
template<typename Subclass = Track>
static std::shared_ptr< Subclass > SharedPointer (Track *pTrack)
 
template<typename Subclass = const Track>
static std::shared_ptr< Subclass > SharedPointer (const Track *pTrack)
 
static const TypeInfoClassTypeInfo ()
 
static void FinishCopy (const Track *n, Track *dest)
 
template<typename TrackType >
static void checkTrackType ()
 
template<typename R , typename TrackType , typename... Functions>
static R CallExecutor (R *, std::tuple<> *, TrackType &, const Functions &...)
 
template<typename R , typename TrackType , typename... Functions, typename Executor , typename... Executors>
static R CallExecutor (R *, std::tuple< Executor, Executors... > *, TrackType &track, const Functions &...functions)
 
template<typename ... Executors>
static constexpr unsigned UsedCases (std::tuple< Executors... > *)
 
template<typename Tag , bool IsConst, typename R , typename ... TrackTypes, typename ... Functions>
static R DoTypeSwitch (std::conditional_t< IsConst, const Track, Track > &track, std::tuple< TrackTypes... > *, const Functions &...functions)
 
- Static Public Member Functions inherited from ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >
static size_t slots ()
 How many static factories have been registered with this specialization of Site. More...
 

Protected Attributes

WaveClipHolders mClips
 
sampleFormat mFormat
 
int mRate
 
std::atomic< float > mGain { 1.0f }
 Atomic because it may be read by worker threads in playback. More...
 
std::atomic< float > mPan { 0.0f }
 Atomic because it may be read by worker threads in playback. More...
 
int mWaveColorIndex
 
float mOldGain [2]
 A memo used by PortAudio thread, doesn't need atomics: More...
 
float mDisplayMin
 
float mDisplayMax
 
float mSpectrumMin
 
float mSpectrumMax
 
int mLastScaleType
 
int mLastdBRange
 
std::vector< LocationmDisplayLocationsCache
 
- Protected Attributes inherited from PlayableTrack
std::atomic< bool > mMute { false }
 Atomic because it may be read by worker threads in playback. More...
 
std::atomic< bool > mSolo { false }
 Atomic because it may be read by worker threads in playback. More...
 
- Protected Attributes inherited from Track
std::weak_ptr< TrackListmList
 
TrackNodePointer mNode {}
 Holds iterator to self, so that TrackList::Find can be constant-time. More...
 
int mIndex
 0-based position of this track in its TrackList More...
 
wxString mName
 
ChannelType mChannel
 
double mOffset
 

Private Member Functions

void Init (const WaveTrack &orig)
 
Track::Holder Clone () const override
 
wxString MakeClipCopyName (const wxString &originalName) const
 
wxString MakeNewClipName () const
 
void DoSetPan (float value)
 
void DoSetGain (float value)
 
void PasteWaveTrack (double t0, const WaveTrack *other)
 

Private Attributes

SampleBlockFactoryPtr mpFactory
 
wxCriticalSection mFlushCriticalSection
 
wxCriticalSection mAppendCriticalSection
 
double mLegacyProjectFileOffset
 
std::unique_ptr< SpectrogramSettingsmpSpectrumSettings
 
std::unique_ptr< WaveformSettingsmpWaveformSettings
 

Friends

class WaveTrackFactory
 

Additional Inherited Members

- Public Attributes inherited from Track
std::pair< int, int > vrulerSize
 
- Protected Member Functions inherited from PlayableTrack
bool DoGetMute () const
 
void DoSetMute (bool value)
 
bool DoGetSolo () const
 
void DoSetSolo (bool value)
 
- Protected Member Functions inherited from Track
void SetLinkType (LinkType linkType, bool completeList=true)
 
void SetChannel (ChannelType c) noexcept
 
- Protected Member Functions inherited from ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >
template<typename Function >
void ForEach (const Function &function)
 Invoke function on each ClientData object that has been created in this. More...
 
template<typename Function >
void ForEach (const Function &function) const
 Invoke function on each ClientData object that has been created in this. More...
 
template<typename Function >
ClientData * FindIf (const Function &function)
 Return pointer to first attachment in this that is not null and satisfies a predicate, or nullptr. More...
 
template<typename Function >
const ClientData * FindIf (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...
 

Detailed Description

A Track that contains audio waveform data.

Definition at line 56 of file WaveTrack.h.

Member Typedef Documentation

◆ Holder

using WaveTrack::Holder = std::shared_ptr<WaveTrack>

Definition at line 105 of file WaveTrack.h.

◆ Location

Definition at line 104 of file WaveTrack.h.

◆ Regions

using WaveTrack::Regions = std::vector < Region >

Definition at line 75 of file WaveTrack.h.

Constructor & Destructor Documentation

◆ WaveTrack() [1/2]

WaveTrack::WaveTrack ( const SampleBlockFactoryPtr pFactory,
sampleFormat  format,
double  rate 
)

Definition at line 137 of file WaveTrack.cpp.

140 , mpFactory(pFactory)
141{
143
144 mFormat = format;
145 mRate = (int) rate;
146 mOldGain[0] = 0.0;
147 mOldGain[1] = 0.0;
148 mWaveColorIndex = 0;
149 mDisplayMin = -1.0;
150 mDisplayMax = 1.0;
151 mSpectrumMin = mSpectrumMax = -1; // so values will default to settings
152 mLastScaleType = -1;
153 mLastdBRange = -1;
154}
int format
Definition: ExportPCM.cpp:56
SampleBlockFactoryPtr mpFactory
Definition: WaveTrack.h:571
float mDisplayMin
Definition: WaveTrack.h:556
sampleFormat mFormat
Definition: WaveTrack.h:541
float mSpectrumMin
Definition: WaveTrack.h:558
int mLastScaleType
Definition: WaveTrack.h:561
float mDisplayMax
Definition: WaveTrack.h:557
int mLastdBRange
Definition: WaveTrack.h:562
float mSpectrumMax
Definition: WaveTrack.h:559
float mOldGain[2]
A memo used by PortAudio thread, doesn't need atomics:
Definition: WaveTrack.h:549
int mWaveColorIndex
Definition: WaveTrack.h:547
double mLegacyProjectFileOffset
Definition: WaveTrack.h:575
int mRate
Definition: WaveTrack.h:542

References format, mDisplayMax, mDisplayMin, mFormat, mLastdBRange, mLastScaleType, mLegacyProjectFileOffset, mOldGain, mRate, mSpectrumMax, mSpectrumMin, and mWaveColorIndex.

◆ WaveTrack() [2/2]

WaveTrack::WaveTrack ( const WaveTrack orig)

Definition at line 156 of file WaveTrack.cpp.

157 : WritableSampleTrack(orig)
158 , mpFactory( orig.mpFactory )
160 ? std::make_unique<SpectrogramSettings>(*orig.mpSpectrumSettings)
161 : nullptr
162 )
164 ? std::make_unique<WaveformSettings>(*orig.mpWaveformSettings)
165 : nullptr
166 )
167{
168 mLastScaleType = -1;
169 mLastdBRange = -1;
170
172
173 Init(orig);
174
175 for (const auto &clip : orig.mClips)
176 mClips.push_back
177 ( std::make_unique<WaveClip>( *clip, mpFactory, true ) );
178}
void Init(const WaveTrack &orig)
Definition: WaveTrack.cpp:181
std::unique_ptr< SpectrogramSettings > mpSpectrumSettings
Definition: WaveTrack.h:577
WaveClipHolders mClips
Definition: WaveTrack.h:539
std::unique_ptr< WaveformSettings > mpWaveformSettings
Definition: WaveTrack.h:578

References Init(), mClips, mLastdBRange, mLastScaleType, mLegacyProjectFileOffset, and mpFactory.

Here is the call graph for this function:

◆ ~WaveTrack()

WaveTrack::~WaveTrack ( )
virtual

Definition at line 237 of file WaveTrack.cpp.

238{
239}

Member Function Documentation

◆ AddClip()

bool WaveTrack::AddClip ( const std::shared_ptr< WaveClip > &  clip)

Append a clip to the track; which must have the same block factory as this track; return success.

Definition at line 1220 of file WaveTrack.cpp.

1221{
1222 if (clip->GetSequence()->GetFactory() != this->mpFactory)
1223 return false;
1224
1225 // Uncomment the following line after we correct the problem of zero-length clips
1226 //if (CanInsertClip(clip))
1227 mClips.push_back(clip); // transfer ownership
1228
1229 return true;
1230}

References mClips.

Referenced by ClearAndPaste(), and EffectReverse::ProcessOneWave().

Here is the caller graph for this function:

◆ Append()

bool WaveTrack::Append ( constSamplePtr  buffer,
sampleFormat  format,
size_t  len,
unsigned int  stride = 1 
)
overridevirtual
Exception safety guarantee:
Partial – Some prefix (maybe none) of the buffer is appended, and no content already flushed to disk is lost.

Implements WritableSampleTrack.

Definition at line 1766 of file WaveTrack.cpp.

1768{
1769 return RightmostOrNewClip()->Append(buffer, format, len, stride);
1770}
bool Append(constSamplePtr buffer, sampleFormat format, size_t len, unsigned int stride)
Definition: WaveClip.cpp:229
WaveClip * RightmostOrNewClip()
Get access to the last (rightmost) clip, or create a clip, if there is not already one.
Definition: WaveTrack.cpp:2378

References WaveClip::Append(), format, and RightmostOrNewClip().

Referenced by BlockGenerator::GenerateTrack(), EffectTwoPassSimpleMono::ProcessOne(), and NyquistEffect::PutCallback().

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

◆ CanInsertClip()

bool WaveTrack::CanInsertClip ( WaveClip clip,
double &  slideBy,
double &  tolerance 
) const

Definition at line 2482 of file WaveTrack.cpp.

2484{
2485 for (const auto &c : mClips)
2486 {
2487 double d1 = c->GetPlayStartTime() - (clip->GetPlayEndTime()+slideBy);
2488 double d2 = (clip->GetPlayStartTime()+slideBy) - c->GetPlayEndTime();
2489 if ( (d1<0) && (d2<0) )
2490 {
2491 // clips overlap.
2492 // Try to rescue it.
2493 // The rescue logic is not perfect, and will typically
2494 // move the clip at most once.
2495 // We divide by 1000 rather than set to 0, to allow for
2496 // a second 'micro move' that is really about rounding error.
2497 if( -d1 < tolerance ){
2498 // right edge of clip overlaps slightly.
2499 // slide clip left a small amount.
2500 slideBy +=d1;
2501 tolerance /=1000;
2502 } else if( -d2 < tolerance ){
2503 // left edge of clip overlaps slightly.
2504 // slide clip right a small amount.
2505 slideBy -= d2;
2506 tolerance /=1000;
2507 }
2508 else
2509 return false; // clips overlap No tolerance left.
2510 }
2511 }
2512
2513 return true;
2514}
double GetPlayStartTime() const noexcept
Definition: WaveClip.cpp:898
double GetPlayEndTime() const
Definition: WaveClip.cpp:908

References WaveClip::GetPlayEndTime(), WaveClip::GetPlayStartTime(), and mClips.

Here is the call graph for this function:

◆ CanOffsetClips()

bool WaveTrack::CanOffsetClips ( const std::vector< WaveClip * > &  clips,
double  amount,
double *  allowedAmount = nullptr 
)

Decide whether the clips could be offset (and inserted) together without overlapping other clips.

Returns
true if possible to offset by (allowedAmount ? *allowedAmount : amount)
Parameters
clipsnot necessarily in this track
amountsigned
[out]allowedAmountif null, test exact amount only; else, largest (in magnitude) possible offset with same sign

Definition at line 2424 of file WaveTrack.cpp.

2428{
2429 if (allowedAmount)
2430 *allowedAmount = amount;
2431
2432 const auto &moving = [&](WaveClip *clip){
2433 // linear search might be improved, but expecting few moving clips
2434 // compared with the fixed clips
2435 return clips.end() != std::find( clips.begin(), clips.end(), clip );
2436 };
2437
2438 for (const auto &c: mClips) {
2439 if ( moving( c.get() ) )
2440 continue;
2441 for (const auto clip : clips) {
2442 if (c->GetPlayStartTime() < clip->GetPlayEndTime() + amount &&
2443 c->GetPlayEndTime() > clip->GetPlayStartTime() + amount)
2444 {
2445 if (!allowedAmount)
2446 return false; // clips overlap
2447
2448 if (amount > 0)
2449 {
2450 if (c->GetPlayStartTime() - clip->GetPlayEndTime() < *allowedAmount)
2451 *allowedAmount = c->GetPlayStartTime() - clip->GetPlayEndTime();
2452 if (*allowedAmount < 0)
2453 *allowedAmount = 0;
2454 } else
2455 {
2456 if (c->GetPlayEndTime() - clip->GetPlayStartTime() > *allowedAmount)
2457 *allowedAmount = c->GetPlayEndTime() - clip->GetPlayStartTime();
2458 if (*allowedAmount > 0)
2459 *allowedAmount = 0;
2460 }
2461 }
2462 }
2463 }
2464
2465 if (allowedAmount)
2466 {
2467 if (*allowedAmount == amount)
2468 return true;
2469
2470 // Check if the NEW calculated amount would not violate
2471 // any other constraint
2472 if (!CanOffsetClips(clips, *allowedAmount, nullptr)) {
2473 *allowedAmount = 0; // play safe and don't allow anything
2474 return false;
2475 }
2476 else
2477 return true;
2478 } else
2479 return true;
2480}
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:101
bool CanOffsetClips(const std::vector< WaveClip * > &clips, double amount, double *allowedAmount=nullptr)
Decide whether the clips could be offset (and inserted) together without overlapping other clips.
Definition: WaveTrack.cpp:2424

References CanOffsetClips(), and mClips.

Referenced by CanOffsetClips().

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

◆ ClassTypeInfo()

auto WaveTrack::ClassTypeInfo ( )
static

Definition at line 329 of file WaveTrack.cpp.

330{
331 return typeInfo();
332}
static const Track::TypeInfo & typeInfo()
Definition: WaveTrack.cpp:316

References typeInfo().

Here is the call graph for this function:

◆ Clear()

void WaveTrack::Clear ( double  t0,
double  t1 
)
override
Exception safety guarantee:
Strong

Definition at line 788 of file WaveTrack.cpp.

789{
790 HandleClear(t0, t1, false, false);
791}
void HandleClear(double t0, double t1, bool addCutLines, bool split)
Definition: WaveTrack.cpp:1233

References HandleClear().

Referenced by Cut(), EffectTruncSilence::DoRemoval(), LabelEditActions::Handler::OnCutLabels(), Generator::Process(), EffectEqualization::ProcessOne(), EffectStereoToMono::ProcessOne(), EffectPaulstretch::ProcessOne(), SyncLockAdjust(), and Trim().

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

◆ ClearAndAddCutLine()

void WaveTrack::ClearAndAddCutLine ( double  t0,
double  t1 
)
Exception safety guarantee:
Strong

Definition at line 794 of file WaveTrack.cpp.

795{
796 HandleClear(t0, t1, true, false);
797}

References HandleClear().

Referenced by EditActions::Handler::OnCut(), and LabelEditActions::Handler::OnCutLabels().

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

◆ ClearAndPaste()

void WaveTrack::ClearAndPaste ( double  t0,
double  t1,
const Track src,
bool  preserve = true,
bool  merge = true,
const TimeWarper effectWarper = NULL 
)
Exception safety guarantee:
Weak – This WaveTrack remains destructible in case of AudacityException. But some of its cutline clips may have been destroyed.

Definition at line 915 of file WaveTrack.cpp.

922{
923 double dur = std::min(t1 - t0, src->GetEndTime());
924
925 // If duration is 0, then it's just a plain paste
926 if (dur == 0.0) {
927 // use Weak-guarantee
928 Paste(t0, src);
929 return;
930 }
931
932 std::vector<SplitInfo> splits;
933 WaveClipHolders cuts;
934
935 //helper routine, that finds SplitInfo by time value,
936 //or creates a new one if no one exists yet
937 auto get_split = [&](double time) {
938 auto it = std::find_if(splits.begin(), splits.end(), [time](const SplitInfo& split) {
939 return split.time == time;
940 });
941 if(it == splits.end())
942 it = splits.insert(
943 splits.end(),
944 { time, nullptr, nullptr, std::nullopt, std::nullopt }
945 );
946 return it;
947 };
948
949 // If provided time warper was NULL, use a default one that does nothing
950 IdentityTimeWarper localWarper;
951 const TimeWarper *warper = (effectWarper ? effectWarper : &localWarper);
952
953 // Align to a sample
956
957 // Save the cut/split lines whether preserving or not since merging
958 // needs to know if a clip boundary is being crossed since Paste()
959 // will add split lines around the pasted clip if so.
960 for (const auto &clip : mClips) {
961 double st;
962
963 // Remember clip boundaries as locations to split
964 // we need to copy clips, trims and names, because the original ones
965 // could be changed later during Clear/Paste routines
966 st = LongSamplesToTime(TimeToLongSamples(clip->GetPlayStartTime()));
967 if (st >= t0 && st <= t1) {
968 auto it = get_split(st);
969 if (clip->GetTrimLeft() != 0)
970 it->right = std::make_shared<WaveClip>(*clip, mpFactory, false, clip->GetSequenceStartTime(), st);
971 it->rightClipName = clip->GetName();
972 }
973
974 st = LongSamplesToTime(TimeToLongSamples(clip->GetPlayEndTime()));
975 if (st >= t0 && st <= t1) {
976 auto it = get_split(st);
977 if (clip->GetTrimRight() != 0)
978 it->left = std::make_shared<WaveClip>(*clip, mpFactory, false, st, clip->GetSequenceEndTime());
979 it->leftClipName = clip->GetName();
980 }
981
982 // Search for cut lines
983 auto &cutlines = clip->GetCutLines();
984 // May erase from cutlines, so don't use range-for
985 for (auto it = cutlines.begin(); it != cutlines.end(); ) {
986 WaveClip *cut = it->get();
987 double cs = LongSamplesToTime(TimeToLongSamples(clip->GetSequenceStartTime() +
988 cut->GetSequenceStartTime()));
989
990 // Remember cut point
991 if (cs >= t0 && cs <= t1) {
992
993 // Remember the absolute offset and add to our cuts array.
994 cut->SetSequenceStartTime(cs);
995 cuts.push_back(std::move(*it)); // transfer ownership!
996 it = cutlines.erase(it);
997 }
998 else
999 ++it;
1000 }
1001 }
1002
1003 const auto tolerance = 2.0 / GetRate();
1004
1005 // Now, clear the selection
1006 HandleClear(t0, t1, false, false);
1007 {
1008
1009 // And paste in the NEW data
1010 Paste(t0, src);
1011 {
1012 // First, merge the NEW clip(s) in with the existing clips
1013 if (merge && splits.size() > 0)
1014 {
1015 // Now t1 represents the absolute end of the pasted data.
1016 t1 = t0 + src->GetEndTime();
1017
1018 // Get a sorted array of the clips
1019 auto clips = SortedClipArray();
1020
1021 // Scan the sorted clips for the first clip whose start time
1022 // exceeds the pasted regions end time.
1023 {
1024 WaveClip *prev = nullptr;
1025 for (const auto clip : clips) {
1026 // Merge this clip and the previous clip if the end time
1027 // falls within it and this isn't the first clip in the track.
1028 if (fabs(t1 - clip->GetPlayStartTime()) < tolerance) {
1029 if (prev)
1030 MergeClips(GetClipIndex(prev), GetClipIndex(clip));
1031 break;
1032 }
1033 prev = clip;
1034 }
1035 }
1036 }
1037
1038 // Refill the array since clips have changed.
1039 auto clips = SortedClipArray();
1040
1041 {
1042 // Scan the sorted clips to look for the start of the pasted
1043 // region.
1044 WaveClip *prev = nullptr;
1045 for (const auto clip : clips) {
1046 if (prev) {
1047 // It must be that clip is what was pasted and it begins where
1048 // prev ends.
1049 // use Weak-guarantee
1050 MergeClips(GetClipIndex(prev), GetClipIndex(clip));
1051 break;
1052 }
1053 if (fabs(t0 - clip->GetPlayEndTime()) < tolerance)
1054 // Merge this clip and the next clip if the start time
1055 // falls within it and this isn't the last clip in the track.
1056 prev = clip;
1057 else
1058 prev = nullptr;
1059 }
1060 }
1061 }
1062
1063 // Restore cut/split lines
1064 if (preserve) {
1065
1066 auto attachLeft = [](WaveClip* target, WaveClip* src)
1067 {
1068 wxASSERT(target->GetTrimLeft() == 0);
1069 if (target->GetTrimLeft() != 0)
1070 return;
1071
1072 auto trim = src->GetPlayEndTime() - src->GetPlayStartTime();
1073 target->Paste(target->GetPlayStartTime(), src);
1074 target->SetTrimLeft(trim);
1075 //Play start time needs to be adjusted after
1076 //prepending data to the sequence
1077 target->Offset(-trim);
1078 };
1079
1080 auto attachRight = [](WaveClip* target, WaveClip* src)
1081 {
1082 wxASSERT(target->GetTrimRight() == 0);
1083 if (target->GetTrimRight() != 0)
1084 return;
1085
1086 auto trim = src->GetPlayEndTime() - src->GetPlayStartTime();
1087 target->Paste(target->GetPlayEndTime(), src);
1088 target->SetTrimRight(trim);
1089 };
1090
1091 // Restore the split lines and trims, transforming the position appropriately
1092 for (const auto& split: splits) {
1093 auto at = LongSamplesToTime(TimeToLongSamples(warper->Warp(split.time)));
1094 for (const auto& clip : GetClips())
1095 {
1096 if (clip->WithinPlayRegion(at))//strictly inside
1097 {
1098 auto newClip = std::make_unique<WaveClip>(*clip, mpFactory, true);
1099
1100 clip->ClearRight(at);
1101 newClip->ClearLeft(at);
1102 if (split.left)
1103 attachRight(clip.get(), split.left.get());
1104 if (split.right)
1105 attachLeft(newClip.get(), split.right.get());
1106 AddClip(std::move(newClip));
1107 break;
1108 }
1109 else if (clip->GetPlayStartSample() == TimeToLongSamples(at) && split.right)
1110 {
1111 attachLeft(clip.get(), split.right.get());
1112 break;
1113 }
1114 else if (clip->GetPlayEndSample() == TimeToLongSamples(at) && split.left)
1115 {
1116 attachRight(clip.get(), split.left.get());
1117 break;
1118 }
1119 }
1120 }
1121
1122 //Restore clip names
1123 for (const auto& split : splits)
1124 {
1125 auto s = TimeToLongSamples(warper->Warp(split.time));
1126 for (auto& clip : GetClips())
1127 {
1128 if (split.rightClipName.has_value() && clip->GetPlayStartSample() == s)
1129 clip->SetName(*split.rightClipName);
1130 else if (split.leftClipName.has_value() && clip->GetPlayEndSample() == s)
1131 clip->SetName(*split.leftClipName);
1132 }
1133 }
1134
1135 // Restore the saved cut lines, also transforming if time altered
1136 for (const auto &clip : mClips) {
1137 double st;
1138 double et;
1139
1140 st = clip->GetPlayStartTime();
1141 et = clip->GetPlayEndTime();
1142
1143 // Scan the cuts for any that live within this clip
1144 for (auto it = cuts.begin(); it != cuts.end();) {
1145 WaveClip *cut = it->get();
1146 //cutlines in this array were orphaned previously
1147 double cs = cut->GetSequenceStartTime();
1148
1149 // Offset the cut from the start of the clip and add it to
1150 // this clips cutlines.
1151 if (cs >= st && cs <= et) {
1152 cut->SetSequenceStartTime(warper->Warp(cs) - st);
1153 clip->GetCutLines().push_back( std::move(*it) ); // transfer ownership!
1154 it = cuts.erase(it);
1155 }
1156 else
1157 ++it;
1158 }
1159 }
1160 }
1161 }
1162}
int min(int a, int b)
std::vector< WaveClipHolder > WaveClipHolders
Definition: WaveClip.h:42
No change to time at all.
Definition: TimeWarper.h:69
double LongSamplesToTime(sampleCount pos) const
Convert correctly between a number of samples and an (absolute) time in seconds.
Definition: SampleTrack.cpp:40
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: SampleTrack.cpp:35
Transforms one point in time to another point. For example, a time stretching effect might use one to...
Definition: TimeWarper.h:62
virtual double Warp(double originalTime) const =0
virtual double GetEndTime() const =0
double GetSequenceStartTime() const noexcept
Definition: WaveClip.cpp:976
void SetSequenceStartTime(double startTime)
Definition: WaveClip.cpp:982
double GetTrimRight() const noexcept
Returns the play end offset in seconds from the ending of the underlying sequence.
Definition: WaveClip.cpp:951
double GetTrimLeft() const noexcept
Returns the play start offset in seconds from the beginning of the underlying sequence.
Definition: WaveClip.cpp:941
void Paste(double t0, const WaveClip *other)
Paste data from other clip, resampling it if not equal rate.
Definition: WaveClip.cpp:406
void SetTrimRight(double trim)
Sets the play end offset in seconds from the ending of the underlying sequence.
Definition: WaveClip.cpp:946
void Offset(double delta) noexcept
Definition: WaveClip.cpp:1009
void SetTrimLeft(double trim)
Sets the play start offset in seconds from the beginning of the underlying sequence.
Definition: WaveClip.cpp:936
void Paste(double t0, const Track *src) override
Definition: WaveTrack.cpp:1563
bool AddClip(const std::shared_ptr< WaveClip > &clip)
Append a clip to the track; which must have the same block factory as this track; return success.
Definition: WaveTrack.cpp:1220
WaveClipPointers SortedClipArray()
Definition: WaveTrack.cpp:2723
int GetClipIndex(const WaveClip *clip) const
Definition: WaveTrack.cpp:2399
double GetRate() const override
Definition: WaveTrack.cpp:481
WaveClipHolders & GetClips()
Definition: WaveTrack.h:322
void MergeClips(int clipidx1, int clipidx2)
Definition: WaveTrack.cpp:2681

References AddClip(), GetClipIndex(), GetClips(), Track::GetEndTime(), WaveClip::GetPlayEndTime(), WaveClip::GetPlayStartTime(), GetRate(), WaveClip::GetSequenceStartTime(), WaveClip::GetTrimLeft(), WaveClip::GetTrimRight(), HandleClear(), SampleTrack::LongSamplesToTime(), mClips, MergeClips(), min(), mpFactory, WaveClip::Offset(), Paste(), WaveClip::Paste(), WaveClip::SetSequenceStartTime(), WaveClip::SetTrimLeft(), WaveClip::SetTrimRight(), SortedClipArray(), SampleTrack::TimeToLongSamples(), and TimeWarper::Warp().

Referenced by TrackSpectrumTransformer::DoFinish(), EffectSBSMS::Finalize(), EditActions::Handler::OnPaste(), Generator::Process(), NyquistEffect::ProcessOne(), EffectNoiseRemoval::ProcessOne(), EffectChangeSpeed::ProcessOne(), and PerTrackEffect::ProcessTrack().

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

◆ Clone()

Track::Holder WaveTrack::Clone ( ) const
overrideprivatevirtual

Implements Track.

Definition at line 452 of file WaveTrack.cpp.

453{
454 return std::make_shared<WaveTrack>( *this );
455}

◆ CloseLock()

bool WaveTrack::CloseLock ( )

Definition at line 1987 of file WaveTrack.cpp.

1988{
1989 for (const auto &clip : mClips)
1990 clip->CloseLock();
1991
1992 return true;
1993}

References mClips.

◆ ConvertToSampleFormat()

void WaveTrack::ConvertToSampleFormat ( sampleFormat  format,
const std::function< void(size_t)> &  progressReport = {} 
)
Exception safety guarantee:
Weak – Might complete on only some clips

Definition at line 598 of file WaveTrack.cpp.

600{
601 for (const auto& clip : mClips)
602 clip->ConvertToSampleFormat(format, progressReport);
603 mFormat = format;
604}

References format, mClips, and mFormat.

Referenced by EffectEqualization::ProcessOne().

Here is the caller graph for this function:

◆ Copy()

Track::Holder WaveTrack::Copy ( double  t0,
double  t1,
bool  forClipboard = true 
) const
override

Definition at line 716 of file WaveTrack.cpp.

717{
718 if (t1 < t0)
720
721 auto result = EmptyCopy();
722 WaveTrack *newTrack = result.get();
723
724 // PRL: Why shouldn't cutlines be copied and pasted too? I don't know, but
725 // that was the old behavior. But this function is also used by the
726 // Duplicate command and I changed its behavior in that case.
727
728 for (const auto &clip : mClips)
729 {
730 if (t0 <= clip->GetPlayStartTime() && t1 >= clip->GetPlayEndTime())
731 {
732 // Whole clip is in copy region
733 //wxPrintf("copy: clip %i is in copy region\n", (int)clip);
734
735 newTrack->mClips.push_back
736 (std::make_unique<WaveClip>(*clip, mpFactory, ! forClipboard));
737 WaveClip *const newClip = newTrack->mClips.back().get();
738 newClip->Offset(-t0);
739 }
740 else if (t1 > clip->GetPlayStartTime() && t0 < clip->GetPlayEndTime())
741 {
742 // Clip is affected by command
743 //wxPrintf("copy: clip %i is affected by command\n", (int)clip);
744
745 const double clip_t0 = std::max(t0, clip->GetPlayStartTime());
746 const double clip_t1 = std::min(t1, clip->GetPlayEndTime());
747
748 auto newClip = std::make_unique<WaveClip>
749 (*clip, mpFactory, ! forClipboard, clip_t0, clip_t1);
750 newClip->SetName(clip->GetName());
751
752 //wxPrintf("copy: clip_t0=%f, clip_t1=%f\n", clip_t0, clip_t1);
753
754 newClip->Offset(-t0);
755 if (newClip->GetPlayStartTime() < 0)
756 newClip->SetPlayStartTime(0);
757
758 newTrack->mClips.push_back(std::move(newClip)); // transfer ownership
759 }
760 }
761
762 // AWD, Oct 2009: If the selection ends in whitespace, create a placeholder
763 // clip representing that whitespace
764 // PRL: Only if we want the track for pasting into other tracks. Not if it
765 // goes directly into a project as in the Duplicate command.
766 if (forClipboard &&
767 newTrack->GetEndTime() + 1.0 / newTrack->GetRate() < t1 - t0)
768 {
769 auto placeholder = std::make_unique<WaveClip>(mpFactory,
770 newTrack->GetSampleFormat(),
771 static_cast<int>(newTrack->GetRate()),
772 0 /*colourindex*/);
773 placeholder->SetIsPlaceholder(true);
774 placeholder->InsertSilence(0, (t1 - t0) - newTrack->GetEndTime());
775 placeholder->Offset(newTrack->GetEndTime());
776 newTrack->mClips.push_back(std::move(placeholder)); // transfer ownership
777 }
778
779 return result;
780}
#define THROW_INCONSISTENCY_EXCEPTION
Throw InconsistencyException, using C++ preprocessor to identify the source code location.
void SetPlayStartTime(double time)
Definition: WaveClip.cpp:903
void SetName(const wxString &name)
Definition: WaveClip.cpp:867
A Track that contains audio waveform data.
Definition: WaveTrack.h:57
sampleFormat GetSampleFormat() const override
Definition: WaveTrack.h:160
Holder EmptyCopy(const SampleBlockFactoryPtr &pFactory={}) const
Definition: WaveTrack.cpp:707
double GetEndTime() const override
Get the time at which the last clip in the track ends, plus recorded stuff.
Definition: WaveTrack.cpp:2015

References EmptyCopy(), GetEndTime(), GetRate(), GetSampleFormat(), mClips, min(), mpFactory, WaveClip::Offset(), and THROW_INCONSISTENCY_EXCEPTION.

Referenced by CopyNonconst(), Cut(), EditActions::Handler::OnSplitCut(), LabelEditActions::Handler::OnSplitCutLabels(), and SplitCut().

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

◆ CopyNonconst()

Track::Holder WaveTrack::CopyNonconst ( double  t0,
double  t1 
)

Definition at line 782 of file WaveTrack.cpp.

783{
784 return Copy(t0, t1);
785}
Track::Holder Copy(double t0, double t1, bool forClipboard=true) const override
Definition: WaveTrack.cpp:716

References Copy().

Referenced by LabelEditActions::Handler::OnCopyLabels(), and LabelEditActions::Handler::OnCutLabels().

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

◆ CreateClip()

WaveClip * WaveTrack::CreateClip ( double  offset = .0,
const wxString &  name = wxEmptyString 
)

Definition at line 2358 of file WaveTrack.cpp.

2359{
2360 auto clip = std::make_unique<WaveClip>(mpFactory, mFormat, mRate, GetWaveColorIndex());
2361 clip->SetName(name);
2362 clip->SetSequenceStartTime(offset);
2363 mClips.push_back(std::move(clip));
2364
2365 return mClips.back().get();
2366}
const TranslatableString name
Definition: Distortion.cpp:82
int GetWaveColorIndex() const
Definition: WaveTrack.h:154

References GetWaveColorIndex(), mClips, mFormat, mpFactory, mRate, and name.

Referenced by AUPImportFileHandle::HandleWaveClip(), HandleXMLChild(), Join(), NewestOrNewClip(), and RightmostOrNewClip().

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

◆ Cut()

Track::Holder WaveTrack::Cut ( double  t0,
double  t1 
)
override

Definition at line 629 of file WaveTrack.cpp.

630{
631 if (t1 < t0)
633
634 auto tmp = Copy(t0, t1);
635
636 Clear(t0, t1);
637
638 return tmp;
639}
void Clear(double t0, double t1) override
Definition: WaveTrack.cpp:788

References Clear(), Copy(), and THROW_INCONSISTENCY_EXCEPTION.

Referenced by PasteWaveTrack(), and SyncLockAdjust().

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

◆ Disjoin()

void WaveTrack::Disjoin ( double  t0,
double  t1 
)
Exception safety guarantee:
Weak

Definition at line 1637 of file WaveTrack.cpp.

1638{
1640 const size_t maxAtOnce = 1048576;
1641 Floats buffer{ maxAtOnce };
1642 Regions regions;
1643
1644 for (const auto &clip : mClips)
1645 {
1646 double startTime = clip->GetPlayStartTime();
1647 double endTime = clip->GetPlayEndTime();
1648
1649 if( endTime < t0 || startTime > t1 )
1650 continue;
1651
1652 //simply look for a sequence of zeroes and if the sequence
1653 //is greater than minimum number, split-DELETE the region
1654
1655 sampleCount seqStart = -1;
1656 auto start = clip->TimeToSamples(std::max(.0, t0 - startTime));
1657 auto end = clip->TimeToSamples(std::min(endTime, t1) - startTime);
1658
1659 auto len = ( end - start );
1660 for( decltype(len) done = 0; done < len; done += maxAtOnce )
1661 {
1662 auto numSamples = limitSampleBufferSize( maxAtOnce, len - done );
1663
1664 clip->GetSamples( ( samplePtr )buffer.get(), floatSample, start + done,
1665 numSamples );
1666 for( decltype(numSamples) i = 0; i < numSamples; i++ )
1667 {
1668 auto curSamplePos = start + done + i;
1669
1670 //start a NEW sequence
1671 if( buffer[ i ] == 0.0 && seqStart == -1 )
1672 seqStart = curSamplePos;
1673 else if( buffer[ i ] != 0.0 || curSamplePos == end - 1 )
1674 {
1675 if( seqStart != -1 )
1676 {
1677 decltype(end) seqEnd;
1678
1679 //consider the end case, where selection ends in zeroes
1680 if( curSamplePos == end - 1 && buffer[ i ] == 0.0 )
1681 seqEnd = end;
1682 else
1683 seqEnd = curSamplePos;
1684 if( seqEnd - seqStart + 1 > minSamples )
1685 {
1686 regions.push_back(
1687 Region(
1688 startTime + clip->SamplesToTime(seqStart),
1689 startTime + clip->SamplesToTime(seqEnd)
1690 )
1691 );
1692 }
1693 seqStart = -1;
1694 }
1695 }
1696 }
1697 }
1698 }
1699
1700 for( unsigned int i = 0; i < regions.size(); i++ )
1701 {
1702 const Region &region = regions.at(i);
1703 SplitDelete(region.start, region.end );
1704 }
1705}
WaveTrack::Regions Regions
Definition: LabelMenus.cpp:23
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:23
@ floatSample
Definition: SampleFormat.h:34
char * samplePtr
Definition: SampleFormat.h:49
WaveTrack::Region Region
#define WAVETRACK_MERGE_POINT_TOLERANCE
Definition: WaveTrack.h:52
void SplitDelete(double t0, double t1)
Definition: WaveTrack.cpp:1165
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:18
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for, if Traits<Type>::iterated_type is defined.
Definition: PackedArray.h:126
Structure to hold region of a wavetrack and a comparison function for sortability.
Definition: WaveTrack.h:62

References PackedArray::end(), WaveTrack::Region::end, floatSample, limitSampleBufferSize(), mClips, min(), SplitDelete(), WaveTrack::Region::start, SampleTrack::TimeToLongSamples(), and WAVETRACK_MERGE_POINT_TOLERANCE.

Referenced by LabelEditActions::Handler::OnDisjoinLabels().

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

◆ DoSetGain()

void WaveTrack::DoSetGain ( float  value)
private

Definition at line 503 of file WaveTrack.cpp.

504{
505 mGain.store(value, std::memory_order_relaxed);
506}
std::atomic< float > mGain
Atomic because it may be read by worker threads in playback.
Definition: WaveTrack.h:544

References mGain.

Referenced by HandleXMLTag(), Init(), Merge(), and SetGain().

Here is the caller graph for this function:

◆ DoSetPan()

void WaveTrack::DoSetPan ( float  value)
private

Definition at line 521 of file WaveTrack.cpp.

522{
523 mPan.store(value, std::memory_order_relaxed);
524}
std::atomic< float > mPan
Atomic because it may be read by worker threads in playback.
Definition: WaveTrack.h:546

References mPan.

Referenced by HandleXMLTag(), Init(), Merge(), and SetPan().

Here is the caller graph for this function:

◆ EmptyCopy()

WaveTrack::Holder WaveTrack::EmptyCopy ( const SampleBlockFactoryPtr pFactory = {}) const

Definition at line 707 of file WaveTrack.cpp.

709{
710 auto result = std::make_shared<WaveTrack>( pFactory, mFormat, mRate );
711 result->Init(*this);
712 result->mpFactory = pFactory ? pFactory : mpFactory;
713 return result;
714}

References mFormat, mpFactory, and mRate.

Referenced by Copy(), TrackSpectrumTransformer::DoStart(), PasteInto(), Generator::Process(), EffectSBSMS::Process(), NyquistEffect::ProcessOne(), EffectEqualization::ProcessOne(), EffectNoiseRemoval::ProcessOne(), EffectStereoToMono::ProcessOne(), EffectChangeSpeed::ProcessOne(), EffectPaulstretch::ProcessOne(), and PerTrackEffect::ProcessTrack().

Here is the caller graph for this function:

◆ ExpandCutLine()

void WaveTrack::ExpandCutLine ( double  cutLinePosition,
double *  cutlineStart = NULL,
double *  cutlineEnd = NULL 
)
Exception safety guarantee:
Strong

Definition at line 2618 of file WaveTrack.cpp.

2620{
2621 bool editClipCanMove = GetEditClipsCanMove();
2622
2623 // Find clip which contains this cut line
2624 double start = 0, end = 0;
2625 auto pEnd = mClips.end();
2626 auto pClip = std::find_if( mClips.begin(), pEnd,
2627 [&](const WaveClipHolder &clip) {
2628 return clip->FindCutLine(cutLinePosition, &start, &end); } );
2629 if (pClip != pEnd)
2630 {
2631 auto &clip = *pClip;
2632 if (!editClipCanMove)
2633 {
2634 // We are not allowed to move the other clips, so see if there
2635 // is enough room to expand the cut line
2636 for (const auto &clip2: mClips)
2637 {
2638 if (clip2->GetPlayStartTime() > clip->GetPlayStartTime() &&
2639 clip->GetPlayEndTime() + end - start > clip2->GetPlayStartTime())
2640 // Strong-guarantee in case of this path
2643 XO("There is not enough room available to expand the cut line"),
2644 XO("Warning"),
2645 "Error:_Insufficient_space_in_track"
2646 };
2647 }
2648 }
2649
2650 clip->ExpandCutLine(cutLinePosition);
2651
2652 // Strong-guarantee provided that the following gives No-fail-guarantee
2653
2654 if (cutlineStart)
2655 *cutlineStart = start;
2656 if (cutlineEnd)
2657 *cutlineEnd = end;
2658
2659 // Move clips which are to the right of the cut line
2660 if (editClipCanMove)
2661 {
2662 for (const auto &clip2 : mClips)
2663 {
2664 if (clip2->GetPlayStartTime() > clip->GetPlayStartTime())
2665 clip2->Offset(end - start);
2666 }
2667 }
2668 }
2669}
@ BadUserAction
Indicates that the user performed an action that is not allowed.
#define XO(s)
Definition: Internat.h:31
std::shared_ptr< WaveClip > WaveClipHolder
Definition: WaveClip.h:41
bool GetEditClipsCanMove()
Definition: WaveTrack.cpp:2850
A MessageBoxException that shows a given, unvarying string.

References BadUserAction, PackedArray::end(), GetEditClipsCanMove(), mClips, and XO.

Here is the call graph for this function:

◆ FindClipByName()

const WaveClip * WaveTrack::FindClipByName ( const wxString &  name) const

Returns nullptr if clip with such name was not found.

Definition at line 442 of file WaveTrack.cpp.

443{
444 for (const auto& clip : mClips)
445 {
446 if (clip->GetName() == name)
447 return clip.get();
448 }
449 return nullptr;
450}

References mClips, and name.

Referenced by MakeClipCopyName(), and MakeNewClipName().

Here is the caller graph for this function:

◆ Flush()

void WaveTrack::Flush ( )
overridevirtual
Exception safety guarantee:
Mixed
Exception safety guarantee:
No-fail – The rightmost clip will be in a flushed state.
Exception safety guarantee:
Partial – Some initial portion (maybe none) of the append buffer of the rightmost clip gets appended; no previously saved contents are lost.

Implements WritableSampleTrack.

Definition at line 1836 of file WaveTrack.cpp.

1837{
1838 // After appending, presumably. Do this to the clip that gets appended.
1840}
void Flush()
Flush must be called after last Append.
Definition: WaveClip.cpp:290

References WaveClip::Flush(), and RightmostOrNewClip().

Referenced by EffectTwoPassSimpleMono::ProcessOne(), and AudioIO::StopStream().

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

◆ Get()

bool WaveTrack::Get ( samplePtr  buffer,
sampleFormat  format,
sampleCount  start,
size_t  len,
fillFormat  fill = fillZero,
bool  mayThrow = true,
sampleCount pNumWithinClips = nullptr 
) const
overridevirtual

MM: Now that each wave track can contain multiple clips, we don't have a continuous space of samples anymore, but we simulate it, because there are a lot of places (e.g. effects) using this interface. This interface makes much sense for modifying samples, but note that it is not time-accurate, because the "offset" is a double value and therefore can lie inbetween samples. But as long as you use the same value for "start" in both calls to "Set" and "Get" it is guaranteed that the same samples are affected.

Implements SampleTrack.

Definition at line 2112 of file WaveTrack.cpp.

2115{
2116 // Simple optimization: When this buffer is completely contained within one clip,
2117 // don't clear anything (because we won't have to). Otherwise, just clear
2118 // everything to be on the safe side.
2119 bool doClear = true;
2120 bool result = true;
2121 sampleCount samplesCopied = 0;
2122 for (const auto &clip: mClips)
2123 {
2124 if (start >= clip->GetPlayStartSample() && start+len <= clip->GetPlayEndSample())
2125 {
2126 doClear = false;
2127 break;
2128 }
2129 }
2130 if (doClear)
2131 {
2132 // Usually we fill in empty space with zero
2133 if( fill == fillZero )
2134 ClearSamples(buffer, format, 0, len);
2135 // but we don't have to.
2136 else if( fill==fillTwo )
2137 {
2138 wxASSERT( format==floatSample );
2139 float * pBuffer = (float*)buffer;
2140 for(size_t i=0;i<len;i++)
2141 pBuffer[i]=2.0f;
2142 }
2143 else
2144 {
2145 wxFAIL_MSG(wxT("Invalid fill format"));
2146 }
2147 }
2148
2149 // Iterate the clips. They are not necessarily sorted by time.
2150 for (const auto &clip: mClips)
2151 {
2152 auto clipStart = clip->GetPlayStartSample();
2153 auto clipEnd = clip->GetPlayEndSample();
2154
2155 if (clipEnd > start && clipStart < start+len)
2156 {
2157 // Clip sample region and Get/Put sample region overlap
2158 auto samplesToCopy =
2159 std::min( start+len - clipStart, clip->GetPlaySamplesCount() );
2160 auto startDelta = clipStart - start;
2161 decltype(startDelta) inclipDelta = 0;
2162 if (startDelta < 0)
2163 {
2164 inclipDelta = -startDelta; // make positive value
2165 samplesToCopy -= inclipDelta;
2166 // samplesToCopy is now either len or
2167 // (clipEnd - clipStart) - (start - clipStart)
2168 // == clipEnd - start > 0
2169 // samplesToCopy is not more than len
2170 //
2171 startDelta = 0;
2172 // startDelta is zero
2173 }
2174 else {
2175 // startDelta is nonnegative and less than len
2176 // samplesToCopy is positive and not more than len
2177 }
2178
2179 if (!clip->GetSamples(
2180 (samplePtr)(((char*)buffer) +
2181 startDelta.as_size_t() *
2183 format, inclipDelta, samplesToCopy.as_size_t(), mayThrow ))
2184 result = false;
2185 else
2186 samplesCopied += samplesToCopy;
2187 }
2188 }
2189 if( pNumWithinClips )
2190 *pNumWithinClips = samplesCopied;
2191 return result;
2192}
void ClearSamples(samplePtr dst, sampleFormat format, size_t start, size_t len)
#define SAMPLE_SIZE(SampleFormat)
Definition: SampleFormat.h:44
@ fillZero
Definition: SampleFormat.h:54
@ fillTwo
Definition: SampleFormat.h:55

References ClearSamples(), fillTwo, fillZero, floatSample, format, mClips, min(), and SAMPLE_SIZE.

Referenced by WaveTrackFactory::Get(), and EffectNoiseRemoval::ProcessOne().

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

◆ GetAllClips() [1/2]

IteratorRange< AllClipsIterator > WaveTrack::GetAllClips ( )
inline

Definition at line 404 of file WaveTrack.h.

405 {
406 return { AllClipsIterator{ *this }, AllClipsIterator{ } };
407 }

◆ GetAllClips() [2/2]

IteratorRange< AllClipsConstIterator > WaveTrack::GetAllClips ( ) const
inline

Definition at line 409 of file WaveTrack.h.

410 {
411 return { AllClipsConstIterator{ *this }, AllClipsConstIterator{ } };
412 }

◆ GetBestBlockSize()

size_t WaveTrack::GetBestBlockSize ( sampleCount  t) const
overridevirtual

This returns a nonnegative number of samples meant to size a memory buffer.

Implements SampleTrack.

Definition at line 1788 of file WaveTrack.cpp.

1789{
1790 auto bestBlockSize = GetMaxBlockSize();
1791
1792 for (const auto &clip : mClips)
1793 {
1794 auto startSample = clip->GetPlayStartSample();
1795 auto endSample = clip->GetPlayEndSample();
1796 if (s >= startSample && s < endSample)
1797 {
1798 bestBlockSize = clip->GetSequence()->GetBestBlockSize(s - clip->GetSequenceStartSample());
1799 break;
1800 }
1801 }
1802
1803 return bestBlockSize;
1804}
size_t GetMaxBlockSize() const override
This returns a nonnegative number of samples meant to size a memory buffer.
Definition: WaveTrack.cpp:1806

References GetMaxBlockSize(), and mClips.

Referenced by EffectNormalize::AnalyseTrackData(), CompareAudioCommand::Apply(), BlockGenerator::GenerateTrack(), NyquistEffect::GetCallback(), TrackSpectrumTransformer::Process(), EffectNoiseRemoval::ProcessOne(), EffectLoudness::ProcessOne(), EffectNormalize::ProcessOne(), EffectChangeSpeed::ProcessOne(), EffectSimpleMono::ProcessOne(), EffectTwoPassSimpleMono::ProcessOne(), EffectReverse::ProcessOneClip(), resampleCB(), VoiceKey::TestDirectionChanges(), VoiceKey::TestEnergy(), and VoiceKey::TestSignChanges().

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

◆ GetBlockStart()

sampleCount WaveTrack::GetBlockStart ( sampleCount  t) const
overridevirtual

This returns a possibly large or negative value.

Implements SampleTrack.

Definition at line 1772 of file WaveTrack.cpp.

1773{
1774 for (const auto &clip : mClips)
1775 {
1776 const auto startSample = clip->GetPlayStartSample();
1777 const auto endSample = clip->GetPlayEndSample();
1778 if (s >= startSample && s < endSample)
1779 {
1780 auto blockStartOffset = clip->GetSequence()->GetBlockStart(clip->ToSequenceSamples(s));
1781 return std::max(startSample, clip->GetSequenceStartSample() + blockStartOffset);
1782 }
1783 }
1784
1785 return -1;
1786}

References mClips.

◆ GetCachedLocations()

const std::vector< Location > & WaveTrack::GetCachedLocations ( ) const
inline

Definition at line 482 of file WaveTrack.h.

482{ return mDisplayLocationsCache; }
std::vector< Location > mDisplayLocationsCache
Definition: WaveTrack.h:563

Referenced by WaveTrackSubView::DrawBoldBoundaries(), anonymous_namespace{CutlineHandle.cpp}::FindMergeLine(), and anonymous_namespace{CutlineHandle.cpp}::IsOverCutline().

Here is the caller graph for this function:

◆ GetChannel()

auto WaveTrack::GetChannel ( ) const
overridevirtual

Reimplemented from Track.

Definition at line 262 of file WaveTrack.cpp.

263{
265 return mChannel;
266 auto pan = GetPan();
267 if( pan < -0.99 )
268 return Track::LeftChannel;
269 if( pan > 0.99 )
270 return Track::RightChannel;
271 return mChannel;
272}
@ LeftChannel
Definition: Track.h:275
@ RightChannel
Definition: Track.h:276
@ MonoChannel
Definition: Track.h:277
ChannelType mChannel
Definition: Track.h:439
float GetPan() const
Definition: WaveTrack.cpp:516

References GetPan(), Track::LeftChannel, Track::mChannel, Track::MonoChannel, and Track::RightChannel.

Here is the call graph for this function:

◆ GetChannelGain()

float WaveTrack::GetChannelGain ( int  channel) const
overridevirtual

Takes gain and pan into account.

Implements SampleTrack.

Definition at line 539 of file WaveTrack.cpp.

540{
541 float left = 1.0;
542 float right = 1.0;
543
544 const auto pan = GetPan();
545 if (pan < 0)
546 right = (pan + 1.0);
547 else if (pan > 0)
548 left = 1.0 - pan;
549
550 const auto gain = GetGain();
551 if ((channel%2) == 0)
552 return left * gain;
553 else
554 return right * gain;
555}
float GetGain() const
Definition: WaveTrack.cpp:498

References GetGain(), and GetPan().

Referenced by AudioIoCallback::AddToOutputChannel(), and MixerTrackCluster::UpdateMeter().

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

◆ GetChannelIgnoringPan()

auto WaveTrack::GetChannelIgnoringPan ( ) const
overridevirtual

May be called from a worker thread

Implements SampleTrack.

Definition at line 258 of file WaveTrack.cpp.

258 {
259 return mChannel;
260}

References Track::mChannel.

Referenced by AudioIoCallback::FillOutputBuffers(), and AudioIoCallback::TrackHasBeenFadedOut().

Here is the caller graph for this function:

◆ GetClipAtSample()

WaveClip * WaveTrack::GetClipAtSample ( sampleCount  sample)

Definition at line 2303 of file WaveTrack.cpp.

2304{
2305 for (const auto &clip: mClips)
2306 {
2307 auto start = clip->GetPlayStartSample();
2308 auto len = clip->GetPlaySamplesCount();
2309
2310 if (sample >= start && sample < start + len)
2311 return clip.get();
2312 }
2313
2314 return NULL;
2315}

References WaveClip::GetPlayStartSample(), and mClips.

Here is the call graph for this function:

◆ GetClipAtTime()

WaveClip * WaveTrack::GetClipAtTime ( double  time)

Definition at line 2319 of file WaveTrack.cpp.

2320{
2321
2322 const auto clips = SortedClipArray();
2323 auto p = std::find_if(clips.rbegin(), clips.rend(), [&] (WaveClip* const& clip) {
2324 return time >= clip->GetPlayStartTime() && time <= clip->GetPlayEndTime(); });
2325
2326 // When two clips are immediately next to each other, the GetPlayEndTime() of the first clip
2327 // and the GetPlayStartTime() of the second clip may not be exactly equal due to rounding errors.
2328 // If "time" is the end time of the first of two such clips, and the end time is slightly
2329 // less than the start time of the second clip, then the first rather than the
2330 // second clip is found by the above code. So correct this.
2331 if (p != clips.rend() && p != clips.rbegin() &&
2332 time == (*p)->GetPlayEndTime() &&
2333 (*p)->SharesBoundaryWithNextClip(*(p-1))) {
2334 p--;
2335 }
2336
2337 return p != clips.rend() ? *p : nullptr;
2338}

References SortedClipArray().

Referenced by SelectHandle::Click(), GetEnvelopeAtTime(), and GetSequenceAtTime().

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

◆ GetClipByIndex() [1/2]

WaveClip * WaveTrack::GetClipByIndex ( int  index)

Definition at line 2406 of file WaveTrack.cpp.

2407{
2408 if(index < (int)mClips.size())
2409 return mClips[index].get();
2410 else
2411 return nullptr;
2412}

References mClips.

Referenced by GetClipByIndex(), MergeClips(), and PasteWaveTrack().

Here is the caller graph for this function:

◆ GetClipByIndex() [2/2]

const WaveClip * WaveTrack::GetClipByIndex ( int  index) const

Definition at line 2414 of file WaveTrack.cpp.

2415{
2416 return const_cast<WaveTrack&>(*this).GetClipByIndex(index);
2417}
WaveClip * GetClipByIndex(int index)
Definition: WaveTrack.cpp:2406

References GetClipByIndex().

Here is the call graph for this function:

◆ GetClipIndex()

int WaveTrack::GetClipIndex ( const WaveClip clip) const

Definition at line 2399 of file WaveTrack.cpp.

2400{
2401 int result;
2402 FindClip(mClips, clip, &result);
2403 return result;
2404}
WaveClipHolders::iterator FindClip(WaveClipHolders &list, const WaveClip *clip, int *distance=nullptr)
Definition: WaveTrack.cpp:1191

References anonymous_namespace{WaveTrack.cpp}::FindClip(), and mClips.

Referenced by ClearAndPaste(), and UpdateLocationsCache().

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

◆ GetClips() [1/2]

WaveClipHolders & WaveTrack::GetClips ( )
inline

Definition at line 322 of file WaveTrack.h.

322{ return mClips; }

Referenced by ProjectFileManager::AddImportedTracks(), WaveClipTrimHandle::AdjustBetweenBorders::AdjustBetweenBorders(), ClearAndPaste(), SpectrumView::DoDraw(), WaveformView::DoDraw(), EffectEqualization::ProcessOne(), EffectReverse::ProcessOneWave(), and anonymous_namespace{ClipMenus.cpp}::TwoChannelsHaveSameBoundaries().

Here is the caller graph for this function:

◆ GetClips() [2/2]

const WaveClipConstHolders & WaveTrack::GetClips ( ) const
inline

Definition at line 323 of file WaveTrack.h.

324 { return reinterpret_cast< const WaveClipConstHolders& >( mClips ); }
std::vector< std::shared_ptr< const WaveClip > > WaveClipConstHolders
Definition: WaveClip.h:43

◆ GetDefaultAudioTrackNamePreference()

wxString WaveTrack::GetDefaultAudioTrackNamePreference ( )
static

Definition at line 100 of file WaveTrack.cpp.

101{
103
104 if (name.empty() || ( name == DefaultName.MSGID() ))
105 // When nothing was specified,
106 // the default-default is whatever translation of...
107 /* i18n-hint: The default name for an audio track. */
108 return DefaultName.Translation();
109 else
110 return name;
111}
static auto DefaultName
Definition: WaveTrack.cpp:98
StringSetting AudioTrackNameSetting
Definition: WaveTrack.cpp:2840
bool ReadWithDefault(T *pVar, const T &defaultValue) const
overload of ReadWithDefault returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:191

References AudioTrackNameSetting, DefaultName, TranslatableString::empty(), name, and Setting< T >::ReadWithDefault().

Referenced by TracksPrefs::Commit(), EffectBase::DoEffect(), ProjectAudioManager::DoRecord(), anonymous_namespace{WaveTrackMenuItems.cpp}::Handler::OnNewStereoTrack(), and anonymous_namespace{WaveTrackMenuItems.cpp}::Handler::OnNewWaveTrack().

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

◆ GetDisplayBounds()

void WaveTrack::GetDisplayBounds ( float *  min,
float *  max 
) const

Definition at line 344 of file WaveTrack.cpp.

345{
346 *min = mDisplayMin;
347 *max = mDisplayMax;
348}

References mDisplayMax, mDisplayMin, and min().

Referenced by EnvelopeHandle::Click(), WaveformVRulerControls::DoHandleWheelRotation(), WaveformVRulerControls::DoUpdateVRuler(), WaveformVZoomHandle::DoZoom(), anonymous_namespace{WaveformView.cpp}::DrawClipWaveform(), and GetInfoCommand::SendTracks().

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

◆ GetEndTime()

double WaveTrack::GetEndTime ( ) const
overridevirtual

Get the time at which the last clip in the track ends, plus recorded stuff.

Returns
time in seconds, or zero if there are no clips in the track.

Implements Track.

Definition at line 2015 of file WaveTrack.cpp.

2016{
2017 bool found = false;
2018 double best = 0.0;
2019
2020 if (mClips.empty())
2021 return 0;
2022
2023 for (const auto &clip : mClips)
2024 if (!found)
2025 {
2026 found = true;
2027 best = clip->GetPlayEndTime();
2028 }
2029 else if (clip->GetPlayEndTime() > best)
2030 best = clip->GetPlayEndTime();
2031
2032 return best;
2033}

References mClips.

Referenced by AUPImportFileHandle::AddSilence(), EffectTruncSilence::Analyze(), Copy(), Effect::GetBounds(), PasteWaveTrack(), EffectChangeSpeed::Process(), EffectSBSMS::Process(), NyquistEffect::ProcessOne(), EffectStereoToMono::ProcessOne(), GetInfoCommand::SendTracks(), SyncLockAdjust(), and Trim().

Here is the caller graph for this function:

◆ GetEnvelopeAtTime()

Envelope * WaveTrack::GetEnvelopeAtTime ( double  time)

Definition at line 2340 of file WaveTrack.cpp.

2341{
2342 WaveClip* clip = GetClipAtTime(time);
2343 if (clip)
2344 return clip->GetEnvelope();
2345 else
2346 return NULL;
2347}
Envelope * GetEnvelope()
Definition: WaveClip.h:205
WaveClip * GetClipAtTime(double time)
Definition: WaveTrack.cpp:2319

References GetClipAtTime(), and WaveClip::GetEnvelope().

Here is the call graph for this function:

◆ GetEnvelopeValues()

void WaveTrack::GetEnvelopeValues ( double *  buffer,
size_t  bufferLen,
double  t0 
) const
overridevirtual

Fetch envelope values corresponding to uniformly separated sample times starting at the given time.

Implements SampleTrack.

Definition at line 2237 of file WaveTrack.cpp.

2239{
2240 // The output buffer corresponds to an unbroken span of time which the callers expect
2241 // to be fully valid. As clips are processed below, the output buffer is updated with
2242 // envelope values from any portion of a clip, start, end, middle, or none at all.
2243 // Since this does not guarantee that the entire buffer is filled with values we need
2244 // to initialize the entire buffer to a default value.
2245 //
2246 // This does mean that, in the cases where a usable clip is located, the buffer value will
2247 // be set twice. Unfortunately, there is no easy way around this since the clips are not
2248 // stored in increasing time order. If they were, we could just track the time as the
2249 // buffer is filled.
2250 for (decltype(bufferLen) i = 0; i < bufferLen; i++)
2251 {
2252 buffer[i] = 1.0;
2253 }
2254
2255 double startTime = t0;
2256 auto tstep = 1.0 / mRate;
2257 double endTime = t0 + tstep * bufferLen;
2258 for (const auto &clip: mClips)
2259 {
2260 // IF clip intersects startTime..endTime THEN...
2261 auto dClipStartTime = clip->GetPlayStartTime();
2262 auto dClipEndTime = clip->GetPlayEndTime();
2263 if ((dClipStartTime < endTime) && (dClipEndTime > startTime))
2264 {
2265 auto rbuf = buffer;
2266 auto rlen = bufferLen;
2267 auto rt0 = t0;
2268
2269 if (rt0 < dClipStartTime)
2270 {
2271 // This is not more than the number of samples in
2272 // (endTime - startTime) which is bufferLen:
2273 auto nDiff = (sampleCount)floor((dClipStartTime - rt0) * mRate + 0.5);
2274 auto snDiff = nDiff.as_size_t();
2275 rbuf += snDiff;
2276 wxASSERT(snDiff <= rlen);
2277 rlen -= snDiff;
2278 rt0 = dClipStartTime;
2279 }
2280
2281 if (rt0 + rlen*tstep > dClipEndTime)
2282 {
2283 auto nClipLen = clip->GetPlayEndSample() - clip->GetPlayStartSample();
2284
2285 if (nClipLen <= 0) // Testing for bug 641, this problem is consistently '== 0', but doesn't hurt to check <.
2286 return;
2287
2288 // This check prevents problem cited in http://bugzilla.audacityteam.org/show_bug.cgi?id=528#c11,
2289 // Gale's cross_fade_out project, which was already corrupted by bug 528.
2290 // This conditional prevents the previous write past the buffer end, in clip->GetEnvelope() call.
2291 // Never increase rlen here.
2292 // PRL bug 827: rewrote it again
2293 rlen = limitSampleBufferSize( rlen, nClipLen );
2294 rlen = std::min(rlen, size_t(floor(0.5 + (dClipEndTime - rt0) / tstep)));
2295 }
2296 // Samples are obtained for the purpose of rendering a wave track,
2297 // so quantize time
2298 clip->GetEnvelope()->GetValues(rbuf, rlen, rt0, tstep);
2299 }
2300 }
2301}

References limitSampleBufferSize(), mClips, min(), and mRate.

Here is the call graph for this function:

◆ GetErrorOpening()

bool WaveTrack::GetErrorOpening ( )
overridevirtual

Reimplemented from Track.

Definition at line 1978 of file WaveTrack.cpp.

1979{
1980 for (const auto &clip : mClips)
1981 if (clip->GetSequence()->GetErrorOpening())
1982 return true;
1983
1984 return false;
1985}

References mClips.

◆ GetGain()

float WaveTrack::GetGain ( ) const

Definition at line 498 of file WaveTrack.cpp.

499{
500 return mGain.load(std::memory_order_relaxed);
501}

References mGain.

Referenced by WaveTrackControls::GainSlider(), GetChannelGain(), Init(), Merge(), GetInfoCommand::SendTracks(), and SetGain().

Here is the caller graph for this function:

◆ GetIdealBlockSize()

size_t WaveTrack::GetIdealBlockSize ( )

Definition at line 1826 of file WaveTrack.cpp.

1827{
1829}
size_t GetIdealBlockSize() const
Definition: Sequence.cpp:82
Sequence * GetSequence()
Definition: WaveClip.h:213
WaveClip * NewestOrNewClip()
Get access to the most recently added clip, or create a clip, if there is not already one....
Definition: WaveTrack.cpp:2368

References Sequence::GetIdealBlockSize(), WaveClip::GetSequence(), and NewestOrNewClip().

Referenced by NyquistEffect::GetCallback().

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

◆ GetIndependentSpectrogramSettings()

SpectrogramSettings & WaveTrack::GetIndependentSpectrogramSettings ( )

Definition at line 815 of file WaveTrack.cpp.

816{
819 std::make_unique<SpectrogramSettings>(SpectrogramSettings::defaults());
820 return *mpSpectrumSettings;
821}
static SpectrogramSettings & defaults()

References SpectrogramSettings::defaults(), and mpSpectrumSettings.

Referenced by SpectrumVRulerControls::DoHandleWheelRotation(), and UseSpectralPrefs().

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

◆ GetIntervals() [1/2]

auto WaveTrack::GetIntervals ( ) const
overridevirtual

Report times on the track where important intervals begin and end, for UI to snap to.

Some intervals may be empty, and no ordering of the intervals is assumed.

Reimplemented from Track.

Definition at line 432 of file WaveTrack.cpp.

433{
434 return MakeIntervals<ConstIntervals>( mClips );
435}

References mClips.

◆ GetIntervals() [2/2]

auto WaveTrack::GetIntervals ( )
overridevirtual

This overload exposes the extra data of the intervals as non-const This overload exposes the extra data of the intervals as non-const

Reimplemented from Track.

Definition at line 437 of file WaveTrack.cpp.

438{
439 return MakeIntervals<Intervals>( mClips );
440}

◆ GetLastdBRange()

int WaveTrack::GetLastdBRange ( ) const
inline

Definition at line 503 of file WaveTrack.h.

503{ return mLastdBRange; }

Referenced by WaveformVRulerControls::DoUpdateVRuler().

Here is the caller graph for this function:

◆ GetLastScaleType()

int WaveTrack::GetLastScaleType ( ) const
inline

Definition at line 500 of file WaveTrack.h.

500{ return mLastScaleType; }

Referenced by WaveformVRulerControls::DoUpdateVRuler().

Here is the caller graph for this function:

◆ GetMaxBlockSize()

size_t WaveTrack::GetMaxBlockSize ( ) const
overridevirtual

This returns a nonnegative number of samples meant to size a memory buffer.

Implements SampleTrack.

Definition at line 1806 of file WaveTrack.cpp.

1807{
1808 decltype(GetMaxBlockSize()) maxblocksize = 0;
1809 for (const auto &clip : mClips)
1810 {
1811 maxblocksize = std::max(maxblocksize, clip->GetSequence()->GetMaxBlockSize());
1812 }
1813
1814 if (maxblocksize == 0)
1815 {
1816 // We really need the maximum block size, so create a
1817 // temporary sequence to get it.
1818 maxblocksize = Sequence{ mpFactory, mFormat }.GetMaxBlockSize();
1819 }
1820
1821 wxASSERT(maxblocksize > 0);
1822
1823 return maxblocksize;
1824}
A WaveTrack contains WaveClip(s). A WaveClip contains a Sequence. A Sequence is primarily an interfac...
Definition: Sequence.h:61

References GetMaxBlockSize(), mClips, mFormat, and mpFactory.

Referenced by EffectNormalize::AnalyseTrackData(), EffectTruncSilence::Analyze(), CompareAudioCommand::Apply(), BlockGenerator::GenerateTrack(), GetBestBlockSize(), GetMaxBlockSize(), EffectCompressor::InitPass1(), TrackSpectrumTransformer::Process(), EffectSBSMS::Process(), EffectEqualization::ProcessOne(), EffectClickRemoval::ProcessOne(), EffectNoiseRemoval::ProcessOne(), EffectStereoToMono::ProcessOne(), EffectNormalize::ProcessOne(), EffectChangeSpeed::ProcessOne(), EffectSimpleMono::ProcessOne(), EffectTwoPassSimpleMono::ProcessOne(), EffectReverse::ProcessOneClip(), PerTrackEffect::ProcessPass(), VoiceKey::TestDirectionChanges(), VoiceKey::TestEnergy(), and VoiceKey::TestSignChanges().

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

◆ GetMinMax()

std::pair< float, float > WaveTrack::GetMinMax ( double  t0,
double  t1,
bool  mayThrow = true 
) const

Definition at line 2040 of file WaveTrack.cpp.

2042{
2043 std::pair<float, float> results {
2044 // we need these at extremes to make sure we find true min and max
2045 FLT_MAX, -FLT_MAX
2046 };
2047 bool clipFound = false;
2048
2049 if (t0 > t1) {
2050 if (mayThrow)
2052 return results;
2053 }
2054
2055 if (t0 == t1)
2056 return results;
2057
2058 for (const auto &clip: mClips)
2059 {
2060 if (t1 >= clip->GetPlayStartTime() && t0 <= clip->GetPlayEndTime())
2061 {
2062 clipFound = true;
2063 auto clipResults = clip->GetMinMax(t0, t1, mayThrow);
2064 if (clipResults.first < results.first)
2065 results.first = clipResults.first;
2066 if (clipResults.second > results.second)
2067 results.second = clipResults.second;
2068 }
2069 }
2070
2071 if(!clipFound)
2072 {
2073 results = { 0.f, 0.f }; // sensible defaults if no clips found
2074 }
2075
2076 return results;
2077}

References mClips, and THROW_INCONSISTENCY_EXCEPTION.

Referenced by EffectNormalize::AnalyseTrack(), and NyquistEffect::ProcessOne().

Here is the caller graph for this function:

◆ GetNumClips()

int WaveTrack::GetNumClips ( ) const

Definition at line 2419 of file WaveTrack.cpp.

2420{
2421 return mClips.size();
2422}

References mClips.

Referenced by PasteWaveTrack().

Here is the caller graph for this function:

◆ GetOffset()

double WaveTrack::GetOffset ( ) const
overridevirtual

Implements Track.

Definition at line 241 of file WaveTrack.cpp.

242{
243 return GetStartTime();
244}
double GetStartTime() const override
Get the time at which the first clip in the track starts.
Definition: WaveTrack.cpp:1995

References GetStartTime().

Referenced by TranscriptionToolBar::GetSamples(), EditActions::Handler::OnSplitNew(), and SetOffset().

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

◆ GetOldChannelGain()

float WaveTrack::GetOldChannelGain ( int  channel) const
overridevirtual

Implements SampleTrack.

Definition at line 557 of file WaveTrack.cpp.

558{
559 return mOldGain[channel%2];
560}

References mOldGain.

Referenced by AudioIoCallback::AddToOutputChannel(), and AudioIoCallback::TrackHasBeenFadedOut().

Here is the caller graph for this function:

◆ GetPan()

float WaveTrack::GetPan ( ) const

Definition at line 516 of file WaveTrack.cpp.

517{
518 return mPan.load(std::memory_order_relaxed);
519}

References mPan.

Referenced by GetChannel(), GetChannelGain(), Init(), Merge(), WaveTrackControls::PanSlider(), GetInfoCommand::SendTracks(), and SetPan().

Here is the caller graph for this function:

◆ GetPlaySamplesCount()

sampleCount WaveTrack::GetPlaySamplesCount ( ) const

Definition at line 577 of file WaveTrack.cpp.

578{
579 sampleCount result{ 0 };
580
581 for (const auto& clip : mClips)
582 result += clip->GetPlaySamplesCount();
583
584 return result;
585}

References mClips.

◆ GetRate()

double WaveTrack::GetRate ( ) const
overridevirtual

◆ GetRMS()

float WaveTrack::GetRMS ( double  t0,
double  t1,
bool  mayThrow = true 
) const

Definition at line 2079 of file WaveTrack.cpp.

2080{
2081 if (t0 > t1) {
2082 if (mayThrow)
2084 return 0.f;
2085 }
2086
2087 if (t0 == t1)
2088 return 0.f;
2089
2090 double sumsq = 0.0;
2091 sampleCount length = 0;
2092
2093 for (const auto &clip: mClips)
2094 {
2095 // If t1 == clip->GetStartTime() or t0 == clip->GetEndTime(), then the clip
2096 // is not inside the selection, so we don't want it.
2097 // if (t1 >= clip->GetStartTime() && t0 <= clip->GetEndTime())
2098 if (t1 >= clip->GetPlayStartTime() && t0 <= clip->GetPlayEndTime())
2099 {
2100 auto clipStart = clip->TimeToSequenceSamples(wxMax(t0, clip->GetPlayStartTime()));
2101 auto clipEnd = clip->TimeToSequenceSamples(wxMin(t1, clip->GetPlayEndTime()));
2102
2103 float cliprms = clip->GetRMS(t0, t1, mayThrow);
2104
2105 sumsq += cliprms * cliprms * (clipEnd - clipStart).as_float();
2106 length += (clipEnd - clipStart);
2107 }
2108 }
2109 return length > 0 ? sqrt(sumsq / length.as_double()) : 0.0;
2110}
double as_double() const
Definition: SampleCount.h:45

References sampleCount::as_double(), mClips, and THROW_INCONSISTENCY_EXCEPTION.

Referenced by EffectLoudness::GetTrackRMS(), and NyquistEffect::ProcessOne().

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

◆ GetSampleFormat()

sampleFormat WaveTrack::GetSampleFormat ( ) const
inlineoverridevirtual

Implements SampleTrack.

Definition at line 160 of file WaveTrack.h.

160{ return mFormat; }

Referenced by Copy(), and SyncLockAdjust().

Here is the caller graph for this function:

◆ GetSequenceAtTime()

Sequence * WaveTrack::GetSequenceAtTime ( double  time)

Definition at line 2349 of file WaveTrack.cpp.

2350{
2351 WaveClip* clip = GetClipAtTime(time);
2352 if (clip)
2353 return clip->GetSequence();
2354 else
2355 return NULL;
2356}

References GetClipAtTime(), and WaveClip::GetSequence().

Here is the call graph for this function:

◆ GetSequenceSamplesCount()

sampleCount WaveTrack::GetSequenceSamplesCount ( ) const

Definition at line 587 of file WaveTrack.cpp.

588{
589 sampleCount result{ 0 };
590
591 for (const auto& clip : mClips)
592 result += clip->GetSequenceSamplesCount();
593
594 return result;
595}

References mClips.

◆ GetSpectrogramSettings() [1/2]

SpectrogramSettings & WaveTrack::GetSpectrogramSettings ( )

Definition at line 807 of file WaveTrack.cpp.

808{
810 return *mpSpectrumSettings;
811 else
813}

References SpectrogramSettings::defaults(), and mpSpectrumSettings.

Here is the call graph for this function:

◆ GetSpectrogramSettings() [2/2]

const SpectrogramSettings & WaveTrack::GetSpectrogramSettings ( ) const

Definition at line 799 of file WaveTrack.cpp.

800{
802 return *mpSpectrumSettings;
803 else
805}

References SpectrogramSettings::defaults(), and mpSpectrumSettings.

Referenced by SpectrumVRulerControls::DoUpdateVRuler(), SpectrumVZoomHandle::DoZoom(), for(), anonymous_namespace{BrushHandle.cpp}::FrequencyToPosition(), anonymous_namespace{SelectHandle.cpp}::FrequencyToPosition(), GetSpectrumBounds(), SpectrumVRulerMenuTable::OnSpectrumScaleType(), anonymous_namespace{BrushHandle.cpp}::PositionToFrequency(), anonymous_namespace{SelectHandle.cpp}::PositionToFrequency(), NyquistEffect::ProcessOne(), SelectHandle::SnapCenterOnce(), SpectrumPrefs::SpectrumPrefs(), and SelectHandle::StartSnappingFreqSelection().

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

◆ GetSpectrumBounds()

void WaveTrack::GetSpectrumBounds ( float *  min,
float *  max 
) const

Definition at line 356 of file WaveTrack.cpp.

357{
358 const double rate = GetRate();
359
361 const SpectrogramSettings::ScaleType type = settings.scaleType;
362
363 const float top = (rate / 2.);
364
365 float bottom;
367 bottom = 0.0f;
368 else if (type == SpectrogramSettings::stPeriod) {
369 // special case
370 const auto half = settings.GetFFTLength() / 2;
371 // EAC returns no data for below this frequency:
372 const float bin2 = rate / half;
373 bottom = bin2;
374 }
375 else
376 // logarithmic, etc.
377 bottom = 1.0f;
378
379 {
380 float spectrumMax = mSpectrumMax;
381 if (spectrumMax < 0)
382 spectrumMax = settings.maxFreq;
383 if (spectrumMax < 0)
384 *max = top;
385 else
386 *max = std::max(bottom, std::min(top, spectrumMax));
387 }
388
389 {
390 float spectrumMin = mSpectrumMin;
391 if (spectrumMin < 0)
392 spectrumMin = settings.minFreq;
393 if (spectrumMin < 0)
394 *min = std::max(bottom, top / 1000.0f);
395 else
396 *min = std::max(bottom, std::min(top, spectrumMin));
397 }
398}
static Settings & settings()
Definition: TrackInfo.cpp:87
Spectrogram settings, either for one track or as defaults.
const SpectrogramSettings & GetSpectrogramSettings() const
Definition: WaveTrack.cpp:799

References GetRate(), GetSpectrogramSettings(), min(), mSpectrumMax, mSpectrumMin, settings(), SpectrogramSettings::stLinear, and SpectrogramSettings::stPeriod.

Referenced by SpectrumVRulerControls::DoHandleWheelRotation(), SpectrumVRulerControls::DoUpdateVRuler(), SpectrumVZoomHandle::DoZoom(), anonymous_namespace{BrushHandle.cpp}::FrequencyToPosition(), anonymous_namespace{SelectHandle.cpp}::FrequencyToPosition(), anonymous_namespace{BrushHandle.cpp}::PositionToFrequency(), anonymous_namespace{SelectHandle.cpp}::PositionToFrequency(), and SpectrumPrefs::SpectrumPrefs().

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

◆ GetStartTime()

double WaveTrack::GetStartTime ( ) const
overridevirtual

Get the time at which the first clip in the track starts.

Returns
time in seconds, or zero if there are no clips in the track

Implements Track.

Definition at line 1995 of file WaveTrack.cpp.

1996{
1997 bool found = false;
1998 double best = 0.0;
1999
2000 if (mClips.empty())
2001 return 0;
2002
2003 for (const auto &clip : mClips)
2004 if (!found)
2005 {
2006 found = true;
2007 best = clip->GetPlayStartTime();
2008 }
2009 else if (clip->GetPlayStartTime() < best)
2010 best = clip->GetPlayStartTime();
2011
2012 return best;
2013}

References mClips.

Referenced by Effect::GetBounds(), GetOffset(), PasteWaveTrack(), EffectChangeSpeed::Process(), EffectSBSMS::Process(), EffectStereoToMono::ProcessOne(), GetInfoCommand::SendTracks(), and Trim().

Here is the caller graph for this function:

◆ GetTypeInfo()

auto WaveTrack::GetTypeInfo ( ) const
overridevirtual

Implements Track.

Definition at line 324 of file WaveTrack.cpp.

325{
326 return typeInfo();
327}

References typeInfo().

Here is the call graph for this function:

◆ GetWaveColorIndex()

int WaveTrack::GetWaveColorIndex ( ) const
inline

Definition at line 154 of file WaveTrack.h.

154{ return mWaveColorIndex; };

Referenced by CreateClip(), and InsertSilence().

Here is the caller graph for this function:

◆ GetWaveformSettings() [1/2]

WaveformSettings & WaveTrack::GetWaveformSettings ( )

Definition at line 853 of file WaveTrack.cpp.

854{
855 // Create on demand
857 mpWaveformSettings = std::make_unique<WaveformSettings>(WaveformSettings::defaults());
858 return *mpWaveformSettings;
859}
static WaveformSettings & defaults()

References WaveformSettings::defaults(), and mpWaveformSettings.

Here is the call graph for this function:

◆ GetWaveformSettings() [2/2]

const WaveformSettings & WaveTrack::GetWaveformSettings ( ) const

Definition at line 847 of file WaveTrack.cpp.

848{
849 // Create on demand
850 return const_cast<WaveTrack*>(this)->GetWaveformSettings();
851}
const WaveformSettings & GetWaveformSettings() const
Definition: WaveTrack.cpp:847

References GetWaveformSettings().

Referenced by EnvelopeHandle::Click(), WaveformView::DoDraw(), WaveformVRulerControls::DoHandleWheelRotation(), WaveformVRulerControls::DoUpdateVRuler(), WaveformVZoomHandle::DoZoom(), anonymous_namespace{WaveformView.cpp}::DrawClipWaveform(), for(), GetWaveformSettings(), WaveformVRulerMenuTable::OnWaveformScaleType(), SetLastdBRange(), SetLastScaleType(), and WaveformPrefs::WaveformPrefs().

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

◆ HandleClear()

void WaveTrack::HandleClear ( double  t0,
double  t1,
bool  addCutLines,
bool  split 
)
Exception safety guarantee:
Strong

Definition at line 1233 of file WaveTrack.cpp.

1235{
1236 // For debugging, use an ASSERT so that we stop
1237 // closer to the problem.
1238 wxASSERT( t1 >= t0 );
1239 if (t1 < t0)
1241
1242 bool editClipCanMove = GetEditClipsCanMove();
1243
1244 WaveClipPointers clipsToDelete;
1245 WaveClipHolders clipsToAdd;
1246
1247 // We only add cut lines when deleting in the middle of a single clip
1248 // The cut line code is not really prepared to handle other situations
1249 if (addCutLines)
1250 {
1251 for (const auto &clip : mClips)
1252 {
1253 if (!clip->BeforePlayStartTime(t1) && !clip->AfterPlayEndTime(t0) &&
1254 (clip->BeforePlayStartTime(t0) || clip->AfterPlayEndTime(t1)))
1255 {
1256 addCutLines = false;
1257 break;
1258 }
1259 }
1260 }
1261
1262 for (const auto &clip : mClips)
1263 {
1264 if (clip->BeforePlayStartTime(t0) && clip->AfterPlayEndTime(t1))
1265 {
1266 // Whole clip must be deleted - remember this
1267 clipsToDelete.push_back(clip.get());
1268 }
1269 else if (!clip->BeforePlayStartTime(t1) && !clip->AfterPlayEndTime(t0))
1270 {
1271 // Clip data is affected by command
1272 if (addCutLines)
1273 {
1274 // Don't modify this clip in place, because we want a strong
1275 // guarantee, and might modify another clip
1276 clipsToDelete.push_back( clip.get() );
1277 auto newClip = std::make_unique<WaveClip>( *clip, mpFactory, true );
1278 newClip->ClearAndAddCutLine( t0, t1 );
1279 clipsToAdd.push_back( std::move( newClip ) );
1280 }
1281 else
1282 {
1283 if (split) {
1284 // Three cases:
1285
1286 if (clip->BeforePlayStartTime(t0)) {
1287 // Delete from the left edge
1288
1289 // Don't modify this clip in place, because we want a strong
1290 // guarantee, and might modify another clip
1291 clipsToDelete.push_back( clip.get() );
1292 auto newClip = std::make_unique<WaveClip>( *clip, mpFactory, true );
1293 newClip->TrimLeft(t1 - clip->GetPlayStartTime());
1294 clipsToAdd.push_back( std::move( newClip ) );
1295 }
1296 else if (clip->AfterPlayEndTime(t1)) {
1297 // Delete to right edge
1298
1299 // Don't modify this clip in place, because we want a strong
1300 // guarantee, and might modify another clip
1301 clipsToDelete.push_back( clip.get() );
1302 auto newClip = std::make_unique<WaveClip>( *clip, mpFactory, true );
1303 newClip->TrimRight(clip->GetPlayEndTime() - t0);
1304
1305 clipsToAdd.push_back( std::move( newClip ) );
1306 }
1307 else {
1308 // Delete in the middle of the clip...we actually create two
1309 // NEW clips out of the left and right halves...
1310
1311 auto leftClip = std::make_unique<WaveClip>(*clip, mpFactory, true);
1312 leftClip->TrimRight(clip->GetPlayEndTime() - t0);
1313 clipsToAdd.push_back(std::move(leftClip));
1314
1315 auto rightClip = std::make_unique<WaveClip>(*clip, mpFactory, true);
1316 rightClip->TrimLeft(t1 - rightClip->GetPlayStartTime());
1317 clipsToAdd.push_back(std::move(rightClip));
1318
1319 clipsToDelete.push_back(clip.get());
1320 }
1321 }
1322 else {
1323 // (We are not doing a split cut)
1324
1325 // Don't modify this clip in place, because we want a strong
1326 // guarantee, and might modify another clip
1327 clipsToDelete.push_back( clip.get() );
1328 auto newClip = std::make_unique<WaveClip>( *clip, mpFactory, true );
1329
1330 // clip->Clear keeps points < t0 and >= t1 via Envelope::CollapseRegion
1331 newClip->Clear(t0,t1);
1332
1333 clipsToAdd.push_back( std::move( newClip ) );
1334 }
1335 }
1336 }
1337 }
1338
1339 // Only now, change the contents of this track
1340 // use No-fail-guarantee for the rest
1341
1342 if (!split && editClipCanMove)
1343 {
1344 // Clip is "behind" the region -- offset it unless we're splitting
1345 // or we're using the "don't move other clips" mode
1346 for (const auto& clip : mClips)
1347 {
1348 if (clip->BeforePlayStartTime(t1))
1349 clip->Offset(-(t1 - t0));
1350 }
1351 }
1352
1353 for (const auto &clip: clipsToDelete)
1354 {
1355 auto myIt = FindClip(mClips, clip);
1356 if (myIt != mClips.end())
1357 mClips.erase(myIt); // deletes the clip!
1358 else
1359 wxASSERT(false);
1360 }
1361
1362 for (auto &clip: clipsToAdd)
1363 mClips.push_back(std::move(clip)); // transfer ownership
1364}
std::vector< WaveClip * > WaveClipPointers
Definition: WaveTrack.h:46

References anonymous_namespace{WaveTrack.cpp}::FindClip(), GetEditClipsCanMove(), mClips, mpFactory, and THROW_INCONSISTENCY_EXCEPTION.

Referenced by Clear(), ClearAndAddCutLine(), ClearAndPaste(), and SplitDelete().

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

◆ HandleXMLChild()

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

Implements XMLTagHandler.

Definition at line 1914 of file WaveTrack.cpp.

1915{
1916 if ( auto pChild = WaveTrackIORegistry::Get()
1917 .CallObjectAccessor(tag, *this) )
1918 return pChild;
1919
1920 //
1921 // This is legacy code (1.2 and previous) and is not called for NEW projects!
1922 //
1923 if (tag == "sequence" || tag == "envelope")
1924 {
1925 // This is a legacy project, so set the cached offset
1927
1928 // Legacy project file tracks are imported as one single wave clip
1929 if (tag == "sequence")
1930 return NewestOrNewClip()->GetSequence();
1931 else if (tag == "envelope")
1932 return NewestOrNewClip()->GetEnvelope();
1933 }
1934
1935 // JKC... for 1.1.0, one step better than what we had, but still badly broken.
1936 // If we see a waveblock at this level, we'd better generate a sequence.
1937 if (tag == "waveblock")
1938 {
1939 // This is a legacy project, so set the cached offset
1942 return pSeq;
1943 }
1944
1945 //
1946 // This is for the NEW file format (post-1.2)
1947 //
1948 if (tag == "waveclip")
1949 return CreateClip();
1950
1951 return nullptr;
1952}
WaveClip * CreateClip(double offset=.0, const wxString &name=wxEmptyString)
Definition: WaveTrack.cpp:2358
static XMLMethodRegistry & Get()
Get the unique instance.

References CreateClip(), XMLMethodRegistry< Host >::Get(), WaveClip::GetEnvelope(), WaveClip::GetSequence(), mLegacyProjectFileOffset, NewestOrNewClip(), and WaveClip::SetSequenceStartTime().

Here is the call graph for this function:

◆ HandleXMLEndTag()

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

Definition at line 1907 of file WaveTrack.cpp.

1908{
1909 // In case we opened a pre-multiclip project, we need to
1910 // simulate closing the waveclip tag.
1911 NewestOrNewClip()->HandleXMLEndTag("waveclip");
1912}
void HandleXMLEndTag(const std::string_view &tag) override
Definition: WaveClip.cpp:362

References WaveClip::HandleXMLEndTag(), and NewestOrNewClip().

Here is the call graph for this function:

◆ HandleXMLTag()

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

Implements XMLTagHandler.

Definition at line 1849 of file WaveTrack.cpp.

1850{
1851 if (tag == "wavetrack") {
1852 double dblValue;
1853 long nValue;
1854
1855 for (auto pair : attrs)
1856 {
1857 auto attr = pair.first;
1858 auto value = pair.second;
1859
1860 if (attr == "rate")
1861 {
1862 // mRate is an int, but "rate" in the project file is a float.
1863 if (!value.TryGet(dblValue) ||
1864 (dblValue < 1.0) || (dblValue > 1000000.0)) // allow a large range to be read
1865 return false;
1866
1867 mRate = lrint(dblValue);
1868 }
1869 else if (attr == "offset" && value.TryGet(dblValue))
1870 {
1871 // Offset is only relevant for legacy project files. The value
1872 // is cached until the actual WaveClip containing the legacy
1873 // track is created.
1874 mLegacyProjectFileOffset = dblValue;
1875 }
1876 else if (this->WritableSampleTrack::HandleXMLAttribute(attr, value))
1877 {}
1878 else if (this->Track::HandleCommonXMLAttribute(attr, value))
1879 ;
1880 else if (attr == "gain" && value.TryGet(dblValue))
1881 DoSetGain(dblValue);
1882 else if (attr == "pan" && value.TryGet(dblValue) &&
1883 (dblValue >= -1.0) && (dblValue <= 1.0))
1884 DoSetPan(dblValue);
1885 else if (attr == "channel")
1886 {
1887 if (!value.TryGet(nValue) ||
1888 !IsValidChannel(nValue))
1889 return false;
1890 mChannel = static_cast<Track::ChannelType>( nValue );
1891 }
1892 else if (attr == "linked" && value.TryGet(nValue))
1893 SetLinkType(ToLinkType(nValue), false);
1894 else if (attr == "colorindex" && value.TryGet(nValue))
1895 // Don't use SetWaveColorIndex as it sets the clips too.
1896 mWaveColorIndex = nValue;
1897 else if (attr == "sampleformat" && value.TryGet(nValue) &&
1899 mFormat = static_cast<sampleFormat>(nValue);
1900 } // while
1901 return true;
1902 }
1903
1904 return false;
1905}
sampleFormat
Definition: SampleFormat.h:29
bool HandleXMLAttribute(const std::string_view &attr, const XMLAttributeValueView &value)
Definition: Track.cpp:364
static bool IsValidSampleFormat(const int nValue)
true if nValue is one of the sampleFormat enum values
Definition: Sequence.cpp:1710
ChannelType
Definition: Track.h:274
void SetLinkType(LinkType linkType, bool completeList=true)
Definition: Track.cpp:153
bool HandleCommonXMLAttribute(const std::string_view &attr, const XMLAttributeValueView &valueView)
Definition: Track.cpp:1264
void DoSetPan(float value)
Definition: WaveTrack.cpp:521
void DoSetGain(float value)
Definition: WaveTrack.cpp:503
#define lrint(dbl)
Definition: float_cast.h:169
bool IsValidChannel(const int nValue)
Definition: WaveTrack.cpp:1843
Track::LinkType ToLinkType(int value)
Definition: WaveTrack.cpp:87

References DoSetGain(), DoSetPan(), Track::HandleCommonXMLAttribute(), PlayableTrack::HandleXMLAttribute(), anonymous_namespace{WaveTrack.cpp}::IsValidChannel(), Sequence::IsValidSampleFormat(), lrint, Track::mChannel, mFormat, mLegacyProjectFileOffset, mRate, mWaveColorIndex, Track::SetLinkType(), and anonymous_namespace{WaveTrack.cpp}::ToLinkType().

Here is the call graph for this function:

◆ Init()

void WaveTrack::Init ( const WaveTrack orig)
private

Definition at line 181 of file WaveTrack.cpp.

182{
184 mpFactory = orig.mpFactory;
185
186 mFormat = orig.mFormat;
188 mRate = orig.mRate;
189 DoSetGain(orig.GetGain());
190 DoSetPan(orig.GetPan());
191 mOldGain[0] = 0.0;
192 mOldGain[1] = 0.0;
198}
void Init(const PlayableTrack &init)
Definition: Track.cpp:303

References DoSetGain(), DoSetPan(), GetGain(), GetPan(), PlayableTrack::Init(), mDisplayLocationsCache, mDisplayMax, mDisplayMin, mFormat, mOldGain, mpFactory, mRate, mSpectrumMax, mSpectrumMin, and mWaveColorIndex.

Referenced by Reinit(), and WaveTrack().

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

◆ InsertSilence()

void WaveTrack::InsertSilence ( double  t,
double  len 
)
override
Exception safety guarantee:
Strong

Definition at line 1597 of file WaveTrack.cpp.

1598{
1599 // Nothing to do, if length is zero.
1600 // Fixes Bug 1626
1601 if( len == 0 )
1602 return;
1603 if (len <= 0)
1605
1606 if (mClips.empty())
1607 {
1608 // Special case if there is no clip yet
1609 auto clip = std::make_unique<WaveClip>(mpFactory, mFormat, mRate, this->GetWaveColorIndex());
1610 clip->InsertSilence(0, len);
1611 // use No-fail-guarantee
1612 mClips.push_back( std::move( clip ) );
1613 return;
1614 }
1615 else {
1616 // Assume at most one clip contains t
1617 const auto end = mClips.end();
1618 const auto it = std::find_if( mClips.begin(), end,
1619 [&](const WaveClipHolder &clip) { return clip->WithinPlayRegion(t); } );
1620
1621 // use Strong-guarantee
1622 if (it != end)
1623 it->get()->InsertSilence(t, len);
1624
1625 // use No-fail-guarantee
1626 for (const auto &clip : mClips)
1627 {
1628 if (clip->BeforePlayStartTime(t))
1629 clip->Offset(len);
1630 }
1631 }
1632}

References PackedArray::end(), GetWaveColorIndex(), mClips, mFormat, mpFactory, mRate, and THROW_INCONSISTENCY_EXCEPTION.

Referenced by AUPImportFileHandle::AddSilence(), EffectSilence::GenerateTrack(), and FFmpegImportFileHandle::Import().

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

◆ IsEmpty()

bool WaveTrack::IsEmpty ( double  t0,
double  t1 
) const

Returns true if there are no WaveClips in the specified region.

Returns
true if no clips in the track overlap the specified time range, false otherwise.

Definition at line 607 of file WaveTrack.cpp.

608{
609 if (t0 > t1)
610 return true;
611
612 //wxPrintf("Searching for overlap in %.6f...%.6f\n", t0, t1);
613 for (const auto &clip : mClips)
614 {
615 if (!clip->BeforePlayStartTime(t1) && !clip->AfterPlayEndTime(t0)) {
616 //wxPrintf("Overlapping clip: %.6f...%.6f\n",
617 // clip->GetStartTime(),
618 // clip->GetEndTime());
619 // We found a clip that overlaps this region
620 return false;
621 }
622 }
623 //wxPrintf("No overlap found\n");
624
625 // Otherwise, no clips overlap this region
626 return true;
627}

References mClips.

Referenced by PasteWaveTrack(), Generator::Process(), and SyncLockAdjust().

Here is the caller graph for this function:

◆ Join()

void WaveTrack::Join ( double  t0,
double  t1 
)
Exception safety guarantee:
Weak

Definition at line 1708 of file WaveTrack.cpp.

1709{
1710 // Merge all WaveClips overlapping selection into one
1711
1712 WaveClipPointers clipsToDelete;
1713 WaveClip* newClip{};
1714
1715 for (const auto &clip: mClips)
1716 {
1717 if (clip->GetPlayStartTime() < t1-(1.0/mRate) &&
1718 clip->GetPlayEndTime()-(1.0/mRate) > t0) {
1719
1720 // Put in sorted order
1721 auto it = clipsToDelete.begin(), end = clipsToDelete.end();
1722 for (; it != end; ++it)
1723 if ((*it)->GetPlayStartTime() > clip->GetPlayStartTime())
1724 break;
1725 //wxPrintf("Insert clip %.6f at position %d\n", clip->GetStartTime(), i);
1726 clipsToDelete.insert(it, clip.get());
1727 }
1728 }
1729
1730 //if there are no clips to DELETE, nothing to do
1731 if( clipsToDelete.size() == 0 )
1732 return;
1733
1734 auto t = clipsToDelete[0]->GetPlayStartTime();
1735 //preserve left trim data if any
1736 newClip = CreateClip(clipsToDelete[0]->GetSequenceStartTime(),
1737 clipsToDelete[0]->GetName());
1738
1739 for (const auto &clip : clipsToDelete)
1740 {
1741 //wxPrintf("t=%.6f adding clip (offset %.6f, %.6f ... %.6f)\n",
1742 // t, clip->GetOffset(), clip->GetStartTime(), clip->GetEndTime());
1743
1744 if (clip->GetPlayStartTime() - t > (1.0 / mRate)) {
1745 double addedSilence = (clip->GetPlayStartTime() - t);
1746 //wxPrintf("Adding %.6f seconds of silence\n");
1747 auto offset = clip->GetPlayStartTime();
1748 auto value = clip->GetEnvelope()->GetValue( offset );
1749 newClip->AppendSilence( addedSilence, value );
1750 t += addedSilence;
1751 }
1752
1753 //wxPrintf("Pasting at %.6f\n", t);
1754 newClip->Paste(t, clip);
1755
1756 t = newClip->GetPlayEndTime();
1757
1758 auto it = FindClip(mClips, clip);
1759 mClips.erase(it); // deletes the clip
1760 }
1761}
wxString GetName() const
Definition: Track.h:458

References CreateClip(), PackedArray::end(), anonymous_namespace{WaveTrack.cpp}::FindClip(), Track::GetName(), mClips, and mRate.

Referenced by LabelEditActions::Handler::OnJoinLabels(), and EffectEqualization::ProcessOne().

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

◆ LinkConsistencyFix()

bool WaveTrack::LinkConsistencyFix ( bool  doFix,
bool  completeList 
)
overridevirtual

Check consistency of channel groups, and maybe fix it.

Parameters
doFixwhether to make any changes to correct inconsistencies
completeListwhether to assume that the TrackList containing this is completely loaded; if false, skip some of the checks
Returns
true if no inconsistencies were found

Reimplemented from Track.

Definition at line 282 of file WaveTrack.cpp.

283{
284 auto err = !WritableSampleTrack::LinkConsistencyFix(doFix, completeList);
285 if (completeList) {
286 auto linkType = GetLinkType();
287 if (static_cast<int>(linkType) == 1 || //Comes from old audacity version
288 linkType == LinkType::Aligned) {
289 auto next =
290 dynamic_cast<WaveTrack*>(*std::next(GetOwner()->Find(this)));
291 if (next == nullptr) {
292 //next track is absent or not a wave track, fix and report error
293 if (doFix) {
294 wxLogWarning(L"Right track %s is expected to be a WaveTrack."
295 "\n Removing link from left wave track %s.",
296 next->GetName(), GetName());
299 }
300 err = true;
301 }
302 else if (doFix) {
303 auto newLinkType =
304 AreAligned(SortedClipArray(), next->SortedClipArray())
306 //not an error
307 if (newLinkType != linkType)
308 SetLinkType(newLinkType);
309 }
310 }
311 }
312 return !err;
313}
Subclass * Find(const RegisteredFactory &key)
Get a (bare) pointer to an attachment, or null, down-cast it to Subclass *; will not create on demand...
Definition: ClientData.h:333
void SetChannel(ChannelType c) noexcept
Definition: Track.cpp:242
virtual bool LinkConsistencyFix(bool doFix=true, bool completeList=true)
Check consistency of channel groups, and maybe fix it.
Definition: Track.cpp:405
std::shared_ptr< TrackList > GetOwner() const
Definition: Track.h:402
LinkType GetLinkType() const noexcept
Definition: Track.cpp:1324
bool AreAligned(const WaveClipPointers &a, const WaveClipPointers &b)
Definition: WaveTrack.cpp:68

References Track::Aligned, anonymous_namespace{WaveTrack.cpp}::AreAligned(), ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >::Find(), Track::GetLinkType(), Track::GetName(), Track::GetOwner(), Track::Group, Track::LinkConsistencyFix(), Track::MonoChannel, Track::None, Track::SetChannel(), Track::SetLinkType(), and SortedClipArray().

Here is the call graph for this function:

◆ MakeClipCopyName()

wxString WaveTrack::MakeClipCopyName ( const wxString &  originalName) const
private

Definition at line 457 of file WaveTrack.cpp.

458{
459 auto name = originalName;
460 for (auto i = 1;; ++i)
461 {
462 if (FindClipByName(name) == nullptr)
463 return name;
464 //i18n-hint Template for clip name generation on copy-paste
465 name = XC("%s.%i", "clip name template").Format(originalName, i).Translation();
466 }
467}
#define XC(s, c)
Definition: Internat.h:37
const WaveClip * FindClipByName(const wxString &name) const
Returns nullptr if clip with such name was not found.
Definition: WaveTrack.cpp:442

References FindClipByName(), name, and XC.

Referenced by PasteWaveTrack().

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

◆ MakeNewClipName()

wxString WaveTrack::MakeNewClipName ( ) const
private

Definition at line 469 of file WaveTrack.cpp.

470{
471 auto name = GetName();
472 for (auto i = 1;; ++i)
473 {
474 if (FindClipByName(name) == nullptr)
475 return name;
476 //i18n-hint Template for clip name generation on inserting new empty clip
477 name = XC("%s %i", "clip name template").Format(GetName(), i).Translation();
478 }
479}

References FindClipByName(), Track::GetName(), name, and XC.

Referenced by NewestOrNewClip(), PasteWaveTrack(), and RightmostOrNewClip().

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

◆ Merge()

void WaveTrack::Merge ( const Track orig)
overridevirtual

Reimplemented from Track.

Definition at line 221 of file WaveTrack.cpp.

222{
223 orig.TypeSwitch( [&](const WaveTrack *pwt) {
224 const WaveTrack &wt = *pwt;
225 DoSetGain(wt.GetGain());
226 DoSetPan(wt.GetPan());
230 ? std::make_unique<SpectrogramSettings>(*wt.mpSpectrumSettings) : nullptr);
232 (wt.mpWaveformSettings ? std::make_unique<WaveformSettings>(*wt.mpWaveformSettings) : nullptr);
233 });
235}
void Merge(const Track &init) override
Definition: Track.cpp:310
R TypeSwitch(const Functions &...functions)
Use this function rather than testing track type explicitly and making down-casts.
Definition: Track.h:824
void SetWaveformSettings(std::unique_ptr< WaveformSettings > &&pSettings)
Definition: WaveTrack.cpp:861
void SetSpectrogramSettings(std::unique_ptr< SpectrogramSettings > &&pSettings)
Definition: WaveTrack.cpp:823

References DoSetGain(), DoSetPan(), GetGain(), GetPan(), mDisplayMax, mDisplayMin, PlayableTrack::Merge(), mpSpectrumSettings, mpWaveformSettings, SetSpectrogramSettings(), SetWaveformSettings(), and Track::TypeSwitch().

Referenced by WaveTrackMenuTable::OnMergeStereo().

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

◆ MergeClips()

void WaveTrack::MergeClips ( int  clipidx1,
int  clipidx2 
)
Exception safety guarantee:
Strong

Definition at line 2681 of file WaveTrack.cpp.

2682{
2683 WaveClip* clip1 = GetClipByIndex(clipidx1);
2684 WaveClip* clip2 = GetClipByIndex(clipidx2);
2685
2686 if (!clip1 || !clip2) // Could happen if one track of a linked pair had a split and the other didn't.
2687 return; // Don't throw, just do nothing.
2688
2689 // Append data from second clip to first clip
2690 // use Strong-guarantee
2691 clip1->Paste(clip1->GetPlayEndTime(), clip2);
2692
2693 // use No-fail-guarantee for the rest
2694 // Delete second clip
2695 auto it = FindClip(mClips, clip2);
2696 mClips.erase(it);
2697}

References anonymous_namespace{WaveTrack.cpp}::FindClip(), GetClipByIndex(), WaveClip::GetPlayEndTime(), mClips, and WaveClip::Paste().

Referenced by ClearAndPaste().

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

◆ New()

WaveTrack * WaveTrack::New ( AudacityProject project)
static

Definition at line 128 of file WaveTrack.cpp.

129{
130 auto &trackFactory = WaveTrackFactory::Get( project );
131 auto &tracks = TrackList::Get( project );
132 auto result = tracks.Add(trackFactory.Create());
133 result->AttachedTrackObjects::BuildAll();
134 return result;
135}
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:467
static WaveTrackFactory & Get(AudacityProject &project)
Definition: WaveTrack.cpp:2800

References TrackList::Get(), and WaveTrackFactory::Get().

Here is the call graph for this function:

◆ NewestOrNewClip()

WaveClip * WaveTrack::NewestOrNewClip ( )

Get access to the most recently added clip, or create a clip, if there is not already one. THIS IS NOT NECESSARILY RIGHTMOST.

Returns
a pointer to the most recently added WaveClip

Definition at line 2368 of file WaveTrack.cpp.

2369{
2370 if (mClips.empty()) {
2372 }
2373 else
2374 return mClips.back().get();
2375}
double mOffset
Definition: Track.h:440
wxString MakeNewClipName() const
Definition: WaveTrack.cpp:469

References CreateClip(), MakeNewClipName(), mClips, and Track::mOffset.

Referenced by GetIdealBlockSize(), HandleXMLChild(), and HandleXMLEndTag().

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

◆ Paste()

void WaveTrack::Paste ( double  t0,
const Track src 
)
override
Exception safety guarantee:
Weak

Definition at line 1563 of file WaveTrack.cpp.

1564{
1565 if (auto other = dynamic_cast<const WaveTrack*>(src))
1566 PasteWaveTrack(t0, other);
1567 else
1568 // THROW_INCONSISTENCY_EXCEPTION; // ?
1569 (void)0;// Empty if intentional.
1570}
void PasteWaveTrack(double t0, const WaveTrack *other)
Definition: WaveTrack.cpp:1403

References PasteWaveTrack().

Referenced by ClearAndPaste(), PasteWaveTrack(), EffectEqualization::ProcessOne(), EffectStereoToMono::ProcessOne(), EffectPaulstretch::ProcessOne(), and SyncLockAdjust().

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

◆ PasteInto()

Track::Holder WaveTrack::PasteInto ( AudacityProject ) const
overridevirtual

Find or create the destination track for a paste, maybe in a different project.

Returns
A smart pointer to the track; its use_count() can tell whether it is new

Implements Track.

Definition at line 423 of file WaveTrack.cpp.

424{
425 auto &trackFactory = WaveTrackFactory::Get( project );
426 auto &pSampleBlockFactory = trackFactory.GetSampleBlockFactory();
427 auto pNewTrack = EmptyCopy( pSampleBlockFactory );
428 pNewTrack->Paste(0.0, this);
429 return pNewTrack;
430}

References EmptyCopy(), and WaveTrackFactory::Get().

Here is the call graph for this function:

◆ PasteWaveTrack()

void WaveTrack::PasteWaveTrack ( double  t0,
const WaveTrack other 
)
private

Definition at line 1403 of file WaveTrack.cpp.

1404{
1405 //
1406 // Pasting is a bit complicated, because with the existence of multiclip mode,
1407 // we must guess the behaviour the user wants.
1408 //
1409 // Currently, two modes are implemented:
1410 //
1411 // - If a single clip should be pasted, and it should be pasted inside another
1412 // clip, no NEW clips are generated. The audio is simply inserted.
1413 // This resembles the old (pre-multiclip support) behaviour. However, if
1414 // the clip is pasted outside of any clip, a NEW clip is generated. This is
1415 // the only behaviour which is different to what was done before, but it
1416 // shouldn't confuse users too much.
1417 //
1418 // - If multiple clips should be pasted, or a single clip that does not fill
1419 // the duration of the pasted track, these are always pasted as single
1420 // clips, and the current clip is split, when necessary. This may seem
1421 // strange at first, but it probably is better than trying to auto-merge
1422 // anything. The user can still merge the clips by hand (which should be a
1423 // simple command reachable by a hotkey or single mouse click).
1424 //
1425
1426 if (other->GetNumClips() == 0)
1427 return;
1428
1429 //wxPrintf("paste: we have at least one clip\n");
1430
1431 bool singleClipMode = (other->GetNumClips() == 1 &&
1432 other->GetStartTime() == 0.0);
1433
1434 const double insertDuration = other->GetEndTime();
1435 if (insertDuration != 0 && insertDuration < 1.0 / mRate)
1436 // PRL: I added this check to avoid violations of preconditions in other WaveClip and Sequence
1437 // methods, but allow the value 0 so I don't subvert the purpose of commit
1438 // 739422ba70ceb4be0bb1829b6feb0c5401de641e which causes append-recording always to make
1439 // a new clip.
1440 return;
1441
1442 //wxPrintf("Check if we need to make room for the pasted data\n");
1443
1444 auto pastingFromTempTrack = !other->GetOwner();
1445 bool editClipCanMove = GetEditClipsCanMove();
1446
1447 // Make room for the pasted data
1448 if (editClipCanMove) {
1449 if (!singleClipMode) {
1450 // We need to insert multiple clips, so split the current clip and
1451 // move everything to the right, then try to paste again
1452 if (!IsEmpty(t0, GetEndTime())) {
1453 auto tmp = Cut(t0, GetEndTime() + 1.0 / mRate);
1454 Paste(t0 + insertDuration, tmp.get());
1455 }
1456 }
1457 else {
1458 // We only need to insert one single clip, so just move all clips
1459 // to the right of the paste point out of the way
1460 for (const auto& clip : mClips)
1461 {
1462 if (clip->GetPlayStartTime() > t0 - (1.0 / mRate))
1463 clip->Offset(insertDuration);
1464 }
1465 }
1466 }
1467
1468 if (singleClipMode)
1469 {
1470 // Single clip mode
1471 // wxPrintf("paste: checking for single clip mode!\n");
1472
1473 WaveClip* insideClip = nullptr;
1474
1475 for (const auto& clip : mClips)
1476 {
1477 if (editClipCanMove)
1478 {
1479 if (clip->WithinPlayRegion(t0))
1480 {
1481 //wxPrintf("t0=%.6f: inside clip is %.6f ... %.6f\n",
1482 // t0, clip->GetStartTime(), clip->GetEndTime());
1483 insideClip = clip.get();
1484 break;
1485 }
1486 }
1487 else
1488 {
1489 // If clips are immovable we also allow prepending to clips
1490 if (clip->WithinPlayRegion(t0) ||
1491 TimeToLongSamples(t0) == clip->GetPlayStartSample())
1492 {
1493 insideClip = clip.get();
1494 break;
1495 }
1496 }
1497 }
1498
1499 if (insideClip)
1500 {
1501 // Exhibit traditional behaviour
1502 //wxPrintf("paste: traditional behaviour\n");
1503 if (!editClipCanMove)
1504 {
1505 // We did not move other clips out of the way already, so
1506 // check if we can paste without having to move other clips
1507 for (const auto& clip : mClips)
1508 {
1509 if (clip->GetPlayStartTime() > insideClip->GetPlayStartTime() &&
1510 insideClip->GetPlayEndTime() + insertDuration >
1511 clip->GetPlayStartTime())
1512 // Strong-guarantee in case of this path
1513 // not that it matters.
1516 XO("There is not enough room available to paste the selection"),
1517 XO("Warning"),
1518 "Error:_Insufficient_space_in_track"
1519 };
1520 }
1521 }
1522 insideClip->Paste(t0, other->GetClipByIndex(0));
1523 return;
1524 }
1525 // Just fall through and exhibit NEW behaviour
1526 }
1527
1528 // Insert NEW clips
1529 //wxPrintf("paste: multi clip mode!\n");
1530
1531 if (!editClipCanMove && !IsEmpty(t0, t0 + insertDuration - 1.0 / mRate))
1532 // Strong-guarantee in case of this path
1533 // not that it matters.
1536 XO("There is not enough room available to paste the selection"),
1537 XO("Warning"),
1538 "Error:_Insufficient_space_in_track"
1539 };
1540
1541 for (const auto& clip : other->mClips)
1542 {
1543 // AWD Oct. 2009: Don't actually paste in placeholder clips
1544 if (!clip->GetIsPlaceholder())
1545 {
1546 auto newClip =
1547 std::make_unique<WaveClip>(*clip, mpFactory, true);
1548 newClip->Resample(mRate);
1549 newClip->Offset(t0);
1550 newClip->MarkChanged();
1551 if (pastingFromTempTrack)
1552 //Clips from the tracks which aren't bound to any TrackList are
1553 //considered to be new entities, thus named using "new" name template
1554 newClip->SetName(MakeNewClipName());
1555 else
1556 newClip->SetName(MakeClipCopyName(clip->GetName()));
1557 mClips.push_back(std::move(newClip)); // transfer ownership
1558 }
1559 }
1560}
Track::Holder Cut(double t0, double t1) override
Definition: WaveTrack.cpp:629
bool IsEmpty(double t0, double t1) const
Returns true if there are no WaveClips in the specified region.
Definition: WaveTrack.cpp:607
int GetNumClips() const
Definition: WaveTrack.cpp:2419
wxString MakeClipCopyName(const wxString &originalName) const
Definition: WaveTrack.cpp:457

References BadUserAction, Cut(), GetClipByIndex(), GetEditClipsCanMove(), GetEndTime(), GetNumClips(), Track::GetOwner(), WaveClip::GetPlayEndTime(), WaveClip::GetPlayStartTime(), GetStartTime(), IsEmpty(), MakeClipCopyName(), MakeNewClipName(), mClips, mpFactory, mRate, Paste(), WaveClip::Paste(), SampleTrack::TimeToLongSamples(), and XO.

Referenced by Paste().

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

◆ Reinit()

void WaveTrack::Reinit ( const WaveTrack orig)

Definition at line 200 of file WaveTrack.cpp.

201{
202 Init(orig);
203
204 {
205 auto &settings = orig.mpSpectrumSettings;
206 if (settings)
207 mpSpectrumSettings = std::make_unique<SpectrogramSettings>(*settings);
208 else
209 mpSpectrumSettings.reset();
210 }
211
212 {
213 auto &settings = orig.mpWaveformSettings;
214 if (settings)
215 mpWaveformSettings = std::make_unique<WaveformSettings>(*settings);
216 else
217 mpWaveformSettings.reset();
218 }
219}

References Init(), mpSpectrumSettings, mpWaveformSettings, and settings().

Referenced by ProjectAudioManager::DoRecord().

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

◆ RemoveAndReturnClip()

std::shared_ptr< WaveClip > WaveTrack::RemoveAndReturnClip ( WaveClip clip)

Definition at line 1207 of file WaveTrack.cpp.

1208{
1209 // Be clear about who owns the clip!!
1210 auto it = FindClip(mClips, clip);
1211 if (it != mClips.end()) {
1212 auto result = std::move(*it); // Array stops owning the clip, before we shrink it
1213 mClips.erase(it);
1214 return result;
1215 }
1216 else
1217 return {};
1218}

References anonymous_namespace{WaveTrack.cpp}::FindClip(), and mClips.

Referenced by EffectReverse::ProcessOneWave().

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

◆ RemoveCutLine()

bool WaveTrack::RemoveCutLine ( double  cutLinePosition)

Definition at line 2671 of file WaveTrack.cpp.

2672{
2673 for (const auto &clip : mClips)
2674 if (clip->RemoveCutLine(cutLinePosition))
2675 return true;
2676
2677 return false;
2678}

References mClips.

◆ Resample()

void WaveTrack::Resample ( int  rate,
BasicUI::ProgressDialog progress = NULL 
)
Exception safety guarantee:
Weak – Partial completion may leave clips at differing sample rates!

Definition at line 2701 of file WaveTrack.cpp.

2702{
2703 for (const auto &clip : mClips)
2704 clip->Resample(rate, progress);
2705
2706 mRate = rate;
2707}

References mClips, and mRate.

◆ RightmostOrNewClip()

WaveClip * WaveTrack::RightmostOrNewClip ( )

Get access to the last (rightmost) clip, or create a clip, if there is not already one.

Returns
a pointer to a WaveClip at the end of the track
Exception safety guarantee:
No-fail

Definition at line 2378 of file WaveTrack.cpp.

2379{
2380 if (mClips.empty()) {
2382 }
2383 else
2384 {
2385 auto it = mClips.begin();
2386 WaveClip *rightmost = (*it++).get();
2387 double maxOffset = rightmost->GetPlayStartTime();
2388 for (auto end = mClips.end(); it != end; ++it)
2389 {
2390 WaveClip *clip = it->get();
2391 double offset = clip->GetPlayStartTime();
2392 if (maxOffset < offset)
2393 maxOffset = offset, rightmost = clip;
2394 }
2395 return rightmost;
2396 }
2397}

References CreateClip(), PackedArray::end(), WaveClip::GetPlayStartTime(), MakeNewClipName(), mClips, and Track::mOffset.

Referenced by AUPImportFileHandle::AddSamples(), Append(), Flush(), and AUPImportFileHandle::HandleEnvelope().

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

◆ Set()

void WaveTrack::Set ( constSamplePtr  buffer,
sampleFormat  format,
sampleCount  start,
size_t  len 
)
Exception safety guarantee:
Weak

Definition at line 2195 of file WaveTrack.cpp.

2197{
2198 for (const auto &clip: mClips)
2199 {
2200 auto clipStart = clip->GetPlayStartSample();
2201 auto clipEnd = clip->GetPlayEndSample();
2202
2203 if (clipEnd > start && clipStart < start+len)
2204 {
2205 // Clip sample region and Get/Put sample region overlap
2206 auto samplesToCopy =
2207 std::min( start+len - clipStart, clip->GetPlaySamplesCount() );
2208 auto startDelta = clipStart - start;
2209 decltype(startDelta) inclipDelta = 0;
2210 if (startDelta < 0)
2211 {
2212 inclipDelta = -startDelta; // make positive value
2213 samplesToCopy -= inclipDelta;
2214 // samplesToCopy is now either len or
2215 // (clipEnd - clipStart) - (start - clipStart)
2216 // == clipEnd - start > 0
2217 // samplesToCopy is not more than len
2218 //
2219 startDelta = 0;
2220 // startDelta is zero
2221 }
2222 else {
2223 // startDelta is nonnegative and less than len
2224 // samplesToCopy is positive and not more than len
2225 }
2226
2227 clip->SetSamples(
2228 (constSamplePtr)(((const char*)buffer) +
2229 startDelta.as_size_t() *
2231 format, inclipDelta, samplesToCopy.as_size_t() );
2232 clip->MarkChanged();
2233 }
2234 }
2235}
const char * constSamplePtr
Definition: SampleFormat.h:50

References format, mClips, min(), and SAMPLE_SIZE.

Referenced by EffectAutoDuck::ApplyDuckFade(), EffectTruncSilence::DoRemoval(), EffectClickRemoval::ProcessOne(), EffectRepair::ProcessOne(), EffectNormalize::ProcessOne(), EffectSimpleMono::ProcessOne(), EffectTwoPassSimpleMono::ProcessOne(), EffectReverse::ProcessOneClip(), and PerTrackEffect::ProcessTrack().

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

◆ SetDisplayBounds()

void WaveTrack::SetDisplayBounds ( float  min,
float  max 
) const

Definition at line 350 of file WaveTrack.cpp.

351{
353 mDisplayMax = max;
354}

References mDisplayMax, mDisplayMin, and min().

Referenced by WaveformVRulerControls::DoUpdateVRuler().

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

◆ SetGain()

void WaveTrack::SetGain ( float  newGain)

Definition at line 508 of file WaveTrack.cpp.

509{
510 if (GetGain() != newGain) {
511 DoSetGain(newGain);
512 Notify();
513 }
514}
void Notify(int code=-1)
Definition: Track.cpp:278

References DoSetGain(), GetGain(), and Track::Notify().

Referenced by MixerTrackCluster::HandleSliderGain().

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

◆ SetLastdBRange()

void WaveTrack::SetLastdBRange ( ) const

Definition at line 339 of file WaveTrack.cpp.

References WaveformSettings::dBRange, GetWaveformSettings(), and mLastdBRange.

Referenced by WaveformVRulerControls::DoUpdateVRuler().

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

◆ SetLastScaleType()

void WaveTrack::SetLastScaleType ( ) const

Definition at line 334 of file WaveTrack.cpp.

References GetWaveformSettings(), mLastScaleType, and WaveformSettings::scaleType.

Referenced by WaveformVRulerControls::DoUpdateVRuler().

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

◆ SetOffset()

void WaveTrack::SetOffset ( double  o)
overridevirtual
Exception safety guarantee:
No-fail

Reimplemented from Track.

Definition at line 247 of file WaveTrack.cpp.

248{
249 double delta = o - GetOffset();
250
251 for (const auto &clip : mClips)
252 // assume No-fail-guarantee
253 clip->Offset(delta);
254
255 mOffset = o;
256}
double GetOffset() const override
Definition: WaveTrack.cpp:241

References GetOffset(), mClips, and Track::mOffset.

Here is the call graph for this function:

◆ SetOldChannelGain()

void WaveTrack::SetOldChannelGain ( int  channel,
float  gain 
)
overridevirtual

Implements WritableSampleTrack.

Definition at line 562 of file WaveTrack.cpp.

563{
564 mOldGain[channel % 2] = gain;
565}

References mOldGain.

Referenced by AudioIoCallback::AddToOutputChannel().

Here is the caller graph for this function:

◆ SetPan()

void WaveTrack::SetPan ( float  newPan)
overridevirtual

Reimplemented from Track.

Definition at line 526 of file WaveTrack.cpp.

527{
528 if (newPan > 1.0)
529 newPan = 1.0;
530 else if (newPan < -1.0)
531 newPan = -1.0;
532
533 if ( GetPan() != newPan ) {
534 DoSetPan(newPan);
535 Notify();
536 }
537}

References DoSetPan(), GetPan(), and Track::Notify().

Referenced by MixerTrackCluster::HandleSliderPan(), WaveTrackMenuTable::OnMergeStereo(), and SetPanFromChannelType().

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

◆ SetPanFromChannelType()

void WaveTrack::SetPanFromChannelType ( )
overridevirtual

Reimplemented from Track.

Definition at line 274 of file WaveTrack.cpp.

275{
277 SetPan( -1.0f );
278 else if( mChannel == Track::RightChannel )
279 SetPan( 1.0f );
280}
void SetPan(float newPan) override
Definition: WaveTrack.cpp:526

References Track::LeftChannel, Track::mChannel, Track::RightChannel, and SetPan().

Here is the call graph for this function:

◆ SetRate()

void WaveTrack::SetRate ( double  newRate)

Definition at line 486 of file WaveTrack.cpp.

487{
488 wxASSERT( newRate > 0 );
489 newRate = std::max( 1.0, newRate );
490 auto ratio = mRate / newRate;
491 mRate = (int) newRate;
492 for (const auto &clip : mClips) {
493 clip->SetRate((int)newRate);
494 clip->SetSequenceStartTime( clip->GetSequenceStartTime() * ratio );
495 }
496}

References mClips, and mRate.

◆ SetSpectrogramSettings()

void WaveTrack::SetSpectrogramSettings ( std::unique_ptr< SpectrogramSettings > &&  pSettings)

Definition at line 823 of file WaveTrack.cpp.

824{
825 if (mpSpectrumSettings != pSettings) {
826 mpSpectrumSettings = std::move(pSettings);
827 }
828}

References mpSpectrumSettings.

Referenced by Merge().

Here is the caller graph for this function:

◆ SetSpectrumBounds()

void WaveTrack::SetSpectrumBounds ( float  min,
float  max 
) const

Definition at line 400 of file WaveTrack.cpp.

401{
403 mSpectrumMax = max;
404}

References min(), mSpectrumMax, and mSpectrumMin.

Here is the call graph for this function:

◆ SetWaveColorIndex()

void WaveTrack::SetWaveColorIndex ( int  colorIndex)
Exception safety guarantee:
Strong

Definition at line 570 of file WaveTrack.cpp.

571{
572 for (const auto &clip : mClips)
573 clip->SetColourIndex( colorIndex );
574 mWaveColorIndex = colorIndex;
575}

References mClips, and mWaveColorIndex.

Referenced by SetTrackVisualsCommand::ApplyInner().

Here is the caller graph for this function:

◆ SetWaveformSettings()

void WaveTrack::SetWaveformSettings ( std::unique_ptr< WaveformSettings > &&  pSettings)

Definition at line 861 of file WaveTrack.cpp.

862{
863 if (mpWaveformSettings != pSettings) {
864 mpWaveformSettings = std::move(pSettings);
865 }
866}

References mpWaveformSettings.

Referenced by Merge().

Here is the caller graph for this function:

◆ Silence()

void WaveTrack::Silence ( double  t0,
double  t1 
)
override

Definition at line 1572 of file WaveTrack.cpp.

1573{
1574 if (t1 < t0)
1576
1577 auto start = TimeToLongSamples(t0);
1578 auto end = TimeToLongSamples(t1);
1579
1580 for (const auto &clip : mClips)
1581 {
1582 auto clipStart = clip->GetPlayStartSample();
1583 auto clipEnd = clip->GetPlayEndSample();
1584
1585 if (clipEnd > start && clipStart < end)
1586 {
1587 auto offset = std::max(start - clipStart, sampleCount(0));
1588 // Clip sample region and Get/Put sample region overlap
1589 auto length = std::min(end, clipEnd) - (clipStart + offset);
1590
1591 clip->SetSilence(offset, length);
1592 }
1593 }
1594}

References PackedArray::end(), mClips, min(), THROW_INCONSISTENCY_EXCEPTION, and SampleTrack::TimeToLongSamples().

Referenced by LabelEditActions::Handler::OnSilenceLabels(), EditActions::Handler::OnSplitCut(), LabelEditActions::Handler::OnSplitCutLabels(), and LabelEditActions::Handler::OnSplitDeleteLabels().

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

◆ SortedClipArray() [1/2]

WaveClipPointers WaveTrack::SortedClipArray ( )

◆ SortedClipArray() [2/2]

WaveClipConstPointers WaveTrack::SortedClipArray ( ) const

Definition at line 2728 of file WaveTrack.cpp.

2729{
2730 return FillSortedClipArray<WaveClipConstPointers>(mClips);
2731}

References mClips.

◆ Split()

void WaveTrack::Split ( double  t0,
double  t1 
)
Exception safety guarantee:
Weak

Definition at line 2517 of file WaveTrack.cpp.

2518{
2519 SplitAt( t0 );
2520 if( t0 != t1 )
2521 SplitAt( t1 );
2522}
void SplitAt(double t)
Definition: WaveTrack.cpp:2525

References SplitAt().

Referenced by LabelEditActions::Handler::OnSplitLabels().

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

◆ SplitAt()

void WaveTrack::SplitAt ( double  t)
Exception safety guarantee:
Weak

Definition at line 2525 of file WaveTrack.cpp.

2526{
2527 for (const auto &c : mClips)
2528 {
2529 if (c->WithinPlayRegion(t))
2530 {
2532 auto newClip = std::make_unique<WaveClip>( *c, mpFactory, true );
2533 c->TrimRightTo(t);// put t on a sample
2534 newClip->TrimLeftTo(t);
2535
2536 // This could invalidate the iterators for the loop! But we return
2537 // at once so it's okay
2538 mClips.push_back(std::move(newClip)); // transfer ownership
2539 return;
2540 }
2541 }
2542}

References SampleTrack::LongSamplesToTime(), mClips, mpFactory, and SampleTrack::TimeToLongSamples().

Referenced by EffectReverse::ProcessOneWave(), and Split().

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

◆ SplitCut()

Track::Holder WaveTrack::SplitCut ( double  t0,
double  t1 
)
Exception safety guarantee:
Strong

Definition at line 642 of file WaveTrack.cpp.

643{
644 if (t1 < t0)
646
647 // SplitCut is the same as 'Copy', then 'SplitDelete'
648 auto tmp = Copy(t0, t1);
649
650 SplitDelete(t0, t1);
651
652 return tmp;
653}

References Copy(), SplitDelete(), and THROW_INCONSISTENCY_EXCEPTION.

Referenced by EditActions::Handler::OnSplitCut(), LabelEditActions::Handler::OnSplitCutLabels(), and EditActions::Handler::OnSplitNew().

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

◆ SplitDelete()

void WaveTrack::SplitDelete ( double  t0,
double  t1 
)
Exception safety guarantee:
Strong

Definition at line 1165 of file WaveTrack.cpp.

1166{
1167 bool addCutLines = false;
1168 bool split = true;
1169 HandleClear(t0, t1, addCutLines, split);
1170}

References HandleClear().

Referenced by Disjoin(), EffectSBSMS::Finalize(), EditActions::Handler::OnSplitDelete(), LabelEditActions::Handler::OnSplitDeleteLabels(), EffectChangeSpeed::ProcessOne(), SplitCut(), and Trim().

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

◆ SyncLockAdjust()

void WaveTrack::SyncLockAdjust ( double  oldT1,
double  newT1 
)
overridevirtual

Reimplemented from Track.

Definition at line 1366 of file WaveTrack.cpp.

1367{
1368 if (newT1 > oldT1) {
1369 // Insert space within the track
1370
1371 // JKC: This is a rare case where using >= rather than > on a float matters.
1372 // GetEndTime() looks through the clips and may give us EXACTLY the same
1373 // value as T1, when T1 was set to be at the end of one of those clips.
1374 if (oldT1 >= GetEndTime())
1375 return;
1376
1377 // If track is empty at oldT1 insert whitespace; otherwise, silence
1378 if (IsEmpty(oldT1, oldT1))
1379 {
1380 // Check if clips can move
1381 if (EditClipsCanMove.Read()) {
1382 auto tmp = Cut (oldT1, GetEndTime() + 1.0/GetRate());
1383 Paste(newT1, tmp.get());
1384 }
1385 return;
1386 }
1387 else {
1388 // AWD: Could just use InsertSilence() on its own here, but it doesn't
1389 // follow EditClipCanMove rules (Paste() does it right)
1390 auto tmp = std::make_shared<WaveTrack>(
1392
1393 tmp->InsertSilence(0.0, newT1 - oldT1);
1394 tmp->Flush();
1395 Paste(oldT1, tmp.get());
1396 }
1397 }
1398 else if (newT1 < oldT1) {
1399 Clear(newT1, oldT1);
1400 }
1401}
BoolSetting EditClipsCanMove
Definition: WaveTrack.cpp:2860
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:185

References Clear(), Cut(), EditClipsCanMove, GetEndTime(), GetRate(), GetSampleFormat(), IsEmpty(), mpFactory, Paste(), and Setting< T >::Read().

Here is the call graph for this function:

◆ Trim()

void WaveTrack::Trim ( double  t0,
double  t1 
)
Exception safety guarantee:
Weak

Definition at line 675 of file WaveTrack.cpp.

676{
677 bool inside0 = false;
678 bool inside1 = false;
679
680 for (const auto &clip : mClips)
681 {
682 if(t1 > clip->GetPlayStartTime() && t1 < clip->GetPlayEndTime())
683 {
684 clip->SetTrimRight(clip->GetTrimRight() + clip->GetPlayEndTime() - t1);
685 inside1 = true;
686 }
687
688 if(t0 > clip->GetPlayStartTime() && t0 < clip->GetPlayEndTime())
689 {
690 clip->SetTrimLeft(clip->GetTrimLeft() + t0 - clip->GetPlayStartTime());
691 inside0 = true;
692 }
693 }
694
695 //if inside0 is false, then the left selector was between
696 //clips, so DELETE everything to its left.
697 if(!inside1 && t1 < GetEndTime())
698 Clear(t1,GetEndTime());
699
700 if(!inside0 && t0 > GetStartTime())
702}

References Clear(), GetEndTime(), GetStartTime(), mClips, and SplitDelete().

Referenced by EditActions::Handler::OnTrim().

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

◆ UpdateLocationsCache()

void WaveTrack::UpdateLocationsCache ( ) const

Definition at line 2544 of file WaveTrack.cpp.

2545{
2546 auto clips = SortedClipArray();
2547
2548 mDisplayLocationsCache.clear();
2549
2550 // Count number of display locations
2551 int num = 0;
2552 {
2553 const WaveClip *prev = nullptr;
2554 for (const auto clip : clips)
2555 {
2556 //enough for estimation
2557 num += clip->NumCutLines();
2558
2559 if (prev && fabs(prev->GetPlayEndTime() -
2560 clip->GetPlayStartTime()) < WAVETRACK_MERGE_POINT_TOLERANCE)
2561 ++num;
2562 prev = clip;
2563 }
2564 }
2565
2566 if (num == 0)
2567 return;
2568
2569 // Alloc necessary number of display locations
2570 mDisplayLocationsCache.reserve(num);
2571
2572 // Add all display locations to cache
2573 int curpos = 0;
2574
2575 const WaveClip *previousClip = nullptr;
2576 for (const auto clip: clips)
2577 {
2578 for (const auto &cc : clip->GetCutLines())
2579 {
2580 auto cutlinePosition = clip->GetSequenceStartTime() + cc->GetSequenceStartTime();
2581 if (clip->WithinPlayRegion(cutlinePosition))
2582 {
2583 // Add cut line expander point
2585 cutlinePosition,
2587 });
2588 }
2589 // If cutline is skipped, we still need to count it
2590 // so that curpos match num at the end
2591 curpos++;
2592 }
2593
2594 if (previousClip)
2595 {
2596 if (fabs(previousClip->GetPlayEndTime() - clip->GetPlayStartTime())
2598 {
2599 // Add merge point
2601 previousClip->GetPlayEndTime(),
2603 GetClipIndex(previousClip),
2604 GetClipIndex(clip)
2605 });
2606 curpos++;
2607 }
2608 }
2609
2610 previousClip = clip;
2611 }
2612
2613 wxASSERT(curpos == num);
2614}
size_t NumCutLines() const
Definition: WaveClip.h:279

References GetClipIndex(), WaveClip::GetPlayEndTime(), WaveClip::GetSequenceStartTime(), WaveTrackLocation::locationCutLine, WaveTrackLocation::locationMergePoint, mDisplayLocationsCache, WaveClip::NumCutLines(), SortedClipArray(), and WAVETRACK_MERGE_POINT_TOLERANCE.

Here is the call graph for this function:

◆ UseSpectralPrefs()

void WaveTrack::UseSpectralPrefs ( bool  bUse = true)

Definition at line 830 of file WaveTrack.cpp.

831{
832 if( bUse ){
833 if( !mpSpectrumSettings )
834 return;
835 // reset it, and next we will be getting the defaults.
836 mpSpectrumSettings.reset();
837 }
838 else {
840 return;
842 }
843}
SpectrogramSettings & GetIndependentSpectrogramSettings()
Definition: WaveTrack.cpp:815

References GetIndependentSpectrogramSettings(), and mpSpectrumSettings.

Here is the call graph for this function:

◆ WriteXML()

void WaveTrack::WriteXML ( XMLWriter xmlFile) const
overridevirtual

Implements Track.

Definition at line 1954 of file WaveTrack.cpp.

1956{
1957 xmlFile.StartTag(wxT("wavetrack"));
1958 this->Track::WriteCommonXMLAttributes( xmlFile );
1959 xmlFile.WriteAttr(wxT("channel"), mChannel);
1960 xmlFile.WriteAttr(wxT("linked"), static_cast<int>(GetLinkType()));
1962 xmlFile.WriteAttr(wxT("rate"), mRate);
1963 xmlFile.WriteAttr(wxT("gain"), static_cast<double>(GetGain()));
1964 xmlFile.WriteAttr(wxT("pan"), static_cast<double>(GetPan()));
1965 xmlFile.WriteAttr(wxT("colorindex"), mWaveColorIndex );
1966 xmlFile.WriteAttr(wxT("sampleformat"), static_cast<long>(mFormat) );
1967
1968 WaveTrackIORegistry::Get().CallWriters(*this, xmlFile);
1969
1970 for (const auto &clip : mClips)
1971 {
1972 clip->WriteXML(xmlFile);
1973 }
1974
1975 xmlFile.EndTag(wxT("wavetrack"));
1976}
void WriteXMLAttributes(XMLWriter &xmlFile) const
Definition: Track.cpp:356
void WriteCommonXMLAttributes(XMLWriter &xmlFile, bool includeNameAndSelected=true) const
Definition: Track.cpp:1251
void CallWriters(const Host &host, XMLWriter &writer)
virtual void StartTag(const wxString &name)
Definition: XMLWriter.cpp:80
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:37
virtual void EndTag(const wxString &name)
Definition: XMLWriter.cpp:103

References XMLMethodRegistry< Host >::CallWriters(), XMLMethodRegistry< Host >::Get(), Track::WriteCommonXMLAttributes(), and PlayableTrack::WriteXMLAttributes().

Here is the call graph for this function:

◆ ZeroLevelYCoordinate()

int WaveTrack::ZeroLevelYCoordinate ( wxRect  rect) const

Definition at line 406 of file WaveTrack.cpp.

407{
408 return rect.GetTop() +
409 (int)((mDisplayMax / (mDisplayMax - mDisplayMin)) * rect.height);
410}

References mDisplayMax, and mDisplayMin.

Referenced by WaveformVRulerControls::DoHandleWheelRotation(), and anonymous_namespace{WaveformView.cpp}::DrawClipWaveform().

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ WaveTrackFactory

friend class WaveTrackFactory
friend

Definition at line 98 of file WaveTrack.h.

Member Data Documentation

◆ mAppendCriticalSection

wxCriticalSection WaveTrack::mAppendCriticalSection
private

Definition at line 574 of file WaveTrack.h.

◆ mClips

WaveClipHolders WaveTrack::mClips
protected

◆ mDisplayLocationsCache

std::vector<Location> WaveTrack::mDisplayLocationsCache
mutableprotected

Definition at line 563 of file WaveTrack.h.

Referenced by Init(), and UpdateLocationsCache().

◆ mDisplayMax

float WaveTrack::mDisplayMax
mutableprotected

◆ mDisplayMin

float WaveTrack::mDisplayMin
mutableprotected

◆ mFlushCriticalSection

wxCriticalSection WaveTrack::mFlushCriticalSection
private

Definition at line 573 of file WaveTrack.h.

◆ mFormat

sampleFormat WaveTrack::mFormat
protected

◆ mGain

std::atomic<float> WaveTrack::mGain { 1.0f }
protected

Atomic because it may be read by worker threads in playback.

Definition at line 544 of file WaveTrack.h.

Referenced by DoSetGain(), and GetGain().

◆ mLastdBRange

int WaveTrack::mLastdBRange
mutableprotected

Definition at line 562 of file WaveTrack.h.

Referenced by SetLastdBRange(), and WaveTrack().

◆ mLastScaleType

int WaveTrack::mLastScaleType
mutableprotected

Definition at line 561 of file WaveTrack.h.

Referenced by SetLastScaleType(), and WaveTrack().

◆ mLegacyProjectFileOffset

double WaveTrack::mLegacyProjectFileOffset
private

Definition at line 575 of file WaveTrack.h.

Referenced by HandleXMLChild(), HandleXMLTag(), and WaveTrack().

◆ mOldGain

float WaveTrack::mOldGain[2]
protected

A memo used by PortAudio thread, doesn't need atomics:

Definition at line 549 of file WaveTrack.h.

Referenced by GetOldChannelGain(), Init(), SetOldChannelGain(), and WaveTrack().

◆ mPan

std::atomic<float> WaveTrack::mPan { 0.0f }
protected

Atomic because it may be read by worker threads in playback.

Definition at line 546 of file WaveTrack.h.

Referenced by DoSetPan(), and GetPan().

◆ mpFactory

SampleBlockFactoryPtr WaveTrack::mpFactory
private

◆ mpSpectrumSettings

std::unique_ptr<SpectrogramSettings> WaveTrack::mpSpectrumSettings
private

◆ mpWaveformSettings

std::unique_ptr<WaveformSettings> WaveTrack::mpWaveformSettings
private

Definition at line 578 of file WaveTrack.h.

Referenced by GetWaveformSettings(), Merge(), Reinit(), and SetWaveformSettings().

◆ mRate

int WaveTrack::mRate
protected

◆ mSpectrumMax

float WaveTrack::mSpectrumMax
mutableprotected

Definition at line 559 of file WaveTrack.h.

Referenced by GetSpectrumBounds(), Init(), SetSpectrumBounds(), and WaveTrack().

◆ mSpectrumMin

float WaveTrack::mSpectrumMin
mutableprotected

Definition at line 558 of file WaveTrack.h.

Referenced by GetSpectrumBounds(), Init(), SetSpectrumBounds(), and WaveTrack().

◆ mWaveColorIndex

int WaveTrack::mWaveColorIndex
protected

Definition at line 547 of file WaveTrack.h.

Referenced by HandleXMLTag(), Init(), SetWaveColorIndex(), and WaveTrack().


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