3 * Copyright (C) 2013-2019 Filipe Coelho <falktx@falktx.com>
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.
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.
17 #ifndef JACKBRIDGE_HPP_INCLUDED
18 #define JACKBRIDGE_HPP_INCLUDED
21 # if defined(WIN64) || defined(_WIN64) || defined(__WIN64__)
32 #include "CarlaDefines.h"
34 #if (defined(__WINE__) || defined(CARLA_OS_WIN)) && defined(__cdecl)
35 # define JACKBRIDGE_API __cdecl
37 # define JACKBRIDGE_API
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>
51 #ifdef CARLA_PROPER_CPP11_SUPPORT
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
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
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 */
82 #define PRE_PACKED_STRUCTURE
83 #define POST_PACKED_STRUCTURE
87 #if (defined(__arm__) || defined(__aarch64__) || defined(__mips__) || defined(__ppc__) || defined(__powerpc__)) && !defined(__APPLE__)
88 # undef POST_PACKED_STRUCTURE
89 # define POST_PACKED_STRUCTURE
92 #define JACK_DEFAULT_AUDIO_TYPE "32 bit float mono audio"
93 #define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi"
95 #define JACK_MAX_FRAMES (4294967295U)
97 #define JackOpenOptions (JackSessionID|JackServerName|JackNoStartServer|JackUseExactName)
98 #define JackLoadOptions (JackLoadInit|JackLoadName|JackUseExactName)
100 #define JACK_POSITION_MASK (JackPositionBBT|JackPositionTimecode|JackBBTFrameOffset|JackAudioVideoRatio|JackVideoFrameOffset)
101 #define EXTENDED_TIME_INFO
103 #define JACK_UUID_SIZE 36
104 #define JACK_UUID_STRING_SIZE (JACK_UUID_SIZE+1) /* includes trailing null */
106 #define JACK_TICK_DOUBLE
111 JackNullOption
= 0x00,
112 JackNoStartServer
= 0x01,
113 JackUseExactName
= 0x02,
114 JackServerName
= 0x04,
121 JackFailure
= 0x0001,
122 JackInvalidOption
= 0x0002,
123 JackNameNotUnique
= 0x0004,
124 JackServerStarted
= 0x0008,
125 JackServerFailed
= 0x0010,
126 JackServerError
= 0x0020,
127 JackNoSuchClient
= 0x0040,
128 JackLoadFailure
= 0x0080,
129 JackInitFailure
= 0x0100,
130 JackShmFailure
= 0x0200,
131 JackVersionError
= 0x0400,
132 JackBackendError
= 0x0800,
133 JackClientZombie
= 0x1000,
134 JackBridgeNativeFailed
= 0x10000
137 enum JackLatencyCallbackMode
{
143 JackPortIsInput
= 0x01,
144 JackPortIsOutput
= 0x02,
145 JackPortIsPhysical
= 0x04,
146 JackPortCanMonitor
= 0x08,
147 JackPortIsTerminal
= 0x10,
148 JackPortIsControlVoltage
= 0x100
151 enum JackTransportState
{
152 JackTransportStopped
= 0,
153 JackTransportRolling
= 1,
154 JackTransportLooping
= 2,
155 JackTransportStarting
= 3
158 enum JackPositionBits
{
159 JackPositionBBT
= 0x010,
160 JackPositionTimecode
= 0x020,
161 JackBBTFrameOffset
= 0x040,
162 JackAudioVideoRatio
= 0x080,
163 JackVideoFrameOffset
= 0x100,
164 JackTickDouble
= 0x200
167 enum JackSessionEventType
{
169 JackSessionSaveAndQuit
= 2,
170 JackSessionSaveTemplate
= 3
173 enum JackSessionFlags
{
174 JackSessionSaveError
= 0x1,
175 JackSessionNeedTerminal
= 0x2
178 enum JackPropertyChange
{
184 typedef uint32_t jack_nframes_t
;
185 typedef uint32_t jack_port_id_t
;
186 typedef uint64_t jack_time_t
;
187 typedef uint64_t jack_uuid_t
;
188 typedef uint64_t jack_unique_t
;
189 typedef uchar jack_midi_data_t
;
190 typedef float jack_default_audio_sample_t
;
192 typedef enum JackOptions jack_options_t
;
193 typedef enum JackStatus jack_status_t
;
194 typedef enum JackLatencyCallbackMode jack_latency_callback_mode_t
;
195 typedef enum JackTransportState jack_transport_state_t
;
196 typedef enum JackPositionBits jack_position_bits_t
;
197 typedef enum JackSessionEventType jack_session_event_type_t
;
198 typedef enum JackSessionFlags jack_session_flags_t
;
199 typedef enum JackPropertyChange jack_property_change_t
;
201 struct _jack_midi_event
{
204 jack_midi_data_t
* buffer
;
207 // NOTE: packed in JACK2 but not in JACK1
209 struct _jack_latency_range
{
212 } POST_PACKED_STRUCTURE
;
215 struct _jack_position
{
216 jack_unique_t unique_1
;
218 jack_nframes_t frame_rate
;
219 jack_nframes_t frame
;
220 jack_position_bits_t valid
;
224 double bar_start_tick
;
227 double ticks_per_beat
;
228 double beats_per_minute
;
231 jack_nframes_t bbt_offset
;
232 float audio_frames_per_video_frame
;
233 jack_nframes_t video_offset
;
236 jack_unique_t unique_2
;
237 } POST_PACKED_STRUCTURE
;
239 struct _jack_session_event
{
240 jack_session_event_type_t type
;
241 const char* session_dir
;
242 const char* client_uuid
;
244 jack_session_flags_t flags
;
248 struct _jack_session_command_t
{
250 const char* client_name
;
252 jack_session_flags_t flags
;
263 uint32_t property_cnt
;
264 jack_property_t
* properties
;
265 uint32_t property_size
;
266 } jack_description_t
;
268 typedef struct _jack_port jack_port_t
;
269 typedef struct _jack_client jack_client_t
;
270 typedef struct _jack_midi_event jack_midi_event_t
;
271 typedef struct _jack_latency_range jack_latency_range_t
;
272 typedef struct _jack_position jack_position_t
;
273 typedef struct _jack_session_event jack_session_event_t
;
274 typedef struct _jack_session_command_t jack_session_command_t
;
276 typedef void (JACKBRIDGE_API
*JackLatencyCallback
)(jack_latency_callback_mode_t mode
, void* arg
);
277 typedef int (JACKBRIDGE_API
*JackProcessCallback
)(jack_nframes_t nframes
, void* arg
);
278 typedef void (JACKBRIDGE_API
*JackThreadInitCallback
)(void* arg
);
279 typedef int (JACKBRIDGE_API
*JackGraphOrderCallback
)(void* arg
);
280 typedef int (JACKBRIDGE_API
*JackXRunCallback
)(void* arg
);
281 typedef int (JACKBRIDGE_API
*JackBufferSizeCallback
)(jack_nframes_t nframes
, void* arg
);
282 typedef int (JACKBRIDGE_API
*JackSampleRateCallback
)(jack_nframes_t nframes
, void* arg
);
283 typedef void (JACKBRIDGE_API
*JackPortRegistrationCallback
)(jack_port_id_t port
, int register_
, void* arg
);
284 typedef void (JACKBRIDGE_API
*JackClientRegistrationCallback
)(const char* name
, int register_
, void* arg
);
285 typedef void (JACKBRIDGE_API
*JackPortConnectCallback
)(jack_port_id_t a
, jack_port_id_t b
, int connect
, void* arg
);
286 typedef void (JACKBRIDGE_API
*JackPortRenameCallback
)(jack_port_id_t port
, const char* old_name
, const char* new_name
, void* arg
);
287 typedef void (JACKBRIDGE_API
*JackFreewheelCallback
)(int starting
, void* arg
);
288 typedef void (JACKBRIDGE_API
*JackShutdownCallback
)(void* arg
);
289 typedef void (JACKBRIDGE_API
*JackInfoShutdownCallback
)(jack_status_t code
, const char* reason
, void* arg
);
290 typedef int (JACKBRIDGE_API
*JackSyncCallback
)(jack_transport_state_t state
, jack_position_t
* pos
, void* arg
);
291 typedef void (JACKBRIDGE_API
*JackTimebaseCallback
)(jack_transport_state_t state
, jack_nframes_t nframes
, jack_position_t
* pos
, int new_pos
, void* arg
);
292 typedef void (JACKBRIDGE_API
*JackSessionCallback
)(jack_session_event_t
* event
, void* arg
);
293 typedef void (JACKBRIDGE_API
*JackPropertyChangeCallback
)(jack_uuid_t subject
, const char* key
, jack_property_change_t change
, void* arg
);
297 #endif // ! JACKBRIDGE_DIRECT
299 JACKBRIDGE_API
bool jackbridge_is_ok() noexcept
;
300 JACKBRIDGE_API
void jackbridge_init();
302 JACKBRIDGE_API
void jackbridge_get_version(int* major_ptr
, int* minor_ptr
, int* micro_ptr
, int* proto_ptr
);
303 JACKBRIDGE_API
const char* jackbridge_get_version_string();
305 JACKBRIDGE_API jack_client_t
* jackbridge_client_open(const char* client_name
, uint32_t options
, jack_status_t
* status
);
306 JACKBRIDGE_API
bool jackbridge_client_close(jack_client_t
* client
);
308 JACKBRIDGE_API
int jackbridge_client_name_size();
309 JACKBRIDGE_API
char* jackbridge_get_client_name(jack_client_t
* client
);
311 JACKBRIDGE_API
char* jackbridge_client_get_uuid(jack_client_t
* client
);
312 JACKBRIDGE_API
char* jackbridge_get_uuid_for_client_name(jack_client_t
* client
, const char* name
);
313 JACKBRIDGE_API
char* jackbridge_get_client_name_by_uuid(jack_client_t
* client
, const char* uuid
);
315 JACKBRIDGE_API
bool jackbridge_uuid_parse(const char* buf
, jack_uuid_t
* uuid
);
316 JACKBRIDGE_API
void jackbridge_uuid_unparse(jack_uuid_t uuid
, char buf
[JACK_UUID_STRING_SIZE
]);
318 JACKBRIDGE_API
bool jackbridge_activate(jack_client_t
* client
);
319 JACKBRIDGE_API
bool jackbridge_deactivate(jack_client_t
* client
);
320 JACKBRIDGE_API
bool jackbridge_is_realtime(jack_client_t
* client
);
322 JACKBRIDGE_API
bool jackbridge_set_thread_init_callback(jack_client_t
* client
, JackThreadInitCallback thread_init_callback
, void* arg
);
323 JACKBRIDGE_API
void jackbridge_on_shutdown(jack_client_t
* client
, JackShutdownCallback shutdown_callback
, void* arg
);
324 JACKBRIDGE_API
void jackbridge_on_info_shutdown(jack_client_t
* client
, JackInfoShutdownCallback shutdown_callback
, void* arg
);
325 JACKBRIDGE_API
bool jackbridge_set_process_callback(jack_client_t
* client
, JackProcessCallback process_callback
, void* arg
);
326 JACKBRIDGE_API
bool jackbridge_set_freewheel_callback(jack_client_t
* client
, JackFreewheelCallback freewheel_callback
, void* arg
);
327 JACKBRIDGE_API
bool jackbridge_set_buffer_size_callback(jack_client_t
* client
, JackBufferSizeCallback bufsize_callback
, void* arg
);
328 JACKBRIDGE_API
bool jackbridge_set_sample_rate_callback(jack_client_t
* client
, JackSampleRateCallback srate_callback
, void* arg
);
329 JACKBRIDGE_API
bool jackbridge_set_client_registration_callback(jack_client_t
* client
, JackClientRegistrationCallback registration_callback
, void* arg
);
330 JACKBRIDGE_API
bool jackbridge_set_port_registration_callback(jack_client_t
* client
, JackPortRegistrationCallback registration_callback
, void* arg
);
331 JACKBRIDGE_API
bool jackbridge_set_port_rename_callback(jack_client_t
* client
, JackPortRenameCallback rename_callback
, void* arg
);
332 JACKBRIDGE_API
bool jackbridge_set_port_connect_callback(jack_client_t
* client
, JackPortConnectCallback connect_callback
, void* arg
);
333 JACKBRIDGE_API
bool jackbridge_set_graph_order_callback(jack_client_t
* client
, JackGraphOrderCallback graph_callback
, void* arg
);
334 JACKBRIDGE_API
bool jackbridge_set_xrun_callback(jack_client_t
* client
, JackXRunCallback xrun_callback
, void* arg
);
335 JACKBRIDGE_API
bool jackbridge_set_latency_callback(jack_client_t
* client
, JackLatencyCallback latency_callback
, void* arg
);
337 JACKBRIDGE_API
bool jackbridge_set_freewheel(jack_client_t
* client
, bool onoff
);
338 JACKBRIDGE_API
bool jackbridge_set_buffer_size(jack_client_t
* client
, jack_nframes_t nframes
);
340 JACKBRIDGE_API jack_nframes_t
jackbridge_get_sample_rate(jack_client_t
* client
);
341 JACKBRIDGE_API jack_nframes_t
jackbridge_get_buffer_size(jack_client_t
* client
);
342 JACKBRIDGE_API
float jackbridge_cpu_load(jack_client_t
* client
);
344 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
);
345 JACKBRIDGE_API
bool jackbridge_port_unregister(jack_client_t
* client
, jack_port_t
* port
);
346 JACKBRIDGE_API
void* jackbridge_port_get_buffer(jack_port_t
* port
, jack_nframes_t nframes
);
348 JACKBRIDGE_API
const char* jackbridge_port_name(const jack_port_t
* port
);
349 JACKBRIDGE_API jack_uuid_t
jackbridge_port_uuid(const jack_port_t
* port
);
350 JACKBRIDGE_API
const char* jackbridge_port_short_name(const jack_port_t
* port
);
351 JACKBRIDGE_API
int jackbridge_port_flags(const jack_port_t
* port
);
352 JACKBRIDGE_API
const char* jackbridge_port_type(const jack_port_t
* port
);
353 JACKBRIDGE_API
bool jackbridge_port_is_mine(const jack_client_t
* client
, const jack_port_t
* port
);
354 JACKBRIDGE_API
int jackbridge_port_connected(const jack_port_t
* port
);
355 JACKBRIDGE_API
bool jackbridge_port_connected_to(const jack_port_t
* port
, const char* port_name
);
356 JACKBRIDGE_API
const char** jackbridge_port_get_connections(const jack_port_t
* port
);
357 JACKBRIDGE_API
const char** jackbridge_port_get_all_connections(const jack_client_t
* client
, const jack_port_t
* port
);
359 JACKBRIDGE_API
bool jackbridge_port_rename(jack_client_t
* client
, jack_port_t
* port
, const char* port_name
);
360 JACKBRIDGE_API
bool jackbridge_port_set_alias(jack_port_t
* port
, const char* alias
);
361 JACKBRIDGE_API
bool jackbridge_port_unset_alias(jack_port_t
* port
, const char* alias
);
362 JACKBRIDGE_API
int jackbridge_port_get_aliases(const jack_port_t
* port
, char* const al
[2]);
364 JACKBRIDGE_API
bool jackbridge_port_request_monitor(jack_port_t
* port
, bool onoff
);
365 JACKBRIDGE_API
bool jackbridge_port_request_monitor_by_name(jack_client_t
* client
, const char* port_name
, bool onoff
);
366 JACKBRIDGE_API
bool jackbridge_port_ensure_monitor(jack_port_t
* port
, bool onoff
);
367 JACKBRIDGE_API
bool jackbridge_port_monitoring_input(jack_port_t
* port
);
369 JACKBRIDGE_API
bool jackbridge_connect(jack_client_t
* client
, const char* source_port
, const char* destination_port
);
370 JACKBRIDGE_API
bool jackbridge_disconnect(jack_client_t
* client
, const char* source_port
, const char* destination_port
);
371 JACKBRIDGE_API
bool jackbridge_port_disconnect(jack_client_t
* client
, jack_port_t
* port
);
373 JACKBRIDGE_API
int jackbridge_port_name_size();
374 JACKBRIDGE_API
int jackbridge_port_type_size();
375 JACKBRIDGE_API
uint32_t jackbridge_port_type_get_buffer_size(jack_client_t
* client
, const char* port_type
);
377 JACKBRIDGE_API
void jackbridge_port_get_latency_range(jack_port_t
* port
, uint32_t mode
, jack_latency_range_t
* range
);
378 JACKBRIDGE_API
void jackbridge_port_set_latency_range(jack_port_t
* port
, uint32_t mode
, jack_latency_range_t
* range
);
379 JACKBRIDGE_API
bool jackbridge_recompute_total_latencies(jack_client_t
* client
);
381 JACKBRIDGE_API
const char** jackbridge_get_ports(jack_client_t
* client
, const char* port_name_pattern
, const char* type_name_pattern
, uint64_t flags
);
382 JACKBRIDGE_API jack_port_t
* jackbridge_port_by_name(jack_client_t
* client
, const char* port_name
);
383 JACKBRIDGE_API jack_port_t
* jackbridge_port_by_id(jack_client_t
* client
, jack_port_id_t port_id
);
385 JACKBRIDGE_API
void jackbridge_free(void* ptr
);
387 JACKBRIDGE_API
uint32_t jackbridge_midi_get_event_count(void* port_buffer
);
388 JACKBRIDGE_API
bool jackbridge_midi_event_get(jack_midi_event_t
* event
, void* port_buffer
, uint32_t event_index
);
389 JACKBRIDGE_API
void jackbridge_midi_clear_buffer(void* port_buffer
);
390 JACKBRIDGE_API
bool jackbridge_midi_event_write(void* port_buffer
, jack_nframes_t time
, const jack_midi_data_t
* data
, uint32_t data_size
);
391 JACKBRIDGE_API jack_midi_data_t
* jackbridge_midi_event_reserve(void* port_buffer
, jack_nframes_t time
, uint32_t data_size
);
393 JACKBRIDGE_API
bool jackbridge_release_timebase(jack_client_t
* client
);
394 JACKBRIDGE_API
bool jackbridge_set_sync_callback(jack_client_t
* client
, JackSyncCallback sync_callback
, void* arg
);
395 JACKBRIDGE_API
bool jackbridge_set_sync_timeout(jack_client_t
* client
, jack_time_t timeout
);
396 JACKBRIDGE_API
bool jackbridge_set_timebase_callback(jack_client_t
* client
, bool conditional
, JackTimebaseCallback timebase_callback
, void* arg
);
397 JACKBRIDGE_API
bool jackbridge_transport_locate(jack_client_t
* client
, jack_nframes_t frame
);
399 JACKBRIDGE_API
uint32_t jackbridge_transport_query(const jack_client_t
* client
, jack_position_t
* pos
);
400 JACKBRIDGE_API jack_nframes_t
jackbridge_get_current_transport_frame(const jack_client_t
* client
);
402 JACKBRIDGE_API
bool jackbridge_transport_reposition(jack_client_t
* client
, const jack_position_t
* pos
);
403 JACKBRIDGE_API
void jackbridge_transport_start(jack_client_t
* client
);
404 JACKBRIDGE_API
void jackbridge_transport_stop(jack_client_t
* client
);
406 JACKBRIDGE_API
bool jackbridge_set_property(jack_client_t
* client
, jack_uuid_t subject
, const char* key
, const char* value
, const char* type
);
407 JACKBRIDGE_API
bool jackbridge_get_property(jack_uuid_t subject
, const char* key
, char** value
, char** type
);
408 JACKBRIDGE_API
void jackbridge_free_description(jack_description_t
* desc
, bool free_description_itself
);
409 JACKBRIDGE_API
bool jackbridge_get_properties(jack_uuid_t subject
, jack_description_t
* desc
);
410 JACKBRIDGE_API
bool jackbridge_get_all_properties(jack_description_t
** descs
);
411 JACKBRIDGE_API
bool jackbridge_remove_property(jack_client_t
* client
, jack_uuid_t subject
, const char* key
);
412 JACKBRIDGE_API
int jackbridge_remove_properties(jack_client_t
* client
, jack_uuid_t subject
);
413 JACKBRIDGE_API
bool jackbridge_remove_all_properties(jack_client_t
* client
);
414 JACKBRIDGE_API
bool jackbridge_set_property_change_callback(jack_client_t
* client
, JackPropertyChangeCallback callback
, void* arg
);
416 JACKBRIDGE_API
bool jackbridge_sem_init(void* sem
) noexcept
;
417 JACKBRIDGE_API
void jackbridge_sem_destroy(void* sem
) noexcept
;
418 JACKBRIDGE_API
bool jackbridge_sem_connect(void* sem
) noexcept
;
419 JACKBRIDGE_API
void jackbridge_sem_post(void* sem
, bool server
) noexcept
;
420 #ifndef CARLA_OS_WASM
421 JACKBRIDGE_API
bool jackbridge_sem_timedwait(void* sem
, uint msecs
, bool server
) noexcept
;
424 JACKBRIDGE_API
bool jackbridge_shm_is_valid(const void* shm
) noexcept
;
425 JACKBRIDGE_API
void jackbridge_shm_init(void* shm
) noexcept
;
426 JACKBRIDGE_API
void jackbridge_shm_attach(void* shm
, const char* name
) noexcept
;
427 JACKBRIDGE_API
void jackbridge_shm_close(void* shm
) noexcept
;
428 JACKBRIDGE_API
void* jackbridge_shm_map(void* shm
, uint64_t size
) noexcept
;
429 JACKBRIDGE_API
void jackbridge_shm_unmap(void* shm
, void* ptr
) noexcept
;
431 JACKBRIDGE_API
void* jackbridge_discovery_pipe_create(const char* argv
[]);
432 JACKBRIDGE_API
void jackbridge_discovery_pipe_message(void* pipe
, const char* key
, const char* value
);
433 JACKBRIDGE_API
void jackbridge_discovery_pipe_destroy(void* pipe
);
435 JACKBRIDGE_API
void jackbridge_parent_deathsig(bool kill
) noexcept
;
437 #endif // JACKBRIDGE_HPP_INCLUDED