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/gtk.h>
48
49#include "zix/ring.h"
50#include "zix/sem.h"
51#include <pthread.h>
52
53typedef struct GraphNode GraphNode;
54typedef struct Graph Graph;
55typedef struct PassthroughProcessor PassthroughProcessor;
56typedef struct MPMCQueue MPMCQueue;
57typedef struct Port Port;
58typedef struct Fader Fader;
59typedef struct Track Track;
60typedef struct Plugin Plugin;
61typedef struct Position Position;
64
65#ifdef HAVE_JACK
66# include "weak_libjack.h"
67#endif
68
75#define ROUTER (AUDIO_ENGINE->router)
76
77typedef struct Router
78{
79 Graph * graph;
80
84
87
90
95
98
99 bool callback_in_progress;
100
103
107
108} Router;
109
110Router *
111router_new (void);
112
118void
119router_recalc_graph (Router * self, bool soft);
120
124void
126
133
138WARN_UNUSED_RESULT HOT NONNULL
139 ACCESS_READ_ONLY (1) static inline bool router_is_processing_kickoff_thread (
140 const Router * const self)
141{
142 return g_thread_self () == self->process_kickoff_thread;
143}
144
148WARN_UNUSED_RESULT HOT NONNULL ACCESS_READ_ONLY (
149 1) static inline bool router_is_processing_thread (const Router * const self)
150{
151#ifdef HAVE_C11_THREADS
152 /* this is called too often so use this optimization */
153 static thread_local bool have_result = false;
154 static thread_local bool is_processing_thread = false;
155#else
156 bool have_result = false;
157 bool is_processing_thread = false;
158#endif
159
160 if (G_LIKELY (have_result))
161 {
162 return is_processing_thread;
163 }
164
165 if (G_UNLIKELY (!self->graph))
166 {
167 have_result = false;
168 is_processing_thread = false;
169 return false;
170 }
171
172 for (int j = 0; j < self->graph->num_threads; j++)
173 {
174 if (pthread_equal (pthread_self (), self->graph->threads[j]->pthread))
175 {
176 is_processing_thread = true;
177 have_result = true;
178 return true;
179 }
180 }
181
182 if (
183 self->graph->main_thread
184 && pthread_equal (pthread_self (), self->graph->main_thread->pthread))
185 {
186 is_processing_thread = true;
187 have_result = true;
188 return true;
189 }
190
191 have_result = true;
192 is_processing_thread = false;
193 return false;
194}
195
203NONNULL void
205 Router * self,
206 const ControlPortChange * change);
207
208void
209router_free (Router * self);
210
215#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:139
void router_recalc_graph(Router *self, bool soft)
Recalculates the process acyclic directed graph.
uint32_t nframes_t
Frame count.
Definition types.h:35
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:138
A Fader is a processor that is used for volume controls and pan.
Definition fader.h:118
A node in the processing graph.
Definition graph_node.h:106
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:138
A Position is made up of bars.beats.sixteenths.ticks.
Definition position.h:129
EngineProcessTimeInfo time_nfo
Time info for this processing cycle.
Definition router.h:86
ZixRing * ctrl_port_change_queue
Message queue for control port changes, used for BPM/time signature changes.
Definition router.h:106
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:83
ZixSem graph_access
Used when recalculating the graph.
Definition router.h:97
nframes_t global_offset
Current global latency offset (max latency of all routes - remaining latency from engine).
Definition router.h:94
nframes_t max_route_playback_latency
Stored for the currently processing cycle.
Definition router.h:89
GThread * process_kickoff_thread
Thread that calls kicks off the cycle.
Definition router.h:102
Track to be inserted into the Project's Tracklist.
Definition track.h:186
Custom types.