Audacity  3.0.3
LabelTrack.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  LabelTrack.h
6 
7  Dominic Mazzoni
8  James Crook
9  Jun Wan
10 
11 **********************************************************************/
12 
13 #ifndef _LABELTRACK_
14 #define _LABELTRACK_
15 
16 #include "SelectedRegion.h"
17 #include "Track.h"
18 
19 
20 class wxTextFile;
21 
22 class AudacityProject;
24 class TimeWarper;
25 
26 struct LabelTrackHit;
28 
29 class AUDACITY_DLL_API LabelStruct
30 {
31 public:
32  LabelStruct() = default;
33  // Copies region
34  LabelStruct(const SelectedRegion& region, const wxString &aTitle);
35  // Copies region but then overwrites other times
36  LabelStruct(const SelectedRegion& region, double t0, double t1,
37  const wxString &aTitle);
38  const SelectedRegion &getSelectedRegion() const { return selectedRegion; }
39  double getDuration() const { return selectedRegion.duration(); }
40  double getT0() const { return selectedRegion.t0(); }
41  double getT1() const { return selectedRegion.t1(); }
42  // Returns true iff the label got inverted:
43  bool AdjustEdge( int iEdge, double fNewTime);
44  void MoveLabel( int iEdge, double fNewTime);
45 
46  struct BadFormatException {};
47  static LabelStruct Import(wxTextFile &file, int &index);
48 
49  void Export(wxTextFile &file) const;
50 
53  {
59  ENDS_IN_LABEL
60  };
61 
66  TimeRelations RegionRelation(double reg_t0, double reg_t1,
67  const LabelTrack *parent = NULL) const;
68 
69 public:
71  wxString title;
72  mutable int width{};
73 
74 // Working storage for on-screen layout.
75  mutable int x{};
76  mutable int x1{};
77  mutable int xText{};
78  mutable int y{};
79 
80  bool updated{};
81 };
82 
83 using LabelArray = std::vector<LabelStruct>;
84 
85 class AUDACITY_DLL_API LabelTrack final
86  : public Track
87  , public wxEvtHandler
88 {
89  public:
90  LabelTrack();
91  LabelTrack(const LabelTrack &orig);
92 
93  virtual ~ LabelTrack();
94 
95  void SetLabel( size_t iLabel, const LabelStruct &newLabel );
96 
97  void SetOffset(double dOffset) override;
98 
99  void SetSelected(bool s) override;
100 
101  double GetOffset() const override;
102  double GetStartTime() const override;
103  double GetEndTime() const override;
104 
105  using Holder = std::shared_ptr<LabelTrack>;
106 
107 private:
108  Track::Holder Clone() const override;
109 
110 public:
111  bool HandleXMLTag(const wxChar *tag, const wxChar **attrs) override;
112  XMLTagHandler *HandleXMLChild(const wxChar *tag) override;
113  void WriteXML(XMLWriter &xmlFile) const override;
114 
115  Track::Holder Cut (double t0, double t1) override;
116  Track::Holder Copy (double t0, double t1, bool forClipboard = true) const override;
117  void Clear(double t0, double t1) override;
118  void Paste(double t, const Track * src) override;
119  bool Repeat(double t0, double t1, int n);
120  void SyncLockAdjust(double oldT1, double newT1) override;
121 
122  void Silence(double t0, double t1) override;
123  void InsertSilence(double t, double len) override;
124 
125  void Import(wxTextFile & f);
126  void Export(wxTextFile & f) const;
127 
128  int GetNumLabels() const;
129  const LabelStruct *GetLabel(int index) const;
130  const LabelArray &GetLabels() const { return mLabels; }
131 
132  void OnLabelAdded( const wxString &title, int pos );
133  //This returns the index of the label we just added.
134  int AddLabel(const SelectedRegion &region, const wxString &title);
135 
136  //This deletes the label at given index.
137  void DeleteLabel(int index);
138 
139  // This pastes labels without shifting existing ones
140  bool PasteOver(double t, const Track *src);
141 
142  // PRL: These functions were not used because they were not overrides! Was that right?
143  //Track::Holder SplitCut(double b, double e) /* not override */;
144  //bool SplitDelete(double b, double e) /* not override */;
145 
146  void ShiftLabelsOnInsert(double length, double pt);
147  void ChangeLabelsOnReverse(double b, double e);
148  void ScaleLabels(double b, double e, double change);
149  double AdjustTimeStampOnScale(double t, double b, double e, double change);
150  void WarpLabels(const TimeWarper &warper);
151 
152  // Returns tab-separated text of all labels completely within given region
153  wxString GetTextOfLabels(double t0, double t1) const;
154 
155  int FindNextLabel(const SelectedRegion& currentSelection);
156  int FindPrevLabel(const SelectedRegion& currentSelection);
157 
158  Track::Holder PasteInto( AudacityProject & ) const override;
159 
161  size_t index;
162  explicit IntervalData(size_t index) : index{index} {};
163  };
164  ConstInterval MakeInterval ( size_t index ) const;
165  Interval MakeInterval ( size_t index );
166  ConstIntervals GetIntervals() const override;
167  Intervals GetIntervals() override;
168 
169  public:
170  void SortLabels();
171 
172  private:
173  TrackKind GetKind() const override { return TrackKind::Label; }
174 
176 
177  // Set in copied label tracks
178  double mClipLen;
179 
180  int miLastLabel; // used by FindNextLabel and FindPrevLabel
181 };
182 
184 {
185  explicit
187  wxEventType commandType, const std::shared_ptr<LabelTrack> &pTrack,
188  const wxString &title,
189  int formerPosition,
190  int presentPosition
191  )
192  : TrackListEvent{ commandType, pTrack }
193  , mTitle{ title }
194  , mFormerPosition{ formerPosition }
195  , mPresentPosition{ presentPosition }
196  {}
197 
198  LabelTrackEvent( const LabelTrackEvent& ) = default;
199  wxEvent *Clone() const override {
200  // wxWidgets will own the event object
201  return safenew LabelTrackEvent(*this); }
202 
203  // invalid for selection events
204  wxString mTitle;
205 
206  // invalid for addition and selection events
207  int mFormerPosition{ -1 };
208 
209  // invalid for deletion and selection events
210  int mPresentPosition{ -1 };
211 };
212 
213 // Posted when a label is added.
214 wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API,
215  EVT_LABELTRACK_ADDITION, LabelTrackEvent);
216 
217 // Posted when a label is deleted.
218 wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API,
219  EVT_LABELTRACK_DELETION, LabelTrackEvent);
220 
221 // Posted when a label is repositioned in the sequence of labels.
222 wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API,
223  EVT_LABELTRACK_PERMUTED, LabelTrackEvent);
224 
225 // Posted when the track is selected or unselected.
226 wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API,
227  EVT_LABELTRACK_SELECTION, LabelTrackEvent);
228 #endif
XMLWriter
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:23
LabelStruct::getDuration
double getDuration() const
Definition: LabelTrack.h:39
TimeWarper
Transforms one point in time to another point. For example, a time stretching effect might use one to...
Definition: TimeWarper.h:62
LabelStruct::title
wxString title
Definition: LabelTrack.h:71
Track::GetEndTime
virtual double GetEndTime() const =0
Track::GetIntervals
virtual ConstIntervals GetIntervals() const
Report times on the track where important intervals begin and end, for UI to snap to.
Definition: Track.cpp:1244
TrackPanelDrawingContext
Definition: TrackPanelDrawingContext.h:22
TrackIntervalData
Optional extra information about an interval, appropriate to a subtype of Track.
Definition: Track.h:186
Track::Cut
virtual Holder Cut(double WXUNUSED(t0), double WXUNUSED(t1))=0
SelectedRegion.h
LabelTrackEvent::mFormerPosition
int mFormerPosition
Definition: LabelTrack.h:207
Track::InsertSilence
virtual void InsertSilence(double WXUNUSED(t), double WXUNUSED(len))=0
LabelTrack
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:88
Track::Paste
virtual void Paste(double WXUNUSED(t), const Track *WXUNUSED(src))=0
Track::SetOffset
virtual void SetOffset(double o)
Definition: Track.h:445
LabelTrack::mClipLen
double mClipLen
Definition: LabelTrack.h:178
wxDECLARE_EXPORTED_EVENT
wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API, EVT_LABELTRACK_ADDITION, LabelTrackEvent)
LabelTrackEvent::mPresentPosition
int mPresentPosition
Definition: LabelTrack.h:210
LabelStruct
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:30
Export
Main class to control the export function.
LabelStruct::WITHIN_LABEL
@ WITHIN_LABEL
Definition: LabelTrack.h:57
Track::GetStartTime
virtual double GetStartTime() const =0
Track::SetSelected
virtual void SetSelected(bool s)
Definition: Track.cpp:90
TrackListEvent
Notification of changes in individual tracks of TrackList, or of TrackList's composition.
Definition: Track.h:1222
LabelTrack::GetKind
TrackKind GetKind() const override
Definition: LabelTrack.h:173
Track::Holder
std::shared_ptr< Track > Holder
Definition: Track.h:336
LabelStruct::selectedRegion
SelectedRegion selectedRegion
Definition: LabelTrack.h:70
LabelTrack::miLastLabel
int miLastLabel
Definition: LabelTrack.h:180
LabelStruct::getT0
double getT0() const
Definition: LabelTrack.h:40
Track::Silence
virtual void Silence(double WXUNUSED(t0), double WXUNUSED(t1))=0
Track::GetOffset
virtual double GetOffset() const =0
LabelStruct::BEFORE_LABEL
@ BEFORE_LABEL
Definition: LabelTrack.h:54
Track::Clone
virtual Holder Clone() const =0
LabelStruct::BadFormatException
Definition: LabelTrack.h:46
LabelTrack::GetLabels
const LabelArray & GetLabels() const
Definition: LabelTrack.h:130
LabelTrackEvent::mTitle
wxString mTitle
Definition: LabelTrack.h:204
LabelStruct::BEGINS_IN_LABEL
@ BEGINS_IN_LABEL
Definition: LabelTrack.h:58
LabelArray
std::vector< LabelStruct > LabelArray
Definition: LabelTrack.h:83
LabelTrackEvent
Definition: LabelTrack.h:184
LabelStruct::getSelectedRegion
const SelectedRegion & getSelectedRegion() const
Definition: LabelTrack.h:38
LabelTrack::IntervalData::IntervalData
IntervalData(size_t index)
Definition: LabelTrack.h:162
XMLTagHandler
This class is an interface which should be implemented by classes which wish to be able to load and s...
Definition: XMLTagHandler.h:62
LabelTrack::IntervalData
Definition: LabelTrack.h:160
TrackKind
TrackKind
Enumerates all subclasses of Track (not just the leaf classes) and the None value.
Definition: Track.h:69
Track::WriteXML
virtual void WriteXML(XMLWriter &xmlFile) const =0
LabelTrackEvent::Clone
wxEvent * Clone() const override
Definition: LabelTrack.h:199
title
static const auto title
Definition: NoUpdatesAvailableDialog.cpp:22
Track
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:239
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
LabelTrack::~ LabelTrack
virtual ~ LabelTrack()
LabelTrack::OnLabelAdded
void OnLabelAdded(const wxString &title, int pos)
LabelStruct::TimeRelations
TimeRelations
Relationships between selection region and labels.
Definition: LabelTrack.h:53
LabelTrackEvent::LabelTrackEvent
LabelTrackEvent(wxEventType commandType, const std::shared_ptr< LabelTrack > &pTrack, const wxString &title, int formerPosition, int presentPosition)
Definition: LabelTrack.h:186
XMLTagHandler::HandleXMLTag
virtual bool HandleXMLTag(const wxChar *tag, const wxChar **attrs)=0
XMLTagHandler::HandleXMLChild
virtual XMLTagHandler * HandleXMLChild(const wxChar *tag)=0
Track::Clear
virtual void Clear(double WXUNUSED(t0), double WXUNUSED(t1))=0
Track.h
declares abstract base class Track, TrackList, and iterators over TrackList
TrackKind::Label
@ Label
LabelStruct::AFTER_LABEL
@ AFTER_LABEL
Definition: LabelTrack.h:55
safenew
#define safenew
Definition: MemoryX.h:10
LabelTrackHit
Definition: LabelGlyphHandle.h:33
Track::Copy
virtual Holder Copy(double WXUNUSED(t0), double WXUNUSED(t1), bool forClipboard=true) const =0
LabelTrack::IntervalData::index
size_t index
Definition: LabelTrack.h:161
Track::PasteInto
virtual Holder PasteInto(AudacityProject &) const =0
Find or create the destination track for a paste, maybe in a different project.
LabelTrack::mLabels
LabelArray mLabels
Definition: LabelTrack.h:175
LabelStruct::SURROUNDS_LABEL
@ SURROUNDS_LABEL
Definition: LabelTrack.h:56
LabelStruct::LabelStruct
LabelStruct()=default
LabelTrackEvent::LabelTrackEvent
LabelTrackEvent(const LabelTrackEvent &)=default
LabelStruct::getT1
double getT1() const
Definition: LabelTrack.h:41
Track::SyncLockAdjust
virtual void SyncLockAdjust(double oldT1, double newT1)
Definition: Track.cpp:293
LabelTrack::Holder
std::shared_ptr< LabelTrack > Holder
Definition: LabelTrack.h:105
NotifyingSelectedRegion
Definition: ViewInfo.h:44
SelectedRegion
Defines a selected portion of a project.
Definition: SelectedRegion.h:35