Update CI version
[carla.git] / source / jackbridge / JackBridgeExport.cpp
blobbdb455339aaee26fcf07e0e456451a0418bbfdba
1 /*
2 * JackBridge (Part 3, Export)
3 * Copyright (C) 2013-2023 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 #include "JackBridgeExport.hpp"
19 #include "CarlaLibUtils.hpp"
20 #include "CarlaUtils.h"
22 // #include <cstdio>
24 // --------------------------------------------------------------------------------------------------------------------
26 class JackBridgeExported
28 public:
29 JackBridgeExported() noexcept
30 : lib(nullptr),
31 func(nullptr)
33 #ifdef CARLA_OS_WIN64
34 lib = lib_open("jackbridge-wine64.dll");
35 #else
36 lib = lib_open("jackbridge-wine32.dll");
37 #endif
38 CARLA_SAFE_ASSERT_RETURN(lib != nullptr,);
40 func = lib_symbol<jackbridge_exported_function_type>(lib, "jackbridge_get_exported_functions");
41 CARLA_SAFE_ASSERT_RETURN(func != nullptr,);
44 ~JackBridgeExported() noexcept
46 if (lib == nullptr)
47 return;
49 lib_close(lib);
50 lib = nullptr;
51 func = nullptr;
54 static const JackBridgeExportedFunctions& getFunctions() noexcept
56 static JackBridgeExportedFunctions fallback;
57 carla_zeroStruct(fallback);
58 fallback.unique1 = 1;
59 fallback.unique2 = 2;
60 fallback.unique3 = 3;
62 static const JackBridgeExported bridge;
63 CARLA_SAFE_ASSERT_RETURN(bridge.func != nullptr, fallback);
65 const JackBridgeExportedFunctions* const funcs = bridge.func();
66 CARLA_SAFE_ASSERT_RETURN(funcs != nullptr, fallback);
67 CARLA_SAFE_ASSERT_RETURN(funcs->unique1 != 0, fallback);
68 CARLA_SAFE_ASSERT_RETURN(funcs->unique1 == funcs->unique2, fallback);
69 CARLA_SAFE_ASSERT_RETURN(funcs->unique2 == funcs->unique3, fallback);
70 CARLA_SAFE_ASSERT_RETURN(funcs->discovery_pipe_destroy_ptr != nullptr, fallback);
72 return *funcs;
75 private:
76 lib_t lib;
77 jackbridge_exported_function_type func;
79 CARLA_PREVENT_HEAP_ALLOCATION
80 CARLA_DECLARE_NON_COPYABLE(JackBridgeExported);
83 // --------------------------------------------------------------------------------------------------------------------
85 static const JackBridgeExportedFunctions& getBridgeInstance() noexcept
87 static const JackBridgeExportedFunctions& funcs(JackBridgeExported::getFunctions());
88 return funcs;
91 // --------------------------------------------------------------------------------------------------------------------
93 bool jackbridge_is_ok() noexcept
95 const JackBridgeExportedFunctions& instance(getBridgeInstance());
96 return (instance.unique1 != 0 && instance.unique1 == instance.unique2 && instance.init_ptr != nullptr);
99 void jackbridge_init()
101 return getBridgeInstance().init_ptr();
104 void jackbridge_get_version(int* major_ptr, int* minor_ptr, int* micro_ptr, int* proto_ptr)
106 return getBridgeInstance().get_version_ptr(major_ptr, minor_ptr, micro_ptr, proto_ptr);
109 const char* jackbridge_get_version_string()
111 return getBridgeInstance().get_version_string_ptr();
114 jack_client_t* jackbridge_client_open(const char* client_name, uint32_t options, jack_status_t* status)
116 return getBridgeInstance().client_open_ptr(client_name, options, status);
119 bool jackbridge_client_close(jack_client_t* client)
121 return getBridgeInstance().client_close_ptr(client);
124 int jackbridge_client_name_size()
126 return getBridgeInstance().client_name_size_ptr();
129 char* jackbridge_get_client_name(jack_client_t* client)
131 return getBridgeInstance().get_client_name_ptr(client);
134 char* jackbridge_client_get_uuid(jack_client_t* client)
136 return getBridgeInstance().client_get_uuid_ptr(client);
139 char* jackbridge_get_uuid_for_client_name(jack_client_t* client, const char* name)
141 return getBridgeInstance().get_uuid_for_client_name_ptr(client, name);
144 char* jackbridge_get_client_name_by_uuid(jack_client_t* client, const char* uuid)
146 return getBridgeInstance().get_client_name_by_uuid_ptr(client, uuid);
149 bool jackbridge_uuid_parse(const char* buf, jack_uuid_t* uuid)
151 return getBridgeInstance().uuid_parse_ptr(buf, uuid);
154 bool jackbridge_activate(jack_client_t* client)
156 return getBridgeInstance().activate_ptr(client);
159 bool jackbridge_deactivate(jack_client_t* client)
161 return getBridgeInstance().deactivate_ptr(client);
164 bool jackbridge_is_realtime(jack_client_t* client)
166 return getBridgeInstance().is_realtime_ptr(client);
169 bool jackbridge_set_thread_init_callback(jack_client_t* client, JackThreadInitCallback thread_init_callback, void* arg)
171 return getBridgeInstance().set_thread_init_callback_ptr(client, thread_init_callback, arg);
174 void jackbridge_on_shutdown(jack_client_t* client, JackShutdownCallback shutdown_callback, void* arg)
176 return getBridgeInstance().on_shutdown_ptr(client, shutdown_callback, arg);
179 void jackbridge_on_info_shutdown(jack_client_t* client, JackInfoShutdownCallback shutdown_callback, void* arg)
181 return getBridgeInstance().on_info_shutdown_ptr(client, shutdown_callback, arg);
184 bool jackbridge_set_process_callback(jack_client_t* client, JackProcessCallback process_callback, void* arg)
186 return getBridgeInstance().set_process_callback_ptr(client, process_callback, arg);
189 bool jackbridge_set_freewheel_callback(jack_client_t* client, JackFreewheelCallback freewheel_callback, void* arg)
191 return getBridgeInstance().set_freewheel_callback_ptr(client, freewheel_callback, arg);
194 bool jackbridge_set_buffer_size_callback(jack_client_t* client, JackBufferSizeCallback bufsize_callback, void* arg)
196 return getBridgeInstance().set_buffer_size_callback_ptr(client, bufsize_callback, arg);
199 bool jackbridge_set_sample_rate_callback(jack_client_t* client, JackSampleRateCallback srate_callback, void* arg)
201 return getBridgeInstance().set_sample_rate_callback_ptr(client, srate_callback, arg);
204 bool jackbridge_set_client_registration_callback(jack_client_t* client, JackClientRegistrationCallback registration_callback, void* arg)
206 return getBridgeInstance().set_client_registration_callback_ptr(client, registration_callback, arg);
209 bool jackbridge_set_port_registration_callback(jack_client_t* client, JackPortRegistrationCallback registration_callback, void *arg)
211 return getBridgeInstance().set_port_registration_callback_ptr(client, registration_callback, arg);
214 bool jackbridge_set_port_rename_callback(jack_client_t* client, JackPortRenameCallback rename_callback, void* arg)
216 return getBridgeInstance().set_port_rename_callback_ptr(client, rename_callback, arg);
219 bool jackbridge_set_port_connect_callback(jack_client_t* client, JackPortConnectCallback connect_callback, void* arg)
221 return getBridgeInstance().set_port_connect_callback_ptr(client, connect_callback, arg);
224 bool jackbridge_set_xrun_callback(jack_client_t* client, JackXRunCallback xrun_callback, void* arg)
226 return getBridgeInstance().set_xrun_callback_ptr(client, xrun_callback, arg);
229 bool jackbridge_set_latency_callback(jack_client_t* client, JackLatencyCallback latency_callback, void* arg)
231 return getBridgeInstance().set_latency_callback_ptr(client, latency_callback, arg);
234 bool jackbridge_set_freewheel(jack_client_t* client, bool onoff)
236 return getBridgeInstance().set_freewheel_ptr(client, onoff);
239 bool jackbridge_set_buffer_size(jack_client_t* client, jack_nframes_t nframes)
241 return getBridgeInstance().set_buffer_size_ptr(client, nframes);
244 jack_nframes_t jackbridge_get_sample_rate(jack_client_t* client)
246 return getBridgeInstance().get_sample_rate_ptr(client);
249 jack_nframes_t jackbridge_get_buffer_size(jack_client_t* client)
251 return getBridgeInstance().get_buffer_size_ptr(client);
254 float jackbridge_cpu_load(jack_client_t* client)
256 return getBridgeInstance().cpu_load_ptr(client);
259 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)
261 return getBridgeInstance().port_register_ptr(client, port_name, port_type, flags, buffer_size);
264 bool jackbridge_port_unregister(jack_client_t* client, jack_port_t* port)
266 return getBridgeInstance().port_unregister_ptr(client, port);
269 void* jackbridge_port_get_buffer(jack_port_t* port, jack_nframes_t nframes)
271 return getBridgeInstance().port_get_buffer_ptr(port, nframes);
274 const char* jackbridge_port_name(const jack_port_t* port)
276 return getBridgeInstance().port_name_ptr(port);
279 jack_uuid_t jackbridge_port_uuid(const jack_port_t* port)
281 return getBridgeInstance().port_uuid_ptr(port);
284 const char* jackbridge_port_short_name(const jack_port_t* port)
286 return getBridgeInstance().port_short_name_ptr(port);
289 int jackbridge_port_flags(const jack_port_t* port)
291 return getBridgeInstance().port_flags_ptr(port);
294 const char* jackbridge_port_type(const jack_port_t* port)
296 return getBridgeInstance().port_type_ptr(port);
299 bool jackbridge_port_is_mine(const jack_client_t* client, const jack_port_t* port)
301 return getBridgeInstance().port_is_mine_ptr(client, port);
304 int jackbridge_port_connected(const jack_port_t* port)
306 return getBridgeInstance().port_connected_ptr(port);
309 bool jackbridge_port_connected_to(const jack_port_t* port, const char* port_name)
311 return getBridgeInstance().port_connected_to_ptr(port, port_name);
314 const char** jackbridge_port_get_connections(const jack_port_t* port)
316 return getBridgeInstance().port_get_connections_ptr(port);
319 const char** jackbridge_port_get_all_connections(const jack_client_t* client, const jack_port_t* port)
321 return getBridgeInstance().port_get_all_connections_ptr(client, port);
324 bool jackbridge_port_rename(jack_client_t* client, jack_port_t* port, const char* port_name)
326 return getBridgeInstance().port_rename_ptr(client, port, port_name);
329 bool jackbridge_port_set_alias(jack_port_t* port, const char* alias)
331 return getBridgeInstance().port_set_alias_ptr(port, alias);
334 bool jackbridge_port_unset_alias(jack_port_t* port, const char* alias)
336 return getBridgeInstance().port_unset_alias_ptr(port, alias);
339 int jackbridge_port_get_aliases(const jack_port_t* port, char* const aliases[2])
341 return getBridgeInstance().port_get_aliases_ptr(port, aliases);
344 bool jackbridge_port_request_monitor(jack_port_t* port, bool onoff)
346 return getBridgeInstance().port_request_monitor_ptr(port, onoff);
349 bool jackbridge_port_request_monitor_by_name(jack_client_t* client, const char* port_name, bool onoff)
351 return getBridgeInstance().port_request_monitor_by_name_ptr(client, port_name, onoff);
354 bool jackbridge_port_ensure_monitor(jack_port_t* port, bool onoff)
356 return getBridgeInstance().port_ensure_monitor_ptr(port, onoff);
359 bool jackbridge_port_monitoring_input(jack_port_t* port)
361 return getBridgeInstance().port_monitoring_input_ptr(port);
364 bool jackbridge_connect(jack_client_t* client, const char* source_port, const char* destination_port)
366 return getBridgeInstance().connect_ptr(client, source_port, destination_port);
369 bool jackbridge_disconnect(jack_client_t* client, const char* source_port, const char* destination_port)
371 return getBridgeInstance().disconnect_ptr(client, source_port, destination_port);
374 bool jackbridge_port_disconnect(jack_client_t* client, jack_port_t* port)
376 return getBridgeInstance().port_disconnect_ptr(client, port);
379 int jackbridge_port_name_size()
381 return getBridgeInstance().port_name_size_ptr();
384 int jackbridge_port_type_size()
386 return getBridgeInstance().port_type_size_ptr();
389 uint32_t jackbridge_port_type_get_buffer_size(jack_client_t* client, const char* port_type)
391 return getBridgeInstance().port_type_get_buffer_size_ptr(client, port_type);
394 void jackbridge_port_get_latency_range(jack_port_t* port, uint32_t mode, jack_latency_range_t* range)
396 return getBridgeInstance().port_get_latency_range_ptr(port, mode, range);
399 void jackbridge_port_set_latency_range(jack_port_t* port, uint32_t mode, jack_latency_range_t* range)
401 return getBridgeInstance().port_set_latency_range_ptr(port, mode, range);
404 bool jackbridge_recompute_total_latencies(jack_client_t* client)
406 return getBridgeInstance().recompute_total_latencies_ptr(client);
409 const char** jackbridge_get_ports(jack_client_t* client, const char* port_name_pattern, const char* type_name_pattern, uint64_t flags)
411 return getBridgeInstance().get_ports_ptr(client, port_name_pattern, type_name_pattern, flags);
414 jack_port_t* jackbridge_port_by_name(jack_client_t* client, const char* port_name)
416 return getBridgeInstance().port_by_name_ptr(client, port_name);
419 jack_port_t* jackbridge_port_by_id(jack_client_t* client, jack_port_id_t port_id)
421 return getBridgeInstance().port_by_id_ptr(client, port_id);
424 void jackbridge_free(void* ptr)
426 return getBridgeInstance().free_ptr(ptr);
429 uint32_t jackbridge_midi_get_event_count(void* port_buffer)
431 return getBridgeInstance().midi_get_event_count_ptr(port_buffer);
434 bool jackbridge_midi_event_get(jack_midi_event_t* event, void* port_buffer, uint32_t event_index)
436 return getBridgeInstance().midi_event_get_ptr(event, port_buffer, event_index);
439 void jackbridge_midi_clear_buffer(void* port_buffer)
441 return getBridgeInstance().midi_clear_buffer_ptr(port_buffer);
444 bool jackbridge_midi_event_write(void* port_buffer, jack_nframes_t time, const jack_midi_data_t* data, uint32_t data_size)
446 return getBridgeInstance().midi_event_write_ptr(port_buffer, time, data, data_size);
449 jack_midi_data_t* jackbridge_midi_event_reserve(void* port_buffer, jack_nframes_t time, uint32_t data_size)
451 return getBridgeInstance().midi_event_reserve_ptr(port_buffer, time, data_size);
454 bool jackbridge_release_timebase(jack_client_t* client)
456 return getBridgeInstance().release_timebase_ptr(client);
459 bool jackbridge_set_sync_callback(jack_client_t* client, JackSyncCallback sync_callback, void* arg)
461 return getBridgeInstance().set_sync_callback_ptr(client, sync_callback, arg);
464 bool jackbridge_set_sync_timeout(jack_client_t* client, jack_time_t timeout)
466 return getBridgeInstance().set_sync_timeout_ptr(client, timeout);
469 bool jackbridge_set_timebase_callback(jack_client_t* client, bool conditional, JackTimebaseCallback timebase_callback, void* arg)
471 return getBridgeInstance().set_timebase_callback_ptr(client, conditional, timebase_callback, arg);
474 bool jackbridge_transport_locate(jack_client_t* client, jack_nframes_t frame)
476 return getBridgeInstance().transport_locate_ptr(client, frame);
479 uint32_t jackbridge_transport_query(const jack_client_t* client, jack_position_t* pos)
481 return getBridgeInstance().transport_query_ptr(client, pos);
484 jack_nframes_t jackbridge_get_current_transport_frame(const jack_client_t* client)
486 return getBridgeInstance().get_current_transport_frame_ptr(client);
489 bool jackbridge_transport_reposition(jack_client_t* client, const jack_position_t* pos)
491 return getBridgeInstance().transport_reposition_ptr(client, pos);
494 void jackbridge_transport_start(jack_client_t* client)
496 return getBridgeInstance().transport_start_ptr(client);
499 void jackbridge_transport_stop(jack_client_t* client)
501 return getBridgeInstance().transport_stop_ptr(client);
504 bool jackbridge_set_property(jack_client_t* client, jack_uuid_t subject, const char* key, const char* value, const char* type)
506 return getBridgeInstance().set_property_ptr(client, subject, key, value, type);
509 bool jackbridge_get_property(jack_uuid_t subject, const char* key, char** value, char** type)
511 return getBridgeInstance().get_property_ptr(subject, key, value, type);
514 void jackbridge_free_description(jack_description_t* desc, bool free_description_itself)
516 return getBridgeInstance().free_description_ptr(desc, free_description_itself);
519 bool jackbridge_get_properties(jack_uuid_t subject, jack_description_t* desc)
521 return getBridgeInstance().get_properties_ptr(subject, desc);
524 bool jackbridge_get_all_properties(jack_description_t** descs)
526 return getBridgeInstance().get_all_properties_ptr(descs);
529 bool jackbridge_remove_property(jack_client_t* client, jack_uuid_t subject, const char* key)
531 return getBridgeInstance().remove_property_ptr(client, subject, key);
534 int jackbridge_remove_properties(jack_client_t* client, jack_uuid_t subject)
536 return getBridgeInstance().remove_properties_ptr(client, subject);
539 bool jackbridge_remove_all_properties(jack_client_t* client)
541 return getBridgeInstance().remove_all_properties_ptr(client);
544 bool jackbridge_set_property_change_callback(jack_client_t* client, JackPropertyChangeCallback callback, void* arg)
546 return getBridgeInstance().set_property_change_callback_ptr(client, callback, arg);
549 bool jackbridge_sem_init(void* sem) noexcept
551 return getBridgeInstance().sem_init_ptr(sem);
554 void jackbridge_sem_destroy(void* sem) noexcept
556 getBridgeInstance().sem_destroy_ptr(sem);
559 bool jackbridge_sem_connect(void* sem) noexcept
561 return getBridgeInstance().sem_connect_ptr(sem);
564 void jackbridge_sem_post(void* sem, bool server) noexcept
566 getBridgeInstance().sem_post_ptr(sem, server);
569 bool jackbridge_sem_timedwait(void* sem, uint msecs, bool server) noexcept
571 return getBridgeInstance().sem_timedwait_ptr(sem, msecs, server);
574 bool jackbridge_shm_is_valid(const void* shm) noexcept
576 return getBridgeInstance().shm_is_valid_ptr(shm);
579 void jackbridge_shm_init(void* shm) noexcept
581 return getBridgeInstance().shm_init_ptr(shm);
584 void jackbridge_shm_attach(void* shm, const char* name) noexcept
586 return getBridgeInstance().shm_attach_ptr(shm, name);
589 void jackbridge_shm_close(void* shm) noexcept
591 return getBridgeInstance().shm_close_ptr(shm);
594 void* jackbridge_shm_map(void* shm, uint64_t size) noexcept
596 return getBridgeInstance().shm_map_ptr(shm, size);
599 void jackbridge_shm_unmap(void* shm, void* ptr) noexcept
601 return getBridgeInstance().shm_unmap_ptr(shm, ptr);
604 // --------------------------------------------------------------------------------------------------------------------
606 void* jackbridge_discovery_pipe_create(const char* argv[])
608 return getBridgeInstance().discovery_pipe_create_ptr(argv);
611 void jackbridge_discovery_pipe_message(void* pipe, const char* key, const char* value)
613 return getBridgeInstance().discovery_pipe_message_ptr(pipe, key, value);
616 void jackbridge_discovery_pipe_destroy(void* pipe)
618 return getBridgeInstance().discovery_pipe_destroy_ptr(pipe);
621 // --------------------------------------------------------------------------------------------------------------------
623 void jackbridge_parent_deathsig(bool kill) noexcept
625 return getBridgeInstance().parent_deathsig_ptr(kill);
628 // --------------------------------------------------------------------------------------------------------------------