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 <Track.h>

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

Public Types

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

Public Member Functions

 ChannelAttachmentsBase (Track &track, Factory factory)
 
 ~ChannelAttachmentsBase () override
 
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...
 
- 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 TrackAttachmentGet (const AttachedTrackObjects::RegisteredFactory &key, Track &track, size_t iChannel)
 
static TrackAttachmentFind (const AttachedTrackObjects::RegisteredFactory &key, Track *pTrack, size_t iChannel)
 

Private Attributes

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

Detailed Description

Holds multiple objects as a single attachment to Track.

Definition at line 511 of file Track.h.

Member Typedef Documentation

◆ Factory

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

Definition at line 514 of file Track.h.

Constructor & Destructor Documentation

◆ ChannelAttachmentsBase()

ChannelAttachmentsBase::ChannelAttachmentsBase ( Track track,
Factory  factory 
)

Definition at line 1320 of file Track.cpp.

1321 : mFactory{ move(factory) }
1322{
1323 // Always construct one channel view
1324 // TODO wide wave tracks -- number of channels will be known earlier, and
1325 // they will all be constructed
1326 mAttachments.push_back(mFactory(track, 0));
1327}
const Factory mFactory
Definition: Track.h:543
std::vector< std::shared_ptr< TrackAttachment > > mAttachments
Definition: Track.h:544
static RegisteredToolbarFactory factory

References mAttachments, and mFactory.

◆ ~ChannelAttachmentsBase()

ChannelAttachmentsBase::~ChannelAttachmentsBase ( )
overridedefault

Member Function Documentation

◆ CopyTo()

void ChannelAttachmentsBase::CopyTo ( Track track) const
overridevirtual

Copy state, for undo/redo purposes.

Reimplemented from TrackAttachment.

Definition at line 1331 of file Track.cpp.

1332{
1333 for (auto &pAttachment : mAttachments)
1334 if (pAttachment)
1335 pAttachment->CopyTo(track);
1336}

References mAttachments.

◆ Find()

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

Definition at line 1305 of file Track.cpp.

1308{
1309 assert(!pTrack || iChannel < pTrack->NChannels());
1310 if (!pTrack)
1311 return nullptr;
1312 const auto pAttachments =
1313 pTrack->AttachedObjects::Find<ChannelAttachmentsBase>(key);
1314 // do not create on demand
1315 if (!pAttachments || iChannel >= pAttachments->mAttachments.size())
1316 return nullptr;
1317 return pAttachments->mAttachments[iChannel].get();
1318}
static const AudacityProject::AttachedObjects::RegisteredFactory key
Definition: Track.cpp:343
Holds multiple objects as a single attachment to Track.
Definition: Track.h:512

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

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

Here is the caller graph for this function:

◆ Get()

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

Definition at line 1286 of file Track.cpp.

1289{
1290 // Precondition of this function; satisfies precondition of factory below
1291 assert(iChannel < track.NChannels());
1292 auto &attachments = track.AttachedObjects::Get<ChannelAttachmentsBase>(key);
1293 auto &objects = attachments.mAttachments;
1294 if (iChannel >= objects.size())
1295 objects.resize(iChannel + 1);
1296 auto &pObject = objects[iChannel];
1297 if (!pObject) {
1298 // Create on demand
1299 pObject = attachments.mFactory(track, iChannel);
1300 assert(pObject); // Precondition of constructor
1301 }
1302 return *pObject;
1303}
virtual size_t NChannels() const =0
Report the number of channels.

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 1352 of file Track.cpp.

1354{
1355 return std::any_of(mAttachments.begin(), mAttachments.end(),
1356 [&](auto &pAttachment) {
1357 return pAttachment && pAttachment->HandleXMLAttribute(attr, valueView);
1358 });
1359}

References mAttachments.

◆ 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 1338 of file Track.cpp.

1339{
1340 for (auto &pAttachment : mAttachments)
1341 if (pAttachment)
1342 pAttachment->Reparent(parent);
1343}

References mAttachments.

◆ WriteXMLAttributes()

void ChannelAttachmentsBase::WriteXMLAttributes ( XMLWriter ) const
overridevirtual

Serialize persistent attributes.

default does nothing

Reimplemented from TrackAttachment.

Definition at line 1345 of file Track.cpp.

1346{
1347 for (auto &pAttachment : mAttachments)
1348 if (pAttachment)
1349 pAttachment->WriteXMLAttributes(writer);
1350}

References mAttachments.

Member Data Documentation

◆ mAttachments

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

◆ mFactory

const Factory ChannelAttachmentsBase::mFactory
private

Definition at line 543 of file Track.h.

Referenced by ChannelAttachmentsBase(), and Get().


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