Audacity  3.0.3
Classes | Namespaces | Typedefs | Enumerations | Functions
Track.h File Reference

declares abstract base class Track, TrackList, and iterators over TrackList More...

#include <vector>
#include <list>
#include <functional>
#include <wx/event.h>
#include <wx/longlong.h>
#include "ClientData.h"
#include "SampleFormat.h"
#include "XMLTagHandler.h"
Include dependency graph for Track.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  TrackTyper::Lookup<... >
 Variadic template implements metafunction with specializations, to associate enum values with types. More...
 
struct  TrackTyper::Lookup< TrackType, std::tuple< Pair< TrackType, Here >, Rest... > >
 Base case of metafunction. More...
 
struct  TrackTyper::Lookup< TrackType, std::tuple< NotHere, Rest... > >
 Recursive case of metafunction. More...
 
class  TrackId
 An in-session identifier of track objects across undo states. It does not persist between sessions. More...
 
struct  TrackIntervalData
 Optional extra information about an interval, appropriate to a subtype of Track. More...
 
class  ConstTrackInterval
 A start and an end time, and non-mutative access to optional extra information. More...
 
class  TrackInterval
 A start and an end time, and mutative access to optional extra information. More...
 
class  Track
 Abstract base class for an object holding data associated with points on a time axis. More...
 
struct  Track::Executor< Params >
 Variadic template implements metafunction with specializations, to dispatch Track::TypeSwitch. More...
 
struct  Track::Dispatcher
 Helper for recursive case of metafunction implementing Track::TypeSwitch. More...
 
struct  Track::Dispatcher::inapplicable< R, ConcreteType, Function, Functions >
 First, recursive case of metafunction, defers generation of operator () More...
 
struct  Track::Dispatcher::applicable1< R, BaseClass, ConcreteType, Function, Functions >
 Second, nonrecursive case of metafunction, generates operator () that calls function without fallthrough. More...
 
struct  Track::Dispatcher::applicable2< R, BaseClass, ConcreteType, Function, Functions >
 Third, recursive case of metafunction, generates operator () that calls function with fallthrough. More...
 
struct  Track::Dispatcher::Switch<... >
 Variadic template implements metafunction with specializations, to choose among implementations of operator () More...
 
struct  Track::Dispatcher::Switch< R, ConcreteType >
 Base case, no more base classes of ConcreteType. More...
 
struct  Track::Dispatcher::Switch< R, ConcreteType, BaseClass, BaseClasses... >
 Recursive case, tries to match function with one base class of ConcreteType. More...
 
struct  Track::Executor< R, ConcreteType >
 Base case of metafunction implementing Track::TypeSwitch generates operator () with nonvoid return. More...
 
struct  Track::Executor< void, ConcreteType >
 Base case of metafunction implementing Track::TypeSwitch generates operator () with void return. More...
 
struct  Track::Executor< R, ConcreteType, Function, Functions... >
 Implements Track::TypeSwitch, its operator() invokes the first function that can accept ConcreteType*. More...
 
struct  Track::Executor< R, const ConcreteType, Function, Functions... >
 Implements const overload of Track::TypeSwitch, its operator() invokes the first function that can accept ConcreteType*. More...
 
class  AudioTrack
 Track subclass holding data representing sound (as notes, or samples, or ...) More...
 
class  PlayableTrack
 AudioTrack subclass that can also be audibly replayed by the program. More...
 
class  TrackIter< TrackType >
 Iterator over only members of a TrackList of the specified subtype, optionally filtered by a predicate; past-end value dereferenceable, to nullptr. More...
 
struct  TrackIterRange< TrackType >
 Range between two TrackIters, usable in range-for statements, and with Visit member functions. More...
 
struct  TrackListEvent
 Notification of changes in individual tracks of TrackList, or of TrackList's composition. More...
 
class  TrackList
 A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list of tracks, event notifications. More...
 

Namespaces

 TrackTyper
 Metaprogramming enabling track_cast even when the subclasses are incomplete types.
 

Typedefs

using TrackArray = std::vector< Track * >
 
using WaveTrackArray = std::vector< std::shared_ptr< WaveTrack > >
 
