Audacity 3.2.0
WaveTrackUtilities.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 WaveTrackUtilities.h
7
8 Paul Licameli
9
10 @brief Various operations on WaveTrack, needing only its public interface
11
12**********************************************************************/
13#ifndef __AUDACITY_WAVE_TRACK_UTILITIES__
14#define __AUDACITY_WAVE_TRACK_UTILITIES__
15
16#include "IteratorX.h"
17#include "WaveTrack.h"
18#include <unordered_set>
19
20class SampleBlock;
21class sampleCount;
22class TrackList;
23class WaveTrack;
24
25#include <functional>
26using ProgressReporter = std::function<void(double)>;
27
28class SampleBlock;
29class TrackList;
30
32
33using SampleBlockID = long long;
34using SampleBlockIDSet = std::unordered_set<SampleBlockID>;
36 std::function<void(const std::shared_ptr<SampleBlock> &)>;
38 std::function<void(std::shared_ptr<const SampleBlock>)>;
39
40using IntervalHolder = std::shared_ptr<WaveTrack::Interval>;
41using IntervalHolders = std::vector<IntervalHolder>;
42using IntervalConstHolder = std::shared_ptr<const WaveTrack::Interval>;
43
46
51class WAVE_TRACK_API AllClipsIterator : public ValueIterator<IntervalHolder>
52{
53public:
54 // Constructs an "end" iterator
56
57 // Construct a "begin" iterator
58 explicit AllClipsIterator(WaveTrack &track);
59
60 value_type operator *() const;
61
62 AllClipsIterator &operator ++();
63
65 friend bool operator ==(
66 const AllClipsIterator &a, const AllClipsIterator &b)
67 { return a.mStack.empty() == b.mStack.empty(); }
68
69 friend bool operator !=(
70 const AllClipsIterator &a, const AllClipsIterator &b)
71 { return !(a == b); }
72
73private:
74 using Stack = std::vector<std::pair<IntervalHolders, size_t>>;
75 void Push(IntervalHolders clips);
76
77 WaveTrack *mpTrack{};
79};
80
83
86class WAVE_TRACK_API AllClipsConstIterator
87 : public ValueIterator<IntervalConstHolder>
88{
89public:
90 // Constructs an "end" iterator
92
93 // Construct a "begin" iterator
94 explicit AllClipsConstIterator(const WaveTrack &track)
95 : mIter{ const_cast<WaveTrack&>(track) }
96 {}
97
98 value_type operator *() const { return *mIter; }
99
101 { ++mIter; return *this; }
102
104 friend bool operator ==(
106 { return a.mIter == b.mIter; }
107
108 friend bool operator !=(
110 { return !(a == b); }
111
112private:
114};
115
117{
118 return { AllClipsIterator{ track }, AllClipsIterator{} };
119}
120
122{
123 return { AllClipsConstIterator{ track }, AllClipsConstIterator{} };
124}
125
128using ProgressReport = std::function<bool(double)>;
129
130WAVE_TRACK_API bool Reverse(WaveTrack &track,
131 sampleCount start, sampleCount len, const ProgressReport &report = {});
132
138WAVE_TRACK_API sampleCount GetSequenceSamplesCount(const WaveTrack &track);
139
144WAVE_TRACK_API size_t CountBlocks(const WaveTrack &track);
145
147
150WAVE_TRACK_API void CloseLock(WaveTrack &track) noexcept;
151
153/*
154 @return whether any cutline existed at the position and was removed
155 */
156WAVE_TRACK_API bool RemoveCutLine(WaveTrack &track, double cutLinePosition);
157
160/*
161 @param[out] cutlineStart start time of the insertion
162 @param[out] cutlineEnd end time of the insertion
163 */
164WAVE_TRACK_API void ExpandCutLine(WaveTrack &track, double cutLinePosition,
165 double* cutlineStart = nullptr, double* cutlineEnd = nullptr);
166
168WAVE_TRACK_API bool HasHiddenData(const WaveTrack &track);
169
171WAVE_TRACK_API void DiscardTrimmed(WaveTrack &track);
172
173// Function to visit all sample blocks from a list of tracks.
174// If a set is supplied, then only visit once each unique block ID not already
175// in that set, and accumulate those into the set as a side-effect.
176// The visitor function may be null.
177WAVE_TRACK_API void VisitBlocks(TrackList &tracks, BlockVisitor visitor,
178 SampleBlockIDSet *pIDs = nullptr);
179
180// Non-mutating version of the above
181WAVE_TRACK_API void InspectBlocks(const TrackList &tracks,
182 BlockInspector inspector, SampleBlockIDSet *pIDs = nullptr);
183
188GetClipsIntersecting(const WaveTrack &track, double t0, double t1);
189
190WAVE_TRACK_API void
192} // namespace WaveTrackUtilities
193
194#endif
std::unordered_set< SampleBlockID > SampleBlockIDSet
Definition: CloudSyncDTO.h:27
auto operator*(PffftAlignedCount x, Integral y) -> std::enable_if_t< std::is_unsigned_v< Integral > &&sizeof(Integral)<=sizeof(size_t), PffftAlignedCount >
const auto tracks
std::function< void(double)> ProgressReporter
Definition: Track.h:48
bool operator==(const WaveTrackLocation &a, const WaveTrackLocation &b)
bool operator!=(const WaveTrackLocation &a, const WaveTrackLocation &b)
Abstract class allows access to contents of a block of sound samples, serialization as XML,...
Definition: SampleBlock.h:47
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:850
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:238
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
std::vector< IntervalConstHolder > IntervalConstHolders
Definition: WaveTrack.h:212
std::vector< std::pair< IntervalHolders, size_t > > Stack
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
WAVE_TRACK_API void InspectBlocks(const TrackList &tracks, BlockInspector inspector, SampleBlockIDSet *pIDs=nullptr)
WAVE_TRACK_API size_t CountBlocks(const WaveTrack &track)
WAVE_TRACK_API sampleCount GetSequenceSamplesCount(const WaveTrack &track)
std::function< void(std::shared_ptr< const SampleBlock >)> BlockInspector
WAVE_TRACK_API bool Reverse(WaveTrack &track, sampleCount start, sampleCount len, const ProgressReport &report={})
WAVE_TRACK_API void ExpandCutLine(WaveTrack &track, double cutLinePosition, double *cutlineStart=nullptr, double *cutlineEnd=nullptr)
WAVE_TRACK_API void CloseLock(WaveTrack &track) noexcept
Should be called upon project close. Not balanced by unlocking calls.
std::vector< IntervalHolder > IntervalHolders
std::shared_ptr< WaveTrack::Interval > IntervalHolder
std::unordered_set< SampleBlockID > SampleBlockIDSet
IteratorRange< AllClipsIterator > GetAllClips(WaveTrack &track)
WAVE_TRACK_API bool RemoveCutLine(WaveTrack &track, double cutLinePosition)
Remove cut line, without expanding the audio in it.
std::function< bool(double)> ProgressReport
WAVE_TRACK_API void ExpandClipTillNextOne(const WaveTrack &track, WaveTrack::Interval &interval)
std::shared_ptr< const WaveTrack::Interval > IntervalConstHolder
WAVE_TRACK_API bool HasHiddenData(const WaveTrack &track)
Whether any clips have hidden audio.
WAVE_TRACK_API void DiscardTrimmed(WaveTrack &track)
Remove hidden audio from all clips.
std::function< void(const std::shared_ptr< SampleBlock > &)> BlockVisitor
WAVE_TRACK_API void VisitBlocks(TrackList &tracks, BlockVisitor visitor, SampleBlockIDSet *pIDs=nullptr)
WAVE_TRACK_API WaveTrack::IntervalConstHolders GetClipsIntersecting(const WaveTrack &track, double t0, double t1)
A convenience for use with range-for.
Definition: IteratorX.h:39
A convenience for defining iterators that return rvalue types, so that they cooperate correctly with ...
Definition: IteratorX.h:25
IntervalConstHolder value_type
Definition: IteratorX.h:27