11namespace tracktion {
inline namespace engine
24 input (std::move (inputNode)),
25 playHeadTime (playHeadTimeToUpdate)
28 AllocateAudioBuffer::no });
33 auto props = input->getNodeProperties();
35 constexpr size_t playHeadPositionNodeMagicHash =
size_t (0x706c617948656164);
37 if (props.nodeID != 0)
38 hash_combine (props.nodeID, playHeadPositionNodeMagicHash);
48 latencyNumSamples = info.nodeGraph.rootNode->getNodeProperties().latencyNumSamples;
52 updateFromPreviousNode (info.nodeGraphToReplace);
58 auto sourceBuffers = input->getProcessedOutput();
59 jassert (sourceBuffers.audio.getNumChannels() == pc.buffers.audio.getNumChannels());
61 pc.buffers.midi.copyFrom (sourceBuffers.midi);
63 updatePlayHeadTime (pc.referenceSampleRange.
getLength());
70 int latencyNumSamples = 0;
71 bool updateReferencePositionOnJump =
true;
75 int64_t numLatencySamplesToCountDown = 0;
76 int64_t referencePositionOnJump = 0;
81 void updatePlayHeadTime (int64_t numSamples)
87 state->numLatencySamplesToCountDown = latencyNumSamples;
88 state->referencePositionOnJump = referenceSamplePosition;
91 if (state->numLatencySamplesToCountDown > 0)
93 const int64_t numSamplesToDecrement =
std::min (state->numLatencySamplesToCountDown, numSamples);
94 state->numLatencySamplesToCountDown -= numSamplesToDecrement;
97 if (
getPlayHead().isPlaying() && state->numLatencySamplesToCountDown <= 0)
99 referenceSamplePosition -= latencyNumSamples;
103 referenceSamplePosition = state->referencePositionOnJump;
107 const double time = tracktion::graph::sampleToTime (timelinePosition,
getSampleRate());
110 updateReferencePositionOnJump =
false;
113 void updateFromPreviousNode (NodeGraph* nodeGraphToReplace)
115 if (
auto oldNode = findNodeWithIDIfNonZero<PlayHeadPositionNode> (nodeGraphToReplace,
getNodeProperties().nodeID))
117 state = oldNode->state;
118 updateReferencePositionOnJump =
false;
constexpr ValueType getStart() const noexcept
constexpr ValueType getLength() const noexcept
A Node that calculates a position to show visually what time is currently being processed by the grap...
tracktion::graph::NodeProperties getNodeProperties() override
Should return the properties of the node.
bool isReadyToProcess() override
Should return true when this node is ready to be processed.
std::vector< tracktion::graph::Node * > getDirectInputNodes() override
Should return all the inputs directly feeding in to this node.
void prepareToPlay(const tracktion::graph::PlaybackInitialisationInfo &info) override
Called once before playback begins for each node.
void process(ProcessContext &pc) override
Called when the node is to be processed.
Base class for Nodes that provides information about the current process call.
juce::Range< int64_t > getReferenceSampleRange() const
Returns the reference sample range (from the DeviceManager) of the current process block.
double getSampleRate() const
Returns the sample rate of the current process block.
tracktion::graph::PlayHeadState & getPlayHeadState()
Returns the PlayHeadState in use.
tracktion::graph::PlayHead & getPlayHead()
Returns the PlayHead in use.
Main graph Node processor class.
void setAudioOutput(Node *sourceNode, const choc::buffer::ChannelArrayView< float > &)
This can be called during your process function to set a view to the output.
void setOptimisations(NodeOptimisations)
This can be called to provide some hints about allocating or playing back a Node to improve efficienc...
Struct to describe a single iteration of a process call.
int64_t referenceSamplePositionToTimelinePosition(int64_t referenceSamplePosition) const
Converts a reference sample position to a timeline position.
Holds the state of a process call.
Holds some really basic properties of a node.
Passed into Nodes when they are being initialised, to give them useful contextual information that th...