using WaveTrackConstArray = std::vector< std::shared_ptr< const WaveTrack > >
 
using NoteTrackConstArray = std::vector< std::shared_ptr< const NoteTrack > >
 
using ListOfTracks = std::list< std::shared_ptr< Track > >
 
using TrackNodePointer = std::pair< ListOfTracks::iterator, ListOfTracks * >
 Pairs a std::list iterator and a pointer to a list, for comparison purposes. More...
 
using TrackTyper::List = std::tuple< Pair< Track, TrackKind::All >, Pair< AudioTrack, TrackKind::Audio >, Pair< PlayableTrack, TrackKind::Playable >, Pair< LabelTrack, TrackKind::Label >, Pair< NoteTrack, TrackKind::Note >, Pair< TimeTrack, TrackKind::Time >, Pair< WaveTrack, TrackKind::Wave > >
 Compile-time map from types to enum values. More...
 
using AttachedTrackObjects = ClientData::Site< Track, ClientData::Base, ClientData::SkipCopying, std::shared_ptr >
 Template generated base class for Track lets it host opaque UI related objects. More...
 

Enumerations

enum  TrackKind {
  TrackKind::None, TrackKind::Wave, TrackKind::Note, TrackKind::Label,
  TrackKind::Time, TrackKind::Audio, TrackKind::Playable, TrackKind::All
}
 Enumerates all subclasses of Track (not just the leaf classes) and the None value. More...
 

Functions

bool operator== (const TrackNodePointer &a, const TrackNodePointer &b)
 
bool operator!= (const TrackNodePointer &a, const TrackNodePointer &b)
 
constexpr bool CompatibleTrackKinds (TrackKind desired, TrackKind actual)
 Compile-time function on enum values. More...
 
template<typename TrackType >
constexpr TrackKind track_kind ()
 Metafunction from track subtype (as template parameter) to enum value. More...
 
template<typename T >
std::enable_if< std::is_pointer< T >::value, T >::type track_cast (Track *track)
 Encapsulate the checked down-casting of track pointers. More...
 
template<typename T >
std::enable_if< std::is_pointer< T >::value &&std::is_const< typename std::remove_pointer< T >::type >::value, T >::type track_cast (const Track *track)
 Encapsulate the checked down-casting of track pointers. More...
 
 wxDECLARE_EXPORTED_EVENT (AUDACITY_DLL_API, EVT_TRACKLIST_SELECTION_CHANGE, TrackListEvent)
 Posted when the set of selected tracks changes. More...
 
 wxDECLARE_EXPORTED_EVENT (AUDACITY_DLL_API, EVT_TRACKLIST_TRACK_DATA_CHANGE, TrackListEvent)
 Posted when certain fields of a track change. More...
 
 wxDECLARE_EXPORTED_EVENT (AUDACITY_DLL_API, EVT_TRACKLIST_TRACK_REQUEST_VISIBLE, TrackListEvent)
 Posted when a track needs to be scrolled into view. More...
 
 wxDECLARE_EXPORTED_EVENT (AUDACITY_DLL_API, EVT_TRACKLIST_PERMUTED, TrackListEvent)
 Posted when tracks are reordered but otherwise unchanged. More...
 
 wxDECLARE_EXPORTED_EVENT (AUDACITY_DLL_API, EVT_TRACKLIST_RESIZING, TrackListEvent)
 Posted when some track changed its height. More...
 
 wxDECLARE_EXPORTED_EVENT (AUDACITY_DLL_API, EVT_TRACKLIST_ADDITION, TrackListEvent)
 Posted when a track has been added to a tracklist. Also posted when one track replaces another. More...
 
 wxDECLARE_EXPORTED_EVENT (AUDACITY_DLL_API, EVT_TRACKLIST_DELETION, TrackListEvent)
 Posted when a track has been deleted from a tracklist. Also posted when one track replaces another. More...
 

Detailed Description

declares abstract base class Track, TrackList, and iterators over TrackList


Audacity: A Digital Audio Editor

Dominic Mazzoni

Definition in file Track.h.

Typedef Documentation

◆ AttachedTrackObjects

Template generated base class for Track lets it host opaque UI related objects.

Definition at line 230 of file Track.h.

◆ ListOfTracks

