tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_WaveNode.h
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7
8 Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9*/
10
11#pragma once
12
14
15namespace tracktion { inline namespace engine
16{
17
18class TimeRangeRemappingReader;
19class EditToClipBeatReader;
20class EditToClipTimeReader;
21class ResamplerReader;
22class PitchAdjustReader;
23class SpeedFadeEditReader;
24
26{
27 TimePosition sourceTime, warpTime;
28};
29
31
32//==============================================================================
33//==============================================================================
35class WaveNode final : public tracktion::graph::Node,
37{
38public:
47 WaveNode (const AudioFile&,
48 TimeRange editTime,
49 TimeDuration offset,
50 TimeRange loopSection,
52 double speedRatio,
53 const juce::AudioChannelSet& sourceChannelsToUse,
54 const juce::AudioChannelSet& destChannelsToFill,
57 bool isOfflineRender);
58
59 //==============================================================================
62 bool isReadyToProcess() override;
63 void process (ProcessContext&) override;
64
65private:
66 //==============================================================================
67 TimeRange editPosition, loopSection;
68 TimeDuration offset;
69 double originalSpeedRatio = 0, outputSampleRate = 44100.0;
70 const EditItemID editItemID;
71 bool isOfflineRender = false;
72
73 AudioFile audioFile;
74 LiveClipLevel clipLevel;
75 juce::Range<int64_t> editPositionInSamples;
76 double audioFileSampleRate = 0;
77 const juce::AudioChannelSet channelsToUse, destChannels;
79
80 struct PerChannelState;
82
83 int64_t editPositionToFileSample (int64_t) const noexcept;
84 int64_t editTimeToFileSample (TimePosition) const noexcept;
85 bool updateFileSampleRate();
86 void replaceChannelStateIfPossible (NodeGraph*, int numChannelsToUse);
87 void replaceChannelStateIfPossible (WaveNode&, int numChannelsToUse);
88 void processSection (ProcessContext&, juce::Range<int64_t> timelineRange);
89
91};
92
93
94//==============================================================================
95//==============================================================================
99class WaveNodeRealTime final : public graph::Node,
100 public TracktionEngineNode,
102{
103public:
104 //==============================================================================
106 enum class ReadAhead : bool { no, yes };
107
108 //==============================================================================
113 TimeRange editTime,
114 TimeDuration offset,
115 TimeRange loopSection,
117 double speedRatio,
118 const juce::AudioChannelSet& sourceChannelsToUse,
119 const juce::AudioChannelSet& destChannelsToFill,
122 bool isOfflineRender,
125 std::optional<tempo::Sequence::Position> editTempoSequence = {},
127 TimeStretcher::ElastiqueProOptions = {},
128 float pitchChangeSemitones = 0.0f,
129 ReadAhead = ReadAhead::no);
130
131 //==============================================================================
133 enum class SyncTempo : bool { no, yes };
134
136 enum class SyncPitch : bool { no, yes };
137
153 BeatRange editTime,
154 BeatDuration offset,
155 BeatRange loopSection,
157 const juce::AudioChannelSet& sourceChannelsToUse,
158 const juce::AudioChannelSet& destChannelsToFill,
161 bool isOfflineRender,
166 tempo::Sequence sourceFileTempoMap,
168 std::optional<tempo::Sequence> chordPitchSequence,
169 float pitchChangeSemitones = 1.0f,
170 ReadAhead = ReadAhead::no);
171
172 //==============================================================================
176 void setDynamicOffsetBeats (BeatDuration) override;
177
178 //==============================================================================
181 bool isReadyToProcess() override;
182 void process (ProcessContext&) override;
183
184private:
185 //==============================================================================
186 BeatRange editPositionBeats, loopSectionBeats;
187 BeatDuration offsetBeats;
188 TimeRange editPositionTime, loopSectionTime;
189 TimeDuration offsetTime;
190 const double speedRatio = 1.0;
191 const EditItemID editItemID;
192 const bool isOfflineRender = false;
193 const ResamplingQuality resamplingQuality;
194
195 const AudioFile audioFile;
196 const SpeedFadeDescription speedFadeDescription;
197 const std::optional<tempo::Sequence::Position> editTempoSequence;
199 TimeStretcher::Mode timeStretcherMode;
200 TimeStretcher::ElastiqueProOptions elastiqueProOptions;
201 LiveClipLevel clipLevel;
202 const juce::AudioChannelSet channelsToUse, destChannels;
203 float pitchChangeSemitones = 0.0;
204 double outputSampleRate = 44100.0;
205 int outputBlockSize = 0;
206 bool isFirstBlock = false;
207 const ReadAhead readAhead;
208
209 size_t stateHash = 0;
210 ResamplerReader* resamplerReader = nullptr;
211 PitchAdjustReader* pitchAdjustReader = nullptr;
215
216 std::shared_ptr<tempo::Sequence> fileTempoSequence;
218 SyncTempo syncTempo = SyncTempo::no;
219 SyncPitch syncPitch = SyncPitch::no;
220 std::shared_ptr<tempo::Sequence> chordPitchSequence;
222
223 bool buildAudioReaderGraph();
224 void replaceStateIfPossible (NodeGraph*);
225 void replaceStateIfPossible (WaveNodeRealTime&);
226 void processSection (ProcessContext&);
227 tempo::Key getKeyToSyncTo (TimePosition) const;
228
230};
231
232}} // namespace tracktion { inline namespace engine
233
234#ifndef DOXYGEN
235template<>
236struct std::hash<tracktion::engine::WarpMap>
237{
238 size_t operator() (const tracktion::engine::WarpMap& w) const noexcept
239 {
240 size_t seed = 0;
241
242 for (const auto& p : w)
243 {
244 tracktion::hash_combine (seed, p.sourceTime.inSeconds());
245 tracktion::hash_combine (seed, p.warpTime.inSeconds());
246 }
247
248 return seed;
249 }
250};
251#endif
Mode
Holds the various algorithms to which can be used (if enabled).
Base class for Nodes that provides information about the current process call.
An Node that plays back a wave file.
bool isReadyToProcess() override
Should return true when this node is ready to be processed.
SyncTempo
Represets whether the file should try and match Edit tempo changes.
graph::NodeProperties getNodeProperties() override
Should return the properties of the node.
void prepareToPlay(const graph::PlaybackInitialisationInfo &) override
Called once before playback begins for each node.
void setDynamicOffsetBeats(BeatDuration) override
Sets an offset to be applied to all times in this node, effectively shifting it forwards or backwards...
SyncPitch
Represets whether the file should try and match Edit pitch changes.
void process(ProcessContext &) override
Called when the node is to be processed.
ReadAhead
Whether or not to use a background thread to read ahead the time-stretch buffer.
An Node that plays back a wave file.
tracktion::graph::NodeProperties getNodeProperties() override
Should return the properties of the node.
void process(ProcessContext &) override
Called when the node is to be processed.
void prepareToPlay(const tracktion::graph::PlaybackInitialisationInfo &) override
Called once before playback begins for each node.
bool isReadyToProcess() override
Should return true when this node is ready to be processed.
Main graph Node processor class.
Struct to describe a single iteration of a process call.
T is_pointer_v
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
ResamplingQuality
Specifies a number of resampling qualities that can be used.
@ lagrange
Lagrange interpolation.
void hash_combine(size_t &seed, const T &v)
Hashes a type with a given seed, modifying the seed.
T operator()(T... args)
typedef int64_t
Represents a duration in beats.
Represents a duration in real-life time.
Represents a position in real-life time.
ID for objects of type EditElement - e.g.
Provides a thread-safe way to share a clip's levels with an audio engine without worrying about the C...
Holds the state of a process call.
Describes the time and type of the speed fade in/outs.
A set of options that can be used in conjunction with the elastiquePro Mode to fine tune the algorith...
Holds a graph in an order ready for processing and a sorted map for quick lookups.
Holds some really basic properties of a node.
Passed into Nodes when they are being initialised, to give them useful contextual information that th...