Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
graph.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2019-2021 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3/*
4 * This file incorporates work covered by the following copyright and
5 * permission notice:
6 *
7 * ---
8 *
9 * Copyright (C) 2017, 2019 Robin Gareus <robin@gareus.org>
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 *
24 * ---
25 */
26
33#ifndef __AUDIO_GRAPH_H__
34#define __AUDIO_GRAPH_H__
35
36#include "dsp/graph_node.h"
37#include "utils/types.h"
38
39#include "zix/sem.h"
40#include <pthread.h>
41
42typedef struct GraphNode GraphNode;
43typedef struct Graph Graph;
44typedef struct MPMCQueue MPMCQueue;
45typedef struct Port Port;
46typedef struct Fader Fader;
47typedef struct Track Track;
48typedef struct SampleProcessor SampleProcessor;
49typedef struct Plugin Plugin;
50typedef struct Position Position;
51typedef struct GraphThread GraphThread;
52typedef struct Router Router;
54
61#define mpmc_queue_push_back_node(q, x) mpmc_queue_push_back (q, (void *) x)
62
63#define mpmc_queue_dequeue_node(q, x) mpmc_queue_dequeue (q, (void **) x)
64
65#define MAX_GRAPH_THREADS 128
66
70typedef struct Graph
71{
74
78
82 GHashTable * graph_nodes;
83
84 /* --- caches for current graph --- */
85 GraphNode * bpm_node;
86 GraphNode * beats_per_bar_node;
87 GraphNode * beat_unit_node;
88
93 size_t n_init_triggers;
94
95 /* Terminal node reference count. */
99 GraphNode ** terminal_nodes;
100
103
106 ZixSem callback_done;
107
109 ZixSem trigger;
110
114
117
120
123
128 GHashTable * setup_graph_nodes;
129
130 GraphNode ** setup_init_trigger_list;
131 size_t num_setup_init_triggers;
132
137 size_t num_setup_terminal_nodes;
138
141
142 /* ------------------------------------ */
143
144 GraphThread * threads[MAX_GRAPH_THREADS];
145 GraphThread * main_thread;
146 gint num_threads;
147
156
159
160} Graph;
161
162void
163graph_print (Graph * graph);
164
165void
166graph_destroy (Graph * graph);
167
168GraphNode *
169graph_find_node_from_port (const Graph * self, const Port * port);
170
171GraphNode *
172graph_find_node_from_plugin (const Graph * self, const Plugin * pl);
173
174GraphNode *
175graph_find_node_from_track (
176 const Graph * self,
177 const Track * track,
178 bool use_setup_nodes);
179
180GraphNode *
181graph_find_node_from_fader (const Graph * self, const Fader * fader);
182
183GraphNode *
184graph_find_node_from_prefader (const Graph * self, const Fader * prefader);
185
186GraphNode *
187graph_find_node_from_sample_processor (
188 const Graph * self,
189 const SampleProcessor * sample_processor);
190
191GraphNode *
192graph_find_node_from_monitor_fader (const Graph * self, const Fader * fader);
193
194GraphNode *
195graph_find_node_from_modulator_macro_processor (
196 const Graph * self,
197 const ModulatorMacroProcessor * processor);
198
199GraphNode *
200graph_find_node_from_channel_send (const Graph * self, const ChannelSend * send);
201
202GraphNode *
203graph_find_initial_processor_node (const Graph * self);
204
205GraphNode *
206graph_find_hw_processor_node (
207 const Graph * self,
208 const HardwareProcessor * processor);
209
214NONNULL GraphNode *
215graph_create_node (Graph * self, GraphNodeType type, void * data);
216
222graph_get_max_route_playback_latency (Graph * graph, bool use_setup_nodes);
223
232HOT void
234
235void
236graph_update_latencies (Graph * self, bool use_setup_nodes);
237
238/*
239 * Adds the graph nodes and connections, then
240 * rechains.
241 *
242 * @param drop_unnecessary_ports Drops any ports
243 * that don't connect anywhere.
244 * @param rechain Whether to rechain or not. If
245 * we are just validating this should be 0.
246 */
247void
248graph_setup (Graph * self, const int drop_unnecessary_ports, const int rechain);
249
263bool
264graph_validate_with_connection (Graph * self, const Port * src, const Port * dest);
265
271int
273
277Graph *
278graph_new_full (Router * router, SampleProcessor * sample_processor);
279
280Graph *
281graph_new (Router * router);
282
286void
288
292void
294
299#endif
Routing graph node.
GraphNodeType
Graph nodes can be either ports or processors.
Definition graph_node.h:67
bool graph_validate_with_connection(Graph *self, const Port *src, const Port *dest)
Adds a new connection for the given src and dest ports and validates the graph.
int graph_start(Graph *graph)
Starts as many threads as there are cores.
void graph_terminate(Graph *self)
Tell all threads to terminate.
void graph_free(Graph *self)
Frees the graph and its members.
NONNULL GraphNode * graph_create_node(Graph *self, GraphNodeType type, void *data)
Creates a new node, adds it to the graph and returns it.
nframes_t graph_get_max_route_playback_latency(Graph *graph, bool use_setup_nodes)
Returns the max playback latency of the trigger nodes.
HOT void graph_on_reached_terminal_node(Graph *self)
Called from a terminal node (from the Graph worked-thread) to indicate it has completed processing.
Graph * graph_new_full(Router *router, SampleProcessor *sample_processor)
Returns a new graph.
uint32_t nframes_t
Frame count.
Definition types.h:39
Channel send.
A Fader is a processor that is used for volume controls and pan.
Definition fader.h:91
A node in the processing graph.
Definition graph_node.h:104
Graph.
Definition graph.h:71
Router * router
Pointer back to router for convenience.
Definition graph.h:73
gint n_terminal_nodes
Number of graph nodes without an outgoing edge.
Definition graph.h:98
ZixSem callback_start
Synchronization with main process callback.
Definition graph.h:105
GPtrArray * external_out_ports
An array of pointers to ports that are exposed to the backend and are outputs.
Definition graph.h:155
MPMCQueue * trigger_queue
Queue containing nodes that can be processed.
Definition graph.h:113
SampleProcessor * sample_processor
Sample processor, if temporary graph for sample processor.
Definition graph.h:158
int initial_processor
Dummy member to make lookups work.
Definition graph.h:140
int destroying
Flag to indicate if graph is currently getting destroyed.
Definition graph.h:77
ZixSem trigger
Wake up graph node process threads.
Definition graph.h:109
GHashTable * setup_graph_nodes
Chain used to setup in the background.
Definition graph.h:128
gint terminate
flag to exit, terminate all process-threads
Definition graph.h:119
gint terminal_refcnt
Remaining unprocessed terminal nodes in this cycle.
Definition graph.h:102
GHashTable * graph_nodes
List of all graph nodes (only used for memory management)
Definition graph.h:82
GraphNode ** init_trigger_list
Nodes without incoming edges.
Definition graph.h:92
GraphNode ** setup_terminal_nodes
Used only when constructing the graph so we can traverse the graph backwards to calculate the playbac...
Definition graph.h:136
guint trigger_queue_size
Number of entries in trigger queue.
Definition graph.h:116
guint idle_thread_cnt
Number of threads waiting for work.
Definition graph.h:122
Hardware processor.
Multiple Producer Multiple Consumer lock-free queue.
Definition mpmc_queue.h:69
Modulator macro button processor.
The base plugin Inheriting plugins must have this as a child.
Definition plugin.h:74
Must ONLY be created via port_new()
Definition port.h:136
A Position is made up of bars.beats.sixteenths.ticks.
Definition position.h:124
A processor to be used in the routing graph for playing samples independent of the timeline.
Track to be inserted into the Project's Tracklist.
Definition track.h:177
Custom types.