Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
zrythm::dsp::graph::GraphScheduler Class Reference

Manages the scheduling and execution of a graph of DSP nodes. More...

#include <src/dsp/graph_scheduler.h>

Public Types

using RunOnMainThreadFunc = std::function<void (std::function<void ()>)>
 Request for a function to run on the main thread (blocking).

Public Member Functions

 GraphScheduler (RunOnMainThreadFunc run_on_main_thread_func, units::sample_rate_t sample_rate, nframes_t max_block_length, bool realtime_threads=true, std::optional< juce::AudioWorkgroup > thread_workgroup=std::nullopt)
 Construct a new Graph Scheduler.
 Z_DISABLE_COPY_MOVE (GraphScheduler)
void rechain_from_node_collection (GraphNodeCollection &&nodes, units::sample_rate_t sample_rate, nframes_t max_block_length)
 Steals the nodes from the given collection and prepares for processing.
void start_threads (std::optional< int > num_threads=std::nullopt)
 Starts the threads that will be processing the graph.
void terminate_threads ()
 Tell all threads to terminate.
auto & get_nodes ()
void run_cycle (EngineProcessTimeInfo time_nfo, nframes_t remaining_preroll_frames, const dsp::ITransport &transport)
 To be called repeatedly by a system audio callback thread.
bool contains_thread (RTThreadId::IdType thread_id)
 Returns whether the given thread is one of the graph threads.
auto get_time_nfo () const
auto get_remaining_preroll_frames () const
auto & get_transport_for_this_cycle () const
 Returns the ITransport instance to be used in this cycle.

Friends

class GraphThread

Detailed Description

Manages the scheduling and execution of a graph of DSP nodes.

The GraphScheduler class is responsible for managing the lifecycle of the graph nodes, including starting and terminating the processing threads, triggering the processing of nodes, and coordinating the overall execution of the graph.

The class provides methods to rechain the graph nodes, start and terminate the processing threads, and run a processing cycle. It also includes various internal data structures and synchronization primitives to facilitate the efficient parallel processing of the graph.

TODO: investigate work contracts as a replacement of task queues: https://github.com/buildingcpp/work_contract

Definition at line 58 of file graph_scheduler.h.

Member Typedef Documentation

◆ RunOnMainThreadFunc

using zrythm::dsp::graph::GraphScheduler::RunOnMainThreadFunc = std::function<void (std::function<void ()>)>

Request for a function to run on the main thread (blocking).

Definition at line 68 of file graph_scheduler.h.

Constructor & Destructor Documentation

◆ GraphScheduler()

zrythm::dsp::graph::GraphScheduler::GraphScheduler ( RunOnMainThreadFunc run_on_main_thread_func,
units::sample_rate_t sample_rate,
nframes_t max_block_length,
bool realtime_threads = true,
std::optional< juce::AudioWorkgroup > thread_workgroup = std::nullopt )

Construct a new Graph Scheduler.

Parameters
sample_rateSample rate.
max_block_lengthMaximum block length run_cycle() is expected to be called with.
realtime_threadsWhether to use threads with realtime privileges.
thread_workgroupOptional workgroup (used on Mac).

Member Function Documentation

◆ get_nodes()

auto & zrythm::dsp::graph::GraphScheduler::get_nodes ( )
inline

Definition at line 123 of file graph_scheduler.h.

◆ get_remaining_preroll_frames()

auto zrythm::dsp::graph::GraphScheduler::get_remaining_preroll_frames ( ) const
inline

Definition at line 142 of file graph_scheduler.h.

◆ get_time_nfo()

auto zrythm::dsp::graph::GraphScheduler::get_time_nfo ( ) const
inline

Definition at line 141 of file graph_scheduler.h.

◆ get_transport_for_this_cycle()

auto & zrythm::dsp::graph::GraphScheduler::get_transport_for_this_cycle ( ) const
inline

Returns the ITransport instance to be used in this cycle.

To be called during processing for example by GraphNode's.

Returns
auto&

Definition at line 153 of file graph_scheduler.h.

◆ rechain_from_node_collection()

void zrythm::dsp::graph::GraphScheduler::rechain_from_node_collection ( GraphNodeCollection && nodes,
units::sample_rate_t sample_rate,
nframes_t max_block_length )

Steals the nodes from the given collection and prepares for processing.

Warning
Nodes added here are expected to be unique for their IProcessable's. This means that an IProcessable-derived object may not be in more than one graph at a time, otherwise release_node_resources() may be called while another graph is using them. FIXME: alleviate this but passing the graph to prepare_for_processing/release_resources and having each processable have a separate cache per graph.
Parameters
nodesNodes to steal.
sample_rateThe current sample rate to prepare the nodes for.
block_lengthThe current block length to prepare the nodes for.

◆ run_cycle()

void zrythm::dsp::graph::GraphScheduler::run_cycle ( EngineProcessTimeInfo time_nfo,
nframes_t remaining_preroll_frames,
const dsp::ITransport & transport )

To be called repeatedly by a system audio callback thread.

Parameters
time_nfo
remaining_preroll_frames

◆ start_threads()

void zrythm::dsp::graph::GraphScheduler::start_threads ( std::optional< int > num_threads = std::nullopt)

Starts the threads that will be processing the graph.

Parameters
num_threadsNumber of threads to use. If not set, uses an appropriate number based on the number of cores. If set, the number will be clamped to reasonable bounds.
Exceptions
ZrythmExceptionon failure.

◆ GraphThread

friend class GraphThread
friend

Definition at line 60 of file graph_scheduler.h.


The documentation for this class was generated from the following file: