Audacity 3.2.0
PlayableTrack.cpp
Go to the documentation of this file.
1/*!********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 PlayableTrack.cpp
6
7 Dominic Mazzoni
8
9 Paul Licameli split from Track.cpp
10
11*******************************************************************//*******************************************************************/
20#include "PlayableTrack.h"
21
22namespace {
24 MuteAndSolo() = default;
26 MuteAndSolo& operator=(const MuteAndSolo &) = delete;
27 ~MuteAndSolo() override;
28 std::unique_ptr<ClientData::Cloneable<>> Clone() const override;
29
30 static MuteAndSolo &Get(PlayableTrack &track);
31 static const MuteAndSolo &Get(const PlayableTrack &track);
32
33 bool GetMute() const;
34 void SetMute(bool value);
35 bool GetSolo() const;
36 void SetSolo(bool value);
37
38private:
40 std::atomic<bool> mMute{ false };
42 std::atomic<bool> mSolo{ false };
43};
44
46muteAndSoloFactory{ [](auto &) { return std::make_unique<MuteAndSolo>(); } };
47
49MuteAndSolo::MuteAndSolo(const MuteAndSolo &other) {
50 SetMute(other.GetMute());
51 SetSolo(other.GetSolo());
52}
53
54MuteAndSolo::~MuteAndSolo() = default;
55
56std::unique_ptr<ClientData::Cloneable<>> MuteAndSolo::Clone() const {
57 return std::make_unique<MuteAndSolo>(*this);
58}
59
61 return track.GetGroupData().Attachments
63}
64
66{
67 return Get(const_cast<PlayableTrack &>(track));
68}
69
70bool MuteAndSolo::GetMute() const
71{
72 return mMute.load(std::memory_order_relaxed);
73}
74
75void MuteAndSolo::SetMute(bool value)
76{
77 mMute.store(value, std::memory_order_relaxed);
78}
79
80bool MuteAndSolo::GetSolo() const
81{
82 return mSolo.load(std::memory_order_relaxed);
83}
84
85void MuteAndSolo::SetSolo(bool value)
86{
87 mSolo.store(value, std::memory_order_relaxed);
88}
89}
90
91
93{
94}
95
97 : Track{ orig, std::move(a) }
98{
99}
100
102{
103}
104
106 const PlayableTrack &orig, ProtectedCreationArg &&a
107) : AudioTrack{ orig, std::move(a) }
108{
109}
110
112{
113 if (DoGetMute() != m) {
114 DoSetMute(m);
115 Notify(true);
116 }
117}
118
120{
121 if (DoGetSolo() != s) {
122 DoSetSolo(s);
123 Notify(true);
124 }
125}
126
128{
129 return MuteAndSolo::Get(*this).GetMute();
130}
131
133{
134 MuteAndSolo::Get(*this).SetMute(value);
135}
136
138{
139 return MuteAndSolo::Get(*this).GetSolo();
140}
141
143{
144 MuteAndSolo::Get(*this).SetSolo(value);
145}
146
147// Serialize, not with tags of its own, but as attributes within a tag.
149{
150 xmlFile.WriteAttr(wxT("mute"), DoGetMute());
151 xmlFile.WriteAttr(wxT("solo"), DoGetSolo());
153}
154
155// Return true iff the attribute is recognized.
156bool PlayableTrack::HandleXMLAttribute(const std::string_view &attr, const XMLAttributeValueView &value)
157{
158 long nValue;
159
160 if (attr == "mute" && value.TryGet(nValue)) {
161 DoSetMute(nValue != 0);
162 return true;
163 }
164 else if (attr == "solo" && value.TryGet(nValue)) {
165 DoSetSolo(nValue != 0);
166 return true;
167 }
168
169 return AudioTrack::HandleXMLAttribute(attr, value);
170}
171
173{
174 static Track::TypeInfo info{
175 { "audio", "audio", XO("Audio Track") },
176 false, &Track::ClassTypeInfo() };
177 return info;
178}
179
181{
182 static Track::TypeInfo info{
183 { "playable", "playable", XO("Playable Track") },
184 false, &AudioTrack::ClassTypeInfo() };
185 return info;
186}
187
189 wxT("/GUI/Solo"),
190 {
191 ByColumns,
192 { XO("Simple"), XO("Multi-track"), XO("None") },
193 { wxT("Simple"), wxT("Multi"), wxT("None") }
194 },
195 0, // "Simple"
197};
wxT("CloseDown"))
XO("Cut/Copy/Paste")
EnumSetting< SoloBehavior > TracksBehaviorsSolo
Extends Track with notions of mute and solo setting.
@ SoloBehaviorSimple
Definition: PlayableTrack.h:70
@ SoloBehaviorMulti
Definition: PlayableTrack.h:71
@ SoloBehaviorNone
Definition: PlayableTrack.h:72
ByColumns_t ByColumns
Definition: Prefs.cpp:489
Track subclass holding data representing sound (as notes, or samples, or ...)
Definition: PlayableTrack.h:21
bool HandleXMLAttribute(const std::string_view &, const XMLAttributeValueView &)
Definition: PlayableTrack.h:32
static const TypeInfo & ClassTypeInfo()
void WriteXMLAttributes(XMLWriter &WXUNUSED(xmlFile)) const
Definition: PlayableTrack.h:29
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:266
Adapts EnumSettingBase to a particular enumeration type.
Definition: Prefs.h:512
AudioTrack subclass that can also be audibly replayed by the program.
Definition: PlayableTrack.h:40
bool HandleXMLAttribute(const std::string_view &attr, const XMLAttributeValueView &value)
void DoSetSolo(bool value)
bool DoGetMute() const
void DoSetMute(bool value)
static const TypeInfo & ClassTypeInfo()
void WriteXMLAttributes(XMLWriter &xmlFile) const
void SetSolo(bool s)
bool DoGetSolo() const
void SetMute(bool m)
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:123
void Notify(bool allChannels, int code=-1)
Definition: Track.cpp:264
static const TypeInfo & ClassTypeInfo()
Definition: Track.cpp:1223
ChannelGroupData & GetGroupData()
Definition: Track.cpp:166
A view into an attribute value. The class does not take the ownership of the data.
bool TryGet(bool &value) const noexcept
Try to get a boolean value from the view.
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:25
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:36
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:196
static const ChannelGroup::Attachments::RegisteredFactory muteAndSoloFactory
STL namespace.
A convenient base class defining abstract virtual Clone() for a given kind of pointer.
Definition: ClientData.h:48
Empty argument passed to some public constructors.
Definition: Track.h:130
MuteAndSolo & operator=(const MuteAndSolo &)=delete