Audacity  3.2.0
Public Member Functions | Static Public Member Functions | List of all members
SampleTrack Class Referenceabstract

#include <SampleTrack.h>

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

Public Member Functions

 ~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 Track &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 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 LinkConsistencyCheck ()
 
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...
 
 Track ()
 
 Track (const Track &orig)
 
virtual ~ Track ()
 
void Init (const Track &orig)
 
virtual Holder Duplicate () const
 
wxString GetName () const
 
void SetName (const wxString &n)
 
wxString GetDefaultName () const
 
void SetDefaultName (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
 
bool ReadXMLTag (const char *tag, const char **attrs)
 
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 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...
 

Additional Inherited Members

- Public Types inherited from Track
enum  LinkType : int { LinkType::None = 0, LinkType::Group = 2, LinkType::Aligned }
 For two tracks describes the type of the linkage. More...
 
enum  ChannelType { LeftChannel = 0, RightChannel = 1, MonoChannel = 2 }
 
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 Attributes inherited from Track
std::pair< int, int > vrulerSize
 
- Protected Member Functions inherited from Track
void SetLinkType (LinkType linkType)
 
void DoSetLinkType (LinkType linkType) noexcept
 
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...
 
- Protected Attributes inherited from PlayableTrack
bool mMute { false }
 
bool mSolo { false }
 
- 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
 
wxString mDefaultName
 
ChannelType mChannel
 
double mOffset
 

Detailed Description

Definition at line 19 of file SampleTrack.h.

Constructor & Destructor Documentation

◆ ~SampleTrack()

SampleTrack::~SampleTrack ( )
overridedefault

Member Function Documentation

◆ ClassTypeInfo()

auto SampleTrack::ClassTypeInfo ( )
static

Definition at line 25 of file SampleTrack.cpp.

26 {
27  return typeInfo();
28 }

References typeInfo().

Referenced by typeInfo2().

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

◆ Get()

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

Retrieve samples from a track in a specified format.

Parameters
bufferreceives the samples
startstarting sample, relative to absolute time zero (not to the track's offset value)
lenhow many samples to get. buffer is assumed sufficiently large
fillhow to assign values for sample positions between clips
mayThrowif false, fill buffer with zeros when there is failure to retrieve samples; else throw
[out]pNumWithinClipsReport how many samples were copied from within clips, rather than filled according to fillFormat; but these were not necessarily one contiguous range.
formatsample format of the destination buffer

Implemented in WaveTrack.

◆ GetBestBlockSize()

virtual size_t SampleTrack::GetBestBlockSize ( sampleCount  t) const
pure virtual

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

Implemented in WaveTrack.

◆ GetBlockStart()

virtual sampleCount SampleTrack::GetBlockStart ( sampleCount  t) const
pure virtual

This returns a possibly large or negative value.

Implemented in WaveTrack.

◆ GetChannelGain()

virtual float SampleTrack::GetChannelGain ( int  channel) const
pure virtual

Takes gain and pan into account.

Implemented in WaveTrack.

◆ GetChannelIgnoringPan()

virtual ChannelType SampleTrack::GetChannelIgnoringPan ( ) const
pure virtual

Implemented in WaveTrack.

◆ GetEnvelopeValues()

virtual void SampleTrack::GetEnvelopeValues ( double *  buffer,
size_t  bufferLen,
double  t0 
) const
pure virtual

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

Implemented in WaveTrack.

◆ GetFloats()

bool SampleTrack::GetFloats ( float *  buffer,
sampleCount  start,
size_t  len,
fillFormat  fill = fillZero,
bool  mayThrow = true,
sampleCount pNumWithinClips = nullptr 
) const
inline

Retrieve samples from a track in floating-point format, regardless of the storage format.

Parameters
bufferreceives the samples
startstarting sample, relative to absolute time zero (not to the track's offset value)
lenhow many samples to get. buffer is assumed sufficiently large
fillhow to assign values for sample positions between clips
mayThrowif false, fill buffer with zeros when there is failure to retrieve samples; else throw
[out]pNumWithinClipsReport how many samples were copied from within clips, rather than filled according to fillFormat; but these were not necessarily one contiguous range.

Cast the pointer to pass it to Get() which handles multiple destination formats

Definition at line 64 of file SampleTrack.h.

67  {
69  return Get(reinterpret_cast<samplePtr>(buffer),
70  floatSample, start, len, fill, mayThrow, pNumWithinClips);
71  }

References floatSample, and ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >::Get().

Referenced by EffectNormalize::AnalyseTrackData(), EffectTruncSilence::Analyze(), CompareAudioCommand::Apply(), EffectAutoDuck::ApplyDuckFade(), EffectTruncSilence::DoRemoval(), NyquistEffect::GetCallback(), VoiceKey::OffBackward(), VoiceKey::OffForward(), VoiceKey::OnBackward(), VoiceKey::OnForward(), EffectAutoDuck::Process(), VampEffect::Process(), TrackSpectrumTransformer::Process(), EffectEqualization::ProcessOne(), EffectClickRemoval::ProcessOne(), EffectRepair::ProcessOne(), EffectFindClipping::ProcessOne(), EffectNormalize::ProcessOne(), EffectChangeSpeed::ProcessOne(), EffectSimpleMono::ProcessOne(), EffectTwoPassSimpleMono::ProcessOne(), EffectPaulstretch::ProcessOne(), EffectReverse::ProcessOneClip(), Effect::ProcessTrack(), resampleCB(), SelectHandle::StartSnappingFreqSelection(), VoiceKey::TestDirectionChanges(), VoiceKey::TestEnergy(), VoiceKey::TestSignChanges(), and MixerTrackCluster::UpdateMeter().

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

◆ GetMaxBlockSize()

virtual size_t SampleTrack::GetMaxBlockSize ( ) const
pure virtual

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

Implemented in WaveTrack.

Referenced by SampleTrackCache::SetTrack().

Here is the caller graph for this function:

◆ GetOldChannelGain()

virtual float SampleTrack::GetOldChannelGain ( int  channel) const
pure virtual

Implemented in WaveTrack.

◆ GetRate()

virtual double SampleTrack::GetRate ( ) const
pure virtual

Implemented in WaveTrack.

Referenced by LongSamplesToTime(), and TimeToLongSamples().

Here is the caller graph for this function:

◆ GetSampleFormat()

virtual sampleFormat SampleTrack::GetSampleFormat ( ) const
pure virtual

Implemented in WaveTrack.

◆ GetTypeInfo()

auto SampleTrack::GetTypeInfo ( ) const
overridevirtual

Implements Track.

Reimplemented in WritableSampleTrack.

Definition at line 30 of file SampleTrack.cpp.

31 {
32  return typeInfo();
33 }

References typeInfo().

Here is the call graph for this function:

◆ LongSamplesToTime()

double SampleTrack::LongSamplesToTime ( sampleCount  pos) const

Convert correctly between a number of samples and an (absolute) time in seconds.

Parameters
posThe time number of samples from the start of the track to convert.
Returns
The time in seconds.

Definition at line 40 of file SampleTrack.cpp.

41 {
42  return pos.as_double() / GetRate();
43 }

References sampleCount::as_double(), and GetRate().

Referenced by AUPImportFileHandle::AddSilence(), anonymous_namespace{SampleHandle.cpp}::adjustTime(), EffectTruncSilence::Analyze(), CompareAudioCommand::Apply(), EffectAutoDuck::ApplyDuckFade(), WaveTrack::ClearAndPaste(), EffectTruncSilence::DoRemoval(), anonymous_namespace{WaveformView.cpp}::DrawClipWaveform(), EffectSBSMS::Finalize(), EditActions::Handler::OnSplitNew(), EffectAutoDuck::Process(), EffectRepeat::Process(), EffectEqualization::ProcessOne(), EffectFindClipping::ProcessOne(), EffectChangeSpeed::ProcessOne(), EffectReverse::ProcessOneWave(), and WaveTrack::SplitAt().

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

◆ TimeToLongSamples()

sampleCount SampleTrack::TimeToLongSamples ( double  t0) const

Convert correctly between an (absolute) time in seconds and a number of samples.

This method will not give the correct results if used on a relative time (difference of two times). Each absolute time must be converted and the numbers of samples differenced: sampleCount start = track->TimeToLongSamples(t0); sampleCount end = track->TimeToLongSamples(t1); sampleCount len = (sampleCount)(end - start); NOT the likes of: sampleCount len = track->TimeToLongSamples(t1 - t0); See also SampleTrack::TimeToLongSamples().

Parameters
t0The time (floating point seconds) to convert
Returns
The number of samples from the start of the track which lie before the given time.

Definition at line 35 of file SampleTrack.cpp.

36 {
37  return sampleCount( floor(t0 * GetRate() + 0.5) );
38 }

References GetRate().

Referenced by anonymous_namespace{SampleHandle.cpp}::adjustTime(), EffectNormalize::AnalyseTrackData(), EffectTruncSilence::Analyze(), CompareAudioCommand::Apply(), EffectAutoDuck::ApplyDuckFade(), WaveTrack::ClearAndPaste(), ClipParameters::ClipParameters(), WaveTrack::Disjoin(), EffectTruncSilence::DoRemoval(), BrushHandle::Drag(), anonymous_namespace{WaveformView.cpp}::DrawClipWaveform(), EffectSBSMS::Finalize(), BlockGenerator::GenerateTrack(), Effect::GetBounds(), EditActions::Handler::OnSplitNew(), WaveTrack::PasteWaveTrack(), anonymous_namespace{BrushHandle.cpp}::PositionToLongSample(), EffectAutoDuck::Process(), EffectChangeSpeed::Process(), NyquistEffect::Process(), EffectRepeat::Process(), EffectReverse::Process(), EffectSBSMS::Process(), NyquistEffect::ProcessOne(), EffectLoudness::ProcessOne(), EffectNormalize::ProcessOne(), EffectChangeSpeed::ProcessOne(), EffectPaulstretch::ProcessOne(), EffectReverse::ProcessOneWave(), Effect::ProcessPass(), WaveTrack::Silence(), WaveTrack::SplitAt(), and SelectHandle::StartSnappingFreqSelection().

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

The documentation for this class was generated from the following files:
floatSample
@ floatSample
Definition: SampleFormat.h:34
sampleCount::as_double
double as_double() const
Definition: SampleCount.h:45
SampleTrack::GetRate
virtual double GetRate() const =0
samplePtr
char * samplePtr
Definition: SampleFormat.h:49
SampleTrack::Get
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.
typeInfo
static const Track::TypeInfo & typeInfo()
Definition: SampleTrack.cpp:17
sampleCount
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:18