Audacity 3.2.0
AnalysisTracks.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 AnalysisTracks.cpp
6
7 Dominic Mazzoni
8 Vaughan Johnson
9 Martyn Shaw
10
11 Paul Licameli split from Effect.cpp
12
13*******************************************************************//*******************************************************************/
19#include "AnalysisTracks.h"
20#include "Effect.h"
21#include "../LabelTrack.h"
22
24 : mpEffect(pEffect)
25{
26 if(!name.empty())
28 else
30}
31
33{
34 mpEffect = that.mpEffect;
35 mpTrack = that.mpTrack;
36 that.Commit();
37}
38
40{
41 mpEffect = nullptr;
42}
43
45{
46 if (mpEffect) {
47 // not committed -- DELETE the label track
48 mpEffect->mTracks->Remove(*mpTrack);
49 }
50}
51
52std::shared_ptr<AddedAnalysisTrack> AddAnalysisTrack(
53 Effect &effect, const wxString &name)
54{
55 return std::shared_ptr<AddedAnalysisTrack>
56 { safenew AddedAnalysisTrack{ &effect, name } };
57}
58
60 Effect *pEffect, const LabelTrack &origTrack, const wxString &name
61) : mpEffect(pEffect)
62{
63 // copy LabelTrack here, so it can be undone on cancel
64 const auto startTime = origTrack.GetStartTime();
65 auto newTrack = origTrack.Copy(startTime, origTrack.GetEndTime());
66
67 mpTrack = static_cast<LabelTrack*>(newTrack.get());
68
69 // Why doesn't LabelTrack::Copy complete the job? :
70 mpTrack->MoveTo(startTime);
71 if (!name.empty())
73
74 // mpOrigTrack came from mTracks which we own but expose as const to subclasses
75 // So it's okay that we cast it back to const
77 pEffect->mTracks->ReplaceOne(const_cast<LabelTrack&>(origTrack),
78 std::move(*TrackList::Temporary(nullptr, newTrack)));
79}
80
82{
83 mpEffect = that.mpEffect;
84 mpTrack = that.mpTrack;
85 mpOrigTrack = std::move(that.mpOrigTrack);
86 that.Commit();
87}
88
90{
91 mpEffect = nullptr;
92}
93
95{
96 if (mpEffect && mpTrack) {
97 // not committed -- DELETE the label track
98 // mpOrigTrack came from mTracks which we own but expose as const to subclasses
99 // So it's okay that we cast it back to const
100 mpEffect->mTracks->ReplaceOne(*mpTrack,
101 std::move(*TrackList::Temporary(nullptr, mpOrigTrack)));
102 }
103}
104
106 Effect &effect, const LabelTrack &origTrack, const wxString &name)
107{
108 return{ &effect, origTrack, name };
109}
std::shared_ptr< AddedAnalysisTrack > AddAnalysisTrack(Effect &effect, const wxString &name)
ModifiedAnalysisTrack ModifyAnalysisTrack(Effect &effect, const LabelTrack &origTrack, const wxString &name)
const TranslatableString name
Definition: Distortion.cpp:76
#define safenew
Definition: MemoryX.h:9
LabelTrack * mpTrack
double GetEndTime() const
Get the maximum of End() values of intervals, or 0 when none.
Definition: Channel.cpp:61
double GetStartTime() const
Get the minimum of Start() values of intervals, or 0 when none.
Definition: Channel.cpp:50
std::shared_ptr< TrackList > mTracks
Definition: EffectBase.h:107
Base class for many of the effects in Audacity.
Definition: Effect.h:26
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:95
Track::Holder Copy(double t0, double t1, bool forClipboard=true) const override
Create new tracks and don't modify this track.
Definition: LabelTrack.cpp:856
static LabelTrack * Create(TrackList &trackList, const wxString &name)
Create a new LabelTrack with specified name and append it to the trackList.
Definition: LabelTrack.cpp:95
void MoveTo(double dOffset) override
Change start time to given time point.
Definition: LabelTrack.cpp:182
std::shared_ptr< Track > mpOrigTrack
void SetName(const wxString &n)
Definition: Track.cpp:69
static TrackListHolder Temporary(AudacityProject *pProject, const Track::Holder &pTrack={})
Definition: Track.cpp:858