using ListOfTracks = std::list< std::shared_ptr< Track > >

Definition at line 53 of file Track.h.

◆ NoteTrackConstArray

using NoteTrackConstArray = std::vector < std::shared_ptr< const NoteTrack > >

Definition at line 49 of file Track.h.

◆ TrackArray

using TrackArray = std::vector< Track* >

Definition at line 45 of file Track.h.

◆ TrackNodePointer

using TrackNodePointer = std::pair< ListOfTracks::iterator, ListOfTracks* >

Pairs a std::list iterator and a pointer to a list, for comparison purposes.

Compare owning lists first, and only if same, then the iterators; else MSVC debug runtime complains.

Definition at line 58 of file Track.h.

◆ WaveTrackArray

using WaveTrackArray = std::vector < std::shared_ptr< WaveTrack > >

Definition at line 46 of file Track.h.

◆ WaveTrackConstArray

using WaveTrackConstArray = std::vector < std::shared_ptr < const WaveTrack > >

Definition at line 47 of file Track.h.

Enumeration Type Documentation

◆ TrackKind

enum TrackKind
strong

Enumerates all subclasses of Track (not just the leaf classes) and the None value.

Enumerator
None 

no class

Wave 
Note 
Label 
Time 
Audio 

nonleaf

Playable 

nonleaf

All 

the root class

Definition at line 68 of file Track.h.

69 {
70  None,
71  Wave,
72  Note,
73  Label,
74  Time,
75  Audio,
76  Playable,
77  All
78 };

Function Documentation

◆ CompatibleTrackKinds()

constexpr bool CompatibleTrackKinds ( TrackKind  desired,
TrackKind  actual 
)
constexpr

Compile-time function on enum values.

It knows all inheritance relations among Track subclasses even where the track types are only forward declared.

Definition at line 83 of file Track.h.

84 {
85  return
86  (desired == actual)
87  ||
88  (desired == TrackKind::All)
89  ||
90  (desired == TrackKind::Audio && actual == TrackKind::Wave)
91 #ifdef USE_MIDI
92  ||
93  (desired == TrackKind::Audio && actual == TrackKind::Note)
94 #endif
95  ||
96  (desired == TrackKind::Playable && actual == TrackKind::Wave)
97 #ifdef EXPERIMENTAL_MIDI_OUT
98  ||
99  (desired == TrackKind::Playable && actual == TrackKind::Note)
100 #endif
101  ;
102 }

References All, Audio, Note, Playable, and Wave.

Referenced by track_cast().

Here is the caller graph for this function:

◆ operator!=()

bool operator!= ( const TrackNodePointer a,
const TrackNodePointer b 
)
inline

Definition at line 64 of file Track.h.

65 { return !(a == b); }

◆ operator==()

bool operator== ( const TrackNodePointer a,
const TrackNodePointer b 
)
inline

Definition at line 61 of file Track.h.

62 { return a.second == b.second && a.first == b.first; }

◆ track_cast() [1/2]

template<typename T >
std::enable_if< std::is_pointer< T >::value &&std::is_const< typename std::remove_pointer< T >::type >::value, T >::type track_cast ( const Track track)
inline

Encapsulate the checked down-casting of track pointers.

Eliminates possibility of error – and not quietly casting away const

Typical usage:

if (auto wt = track_cast<const WaveTrack*>(track)) { ... }

This overload for const pointers can cast only to other const pointer types.

Definition at line 909 of file Track.h.

910 {
911  using BareType = typename std::remove_pointer< T >::type;
912  if (track &&
913  CompatibleTrackKinds( track_kind<BareType>(), track->GetKind() ))
914  return reinterpret_cast<T>(track);
915  else
916  return nullptr;
917 }

References CompatibleTrackKinds(), and Track::GetKind().

Here is the call graph for this function:

◆ track_cast() [2/2]

template<typename T >
std::enable_if< std::is_pointer< T >::value, T >::type track_cast ( Track track)
inline

Encapsulate the checked down-casting of track pointers.

Eliminates possibility of error – and not quietly casting away const

Typical usage:

if (auto wt = track_cast<const WaveTrack*>(track)) { ... }

Definition at line 891 of file Track.h.

