31#include "dsp/itransport.h"
32#include "dsp/tempo_map.h"
33#include "utils/units.h"
42namespace zrythm::dsp::graph
56 units::sample_u64_t transport_position,
57 units::sample_u32_t nframes)
60 .transport_position_ = transport_position,
61 .buffer_offset_ = units::samples (0),
66 [[gnu::hot]]
constexpr units::sample_u64_t end_position ()
const noexcept
114 return units::samples (0);
127 units::sample_rate_t sample_rate,
128 units::sample_u32_t max_block_length);
131 virtual void prepare_for_processing_impl (
133 units::sample_rate_t sample_rate,
134 units::sample_u32_t max_block_length)
139 [[gnu::hot]]
virtual void process_block (
142 const dsp::TempoMap &tempo_map)
noexcept [[clang::nonblocking]] { };
185 GraphNode (
const GraphNode &) =
delete;
186 GraphNode &operator= (
const GraphNode &) =
delete;
187 GraphNode (GraphNode &&) =
delete;
188 GraphNode &operator= (GraphNode &&) =
delete;
189 ~GraphNode ()
noexcept =
default;
195 NodeId get_id ()
const {
return node_id_; }
209 units::sample_u64_t remaining_preroll_frames,
211 const dsp::TempoMap &tempo_map)
const;
213 units::sample_u32_t get_single_playback_latency ()
const
215 return processable_.get_single_playback_latency ();
227 void connect_to (GraphNode &target);
239 IProcessable &get_processable () {
return processable_; }
240 const IProcessable &get_processable ()
const {
return processable_; }
245 auto &
feeds ()
const {
return childnodes_; }
250 auto &
depends ()
const {
return parentnodes_; }
252 bool remove_feed (
const GraphNode &feed);
253 bool remove_depend (
const GraphNode &depend);
269 [[gnu::hot]]
void compensate_latency (
271 units::sample_u32_t remaining_preroll_frames,
273 const dsp::TempoMap &tempo_map)
const;
284 [[gnu::hot]]
void process_chunks_after_splitting_at_loop_points (
287 const dsp::TempoMap &tempo_map)
const;
318 bool terminal_{
false };
319 bool initial_{
false };
330 std::vector<std::reference_wrapper<GraphNode>> parentnodes_;
337 std::vector<std::reference_wrapper<GraphNode>> childnodes_;
339 IProcessable &processable_;
344 bool bypass_ =
false;
403 std::unique_ptr<InitialProcessor> initial_processor_;
Manages the collection of graph nodes.
void update_latencies()
Updates the latencies of all nodes.
void set_initial_and_terminal_nodes()
Updates the initial and terminal nodes based on graph_nodes_.
void finalize_nodes()
Sets the initial/terminal nodes.
std::vector< std::reference_wrapper< GraphNode > > trigger_nodes_
A subset of graph_nodes_ that are trigger nodes.
std::vector< std::reference_wrapper< GraphNode > > terminal_nodes_
A subset of graph_nodes_ that are terminal nodes.
units::sample_u32_t get_max_route_playback_latency() const
Returns the max playback latency of the trigger nodes.
std::vector< std::unique_ptr< GraphNode > > graph_nodes_
All nodes in the graph.
Represents a node in a DSP graph.
int init_refcount_
Initial incoming node count.
std::string print_node_to_str() const
For general debugging.
units::sample_u32_t capture_latency_
The capture latency of the node, in samples.
std::atomic< int > refcount_
Incoming node count.
auto & feeds() const
Read-only access to child nodes (outgoing connections).
units::sample_u32_t playback_latency_
The playback latency of the node, in samples.
void set_route_playback_latency(units::sample_u32_t dest_latency)
Sets the playback latency of the given node recursively.
units::sample_u32_t route_playback_latency_
The route's playback latency so far.
auto & depends() const
Read-only access to parent nodes (incoming connections).
void process(dsp::graph::ProcessBlockInfo time_nfo, units::sample_u64_t remaining_preroll_frames, const dsp::ITransport &transport, const dsp::TempoMap &tempo_map) const
Processes the GraphNode.
void set_skip_processing(bool skip)
Sets whether processing should be skipped for this node.
Interface for objects that can be processed in the DSP graph.
virtual utils::Utf8String get_node_name() const =0
Returns a human friendly name of the node.
void prepare_for_processing(const GraphNode *node, units::sample_rate_t sample_rate, units::sample_u32_t max_block_length)
Called to allocate resources required for processing.
virtual void release_resources()
Called to release resources allocated by prepare_for_processing().
virtual units::sample_u32_t get_single_playback_latency() const
Returns the latency of only the given processable, without adding the previous/next latencies (zero l...
utils::Utf8String get_node_name() const override
Returns a human friendly name of the node.
Lightweight UTF-8 string wrapper with safe conversions.
Common struct to pass around during processing to avoid repeating the data in function arguments.
units::sample_u32_t buffer_offset_
Offset in the current processing cycle's audio buffer, between 0 and the number of frames in AudioEng...
units::sample_u32_t nframes_
Number of frames to process in this call, starting from the offset.
units::sample_u64_t transport_position_
Transport (timeline) position at the start of this chunk (already taking into account the offset).