Audacity 3.2.0
Public Types | Public Member Functions | Static Protected Member Functions | Private Attributes | List of all members
ChannelAttachmentsBase Class Reference

Holds multiple objects as a single attachment to Track. More...

#include <ChannelAttachments.h>

Inheritance diagram for ChannelAttachmentsBase:
[legend]
Collaboration diagram for ChannelAttachmentsBase:
[legend]

Public Types

using Factory = std::function< std::shared_ptr< ChannelAttachment >(Track &, size_t)>
 

Public Member Functions

 ChannelAttachmentsBase (Track &track, Factory factory)
 
 ~ChannelAttachmentsBase () override
 
 ChannelAttachmentsBase (const ChannelAttachmentsBase &)=delete
 
ChannelAttachmentsBaseoperator= (const ChannelAttachmentsBase &)=delete
 
 ChannelAttachmentsBase (ChannelAttachmentsBase &)=delete
 
ChannelAttachmentsBaseoperator= (ChannelAttachmentsBase &&other)
 
size_t Size () const
 
void CopyTo (Track &track) const override
 Copy state, for undo/redo purposes. More...
 
void Reparent (const std::shared_ptr< Track > &parent) override
 Object may be shared among tracks but hold a special back-pointer to one of them; reassign it. More...
 
void WriteXMLAttributes (XMLWriter &writer) const override
 Serialize persistent attributes. More...
 
bool HandleXMLAttribute (const std::string_view &attr, const XMLAttributeValueView &valueView) override
 Deserialize an attribute, returning true if recognized. More...
 
void MakeStereo (const std::shared_ptr< Track > &parent, ChannelAttachmentsBase &&other)
 
void SwapChannels (const std::shared_ptr< Track > &parent)
 
void Erase (const std::shared_ptr< Track > &parent, size_t index)
 
- Public Member Functions inherited from TrackAttachment
virtual ~TrackAttachment ()
 
virtual void CopyTo (Track &track) const
 Copy state, for undo/redo purposes. More...
 
virtual void Reparent (const std::shared_ptr< Track > &parent)
 Object may be shared among tracks but hold a special back-pointer to one of them; reassign it. More...
 
virtual void WriteXMLAttributes (XMLWriter &) const
 Serialize persistent attributes. More...
 
virtual bool HandleXMLAttribute (const std::string_view &attr, const XMLAttributeValueView &valueView)
 Deserialize an attribute, returning true if recognized. More...
 
- Public Member Functions inherited from ClientData::Base
virtual ~Base ()
 

Static Protected Member Functions

static ChannelAttachmentGet (const AttachedTrackObjects::RegisteredFactory &key, Track &track, size_t iChannel)
 
static ChannelAttachmentFind (const AttachedTrackObjects::RegisteredFactory &key, Track *pTrack, size_t iChannel)
 

Private Attributes

const Factory mFactory
 
std::vector< std::shared_ptr< ChannelAttachment > > mAttachments
 

Detailed Description

Holds multiple objects as a single attachment to Track.

Definition at line 51 of file ChannelAttachments.h.

Member Typedef Documentation

◆ Factory

using ChannelAttachmentsBase::Factory = std::function<std::shared_ptr<ChannelAttachment>(Track &, size_t)>

Definition at line 54 of file ChannelAttachments.h.

Constructor & Destructor Documentation

◆ ChannelAttachmentsBase() [1/3]

ChannelAttachmentsBase::ChannelAttachmentsBase ( Track track,
Factory  factory 
)

Definition at line 76 of file ChannelAttachments.cpp.

77 : mFactory{ move(factory) }
78{
79 const auto nChannels = track.NChannels();
80 for (size_t iChannel = 0; iChannel < nChannels; ++iChannel)
81 mAttachments.push_back(mFactory(track, iChannel));
82}
static RegisteredToolbarFactory factory
std::vector< std::shared_ptr< ChannelAttachment > > mAttachments
virtual size_t NChannels() const =0
Report the number of channels.

References anonymous_namespace{StretchingSequenceIntegrationTest.cpp}::iChannel, mAttachments, mFactory, and ChannelGroup::NChannels().

Here is the call graph for this function:

◆ ~ChannelAttachmentsBase()

ChannelAttachmentsBase::~ChannelAttachmentsBase ( )
overridedefault

◆ ChannelAttachmentsBase() [2/3]

