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.Attachments::Get<MuteAndSolo>(muteAndSoloFactory);
62}
63
65{
66 return Get(const_cast<PlayableTrack &>(track));
67}
68
69bool MuteAndSolo::GetMute() const
70{
71 return mMute.load(std::memory_order_relaxed);
72}
73
74void MuteAndSolo::SetMute(bool value)
75{
76 mMute.store(value, std::memory_order_relaxed);
77}
78
79bool MuteAndSolo::GetSolo() const
80{
81 return mSolo.load(std::memory_order_relaxed);
82}
83
84void MuteAndSolo::SetSolo(bool value)
85{
86 mSolo.store(value, std::memory_order_relaxed);
87}
88}
89
90
92{
93}
94
96 : Track{ orig, std::move(a) }
97{
98}
99
101{
102}
103
105 const PlayableTrack &orig, ProtectedCreationArg &&a
106) : AudioTrack{ orig, std::move(a) }
107{
108}
109
111{
112 if (DoGetMute() != m) {
113 DoSetMute(m);
114 Notify(true);
115 }
116}
117
119{
120 if (DoGetSolo() != s) {
121 DoSetSolo(s);
122 Notify(true);
123 }
124}
125
127{
128 return MuteAndSolo::Get(*this).GetMute();
129}
130
132{
133 MuteAndSolo::Get(*this).SetMute(value);
134}
135
137{
138 return MuteAndSolo::Get(*this).GetSolo();
139}
140
142{
143 MuteAndSolo::Get(*this).SetSolo(value);
144}
145
146// Serialize, not with tags of its own, but as attributes within a tag.
148{
149 xmlFile.WriteAttr(wxT("mute"), DoGetMute());
150 xmlFile.WriteAttr(wxT("solo"), DoGetSolo());
152}
153
154// Return true iff the attribute is recognized.
155bool PlayableTrack::HandleXMLAttribute(const std::string_view &attr, const XMLAttributeValueView &value)
156{
157 long nValue;
158
159 if (attr == "mute" && value.TryGet(nValue)) {
160 DoSetMute(nValue != 0);
161 return true;
162 }
163 else if (attr == "solo" && value.TryGet(nValue)) {
164 DoSetSolo(nValue != 0);
165 return true;
166 }
167
168 return AudioTrack::HandleXMLAttribute(attr, value);
169}
170
172{
173 static Track::TypeInfo info{
174 { "audio", "audio", XO("Audio Track") },
175 false, &Track::ClassTypeInfo() };
176 return info;
177}
178
180{
181 static Track::TypeInfo info{
182 { "playable", "playable", XO("Playable Track") },
183 false, &AudioTrack::ClassTypeInfo() };
184 return info;
185}
186
188 wxT("/GUI/Solo"),
189 {
190 ByColumns,
191 { XO("Multi-track"), XO("Simple")},
192 { wxT("Multi"), wxT("Simple")}
193 },
194 0, // "Multi-track"
196};
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
ByColumns_t ByColumns
Definition: Prefs.cpp:515
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:275
Adapts EnumSettingBase to a particular enumeration type.
Definition: Prefs.h:514
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:110
void Notify(bool allChannels, int code=-1)
Definition: Track.cpp:234
static const TypeInfo & ClassTypeInfo()
Definition: Track.cpp:790
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:201
template struct REGISTRIES_API Cloneable<>
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:50
Empty argument passed to some public constructors.
Definition: Track.h:117
MuteAndSolo & operator=(const MuteAndSolo &)=delete