--- jackweakapi.cpp 2019-10-31 13:29:35.024491300 +0100 +++ JackWeakAPI.c 2019-10-31 11:36:23.281997500 +0100 @@ -1,11 +1,8 @@ //============================================================================= -// MuseScore -// Linux Music Score Editor // -// jackWeakAPI based on code from Stéphane Letz (Grame) -// partly based on Julien Pommier (PianoTeq : http://www.pianoteq.com/) code. +// jackWeakAPI partly based on Julien Pommier (PianoTeq : http://www.pianoteq.com/) code. // -// Copyright (C) 2002-2019 Werner Schweer and others +// Copyright (C) 2002-2007 Werner Schweer and others // Copyright (C) 2009 Grame // This program is free software; you can redistribute it and/or modify @@ -22,12 +19,6 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#if (defined (_MSCVER) || defined (_MSC_VER)) - // Include stdint.h and #define _STDINT_H to prevent from redefining types - // #undef UNICODE to force LoadLibrary to use the char-based implementation instead of the wchar_t one. - #include - #define _STDINT_H 1 -#endif #include #include #include @@ -35,13 +26,9 @@ #include #ifndef WIN32 #include -//for backward compatibility of Jack headers. Might not be necessary. -typedef pthread_t jack_native_thread_t; #endif #include -#include - -using std::cerr; +#include /* dynamically load libjack and forward all registered calls to libjack (similar to what relaytool is trying to do, but more portably..) @@ -58,51 +45,39 @@ static void *libjack_handle = 0; #endif #ifndef WIN32 -// Since MSVC does not support the __attribute(constructor)__ extension, an alternative through -// static object construction is implemented. -// See https://stackoverflow.com/questions/1113409/attribute-constructor-equivalent-in-vc for a similar -// approach. -//#if (!defined (_MSCVER) && !defined (_MSC_VER)) static void __attribute__((constructor)) tryload_libjack() #else -static int tryload_libjack(); -static int tryload_static = tryload_libjack(); -static int tryload_libjack() +void tryload_libjack() #endif { if (getenv("SKIP_LIBJACK") == 0) { // just in case libjack is causing troubles.. #ifdef __APPLE__ libjack_handle = dlopen("libjack.0.dylib", RTLD_LAZY); if (!libjack_handle) { - qDebug("dlopen error : %s ", dlerror()); + fprintf(stderr, "dlopen error : %s \n", dlerror()); } libjack_handle = dlopen("/usr/local/lib/libjack.0.dylib", RTLD_LAZY); if (!libjack_handle) { - qDebug("dlopen error : %s ", dlerror()); + fprintf(stderr, "dlopen error : %s \n", dlerror()); } #elif defined(WIN32) - // Force char implementation of library instead of possibly wchar_t implementation to be called. #ifdef _WIN64 - libjack_handle = LoadLibraryA("libjack64.dll"); + libjack_handle = LoadLibrary("libjack64.dll"); #else - libjack_handle = LoadLibraryA("libjack.dll"); + libjack_handle = LoadLibrary("libjack.dll"); #endif #else libjack_handle = dlopen("libjack.so.0", RTLD_LAZY); #endif } libjack_is_present = (libjack_handle != 0); -#ifdef WIN32 -//#if (defined (_MSCVER) || defined (_MSC_VER)) - return 1; -#endif } void *load_jack_function(const char *fn_name) { void *fn = 0; if (!libjack_handle) { - qDebug("libjack not found, so do not try to load %s ffs !", fn_name); + fprintf (stderr, "libjack not found, so do not try to load %s ffs !\n", fn_name); return 0; } #ifdef WIN32 @@ -114,9 +89,9 @@ #ifdef WIN32 char* lpMsgBuf; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,NULL,GetLastError(),MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),(LPTSTR) &lpMsgBuf,0,NULL ); - qDebug("could not GetProcAddress( %s ), %s ", fn_name, lpMsgBuf) ; + fprintf(stderr, "could not GetProcAddress( %s ), %s \n", fn_name, lpMsgBuf); #else - qDebug ("could not dlsym( %s ), %s ", fn_name, dlerror()) ; + fprintf(stderr, "could not dlsym( %s ), %s \n", fn_name, dlerror()); #endif } return fn; @@ -162,8 +137,8 @@ const char *load_init), (client_name, load_name, load_init)); DECL_VOID_FUNCTION(jack_internal_client_close, (const char *client_name), (client_name)); DECL_FUNCTION(int, jack_is_realtime, (jack_client_t *client), (client)); -//WS DECL_VOID_FUNCTION(jack_on_shutdown, (jack_client_t *client, JackShutdownCallback shutdown_callback, void *arg), (client, shutdown_callback, arg)); -//DECL_VOID_FUNCTION(jack_on_info_shutdown, (jack_client_t* client, JackInfoShutdownCallback shutdown_callback, void* arg), (client, shutdown_callback, arg)); +DECL_VOID_FUNCTION(jack_on_shutdown, (jack_client_t *client, JackShutdownCallback shutdown_callback, void *arg), (client, shutdown_callback, arg)); +DECL_VOID_FUNCTION(jack_on_info_shutdown, (jack_client_t* client, JackInfoShutdownCallback shutdown_callback, void* arg), (client, shutdown_callback, arg)); DECL_FUNCTION(int, jack_set_process_callback, (jack_client_t *client, JackProcessCallback process_callback, void *arg), (client, process_callback, arg)); @@ -172,9 +147,9 @@ // DECL_FUNCTION(jack_nframes_t, jack_cycle_wait, (jack_client_t *client), (client)); DECL_VOID_FUNCTION(jack_cycle_signal, (jack_client_t *client, int status), (client, status)); -//DECL_FUNCTION(int, jack_set_process_thread, (jack_client_t *client, -// JackThreadCallback fun, -// void *arg), (client, fun, arg)); +DECL_FUNCTION(int, jack_set_process_thread, (jack_client_t *client, + JackThreadCallback fun, + void *arg), (client, fun, arg)); DECL_FUNCTION(int, jack_set_thread_init_callback, (jack_client_t *client, JackThreadInitCallback thread_init_callback, void *arg), (client, thread_init_callback, arg)); @@ -198,18 +173,18 @@ DECL_FUNCTION(int, jack_set_port_connect_callback, (jack_client_t *client, JackPortConnectCallback connect_callback, void *arg), (client, connect_callback, arg)); -//WS DECL_FUNCTION(int, jack_set_port_rename_callback, (jack_client_t *client, -// JackPortRenameCallback rename_callback, -// void *arg), (client, rename_callback, arg)); +DECL_FUNCTION(int, jack_set_port_rename_callback, (jack_client_t *client, + JackPortRenameCallback rename_callback, + void *arg), (client, rename_callback, arg)); DECL_FUNCTION(int, jack_set_graph_order_callback, (jack_client_t *client, JackGraphOrderCallback graph_callback, void *arg), (client, graph_callback, arg)); DECL_FUNCTION(int, jack_set_xrun_callback, (jack_client_t *client, JackXRunCallback xrun_callback, void *arg), (client, xrun_callback, arg)); -//DECL_FUNCTION(int, jack_set_latency_callback, (jack_client_t *client, -// JackLatencyCallback latency_callback, -// void *arg), (client, latency_callback, arg)); +DECL_FUNCTION(int, jack_set_latency_callback, (jack_client_t *client, + JackLatencyCallback latency_callback, + void *arg), (client, latency_callback, arg)); DECL_FUNCTION(int, jack_activate, (jack_client_t *client), (client)); DECL_FUNCTION(int, jack_deactivate, (jack_client_t *client), (client)); DECL_FUNCTION_NULL(jack_port_t *, jack_port_register, (jack_client_t *client, const char *port_name, const char *port_type, @@ -221,7 +196,7 @@ DECL_FUNCTION_NULL(const char*, jack_port_short_name, (const jack_port_t *port), (port)); DECL_FUNCTION(int, jack_port_flags, (const jack_port_t *port), (port)); DECL_FUNCTION_NULL(const char*, jack_port_type, (const jack_port_t *port), (port)); -//WS DECL_FUNCTION(jack_port_type_id_t, jack_port_type_id, (const jack_port_t *port), (port)); +DECL_FUNCTION(jack_port_type_id_t, jack_port_type_id, (const jack_port_t *port), (port)); DECL_FUNCTION(int, jack_port_is_mine, (const jack_client_t *client, const jack_port_t* port), (client, port)); DECL_FUNCTION(int, jack_port_connected, (const jack_port_t *port), (port)); DECL_FUNCTION(int, jack_port_connected_to, (const jack_port_t *port, const char *port_name), (port, port_name)); @@ -233,12 +208,12 @@ DECL_FUNCTION(jack_nframes_t, jack_port_get_total_latency ,(jack_client_t * client, jack_port_t *port), (client, port)); DECL_VOID_FUNCTION(jack_port_set_latency, (jack_port_t * port, jack_nframes_t frames), (port, frames)); DECL_FUNCTION(int, jack_recompute_total_latency, (jack_client_t* client, jack_port_t* port), (client, port)); -//DECL_VOID_FUNCTION(jack_port_get_latency_range, (jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range), (port, mode, range)); -//DECL_VOID_FUNCTION(jack_port_set_latency_range, (jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range), (port, mode, range)); +DECL_VOID_FUNCTION(jack_port_get_latency_range, (jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range), (port, mode, range)); +DECL_VOID_FUNCTION(jack_port_set_latency_range, (jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range), (port, mode, range)); DECL_FUNCTION(int, jack_recompute_total_latencies, (jack_client_t* client),(client)); DECL_FUNCTION(int, jack_port_set_name, (jack_port_t *port, const char *port_name), (port, port_name)); -//DECL_FUNCTION(int, jack_port_rename, (jack_client_t *client, jack_port_t *port, const char *port_name), (client, port, port_name)); +DECL_FUNCTION(int, jack_port_rename, (jack_client_t *client, jack_port_t *port, const char *port_name), (client, port, port_name)); DECL_FUNCTION(int, jack_port_set_alias, (jack_port_t *port, const char *alias), (port, alias)); DECL_FUNCTION(int, jack_port_unset_alias, (jack_port_t *port, const char *alias), (port, alias)); DECL_FUNCTION(int, jack_port_get_aliases, (const jack_port_t *port, char* const aliases[2]), (port,aliases)); @@ -251,7 +226,7 @@ DECL_FUNCTION(int, jack_port_disconnect, (jack_client_t * client, jack_port_t * port), (client, port)); DECL_FUNCTION(int, jack_port_name_size,(),()); DECL_FUNCTION(int, jack_port_type_size,(),()); -//DECL_FUNCTION(size_t, jack_port_type_get_buffer_size, (jack_client_t *client, const char* port_type), (client, port_type)); +DECL_FUNCTION(size_t, jack_port_type_get_buffer_size, (jack_client_t *client, const char* port_type), (client, port_type)); DECL_FUNCTION(jack_nframes_t, jack_get_sample_rate, (jack_client_t *client), (client)); DECL_FUNCTION(jack_nframes_t, jack_get_buffer_size, (jack_client_t *client), (client)); @@ -289,8 +264,8 @@ DECL_FUNCTION(int, jack_transport_reposition, (jack_client_t *client, const jack_position_t *pos), (client, pos)); DECL_VOID_FUNCTION(jack_transport_start, (jack_client_t *client), (client)); DECL_VOID_FUNCTION(jack_transport_stop, (jack_client_t *client), (client)); -//DECL_VOID_FUNCTION(jack_get_transport_info, (jack_client_t *client, jack_transport_info_t *tinfo), (client,tinfo)); -//DECL_VOID_FUNCTION(jack_set_transport_info, (jack_client_t *client, jack_transport_info_t *tinfo), (client,tinfo)); +DECL_VOID_FUNCTION(jack_get_transport_info, (jack_client_t *client, jack_transport_info_t *tinfo), (client,tinfo)); +DECL_VOID_FUNCTION(jack_set_transport_info, (jack_client_t *client, jack_transport_info_t *tinfo), (client,tinfo)); DECL_FUNCTION(int, jack_client_real_time_priority, (jack_client_t* client), (client)); DECL_FUNCTION(int, jack_client_max_real_time_priority, (jack_client_t* client), (client)); @@ -306,7 +281,7 @@ DECL_FUNCTION(int, jack_client_stop_thread, (jack_client_t* client, jack_native_thread_t thread), (client, thread)); DECL_FUNCTION(int, jack_client_kill_thread, (jack_client_t* client, jack_native_thread_t thread), (client, thread)); #ifndef WIN32 -//WS DECL_VOID_FUNCTION(jack_set_thread_creator, (jack_thread_creator_t jtc), (jtc)); +DECL_VOID_FUNCTION(jack_set_thread_creator, (jack_thread_creator_t jtc), (jtc)); #endif DECL_FUNCTION(char *, jack_get_internal_client_name, (jack_client_t *client, jack_intclient_t intclient), (client, intclient)); DECL_FUNCTION(jack_intclient_t, jack_internal_client_handle, (jack_client_t *client, const char *client_name, jack_status_t *status), (client, client_name, status)); @@ -321,19 +296,18 @@ DECL_VOID_FUNCTION(jack_free, (void* ptr), (ptr)); // session -//DECL_FUNCTION(int, jack_set_session_callback, (jack_client_t* ext_client, JackSessionCallback session_callback, void* arg), (ext_client, session_callback, arg)); -//DECL_FUNCTION(jack_session_command_t*, jack_session_notify, (jack_client_t* ext_client, const char* target, jack_session_event_type_t ev_type, const char* path), (ext_client, target, ev_type, path)); -//DECL_FUNCTION(int, jack_session_reply, (jack_client_t* ext_client, jack_session_event_t *event), (ext_client, event)); -//DECL_VOID_FUNCTION(jack_session_event_free, (jack_session_event_t* ev), (ev)); -//DECL_FUNCTION(char*, jack_client_get_uuid, (jack_client_t* ext_client),(ext_client)); -//DECL_FUNCTION(char*, jack_get_uuid_for_client_name, (jack_client_t* ext_client, const char* client_name),(ext_client, client_name)); -//DECL_FUNCTION(char*, jack_get_client_name_by_uuid, (jack_client_t* ext_client, const char* client_uuid),(ext_client, client_uuid)); -//DECL_FUNCTION(int, jack_reserve_client_name, (jack_client_t* ext_client, const char* name, const char* uuid),(ext_client, name, uuid)); -//DECL_VOID_FUNCTION(jack_session_commands_free, (jack_session_command_t *cmds),(cmds)); -//DECL_FUNCTION(int, jack_client_has_session_callback, (jack_client_t *client, const char* client_name),(client, client_name)); +DECL_FUNCTION(int, jack_set_session_callback, (jack_client_t* ext_client, JackSessionCallback session_callback, void* arg), (ext_client, session_callback, arg)); +DECL_FUNCTION(jack_session_command_t*, jack_session_notify, (jack_client_t* ext_client, const char* target, jack_session_event_type_t ev_type, const char* path), (ext_client, target, ev_type, path)); +DECL_FUNCTION(int, jack_session_reply, (jack_client_t* ext_client, jack_session_event_t *event), (ext_client, event)); +DECL_VOID_FUNCTION(jack_session_event_free, (jack_session_event_t* ev), (ev)); +DECL_FUNCTION(char*, jack_client_get_uuid, (jack_client_t* ext_client),(ext_client)); +DECL_FUNCTION(char*, jack_get_uuid_for_client_name, (jack_client_t* ext_client, const char* client_name),(ext_client, client_name)); +DECL_FUNCTION(char*, jack_get_client_name_by_uuid, (jack_client_t* ext_client, const char* client_uuid),(ext_client, client_uuid)); +DECL_FUNCTION(int, jack_reserve_client_name, (jack_client_t* ext_client, const char* name, const char* uuid),(ext_client, name, uuid)); +DECL_VOID_FUNCTION(jack_session_commands_free, (jack_session_command_t *cmds),(cmds)); +DECL_FUNCTION(int, jack_client_has_session_callback, (jack_client_t *client, const char* client_name),(client, client_name)); // MIDI - DECL_FUNCTION(jack_nframes_t, jack_midi_get_event_count, (void* port_buffer), (port_buffer)); DECL_FUNCTION(int, jack_midi_event_get, (jack_midi_event_t* event, void* port_buffer, jack_nframes_t event_index), (event, port_buffer, event_index)) ; DECL_VOID_FUNCTION(jack_midi_clear_buffer, (void* port_buffer), (port_buffer));