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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_RackInstanceNode.cpp
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
12namespace tracktion { inline namespace engine
13{
14
16 : input (std::move (inputNode)), channelMap (std::move (channelMapToUse))
17{
18 assert (input);
19
20 for (auto& chan : channelMap)
21 {
22 assert (std::get<2> (chan) != nullptr);
23 maxNumChannels = std::max (maxNumChannels,
24 std::get<1> (chan) + 1);
25 }
26
27 for (size_t chan = 0; chan < 2; ++chan)
28 lastGain[chan] = dbToGain (std::get<2> (channelMap[chan])->getCurrentValue());
29
30}
31
36
38{
39 auto props = input->getNodeProperties();
40 props.numberOfChannels = (int) maxNumChannels;
41 props.hasMidi = true;
42 props.hasAudio = true;
43
44 return props;
45}
46
48{
49 if (input->numOutputNodes > 1)
50 return;
51
52 const auto inputNumChannels = input->getNodeProperties().numberOfChannels;
53 const auto desiredNumChannels = getNodeProperties().numberOfChannels;
54
55 if (info.enableNodeMemorySharing && inputNumChannels >= desiredNumChannels)
56 {
57 canUseSourceBuffers = true;
58 setOptimisations ({ tracktion::graph::ClearBuffers::no,
59 tracktion::graph::AllocateAudioBuffer::no });
60 }
61}
62
64{
65 return input->hasProcessed();
66}
67
68void RackInstanceNode::preProcess (choc::buffer::FrameCount, juce::Range<int64_t>)
69{
70 if (canUseSourceBuffers)
71 setBufferViewToUse (input.get(), input->getProcessedOutput().audio);
72}
73
75{
76 assert ((int) pc.buffers.audio.getNumChannels() == maxNumChannels);
77 auto inputBuffers = input->getProcessedOutput();
78
79 // Always copy MIDI
80 pc.buffers.midi.copyFrom (inputBuffers.midi);
81
82 // Copy audio applying gain
83 int channel = 0;
84
85 for (auto& chan : channelMap)
86 {
87 auto srcChan = std::get<0> (chan);
88 auto destChan = std::get<1> (chan);
89
90 if (srcChan < 0)
91 continue;
92
93 if (destChan < 0)
94 continue;
95
96 if ((choc::buffer::ChannelCount) srcChan >= inputBuffers.audio.getNumChannels())
97 continue;
98
99 auto src = inputBuffers.audio.getChannel ((choc::buffer::ChannelCount) srcChan);
100 auto dest = pc.buffers.audio.getChannel ((choc::buffer::ChannelCount) destChan);
101 auto gain = dbToGain (std::get<2> (chan)->getCurrentValue());
102
103 copyIfNotAliased (dest, src);
104
105 if (gain == lastGain[channel])
106 {
107 if (gain != 1.0f)
108 applyGain (dest, gain);
109 }
110 else
111 {
112 juce::SmoothedValue<float> smoother (lastGain[channel]);
113 smoother.setTargetValue (gain);
114 smoother.reset ((int) dest.getNumFrames());
115 applyGainPerFrame (dest, [&] { return smoother.getNextValue(); });
116
117 lastGain[channel] = gain;
118 }
119
120 ++channel;
121 }
122}
123
124}} // namespace tracktion { inline namespace engine
assert
FloatType getNextValue() noexcept
void reset(double sampleRate, double rampLengthInSeconds) noexcept
void setTargetValue(FloatType newValue) noexcept
void process(ProcessContext &) override
Called when the node is to be processed.
std::vector< Node * > getDirectInputNodes() override
Should return all the inputs directly feeding in to this node.
void prepareToPlay(const tracktion::graph::PlaybackInitialisationInfo &) override
Called once before playback begins for each node.
RackInstanceNode(std::unique_ptr< Node >, ChannelMap channelMap)
Creates a RackInstanceNode that maps an input node channel to an output channel and applies a gain pa...
tracktion::graph::NodeProperties getNodeProperties() override
Should return the properties of the node.
void preProcess(choc::buffer::FrameCount, juce::Range< int64_t >) override
Called when the node is to be processed, just before process.
bool isReadyToProcess() override
Should return true when this node is ready to be processed.
void setOptimisations(NodeOptimisations)
This can be called to provide some hints about allocating or playing back a Node to improve efficienc...
void setBufferViewToUse(Node *sourceNode, const choc::buffer::ChannelArrayView< float > &)
This can be called during prepareToPlay to set a BufferView to use which can improve efficiency.
Struct to describe a single iteration of a process call.
T is_pointer_v
typedef int
T max(T... args)
Holds some really basic properties of a node.
Passed into Nodes when they are being initialised, to give them useful contextual information that th...