Audacity 3.2.0
ChannelAttachments.h
Go to the documentation of this file.
1/*!********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file ChannelAttachments.h
6 @brief Adapts TrackAttachment interface with extra channel index argument
7
8 Dominic Mazzoni
9
10 Paul Licameli split from Track.h
11
12**********************************************************************/
13#ifndef __AUDACITY_CHANNEL_ATTACHMENTS__
14#define __AUDACITY_CHANNEL_ATTACHMENTS__
15
16#include "Track.h"
17
20class TRACK_API ChannelAttachment
21{
22public:
24
26
30 virtual void CopyTo(Track &track, size_t iChannel) const;
31
33
37 virtual void Reparent(const std::shared_ptr<Track> &parent, size_t iChannel);
38
40
41 virtual void WriteXMLAttributes(XMLWriter &writer, size_t iChannel) const;
42
44
45 virtual bool HandleXMLAttribute(
46 const std::string_view& attr, const XMLAttributeValueView& valueView,
47 size_t iChannel);
48};
49
52{
53public:
54 using Factory =
55 std::function<std::shared_ptr<ChannelAttachment>(Track &, size_t)>;
56
59
60 // No copying
63
64 // No move construction
66
67 // Move assignment is allowed
73
74 size_t Size() const { return mAttachments.size(); }
75
76 // Override all the TrackAttachment virtuals and pass through to each
77 void CopyTo(Track &track) const override;
78 void Reparent(const std::shared_ptr<Track> &parent) override;
79 void WriteXMLAttributes(XMLWriter &writer) const override;
80 bool HandleXMLAttribute(
81 const std::string_view& attr, const XMLAttributeValueView& valueView)
82 override;
83
86
92 void MakeStereo(const std::shared_ptr<Track> &parent,
94
99 void SwapChannels(const std::shared_ptr<Track> &parent);
100
103
106 void Erase(const std::shared_ptr<Track> &parent, size_t index);
107
108protected:
112 static ChannelAttachment &Get(
114 Track &track, size_t iChannel);
118 static ChannelAttachment *Find(
120 Track *pTrack, size_t iChannel);
121
122private:
124 std::vector<std::shared_ptr<ChannelAttachment>> mAttachments;
125};
126
128template<typename Attachment>
130{
131 static_assert(std::is_base_of_v<ChannelAttachment, Attachment>);
132public:
133 ~ChannelAttachments() override = default;
134
138 static Attachment &Get(
140 Track &track, size_t iChannel)
141 {
142 return static_cast<Attachment&>(
144 }
148 static Attachment *Find(
150 Track *pTrack, size_t iChannel)
151 {
152 return static_cast<Attachment*>(
154 }
155
157
165 template<typename F,
166 typename sfinae = std::enable_if_t<std::is_convertible_v<
167 std::invoke_result_t<F, Track&, size_t>, std::shared_ptr<Attachment>
168 >>
169 >
170 explicit ChannelAttachments(Track &track, F &&f)
171 : ChannelAttachmentsBase{ track, std::forward<F>(f) }
172 {}
173};
174
175#endif
static RegisteredToolbarFactory factory
static const AudacityProject::AttachedObjects::RegisteredFactory key
declares abstract base class Track, TrackList, and iterators over TrackList
virtual ~ChannelAttachment()
Holds multiple objects as a single attachment to Track.
ChannelAttachmentsBase(const ChannelAttachmentsBase &)=delete
std::vector< std::shared_ptr< ChannelAttachment > > mAttachments
~ChannelAttachmentsBase() override
ChannelAttachmentsBase & operator=(const ChannelAttachmentsBase &)=delete
static ChannelAttachment & Get(const AttachedTrackObjects::RegisteredFactory &key, Track &track, size_t iChannel)
std::function< std::shared_ptr< ChannelAttachment >(Track &, size_t)> Factory
static ChannelAttachment * Find(const AttachedTrackObjects::RegisteredFactory &key, Track *pTrack, size_t iChannel)
ChannelAttachmentsBase(ChannelAttachmentsBase &)=delete
Holds multiple objects of the parameter type as a single attachment to Track.
~ChannelAttachments() override=default
static Attachment * Find(const AttachedTrackObjects::RegisteredFactory &key, Track *pTrack, size_t iChannel)
ChannelAttachments(Track &track, F &&f)
Type-erasing constructor.
static Attachment & Get(const AttachedTrackObjects::RegisteredFactory &key, Track &track, size_t iChannel)
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:275
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
A view into an attribute value. The class does not take the ownership of the data.
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:25
PROJECT_FILE_IO_API wxString Find(const FilePath &path)
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:202
STL namespace.