|
Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
|
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 |
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.
| 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.
| 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.
| sample_rate | Sample rate. |
| max_block_length | Maximum block length run_cycle() is expected to be called with. |
| realtime_threads | Whether to use threads with realtime privileges. |
| thread_workgroup | Optional workgroup (used on Mac). |
|
inline |
Definition at line 123 of file graph_scheduler.h.
|
inline |
Definition at line 142 of file graph_scheduler.h.
|
inline |
Definition at line 141 of file graph_scheduler.h.
|
inline |
Returns the ITransport instance to be used in this cycle.
To be called during processing for example by GraphNode's.
Definition at line 153 of file graph_scheduler.h.
| 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.
| nodes | Nodes to steal. |
| sample_rate | The current sample rate to prepare the nodes for. |
| block_length | The current block length to prepare the nodes for. |
| 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.
| time_nfo | |
| remaining_preroll_frames |
| void zrythm::dsp::graph::GraphScheduler::start_threads | ( | std::optional< int > | num_threads = std::nullopt | ) |
Starts the threads that will be processing the graph.
| num_threads | Number 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. |
| ZrythmException | on failure. |
|
friend |
Definition at line 60 of file graph_scheduler.h.