ChannelAttachmentsBase::ChannelAttachmentsBase ( const ChannelAttachmentsBase )
delete

◆ ChannelAttachmentsBase() [3/3]

ChannelAttachmentsBase::ChannelAttachmentsBase ( ChannelAttachmentsBase )
delete

Member Function Documentation

◆ CopyTo()

void ChannelAttachmentsBase::CopyTo ( Track track) const
overridevirtual

Copy state, for undo/redo purposes.

Reimplemented from TrackAttachment.

Definition at line 86 of file ChannelAttachments.cpp.

87{
88 // Maybe making a narrow empty copy so limit to the other track's number
89 // of channels
90 const size_t nn = std::min(mAttachments.size(), track.NChannels());
91 for (size_t ii = 0; ii < nn; ++ii) {
92 if (mAttachments[ii])
93 mAttachments[ii]->CopyTo(track, ii);
94 }
95}
int min(int a, int b)

References mAttachments, min(), and ChannelGroup::NChannels().

Here is the call graph for this function:

◆ Erase()

void ChannelAttachmentsBase::Erase ( const std::shared_ptr< Track > &  parent,
size_t  index 
)

Erase attachment at a given index, if it existed, moving later-indexed attachments to earlier indices

Calls Reparent, so it needs a track

Definition at line 156 of file ChannelAttachments.cpp.

158{
159 auto size = mAttachments.size();
160 if (index < size) {
161 mAttachments.erase(mAttachments.begin() + index);
162 for (--size; index < size; ++index)
163 if (auto &pAttachment = mAttachments[index])
164 pAttachment->Reparent(parent, index);
165 }
166}

References mAttachments, and size.

◆ Find()

ChannelAttachment * ChannelAttachmentsBase::Find ( const AttachedTrackObjects::RegisteredFactory key,
Track pTrack,
size_t  iChannel 
)
staticprotected
Precondition
!pTrack || iChannel < pTrack->NChannels()

Definition at line 61 of file ChannelAttachments.cpp.

64{
65 assert(!pTrack || iChannel < pTrack->NChannels());
66 if (!pTrack)
67 return nullptr;
68 const auto pAttachments =
69 pTrack->AttachedObjects::Find<ChannelAttachmentsBase>(key);
70 // do not create on demand
71 if (!pAttachments || iChannel >= pAttachments->mAttachments.size())
72 return nullptr;
73 return pAttachments->mAttachments[iChannel].get();
74}
static const AudacityProject::AttachedObjects::RegisteredFactory key
Holds multiple objects as a single attachment to Track.

References anonymous_namespace{StretchingSequenceIntegrationTest.cpp}::iChannel, key, and mAttachments.

Referenced by ChannelAttachments< Attachment >::Find().

Here is the caller graph for this function:

◆ Get()

ChannelAttachment & ChannelAttachmentsBase::Get ( const AttachedTrackObjects::RegisteredFactory key,
Track track,
size_t  iChannel 
)
staticprotected
Precondition
iChannel < track.NChannels()

Definition at line 42 of file ChannelAttachments.cpp.

45{
46 // Precondition of this function; satisfies precondition of factory below
47 assert(iChannel < track.NChannels());
48 auto &attachments = track.AttachedObjects::Get<ChannelAttachmentsBase>(key);
49 auto &objects = attachments.mAttachments;
50 if (iChannel >= objects.size())
51 objects.resize(iChannel + 1);
52 auto &pObject = objects[iChannel];
53 if (!pObject) {
54 // Create on demand
55 pObject = attachments.mFactory(track, iChannel);
56 assert(pObject); // Precondition of constructor
57 }
58 return *pObject;
59}

References anonymous_namespace{StretchingSequenceIntegrationTest.cpp}::iChannel, key, mAttachments, mFactory, and ChannelGroup::NChannels().

Referenced by ChannelAttachments< Attachment >::Get().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleXMLAttribute()

bool ChannelAttachmentsBase::HandleXMLAttribute ( const std::string_view &  attr,
const XMLAttributeValueView valueView 
)
overridevirtual

Deserialize an attribute, returning true if recognized.

default recognizes no attributes, and returns false

Reimplemented from TrackAttachment.

Definition at line 115 of file ChannelAttachments.cpp.

