Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
router.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_ROUTING_H__
34#define __AUDIO_ROUTING_H__
35
36#include "zrythm-config.h"
37
38#ifdef HAVE_C11_THREADS
39# include <threads.h>
40#endif
41
42#include "dsp/engine.h"
43#include "dsp/graph.h"
44#include "dsp/graph_thread.h"
45#include "utils/types.h"
46
47#include "gtk_wrapper.h"
48#include "zix/ring.h"
49#include "zix/sem.h"
50#include <pthread.h>
51
52typedef struct GraphNode GraphNode;
53typedef struct Graph Graph;
54typedef struct PassthroughProcessor PassthroughProcessor;
55typedef struct MPMCQueue MPMCQueue;
56typedef struct Port Port;
57typedef struct Fader Fader;
58typedef struct Track Track;
59typedef struct Plugin Plugin;
60typedef struct Position Position;
63
70#define ROUTER (AUDIO_ENGINE->router)
71
72typedef struct Router
73{
74 Graph * graph;
75
79
82
85
90
93
94 bool callback_in_progress;
95
98
102
103} Router;
104
105Router *
106router_new (void);
107
113void
114router_recalc_graph (Router * self, bool soft);
115
119void
121
128
133WARN_UNUSED_RESULT HOT NONNULL
134 ACCESS_READ_ONLY (1) static inline bool router_is_processing_kickoff_thread (
135 const Router * const self)
136{
137 return g_thread_self () == self->process_kickoff_thread;
138}
139
143WARN_UNUSED_RESULT HOT NONNULL ACCESS_READ_ONLY (
144 1) static inline bool router_is_processing_thread (const Router * const self)
145{
146#ifdef HAVE_C11_THREADS
147 /* this is called too often so use this optimization */
148 static thread_local bool have_result = false;
149 static thread_local bool is_processing_thread = false;
150#else
151 bool have_result = false;
152 bool is_processing_thread = false;
153#endif
154
155 if (G_LIKELY (have_result))
156 {
157 return is_processing_thread;
158 }
159
160 if (G_UNLIKELY (!self->graph))
161 {
162 have_result = false;
163 is_processing_thread = false;
164 return false;
165 }
166
167 for (int j = 0; j < self->graph->num_threads; j++)
168 {
169 if (pthread_equal (pthread_self (), self->graph->threads[j]->pthread))
170 {
171 is_processing_thread = true;
172 have_result = true;
173 return true;
174 }
175 }
176
177 if (
178 self->graph->main_thread
179 && pthread_equal (pthread_self (), self->graph->main_thread->pthread))
180 {
181 is_processing_thread = true;
182 have_result = true;
183 return true;
184 }
185
186 have_result = true;
187 is_processing_thread = false;
188 return false;
189}
190
198NONNULL void
200 Router * self,
201 const ControlPortChange * change);
202
203void
204router_free (Router * self);
205
210#endif
The audio engine.
Routing graph.
Routing graph thread.
nframes_t router_get_max_route_playback_latency(Router *router)
Returns the max playback latency of the trigger nodes.
void router_start_cycle(Router *self, EngineProcessTimeInfo time_nfo)
Starts a new cycle.
NONNULL void router_queue_control_port_change(Router *self, const ControlPortChange *change)
Queues a control port change to be applied when processing starts.
WARN_UNUSED_RESULT HOT NONNULL ACCESS_READ_ONLY(1) static inline bool router_is_processing_kickoff_thread(const Router *const self)
Returns whether this is the thread that kicks off processing (thread that calls router_start_cycle())...
Definition router.h:134
void router_recalc_graph(Router *self, bool soft)
Recalculates the process acyclic directed graph.
uint32_t nframes_t
Frame count.
Definition types.h:39
Used for queueing changes to be applied during processing.
Common struct to pass around during processing to avoid repeating the data in function arguments.
Definition types.h:142
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
Multiple Producer Multiple Consumer lock-free queue.
Definition mpmc_queue.h:69
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
EngineProcessTimeInfo time_nfo
Time info for this processing cycle.
Definition router.h:81
ZixRing * ctrl_port_change_queue
Message queue for control port changes, used for BPM/time signature changes.
Definition router.h:101
int graph_setup_in_progress
An atomic variable to check if the graph is currently being setup (so that we can avoid accessing buf...
Definition router.h:78
ZixSem graph_access
Used when recalculating the graph.
Definition router.h:92
nframes_t global_offset
Current global latency offset (max latency of all routes - remaining latency from engine).
Definition router.h:89
nframes_t max_route_playback_latency
Stored for the currently processing cycle.
Definition router.h:84
GThread * process_kickoff_thread
Thread that calls kicks off the cycle.
Definition router.h:97
Track to be inserted into the Project's Tracklist.
Definition track.h:177
Custom types.