comparison DPF-Prymula-audioplugins/dpf/distrho/src/jackbridge/JackBridge.hpp @ 3:84e66ea83026

DPF-Prymula-audioplugins-0.231015-2
author prymula <prymula76@outlook.com>
date Mon, 16 Oct 2023 21:53:34 +0200
parents
children
comparison
equal deleted inserted replaced
2:cf2cb71d31dd 3:84e66ea83026
1 /*
2 * JackBridge for DPF
3 * Copyright (C) 2013-2021 Filipe Coelho <falktx@falktx.com>
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any purpose with
6 * or without fee is hereby granted, provided that the above copyright notice and this
7 * permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
10 * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
11 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #ifndef JACKBRIDGE_HPP_INCLUDED
18 #define JACKBRIDGE_HPP_INCLUDED
19
20 #ifdef __WINE__
21 # if defined(WIN64) || defined(_WIN64) || defined(__WIN64__)
22 # define __WINE64__
23 # endif
24 # undef WIN32
25 # undef WIN64
26 # undef _WIN32
27 # undef _WIN64
28 # undef __WIN32__
29 # undef __WIN64__
30 #endif
31
32 #include "../DistrhoDefines.h"
33
34 #if (defined(__WINE__) || defined(DISTRHO_OS_WINDOWS)) && defined(__cdecl)
35 # define JACKBRIDGE_API __cdecl
36 #else
37 # define JACKBRIDGE_API
38 #endif
39
40 #ifdef JACKBRIDGE_DIRECT
41 # include <jack/jack.h>
42 # include <jack/midiport.h>
43 # include <jack/transport.h>
44 # include <jack/session.h>
45 # include <jack/metadata.h>
46 # include <jack/uuid.h>
47 #else
48
49 #include <cstddef>
50
51 #ifdef DISTRHO_PROPER_CPP11_SUPPORT
52 # include <cstdint>
53 #else
54 # include <stdint.h>
55 #endif
56
57 #ifndef POST_PACKED_STRUCTURE
58 # if defined(__GNUC__)
59 /* POST_PACKED_STRUCTURE needs to be a macro which
60 expands into a compiler directive. The directive must
61 tell the compiler to arrange the preceding structure
62 declaration so that it is packed on byte-boundaries rather
63 than use the natural alignment of the processor and/or
64 compiler.
65 */
66 #define PRE_PACKED_STRUCTURE
67 #define POST_PACKED_STRUCTURE __attribute__((__packed__))
68 # elif defined(_MSC_VER)
69 #define PRE_PACKED_STRUCTURE1 __pragma(pack(push,1))
70 #define PRE_PACKED_STRUCTURE PRE_PACKED_STRUCTURE1
71 /* PRE_PACKED_STRUCTURE needs to be a macro which
72 expands into a compiler directive. The directive must
73 tell the compiler to arrange the following structure
74 declaration so that it is packed on byte-boundaries rather
75 than use the natural alignment of the processor and/or
76 compiler.
77 */
78 #define POST_PACKED_STRUCTURE ;__pragma(pack(pop))
79 /* and POST_PACKED_STRUCTURE needs to be a macro which
80 restores the packing to its previous setting */
81 # else
82 #define PRE_PACKED_STRUCTURE
83 #define POST_PACKED_STRUCTURE
84 # endif
85 #endif
86
87 #define JACK_DEFAULT_AUDIO_TYPE "32 bit float mono audio"
88 #define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi"
89
90 #define JACK_MAX_FRAMES (4294967295U)
91
92 #define JackOpenOptions (JackSessionID|JackServerName|JackNoStartServer|JackUseExactName)
93 #define JackLoadOptions (JackLoadInit|JackLoadName|JackUseExactName)
94
95 #define JACK_POSITION_MASK (JackPositionBBT|JackPositionTimecode|JackBBTFrameOffset|JackAudioVideoRatio|JackVideoFrameOffset)
96 #define EXTENDED_TIME_INFO
97
98 #define JACK_UUID_SIZE 36
99 #define JACK_UUID_STRING_SIZE (JACK_UUID_SIZE+1) /* includes trailing null */
100 #define JACK_UUID_EMPTY_INITIALIZER 0
101
102 #define JACK_TICK_DOUBLE
103
104 extern "C" {
105
106 enum JackOptions {
107 JackNullOption = 0x00,
108 JackNoStartServer = 0x01,
109 JackUseExactName = 0x02,
110 JackServerName = 0x04,
111 JackLoadName = 0x08,
112 JackLoadInit = 0x10,
113 JackSessionID = 0x20
114 };
115
116 enum JackStatus {
117 JackFailure = 0x0001,
118 JackInvalidOption = 0x0002,
119 JackNameNotUnique = 0x0004,
120 JackServerStarted = 0x0008,
121 JackServerFailed = 0x0010,
122 JackServerError = 0x0020,
123 JackNoSuchClient = 0x0040,
124 JackLoadFailure = 0x0080,
125 JackInitFailure = 0x0100,
126 JackShmFailure = 0x0200,
127 JackVersionError = 0x0400,
128 JackBackendError = 0x0800,
129 JackClientZombie = 0x1000,
130 JackBridgeNativeFailed = 0x10000
131 };
132
133 enum JackLatencyCallbackMode {
134 JackCaptureLatency,
135 JackPlaybackLatency
136 };
137
138 enum JackPortFlags {
139 JackPortIsInput = 0x01,
140 JackPortIsOutput = 0x02,
141 JackPortIsPhysical = 0x04,
142 JackPortCanMonitor = 0x08,
143 JackPortIsTerminal = 0x10,
144 JackPortIsControlVoltage = 0x100
145 };
146
147 enum JackTransportState {
148 JackTransportStopped = 0,
149 JackTransportRolling = 1,
150 JackTransportLooping = 2,
151 JackTransportStarting = 3
152 };
153
154 enum JackPositionBits {
155 JackPositionBBT = 0x010,
156 JackPositionTimecode = 0x020,
157 JackBBTFrameOffset = 0x040,
158 JackAudioVideoRatio = 0x080,
159 JackVideoFrameOffset = 0x100,
160 JackTickDouble = 0x200
161 };
162
163 enum JackSessionEventType {
164 JackSessionSave = 1,
165 JackSessionSaveAndQuit = 2,
166 JackSessionSaveTemplate = 3
167 };
168
169 enum JackSessionFlags {
170 JackSessionSaveError = 0x1,
171 JackSessionNeedTerminal = 0x2
172 };
173
174 enum JackPropertyChange {
175 PropertyCreated,
176 PropertyChanged,
177 PropertyDeleted
178 };
179
180 typedef uint32_t jack_nframes_t;
181 typedef uint32_t jack_port_id_t;
182 typedef uint64_t jack_time_t;
183 typedef uint64_t jack_uuid_t;
184 typedef uint64_t jack_unique_t;
185 typedef uchar jack_midi_data_t;
186 typedef float jack_default_audio_sample_t;
187
188 typedef enum JackOptions jack_options_t;
189 typedef enum JackStatus jack_status_t;
190 typedef enum JackLatencyCallbackMode jack_latency_callback_mode_t;
191 typedef enum JackTransportState jack_transport_state_t;
192 typedef enum JackPositionBits jack_position_bits_t;
193 typedef enum JackSessionEventType jack_session_event_type_t;
194 typedef enum JackSessionFlags jack_session_flags_t;
195 typedef enum JackPropertyChange jack_property_change_t;
196
197 struct _jack_midi_event {
198 jack_nframes_t time;
199 size_t size;
200 jack_midi_data_t* buffer;
201 };
202
203 // NOTE: packed in JACK2 but not in JACK1
204 PRE_PACKED_STRUCTURE
205 struct _jack_latency_range {
206 jack_nframes_t min;
207 jack_nframes_t max;
208 } POST_PACKED_STRUCTURE;
209
210 PRE_PACKED_STRUCTURE
211 struct _jack_position {
212 jack_unique_t unique_1;
213 jack_time_t usecs;
214 jack_nframes_t frame_rate;
215 jack_nframes_t frame;
216 jack_position_bits_t valid;
217 int32_t bar;
218 int32_t beat;
219 int32_t tick;
220 double bar_start_tick;
221 float beats_per_bar;
222 float beat_type;
223 double ticks_per_beat;
224 double beats_per_minute;
225 double frame_time;
226 double next_time;
227 jack_nframes_t bbt_offset;
228 float audio_frames_per_video_frame;
229 jack_nframes_t video_offset;
230 double tick_double;
231 int32_t padding[5];
232 jack_unique_t unique_2;
233 } POST_PACKED_STRUCTURE;
234
235 struct _jack_session_event {
236 jack_session_event_type_t type;
237 const char* session_dir;
238 const char* client_uuid;
239 char* command_line;
240 jack_session_flags_t flags;
241 uint32_t future;
242 };
243
244 struct _jack_session_command_t {
245 const char* uuid;
246 const char* client_name;
247 const char* command;
248 jack_session_flags_t flags;
249 };
250
251 typedef struct {
252 const char* key;
253 const char* data;
254 const char* type;
255 } jack_property_t;
256
257 typedef struct {
258 jack_uuid_t subject;
259 uint32_t property_cnt;
260 jack_property_t* properties;
261 uint32_t property_size;
262 } jack_description_t;
263
264 typedef struct _jack_port jack_port_t;
265 typedef struct _jack_client jack_client_t;
266 typedef struct _jack_midi_event jack_midi_event_t;
267 typedef struct _jack_latency_range jack_latency_range_t;
268 typedef struct _jack_position jack_position_t;
269 typedef struct _jack_session_event jack_session_event_t;
270 typedef struct _jack_session_command_t jack_session_command_t;
271
272 typedef void (JACKBRIDGE_API *JackLatencyCallback)(jack_latency_callback_mode_t mode, void* arg);
273 typedef int (JACKBRIDGE_API *JackProcessCallback)(jack_nframes_t nframes, void* arg);
274 typedef void (JACKBRIDGE_API *JackThreadInitCallback)(void* arg);
275 typedef int (JACKBRIDGE_API *JackGraphOrderCallback)(void* arg);
276 typedef int (JACKBRIDGE_API *JackXRunCallback)(void* arg);
277 typedef int (JACKBRIDGE_API *JackBufferSizeCallback)(jack_nframes_t nframes, void* arg);
278 typedef int (JACKBRIDGE_API *JackSampleRateCallback)(jack_nframes_t nframes, void* arg);
279 typedef void (JACKBRIDGE_API *JackPortRegistrationCallback)(jack_port_id_t port, int register_, void* arg);
280 typedef void (JACKBRIDGE_API *JackClientRegistrationCallback)(const char* name, int register_, void* arg);
281 typedef void (JACKBRIDGE_API *JackPortConnectCallback)(jack_port_id_t a, jack_port_id_t b, int connect, void* arg);
282 typedef void (JACKBRIDGE_API *JackPortRenameCallback)(jack_port_id_t port, const char* old_name, const char* new_name, void* arg);
283 typedef void (JACKBRIDGE_API *JackFreewheelCallback)(int starting, void* arg);
284 typedef void (JACKBRIDGE_API *JackShutdownCallback)(void* arg);
285 typedef void (JACKBRIDGE_API *JackInfoShutdownCallback)(jack_status_t code, const char* reason, void* arg);
286 typedef int (JACKBRIDGE_API *JackSyncCallback)(jack_transport_state_t state, jack_position_t* pos, void* arg);
287 typedef void (JACKBRIDGE_API *JackTimebaseCallback)(jack_transport_state_t state, jack_nframes_t nframes, jack_position_t* pos, int new_pos, void* arg);
288 typedef void (JACKBRIDGE_API *JackSessionCallback)(jack_session_event_t* event, void* arg);
289 typedef void (JACKBRIDGE_API *JackPropertyChangeCallback)(jack_uuid_t subject, const char* key, jack_property_change_t change, void* arg);
290 typedef void *(JACKBRIDGE_API *JackThreadCallback)(void* arg);
291
292 } // extern "C"
293
294 #endif // ! JACKBRIDGE_DIRECT
295
296 JACKBRIDGE_API bool jackbridge_is_ok() noexcept;
297 JACKBRIDGE_API void jackbridge_init();
298
299 JACKBRIDGE_API void jackbridge_get_version(int* major_ptr, int* minor_ptr, int* micro_ptr, int* proto_ptr);
300 JACKBRIDGE_API const char* jackbridge_get_version_string();
301
302 JACKBRIDGE_API jack_client_t* jackbridge_client_open(const char* client_name, uint32_t options, jack_status_t* status);
303 JACKBRIDGE_API bool jackbridge_client_close(jack_client_t* client);
304
305 JACKBRIDGE_API int jackbridge_client_name_size();
306 JACKBRIDGE_API const char* jackbridge_get_client_name(jack_client_t* client);
307
308 JACKBRIDGE_API char* jackbridge_client_get_uuid(jack_client_t* client);
309 JACKBRIDGE_API char* jackbridge_get_uuid_for_client_name(jack_client_t* client, const char* name);
310 JACKBRIDGE_API char* jackbridge_get_client_name_by_uuid(jack_client_t* client, const char* uuid);
311
312 JACKBRIDGE_API bool jackbridge_uuid_parse(const char* buf, jack_uuid_t* uuid);
313 JACKBRIDGE_API void jackbridge_uuid_unparse(jack_uuid_t uuid, char buf[JACK_UUID_STRING_SIZE]);
314
315 JACKBRIDGE_API bool jackbridge_activate(jack_client_t* client);
316 JACKBRIDGE_API bool jackbridge_deactivate(jack_client_t* client);
317 JACKBRIDGE_API bool jackbridge_is_realtime(jack_client_t* client);
318
319 JACKBRIDGE_API bool jackbridge_set_thread_init_callback(jack_client_t* client, JackThreadInitCallback thread_init_callback, void* arg);
320 JACKBRIDGE_API void jackbridge_on_shutdown(jack_client_t* client, JackShutdownCallback shutdown_callback, void* arg);
321 JACKBRIDGE_API void jackbridge_on_info_shutdown(jack_client_t* client, JackInfoShutdownCallback shutdown_callback, void* arg);
322 JACKBRIDGE_API bool jackbridge_set_process_callback(jack_client_t* client, JackProcessCallback process_callback, void* arg);
323 JACKBRIDGE_API bool jackbridge_set_freewheel_callback(jack_client_t* client, JackFreewheelCallback freewheel_callback, void* arg);
324 JACKBRIDGE_API bool jackbridge_set_buffer_size_callback(jack_client_t* client, JackBufferSizeCallback bufsize_callback, void* arg);
325 JACKBRIDGE_API bool jackbridge_set_sample_rate_callback(jack_client_t* client, JackSampleRateCallback srate_callback, void* arg);
326 JACKBRIDGE_API bool jackbridge_set_client_registration_callback(jack_client_t* client, JackClientRegistrationCallback registration_callback, void* arg);
327 JACKBRIDGE_API bool jackbridge_set_port_registration_callback(jack_client_t* client, JackPortRegistrationCallback registration_callback, void* arg);
328 JACKBRIDGE_API bool jackbridge_set_port_rename_callback(jack_client_t* client, JackPortRenameCallback rename_callback, void* arg);
329 JACKBRIDGE_API bool jackbridge_set_port_connect_callback(jack_client_t* client, JackPortConnectCallback connect_callback, void* arg);
330 JACKBRIDGE_API bool jackbridge_set_graph_order_callback(jack_client_t* client, JackGraphOrderCallback graph_callback, void* arg);
331 JACKBRIDGE_API bool jackbridge_set_xrun_callback(jack_client_t* client, JackXRunCallback xrun_callback, void* arg);
332 JACKBRIDGE_API bool jackbridge_set_latency_callback(jack_client_t* client, JackLatencyCallback latency_callback, void* arg);
333
334 JACKBRIDGE_API bool jackbridge_set_freewheel(jack_client_t* client, bool onoff);
335 JACKBRIDGE_API bool jackbridge_set_buffer_size(jack_client_t* client, jack_nframes_t nframes);
336
337 JACKBRIDGE_API jack_nframes_t jackbridge_get_sample_rate(jack_client_t* client);
338 JACKBRIDGE_API jack_nframes_t jackbridge_get_buffer_size(jack_client_t* client);
339 JACKBRIDGE_API float jackbridge_cpu_load(jack_client_t* client);
340
341 JACKBRIDGE_API jack_port_t* jackbridge_port_register(jack_client_t* client, const char* port_name, const char* port_type, uint64_t flags, uint64_t buffer_size);
342 JACKBRIDGE_API bool jackbridge_port_unregister(jack_client_t* client, jack_port_t* port);
343 JACKBRIDGE_API void* jackbridge_port_get_buffer(jack_port_t* port, jack_nframes_t nframes);
344
345 JACKBRIDGE_API const char* jackbridge_port_name(const jack_port_t* port);
346 JACKBRIDGE_API jack_uuid_t jackbridge_port_uuid(const jack_port_t* port);
347 JACKBRIDGE_API const char* jackbridge_port_short_name(const jack_port_t* port);
348 JACKBRIDGE_API int jackbridge_port_flags(const jack_port_t* port);
349 JACKBRIDGE_API const char* jackbridge_port_type(const jack_port_t* port);
350 JACKBRIDGE_API bool jackbridge_port_is_mine(const jack_client_t* client, const jack_port_t* port);
351 JACKBRIDGE_API int jackbridge_port_connected(const jack_port_t* port);
352 JACKBRIDGE_API bool jackbridge_port_connected_to(const jack_port_t* port, const char* port_name);
353 JACKBRIDGE_API const char** jackbridge_port_get_connections(const jack_port_t* port);
354 JACKBRIDGE_API const char** jackbridge_port_get_all_connections(const jack_client_t* client, const jack_port_t* port);
355
356 JACKBRIDGE_API bool jackbridge_port_rename(jack_client_t* client, jack_port_t* port, const char* port_name);
357 JACKBRIDGE_API bool jackbridge_port_set_alias(jack_port_t* port, const char* alias);
358 JACKBRIDGE_API bool jackbridge_port_unset_alias(jack_port_t* port, const char* alias);
359 JACKBRIDGE_API int jackbridge_port_get_aliases(const jack_port_t* port, char* const al[2]);
360
361 JACKBRIDGE_API bool jackbridge_port_request_monitor(jack_port_t* port, bool onoff);
362 JACKBRIDGE_API bool jackbridge_port_request_monitor_by_name(jack_client_t* client, const char* port_name, bool onoff);
363 JACKBRIDGE_API bool jackbridge_port_ensure_monitor(jack_port_t* port, bool onoff);
364 JACKBRIDGE_API bool jackbridge_port_monitoring_input(jack_port_t* port);
365
366 JACKBRIDGE_API bool jackbridge_connect(jack_client_t* client, const char* source_port, const char* destination_port);
367 JACKBRIDGE_API bool jackbridge_disconnect(jack_client_t* client, const char* source_port, const char* destination_port);
368 JACKBRIDGE_API bool jackbridge_port_disconnect(jack_client_t* client, jack_port_t* port);
369
370 JACKBRIDGE_API int jackbridge_port_name_size();
371 JACKBRIDGE_API int jackbridge_port_type_size();
372 JACKBRIDGE_API uint32_t jackbridge_port_type_get_buffer_size(jack_client_t* client, const char* port_type);
373
374 JACKBRIDGE_API void jackbridge_port_get_latency_range(jack_port_t* port, uint32_t mode, jack_latency_range_t* range);
375 JACKBRIDGE_API void jackbridge_port_set_latency_range(jack_port_t* port, uint32_t mode, jack_latency_range_t* range);
376 JACKBRIDGE_API bool jackbridge_recompute_total_latencies(jack_client_t* client);
377
378 JACKBRIDGE_API const char** jackbridge_get_ports(jack_client_t* client, const char* port_name_pattern, const char* type_name_pattern, uint64_t flags);
379 JACKBRIDGE_API jack_port_t* jackbridge_port_by_name(jack_client_t* client, const char* port_name);
380 JACKBRIDGE_API jack_port_t* jackbridge_port_by_id(jack_client_t* client, jack_port_id_t port_id);
381
382 JACKBRIDGE_API void jackbridge_free(void* ptr);
383
384 JACKBRIDGE_API uint32_t jackbridge_midi_get_event_count(void* port_buffer);
385 JACKBRIDGE_API bool jackbridge_midi_event_get(jack_midi_event_t* event, void* port_buffer, uint32_t event_index);
386 JACKBRIDGE_API void jackbridge_midi_clear_buffer(void* port_buffer);
387 JACKBRIDGE_API bool jackbridge_midi_event_write(void* port_buffer, jack_nframes_t time, const jack_midi_data_t* data, uint32_t data_size);
388 JACKBRIDGE_API jack_midi_data_t* jackbridge_midi_event_reserve(void* port_buffer, jack_nframes_t time, uint32_t data_size);
389
390 JACKBRIDGE_API bool jackbridge_release_timebase(jack_client_t* client);
391 JACKBRIDGE_API bool jackbridge_set_sync_callback(jack_client_t* client, JackSyncCallback sync_callback, void* arg);
392 JACKBRIDGE_API bool jackbridge_set_sync_timeout(jack_client_t* client, jack_time_t timeout);
393 JACKBRIDGE_API bool jackbridge_set_timebase_callback(jack_client_t* client, bool conditional, JackTimebaseCallback timebase_callback, void* arg);
394 JACKBRIDGE_API bool jackbridge_transport_locate(jack_client_t* client, jack_nframes_t frame);
395
396 JACKBRIDGE_API uint32_t jackbridge_transport_query(const jack_client_t* client, jack_position_t* pos);
397 JACKBRIDGE_API jack_nframes_t jackbridge_get_current_transport_frame(const jack_client_t* client);
398
399 JACKBRIDGE_API bool jackbridge_transport_reposition(jack_client_t* client, const jack_position_t* pos);
400 JACKBRIDGE_API void jackbridge_transport_start(jack_client_t* client);
401 JACKBRIDGE_API void jackbridge_transport_stop(jack_client_t* client);
402
403 JACKBRIDGE_API bool jackbridge_set_property(jack_client_t* client, jack_uuid_t subject, const char* key, const char* value, const char* type);
404 JACKBRIDGE_API bool jackbridge_get_property(jack_uuid_t subject, const char* key, char** value, char** type);
405 JACKBRIDGE_API void jackbridge_free_description(jack_description_t* desc, bool free_description_itself);
406 JACKBRIDGE_API bool jackbridge_get_properties(jack_uuid_t subject, jack_description_t* desc);
407 JACKBRIDGE_API bool jackbridge_get_all_properties(jack_description_t** descs);
408 JACKBRIDGE_API bool jackbridge_remove_property(jack_client_t* client, jack_uuid_t subject, const char* key);
409 JACKBRIDGE_API int jackbridge_remove_properties(jack_client_t* client, jack_uuid_t subject);
410 JACKBRIDGE_API bool jackbridge_remove_all_properties(jack_client_t* client);
411 JACKBRIDGE_API bool jackbridge_set_property_change_callback(jack_client_t* client, JackPropertyChangeCallback callback, void* arg);
412
413 JACKBRIDGE_API bool jackbridge_set_process_thread(jack_client_t* client, JackThreadCallback callback, void* arg);
414 JACKBRIDGE_API jack_nframes_t jackbridge_cycle_wait(jack_client_t* client);
415 JACKBRIDGE_API void jackbridge_cycle_signal(jack_client_t* client, int status);
416
417 #endif // JACKBRIDGE_HPP_INCLUDED