117{
118 size_t ii = 0;
119 return any_of(mAttachments.begin(), mAttachments.end(),
120 [&](auto &pAttachment) {
121 bool result = pAttachment &&
122 pAttachment->HandleXMLAttribute(attr, valueView, ii);
123 ++ii;
124 return result;
125 });
126}

References mAttachments.

◆ MakeStereo()

void ChannelAttachmentsBase::MakeStereo ( const std::shared_ptr< Track > &  parent,
ChannelAttachmentsBase &&  other 
)

Append the other's attachments to this, assuming concrete subclasses are the same

Calls Reparent, so it needs a track

Precondition
typeid(*this) == typeid(other)
Size() <= 1
other.Size() <= 1

Definition at line 128 of file ChannelAttachments.cpp.

130{
131 assert(typeid(*this) == typeid(other));
132 assert(Size() <= 1);
133 assert(other.Size() <= 1);
134 if (mAttachments.empty())
135 mAttachments.resize(1);
136 auto index = mAttachments.size();
137 for (auto &ptr : other.mAttachments) {
138 if (auto &pAttachment = mAttachments.emplace_back(move(ptr)))
139 pAttachment->Reparent(parent, index++);
140 }
141 other.mAttachments.clear();
142}

References mAttachments, and Size().

Here is the call graph for this function:

◆ operator=() [1/2]

ChannelAttachmentsBase & ChannelAttachmentsBase::operator= ( ChannelAttachmentsBase &&  other)
Precondition
typeid(*this) == typeid(other)
same factories (can't express that in code)

Definition at line 17 of file ChannelAttachments.cpp.

18{
19 assert(typeid(*this) == typeid(other));
20 mAttachments = move(other.mAttachments);
21 return *this;
22}

References mAttachments.

◆ operator=() [2/2]

ChannelAttachmentsBase & ChannelAttachmentsBase::operator= ( const ChannelAttachmentsBase )
delete

◆ Reparent()

void ChannelAttachmentsBase::Reparent ( const std::shared_ptr< Track > &  parent)
overridevirtual

Object may be shared among tracks but hold a special back-pointer to one of them; reassign it.

default does nothing

Reimplemented from TrackAttachment.

Definition at line 97 of file ChannelAttachments.cpp.

98{
99 const size_t nn = mAttachments.size();
100 for (size_t ii = 0; ii < nn; ++ii) {
101 if (mAttachments[ii])
102 mAttachments[ii]->Reparent(parent, ii);
103 }
104}

References mAttachments.

◆ Size()

size_t ChannelAttachmentsBase::Size ( ) const
inline

Definition at line 74 of file ChannelAttachments.h.

74{ return mAttachments.size(); }

Referenced by MakeStereo(), and SwapChannels().

Here is the caller graph for this function:

◆ SwapChannels()

void ChannelAttachmentsBase::SwapChannels ( const std::shared_ptr< Track > &  parent)

Calls Reparent, so it needs a track

Precondition
Size() <= 2

Definition at line 144 of file ChannelAttachments.cpp.

145{
146 assert(Size() <= 2);
147 if (mAttachments.empty())
148 return;
149 mAttachments.resize(2);
151 for (auto ii : { 0, 1 })
152 if (const auto &pAttachment = mAttachments[ii])
153 pAttachment->Reparent(parent, ii);
154}
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:628

References mAttachments, Size(), and anonymous_namespace{NoteTrack.cpp}::swap().

Here is the call graph for this function:

◆ WriteXMLAttributes()

void ChannelAttachmentsBase::WriteXMLAttributes ( XMLWriter ) const
overridevirtual

Serialize persistent attributes.

default does nothing

Reimplemented from TrackAttachment.

Definition at line 106 of file ChannelAttachments.cpp.

107{
108 const size_t nn = mAttachments.size();
109 for (size_t ii = 0; ii < nn; ++ii) {
110 if (mAttachments[ii])
111 mAttachments[ii]->WriteXMLAttributes(writer, ii);
112 }
113}

References mAttachments.

Member Data Documentation

◆ mAttachments

std::vector<std::shared_ptr<ChannelAttachment> > ChannelAttachmentsBase::mAttachments
private

◆ mFactory

const Factory ChannelAttachmentsBase::mFactory
private

Definition at line 123 of file ChannelAttachments.h.

Referenced by ChannelAttachmentsBase(), and Get().


The documentation for this class was generated from the following files: