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 // Label tracks are always leaders
48 assert(mpTrack->IsLeader());
49 // not committed -- DELETE the label track
50 mpEffect->mTracks->Remove(*mpTrack);
51 }
52}
53
54std::shared_ptr<AddedAnalysisTrack> AddAnalysisTrack(
55 Effect &effect, const wxString &name)
56{
57 return std::shared_ptr<AddedAnalysisTrack>
58 { safenew AddedAnalysisTrack{ &effect, name } };
59}
60
62 Effect *pEffect, const LabelTrack &origTrack, const wxString &name
63) : mpEffect(pEffect)
64{
65 // copy LabelTrack here, so it can be undone on cancel
66 const auto startTime = origTrack.GetStartTime();
67 auto list = origTrack.Copy(startTime, origTrack.GetEndTime());
68 auto newTrack = (*list->begin())->SharedPointer();
69
70 mpTrack = static_cast<LabelTrack*>(newTrack.get());
71
72 // Why doesn't LabelTrack::Copy complete the job? :
73 mpTrack->MoveTo(startTime);
74 if (!name.empty())
76
77 // mpOrigTrack came from mTracks which we own but expose as const to subclasses
78 // So it's okay that we cast it back to const
80 pEffect->mTracks->ReplaceOne(const_cast<LabelTrack&>(origTrack),
81 std::move(*list));
82}
83
85{
86 mpEffect = that.mpEffect;
87 mpTrack = that.mpTrack;
88 mpOrigTrack = std::move(that.mpOrigTrack);
89 that.Commit();
90}
91
93{
94 mpEffect = nullptr;
95}
96
98{
99 if (mpEffect && mpTrack) {
100 // not committed -- DELETE the label track
101 // mpOrigTrack came from mTracks which we own but expose as const to subclasses
102 // So it's okay that we cast it back to const
103 mpEffect->mTracks->ReplaceOne(*mpTrack, std::move(*mpOrigTrack));
104 }
105}
106
108 Effect &effect, const LabelTrack &origTrack, const wxString &name)
109{
110 return{ &effect, origTrack, name };
111}
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:135
double GetStartTime() const
Get the minimum of Start() values of intervals, or 0 when none.
Definition: Channel.cpp:124
std::shared_ptr< TrackList > mTracks
Definition: EffectBase.h:109
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:87
TrackListHolder Copy(double t0, double t1, bool forClipboard=true) const override
Create new tracks and don't modify this track.
Definition: LabelTrack.cpp:735
static LabelTrack * Create(TrackList &trackList, const wxString &name)
Create a new LabelTrack with specified name and append it to the trackList.
Definition: LabelTrack.cpp:76
void MoveTo(double dOffset) override
Change start time to given time point.
Definition: LabelTrack.cpp:166
std::shared_ptr< TrackList > mpOrigTrack
bool IsLeader() const override
Definition: Track.cpp:291
void SetName(const wxString &n)
Definition: Track.cpp:61