892 {
893  using BareType = typename std::remove_pointer< T >::type;
894  if (track &&
895  CompatibleTrackKinds( track_kind<BareType>(), track->GetKind() ))
896  return reinterpret_cast<T>(track);
897  else
898  return nullptr;
899 }

References CompatibleTrackKinds(), and Track::GetKind().

Here is the call graph for this function:

◆ track_kind()

template<typename TrackType >
constexpr TrackKind track_kind ( )
constexpr

Metafunction from track subtype (as template parameter) to enum value.

Definition at line 137 of file Track.h.

138 {
139  using namespace TrackTyper;
141 }

◆ wxDECLARE_EXPORTED_EVENT() [1/7]

wxDECLARE_EXPORTED_EVENT ( AUDACITY_DLL_API  ,
EVT_TRACKLIST_ADDITION  ,
TrackListEvent   
)

Posted when a track has been added to a tracklist. Also posted when one track replaces another.

◆ wxDECLARE_EXPORTED_EVENT() [2/7]

wxDECLARE_EXPORTED_EVENT ( AUDACITY_DLL_API  ,
EVT_TRACKLIST_DELETION  ,
TrackListEvent   
)

Posted when a track has been deleted from a tracklist. Also posted when one track replaces another.

mpTrack points to the first track after the deletion, if there is one.

◆ wxDECLARE_EXPORTED_EVENT() [3/7]

wxDECLARE_EXPORTED_EVENT ( AUDACITY_DLL_API  ,
EVT_TRACKLIST_PERMUTED  ,
TrackListEvent   
)

Posted when tracks are reordered but otherwise unchanged.

mpTrack points to the moved track that is earliest in the New ordering.

◆ wxDECLARE_EXPORTED_EVENT() [4/7]

wxDECLARE_EXPORTED_EVENT ( AUDACITY_DLL_API  ,
EVT_TRACKLIST_RESIZING  ,
TrackListEvent   
)

Posted when some track changed its height.

◆ wxDECLARE_EXPORTED_EVENT() [5/7]

wxDECLARE_EXPORTED_EVENT ( AUDACITY_DLL_API  ,
EVT_TRACKLIST_SELECTION_CHANGE  ,
TrackListEvent   
)

Posted when the set of selected tracks changes.

◆ wxDECLARE_EXPORTED_EVENT() [6/7]

wxDECLARE_EXPORTED_EVENT ( AUDACITY_DLL_API  ,
EVT_TRACKLIST_TRACK_DATA_CHANGE  ,
TrackListEvent   
)

Posted when certain fields of a track change.

◆ wxDECLARE_EXPORTED_EVENT() [7/7]

wxDECLARE_EXPORTED_EVENT ( AUDACITY_DLL_API  ,
EVT_TRACKLIST_TRACK_REQUEST_VISIBLE  ,
TrackListEvent   
)

Posted when a track needs to be scrolled into view.

TrackTyper
Metaprogramming enabling track_cast even when the subclasses are incomplete types.
Definition: Track.h:105
TrackKind::None
@ None
no class
TrackKind::Playable
@ Playable
nonleaf
TrackKind::All
@ All
the root class
TrackKind::Time
@ Time
TrackKind::Audio
@ Audio
nonleaf
TrackTyper::Lookup
Variadic template implements metafunction with specializations, to associate enum values with types.
Definition: Track.h:119
Track::GetKind
virtual TrackKind GetKind() const
Definition: Track.h:483
CompatibleTrackKinds
constexpr bool CompatibleTrackKinds(TrackKind desired, TrackKind actual)
Compile-time function on enum values.
Definition: Track.h:83
TrackTyper::List
std::tuple< Pair< Track, TrackKind::All >, Pair< AudioTrack, TrackKind::Audio >, Pair< PlayableTrack, TrackKind::Playable >, Pair< LabelTrack, TrackKind::Label >, Pair< NoteTrack, TrackKind::Note >, Pair< TimeTrack, TrackKind::Time >, Pair< WaveTrack, TrackKind::Wave > > List
Compile-time map from types to enum values.
Definition: Track.h:117
TrackKind::Wave
@ Wave
TrackKind::Label
@ Label
TrackKind::Note
@ Note