Audacity 3.2.0
Channel.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 Channel.cpp
6
7 Dominic Mazzoni
8
9 Paul Licameli split from Track.h
10
11*//*******************************************************************/
12#include "Channel.h"
13
14#include <algorithm>
15#include <numeric>
16
18
20
22 const ChannelGroup &group, double start, double end
23) : ChannelGroupInterval{ start, end }
24 , mNChannels{ group.NChannels() }
25{
26 assert(group.IsLeader());
27 assert(mNChannels >= 1); // Post of ChannelGroup::NChannels
28}
29
31
32Channel::~Channel() = default;
33
35{
36 auto &group = DoGetChannelGroup();
37 int index = -1;
38 for (size_t ii = 0, nn = group.NChannels(); ii < nn; ++ii)
39 if (group.GetChannel(ii).get() == this) {
40 index = ii;
41 break;
42 }
43 // post of DoGetChannelGroup
44 assert(index >= 0);
45
46 // TODO wide wave tracks -- remove this stronger assertion
47 assert(index == 0);
48
49 return index;
50}
51
53{
54 auto &group = ReallyDoGetChannelGroup();
55 int index = -1;
56 for (size_t ii = 0, nn = group.NChannels(); ii < nn; ++ii)
57 if (group.GetChannel(ii).get() == this) {
58 index = ii;
59 break;
60 }
61 assert(index >= 0);
62 return index;
63}
64
66{
67 assert(FindChannelIndex() >= 0);
68 return DoGetChannelGroup();
69}
70
73 assert(FindChannelIndex() >= 0);
74 return DoGetChannelGroup();
75}
76
78{
79 return FindChannelIndex();
80}
81
83{
84 return DoGetChannelGroup();
85}
86
88
90{
91 // Deep copy of any group data
93 std::make_unique<ChannelGroupData>(*orig.mpGroupData) : nullptr;
94}
95
97{
98 mpGroupData.reset();
99}
100
101auto ChannelGroup::DetachGroupData() -> std::unique_ptr<ChannelGroupData>
102{
103 return move(mpGroupData);
104}
105
106void ChannelGroup::AssignGroupData(std::unique_ptr<ChannelGroupData> pGroupData)
107{
108 mpGroupData = move(pGroupData);
109}
110
112{
113 if (!mpGroupData)
114 // Make on demand
115 mpGroupData = std::make_unique<ChannelGroupData>();
116 return *mpGroupData;
117}
118
120{
121 return const_cast<ChannelGroup *>(this)->GetGroupData();
122}
123
125{
126 auto range = Intervals();
127 if (range.empty())
128 return 0;
129 return std::accumulate(range.first, range.second,
130 std::numeric_limits<double>::max(),
131 [](double acc, const auto &pInterval){
132 return std::min(acc, pInterval->Start()); });
133}
134
136{
137 auto range = Intervals();
138 if (range.empty())
139 return 0;
140 return std::accumulate(range.first, range.second,
141 std::numeric_limits<double>::lowest(),
142 [](double acc, const auto &pInterval){
143 return std::max(acc, pInterval->End()); });
144}
Abstract class ChannelGroup with two discrete iterable dimensions, channels and intervals; subclasses...
double GetEndTime() const
Get the maximum of End() values of intervals, or 0 when none.
Definition: Channel.cpp:135
double GetStartTime() const
Get the minimum of Start() values of intervals, or 0 when none.
Definition: Channel.cpp:124
virtual bool IsLeader() const =0
void AssignGroupData(std::unique_ptr< ChannelGroupData > pGroupData)
Replace any previous attachments.
Definition: Channel.cpp:106
IteratorRange< IntervalIterator< IntervalType > > Intervals()
Get range of intervals with mutative access.
Definition: Channel.h:513
std::unique_ptr< ChannelGroupData > mpGroupData
Definition: Channel.h:605
ChannelGroupData & GetGroupData()
Make attachment site on demand as needed.
Definition: Channel.cpp:111
std::unique_ptr< ChannelGroupData > DetachGroupData()
Move attachments out.
Definition: Channel.cpp:101
void Init(const ChannelGroup &other)
Copy, including cloning of attached objects.
Definition: Channel.cpp:89
virtual ~ChannelGroup()
void DestroyGroupData()
Leave all attachments null.
Definition: Channel.cpp:96
A start and an end time, and whatever else subclasses associate with them.
Definition: Channel.h:30
virtual ~ChannelGroupInterval()
virtual ~Channel()
int FindChannelIndex() const
Definition: Channel.cpp:34
virtual ChannelGroup & ReallyDoGetChannelGroup() const
This is temporary! It defaults to call the above.
Definition: Channel.cpp:82
ChannelGroup & GetChannelGroup()
Channel object's lifetime is assumed to be nested in its Track's.
Definition: Channel.cpp:71
virtual ChannelGroup & DoGetChannelGroup() const =0
Subclass must override.
size_t GetChannelIndex() const
Definition: Channel.cpp:77
size_t ReallyGetChannelIndex() const
Definition: Channel.cpp:52
virtual ~ChannelInterval()
const size_t mNChannels
Definition: Channel.h:174
~WideChannelGroupInterval() override
WideChannelGroupInterval(const ChannelGroup &group, double start, double end)
Definition: Channel.cpp:21
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159