2010-01-23 19:44:49 +00:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
Audacity: A Digital Audio Editor
|
|
|
|
|
|
|
|
LabelTrack.h
|
|
|
|
|
|
|
|
Dominic Mazzoni
|
|
|
|
James Crook
|
|
|
|
Jun Wan
|
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
#ifndef _LABELTRACK_
|
|
|
|
#define _LABELTRACK_
|
|
|
|
|
2014-10-05 17:10:09 +00:00
|
|
|
#include "SelectedRegion.h"
|
2010-01-23 19:44:49 +00:00
|
|
|
#include "Track.h"
|
|
|
|
|
|
|
|
|
|
|
|
class wxTextFile;
|
|
|
|
|
|
|
|
class AudacityProject;
|
2018-02-16 23:07:59 +00:00
|
|
|
class NotifyingSelectedRegion;
|
2010-01-23 19:44:49 +00:00
|
|
|
class TimeWarper;
|
|
|
|
|
2017-06-18 01:37:41 +00:00
|
|
|
struct LabelTrackHit;
|
2017-06-23 23:28:38 +00:00
|
|
|
struct TrackPanelDrawingContext;
|
2017-06-18 01:37:41 +00:00
|
|
|
|
2020-09-28 12:50:18 +00:00
|
|
|
class AUDACITY_DLL_API LabelStruct
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-11-08 21:53:45 +00:00
|
|
|
LabelStruct() = default;
|
2014-10-05 17:10:09 +00:00
|
|
|
// Copies region
|
|
|
|
LabelStruct(const SelectedRegion& region, const wxString &aTitle);
|
|
|
|
// Copies region but then overwrites other times
|
|
|
|
LabelStruct(const SelectedRegion& region, double t0, double t1,
|
|
|
|
const wxString &aTitle);
|
2015-04-10 03:37:39 +00:00
|
|
|
const SelectedRegion &getSelectedRegion() const { return selectedRegion; }
|
2014-10-05 17:10:09 +00:00
|
|
|
double getDuration() const { return selectedRegion.duration(); }
|
|
|
|
double getT0() const { return selectedRegion.t0(); }
|
|
|
|
double getT1() const { return selectedRegion.t1(); }
|
|
|
|
// Returns true iff the label got inverted:
|
|
|
|
bool AdjustEdge( int iEdge, double fNewTime);
|
2010-02-07 11:11:35 +00:00
|
|
|
void MoveLabel( int iEdge, double fNewTime);
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2016-07-10 23:09:48 +00:00
|
|
|
struct BadFormatException {};
|
2016-07-13 02:16:15 +00:00
|
|
|
static LabelStruct Import(wxTextFile &file, int &index);
|
2016-07-10 23:09:48 +00:00
|
|
|
|
|
|
|
void Export(wxTextFile &file) const;
|
|
|
|
|
2010-09-18 17:41:15 +00:00
|
|
|
/// Relationships between selection region and labels
|
|
|
|
enum TimeRelations
|
|
|
|
{
|
|
|
|
BEFORE_LABEL,
|
|
|
|
AFTER_LABEL,
|
|
|
|
SURROUNDS_LABEL,
|
|
|
|
WITHIN_LABEL,
|
|
|
|
BEGINS_IN_LABEL,
|
|
|
|
ENDS_IN_LABEL
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Returns relationship between a region described and this label; if
|
|
|
|
/// parent is set, it will consider point labels at the very beginning
|
|
|
|
/// and end of parent to be within a region that borders them (this makes
|
2016-02-14 23:50:45 +00:00
|
|
|
/// it possible to DELETE capture all labels with a Select All).
|
2010-09-18 17:41:15 +00:00
|
|
|
TimeRelations RegionRelation(double reg_t0, double reg_t1,
|
2016-06-23 19:03:30 +00:00
|
|
|
const LabelTrack *parent = NULL) const;
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
public:
|
2014-10-05 17:10:09 +00:00
|
|
|
SelectedRegion selectedRegion;
|
2010-01-23 19:44:49 +00:00
|
|
|
wxString title; /// Text of the label.
|
2018-11-08 21:53:45 +00:00
|
|
|
mutable int width{}; /// width of the text in pixels.
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
// Working storage for on-screen layout.
|
2018-11-08 21:53:45 +00:00
|
|
|
mutable int x{}; /// Pixel position of left hand glyph
|
|
|
|
mutable int x1{}; /// Pixel position of right hand glyph
|
|
|
|
mutable int xText{}; /// Pixel position of left hand side of text box
|
|
|
|
mutable int y{}; /// Pixel position of label.
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2018-11-08 21:53:45 +00:00
|
|
|
bool updated{}; /// flag to tell if the label times were updated
|
2010-01-23 19:44:49 +00:00
|
|
|
};
|
|
|
|
|
2016-06-30 19:56:57 +00:00
|
|
|
using LabelArray = std::vector<LabelStruct>;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2018-12-05 19:10:05 +00:00
|
|
|
class AUDACITY_DLL_API LabelTrack final
|
|
|
|
: public Track
|
|
|
|
, public wxEvtHandler
|
2013-08-22 20:52:56 +00:00
|
|
|
{
|
2010-01-23 19:44:49 +00:00
|
|
|
public:
|
2020-07-02 16:42:25 +00:00
|
|
|
LabelTrack();
|
2010-01-23 19:44:49 +00:00
|
|
|
LabelTrack(const LabelTrack &orig);
|
|
|
|
|
|
|
|
virtual ~ LabelTrack();
|
2015-07-07 03:12:16 +00:00
|
|
|
|
2018-11-08 21:53:45 +00:00
|
|
|
void SetLabel( size_t iLabel, const LabelStruct &newLabel );
|
|
|
|
|
2016-02-24 06:06:47 +00:00
|
|
|
void SetOffset(double dOffset) override;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2019-07-31 19:31:09 +00:00
|
|
|
void SetSelected(bool s) override;
|
|
|
|
|
2016-02-24 06:06:47 +00:00
|
|
|
double GetOffset() const override;
|
|
|
|
double GetStartTime() const override;
|
|
|
|
double GetEndTime() const override;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2018-11-19 04:07:05 +00:00
|
|
|
using Holder = std::shared_ptr<LabelTrack>;
|
2018-11-19 01:15:26 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Track::Holder Clone() const override;
|
2015-08-23 23:02:06 +00:00
|
|
|
|
2018-11-19 01:15:26 +00:00
|
|
|
public:
|
2016-02-24 06:06:47 +00:00
|
|
|
bool HandleXMLTag(const wxChar *tag, const wxChar **attrs) override;
|
|
|
|
XMLTagHandler *HandleXMLChild(const wxChar *tag) override;
|
2017-02-22 19:23:35 +00:00
|
|
|
void WriteXML(XMLWriter &xmlFile) const override;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2016-03-02 20:36:44 +00:00
|
|
|
Track::Holder Cut (double t0, double t1) override;
|
2016-11-26 13:48:08 +00:00
|
|
|
Track::Holder Copy (double t0, double t1, bool forClipboard = true) const override;
|
2017-03-23 15:10:14 +00:00
|
|
|
void Clear(double t0, double t1) override;
|
|
|
|
void Paste(double t, const Track * src) override;
|
2010-01-23 19:44:49 +00:00
|
|
|
bool Repeat(double t0, double t1, int n);
|
2020-05-31 11:58:59 +00:00
|
|
|
void SyncLockAdjust(double oldT1, double newT1) override;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2017-03-23 15:10:14 +00:00
|
|
|
void Silence(double t0, double t1) override;
|
|
|
|
void InsertSilence(double t, double len) override;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
void Import(wxTextFile & f);
|
2016-06-23 19:03:30 +00:00
|
|
|
void Export(wxTextFile & f) const;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
int GetNumLabels() const;
|
|
|
|
const LabelStruct *GetLabel(int index) const;
|
2019-06-09 00:35:21 +00:00
|
|
|
const LabelArray &GetLabels() const { return mLabels; }
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2018-12-05 21:16:31 +00:00
|
|
|
void OnLabelAdded( const wxString &title, int pos );
|
2010-01-23 19:44:49 +00:00
|
|
|
//This returns the index of the label we just added.
|
2018-12-05 21:16:31 +00:00
|
|
|
int AddLabel(const SelectedRegion ®ion, const wxString &title);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
//This deletes the label at given index.
|
|
|
|
void DeleteLabel(int index);
|
|
|
|
|
2010-02-16 20:50:38 +00:00
|
|
|
// This pastes labels without shifting existing ones
|
2016-02-27 17:54:57 +00:00
|
|
|
bool PasteOver(double t, const Track *src);
|
2016-02-23 19:27:43 +00:00
|
|
|
|
|
|
|
// PRL: These functions were not used because they were not overrides! Was that right?
|
2016-03-02 20:36:44 +00:00
|
|
|
//Track::Holder SplitCut(double b, double e) /* not override */;
|
2016-02-23 19:27:43 +00:00
|
|
|
//bool SplitDelete(double b, double e) /* not override */;
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
void ShiftLabelsOnInsert(double length, double pt);
|
|
|
|
void ChangeLabelsOnReverse(double b, double e);
|
|
|
|
void ScaleLabels(double b, double e, double change);
|
|
|
|
double AdjustTimeStampOnScale(double t, double b, double e, double change);
|
|
|
|
void WarpLabels(const TimeWarper &warper);
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
// Returns tab-separated text of all labels completely within given region
|
2016-06-23 19:03:30 +00:00
|
|
|
wxString GetTextOfLabels(double t0, double t1) const;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2016-10-18 14:50:42 +00:00
|
|
|
int FindNextLabel(const SelectedRegion& currentSelection);
|
|
|
|
int FindPrevLabel(const SelectedRegion& currentSelection);
|
|
|
|
|
2021-01-29 05:25:33 +00:00
|
|
|
Track::Holder PasteInto( AudacityProject & ) const override;
|
|
|
|
|
2020-09-09 11:35:58 +00:00
|
|
|
struct IntervalData final : Track::IntervalData {
|
|
|
|
size_t index;
|
|
|
|
explicit IntervalData(size_t index) : index{index} {};
|
|
|
|
};
|
2020-09-20 18:02:49 +00:00
|
|
|
ConstInterval MakeInterval ( size_t index ) const;
|
|
|
|
Interval MakeInterval ( size_t index );
|
2020-09-09 11:35:58 +00:00
|
|
|
ConstIntervals GetIntervals() const override;
|
|
|
|
Intervals GetIntervals() override;
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
public:
|
2018-12-05 19:10:05 +00:00
|
|
|
void SortLabels();
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
private:
|
2017-01-06 18:55:57 +00:00
|
|
|
TrackKind GetKind() const override { return TrackKind::Label; }
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
LabelArray mLabels;
|
|
|
|
|
2010-02-16 20:50:38 +00:00
|
|
|
// Set in copied label tracks
|
2010-01-23 19:44:49 +00:00
|
|
|
double mClipLen;
|
|
|
|
|
2016-10-18 14:50:42 +00:00
|
|
|
int miLastLabel; // used by FindNextLabel and FindPrevLabel
|
2010-01-23 19:44:49 +00:00
|
|
|
};
|
|
|
|
|
2018-12-05 19:10:05 +00:00
|
|
|
struct LabelTrackEvent : TrackListEvent
|
|
|
|
{
|
|
|
|
explicit
|
|
|
|
LabelTrackEvent(
|
|
|
|
wxEventType commandType, const std::shared_ptr<LabelTrack> &pTrack,
|
|
|
|
const wxString &title,
|
|
|
|
int formerPosition,
|
|
|
|
int presentPosition
|
|
|
|
)
|
|
|
|
: TrackListEvent{ commandType, pTrack }
|
|
|
|
, mTitle{ title }
|
|
|
|
, mFormerPosition{ formerPosition }
|
|
|
|
, mPresentPosition{ presentPosition }
|
|
|
|
{}
|
|
|
|
|
|
|
|
LabelTrackEvent( const LabelTrackEvent& ) = default;
|
|
|
|
wxEvent *Clone() const override {
|
|
|
|
// wxWidgets will own the event object
|
|
|
|
return safenew LabelTrackEvent(*this); }
|
|
|
|
|
2019-07-31 19:31:09 +00:00
|
|
|
// invalid for selection events
|
2018-12-05 19:10:05 +00:00
|
|
|
wxString mTitle;
|
|
|
|
|
2019-07-31 19:31:09 +00:00
|
|
|
// invalid for addition and selection events
|
2018-12-05 19:10:05 +00:00
|
|
|
int mFormerPosition{ -1 };
|
|
|
|
|
2019-07-31 19:31:09 +00:00
|
|
|
// invalid for deletion and selection events
|
2018-12-05 19:10:05 +00:00
|
|
|
int mPresentPosition{ -1 };
|
|
|
|
};
|
|
|
|
|
|
|
|
// Posted when a label is added.
|
|
|
|
wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API,
|
|
|
|
EVT_LABELTRACK_ADDITION, LabelTrackEvent);
|
|
|
|
|
|
|
|
// Posted when a label is deleted.
|
|
|
|
wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API,
|
|
|
|
EVT_LABELTRACK_DELETION, LabelTrackEvent);
|
|
|
|
|
|
|
|
// Posted when a label is repositioned in the sequence of labels.
|
|
|
|
wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API,
|
|
|
|
EVT_LABELTRACK_PERMUTED, LabelTrackEvent);
|
2019-07-31 19:31:09 +00:00
|
|
|
|
|
|
|
// Posted when the track is selected or unselected.
|
|
|
|
wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API,
|
|
|
|
EVT_LABELTRACK_SELECTION, LabelTrackEvent);
|
2010-01-23 19:44:49 +00:00
|
|
|
#endif
|