Use jack_client_open instead of old jack_client_new.
[jack2.git] / common / JackWeakAPI.cpp
blob81e21d3578e637438233d3e4ddf105a359f02c38
1 /*
2 Copyright (C) 2009 Grame
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 Completed from Julien Pommier (PianoTeq : http://www.pianoteq.com/) code.
24 #include <jack/jack.h>
25 #include <jack/thread.h>
26 #include <jack/midiport.h>
27 #include <math.h>
28 #include <dlfcn.h>
29 #include <stdlib.h>
30 #include <cassert>
31 #include <iostream>
33 /* dynamically load libjack and forward all registered calls to libjack
34 (similar to what relaytool is trying to do, but more portably..)
37 typedef void (*print_function)(const char *);
38 typedef void *(*thread_routine)(void*);
40 using std::cerr;
42 int libjack_is_present = 0; // public symbol, similar to what relaytool does.
43 static void *libjack_handle = 0;
45 static void __attribute__((constructor)) tryload_libjack()
47 if (getenv("SKIP_LIBJACK") == 0) { // just in case libjack is causing troubles..
48 #ifdef __APPLE__
49 libjack_handle = dlopen("libjack.0.dylib", RTLD_LAZY);
50 #else
51 libjack_handle = dlopen("libjack.so.0", RTLD_LAZY);
52 #endif
55 libjack_is_present = (libjack_handle != 0);
58 void *load_jack_function(const char *fn_name)
60 void *fn = 0;
61 if (!libjack_handle) {
62 std::cerr << "libjack not found, so do not try to load " << fn_name << " ffs !\n";
63 return 0;
65 fn = dlsym(libjack_handle, fn_name);
66 if (!fn) {
67 std::cerr << "could not dlsym(" << libjack_handle << "), " << dlerror() << "\n";
69 return fn;
72 #define DECL_FUNCTION(return_type, fn_name, arguments_types, arguments) \
73 typedef return_type (*fn_name##_ptr_t)arguments_types; \
74 return_type fn_name arguments_types { \
75 static fn_name##_ptr_t fn = 0; \
76 if (fn == 0) { fn = (fn_name##_ptr_t)load_jack_function(#fn_name); } \
77 if (fn) return (*fn)arguments; \
78 else return (return_type)-1; \
81 #define DECL_VOID_FUNCTION(fn_name, arguments_types, arguments) \
82 typedef void (*fn_name##_ptr_t)arguments_types; \
83 void fn_name arguments_types { \
84 static fn_name##_ptr_t fn = 0; \
85 if (fn == 0) { fn = (fn_name##_ptr_t)load_jack_function(#fn_name); } \
86 if (fn) (*fn)arguments; \
89 DECL_VOID_FUNCTION(jack_get_version, (int *major_ptr, int *minor_ptr, int *micro_ptr, int *proto_ptr), (major_ptr, minor_ptr, micro_ptr, proto_ptr));
90 DECL_FUNCTION(const char *, jack_get_version_string, (), ());
91 DECL_FUNCTION(jack_client_t *, jack_client_open, (const char *client_name, jack_options_t options, jack_status_t *status, ...),
92 (client_name, options, status));
93 DECL_FUNCTION(int, jack_client_close, (jack_client_t *client), (client));
94 DECL_FUNCTION(jack_client_t *, jack_client_new, (const char *client_name), (client_name));
95 DECL_FUNCTION(int, jack_client_name_size, (), ());
96 DECL_FUNCTION(char*, jack_get_client_name, (jack_client_t *client), (client));
97 DECL_FUNCTION(int, jack_internal_client_new, (const char *client_name,
98 const char *load_name,
99 const char *load_init), (client_name, load_name, load_init));
100 DECL_VOID_FUNCTION(jack_internal_client_close, (const char *client_name), (client_name));
101 DECL_FUNCTION(int, jack_is_realtime, (jack_client_t *client), (client));
102 DECL_VOID_FUNCTION(jack_on_shutdown, (jack_client_t *client, JackShutdownCallback shutdown_callback, void *arg), (client, shutdown_callback, arg));
103 DECL_VOID_FUNCTION(jack_on_info_shutdown, (jack_client_t* client, JackInfoShutdownCallback shutdown_callback, void* arg), (client, shutdown_callback, arg));
104 DECL_FUNCTION(int, jack_set_process_callback, (jack_client_t *client,
105 JackProcessCallback process_callback,
106 void *arg), (client, process_callback, arg));
107 DECL_FUNCTION(jack_nframes_t, jack_thread_wait, (jack_client_t *client, int status), (client, status));
110 DECL_FUNCTION(jack_nframes_t, jack_cycle_wait, (jack_client_t *client), (client));
111 DECL_VOID_FUNCTION(jack_cycle_signal, (jack_client_t *client, int status), (client, status));
112 DECL_FUNCTION(int, jack_set_process_thread, (jack_client_t *client,
113 JackThreadCallback fun,
114 void *arg), (client, fun, arg));
115 DECL_FUNCTION(int, jack_set_thread_init_callback, (jack_client_t *client,
116 JackThreadInitCallback thread_init_callback,
117 void *arg), (client, thread_init_callback, arg));
118 DECL_FUNCTION(int, jack_set_freewheel_callback, (jack_client_t *client,
119 JackFreewheelCallback freewheel_callback,
120 void *arg), (client, freewheel_callback, arg));
121 DECL_FUNCTION(int, jack_set_freewheel, (jack_client_t *client, int onoff), (client, onoff));
122 DECL_FUNCTION(int, jack_set_buffer_size, (jack_client_t *client, jack_nframes_t nframes), (client, nframes));
123 DECL_FUNCTION(int, jack_set_buffer_size_callback, (jack_client_t *client,
124 JackBufferSizeCallback bufsize_callback,
125 void *arg), (client, bufsize_callback, arg));
126 DECL_FUNCTION(int, jack_set_sample_rate_callback, (jack_client_t *client,
127 JackSampleRateCallback srate_callback,
128 void *arg), (client, srate_callback, arg));
129 DECL_FUNCTION(int, jack_set_client_registration_callback, (jack_client_t *client,
130 JackClientRegistrationCallback registration_callback,
131 void *arg), (client, registration_callback, arg));
132 DECL_FUNCTION(int, jack_set_port_registration_callback, (jack_client_t *client,
133 JackPortRegistrationCallback registration_callback,
134 void *arg), (client, registration_callback, arg));
135 DECL_FUNCTION(int, jack_set_port_connect_callback, (jack_client_t *client,
136 JackPortConnectCallback connect_callback,
137 void *arg), (client, connect_callback, arg));
138 DECL_FUNCTION(int, jack_set_port_rename_callback, (jack_client_t *client,
139 JackPortRenameCallback rename_callback,
140 void *arg), (client, rename_callback, arg));
141 DECL_FUNCTION(int, jack_set_graph_order_callback, (jack_client_t *client,
142 JackGraphOrderCallback graph_callback,
143 void *arg), (client, graph_callback, arg));
144 DECL_FUNCTION(int, jack_set_xrun_callback, (jack_client_t *client,
145 JackXRunCallback xrun_callback,
146 void *arg), (client, xrun_callback, arg));
147 DECL_FUNCTION(int, jack_activate, (jack_client_t *client), (client));
148 DECL_FUNCTION(int, jack_deactivate, (jack_client_t *client), (client));
149 DECL_FUNCTION(jack_port_t *, jack_port_register, (jack_client_t *client, const char *port_name, const char *port_type,
150 unsigned long flags, unsigned long buffer_size),
151 (client, port_name, port_type, flags, buffer_size));
152 DECL_FUNCTION(int, jack_port_unregister, (jack_client_t *client, jack_port_t* port), (client, port));
153 DECL_FUNCTION(void *, jack_port_get_buffer, (jack_port_t *port, jack_nframes_t nframes), (port, nframes));
154 DECL_FUNCTION(const char*, jack_port_name, (const jack_port_t *port), (port));
155 DECL_FUNCTION(const char*, jack_port_short_name, (const jack_port_t *port), (port));
156 DECL_FUNCTION(int, jack_port_flags, (const jack_port_t *port), (port));
157 DECL_FUNCTION(const char*, jack_port_type, (const jack_port_t *port), (port));
158 DECL_FUNCTION(jack_port_type_id_t, jack_port_type_id, (const jack_port_t *port), (port));
159 DECL_FUNCTION(int, jack_port_is_mine, (const jack_client_t *client, const jack_port_t* port), (client, port));
160 DECL_FUNCTION(int, jack_port_connected, (const jack_port_t *port), (port));
161 DECL_FUNCTION(int, jack_port_connected_to, (const jack_port_t *port, const char *port_name), (port, port_name));
162 DECL_FUNCTION(const char**, jack_port_get_connections, (const jack_port_t *port), (port));
163 DECL_FUNCTION(const char**, jack_port_get_all_connections, (const jack_client_t *client,const jack_port_t *port), (client, port));
164 DECL_FUNCTION(int, jack_port_tie, (jack_port_t *src, jack_port_t *dst), (src, dst));
165 DECL_FUNCTION(int, jack_port_untie, (jack_port_t *port), (port));
166 DECL_FUNCTION(jack_nframes_t, jack_port_get_latency, (jack_port_t *port), (port));
167 DECL_FUNCTION(jack_nframes_t, jack_port_get_total_latency ,(jack_client_t * client, jack_port_t *port), (client, port));
168 DECL_VOID_FUNCTION(jack_port_set_latency, (jack_port_t * port, jack_nframes_t frames), (port, frames));
169 DECL_FUNCTION(int, jack_recompute_total_latency, (jack_client_t* client, jack_port_t* port), (client, port));
170 DECL_FUNCTION(int, jack_recompute_total_latencies, (jack_client_t* client),(client));
172 DECL_FUNCTION(int, jack_port_set_name, (jack_port_t *port, const char *port_name), (port, port_name));
173 DECL_FUNCTION(int, jack_port_set_alias, (jack_port_t *port, const char *alias), (port, alias));
174 DECL_FUNCTION(int, jack_port_unset_alias, (jack_port_t *port, const char *alias), (port, alias));
175 DECL_FUNCTION(int, jack_port_get_aliases, (const jack_port_t *port, char* const aliases[2]), (port,aliases));
176 DECL_FUNCTION(int, jack_port_request_monitor, (jack_port_t *port, int onoff), (port, onoff));
177 DECL_FUNCTION(int, jack_port_request_monitor_by_name, (jack_client_t *client, const char *port_name, int onoff), (client, port_name, onoff));
178 DECL_FUNCTION(int, jack_port_ensure_monitor, (jack_port_t *port, int onoff), (port, onoff));
179 DECL_FUNCTION(int, jack_port_monitoring_input, (jack_port_t *port) ,(port));
180 DECL_FUNCTION(int, jack_connect, (jack_client_t * client, const char *source_port, const char *destination_port), (client, source_port, destination_port));
181 DECL_FUNCTION(int, jack_disconnect, (jack_client_t * client, const char *source_port, const char *destination_port), (client, source_port, destination_port));
182 DECL_FUNCTION(int, jack_port_disconnect, (jack_client_t * client, jack_port_t * port), (client, port));
183 DECL_FUNCTION(int, jack_port_name_size,(),());
184 DECL_FUNCTION(int, jack_port_type_size,(),());
186 DECL_FUNCTION(jack_nframes_t, jack_get_sample_rate, (jack_client_t *client), (client));
187 DECL_FUNCTION(jack_nframes_t, jack_get_buffer_size, (jack_client_t *client), (client));
188 DECL_FUNCTION(const char**, jack_get_ports, (jack_client_t *client, const char *port_name_pattern, const char * type_name_pattern,
189 unsigned long flags), (client, port_name_pattern, type_name_pattern, flags));
190 DECL_FUNCTION(jack_port_t *, jack_port_by_name, (jack_client_t * client, const char *port_name), (client, port_name));
191 DECL_FUNCTION(jack_port_t *, jack_port_by_id, (jack_client_t *client, jack_port_id_t port_id), (client, port_id));
193 DECL_FUNCTION(int, jack_engine_takeover_timebase, (jack_client_t * client), (client));
194 DECL_FUNCTION(jack_nframes_t, jack_frames_since_cycle_start, (const jack_client_t * client), (client));
195 DECL_FUNCTION(jack_time_t, jack_get_time, (), ());
196 DECL_FUNCTION(jack_nframes_t, jack_time_to_frames, (const jack_client_t *client, jack_time_t time), (client, time));
197 DECL_FUNCTION(jack_time_t, jack_frames_to_time, (const jack_client_t *client, jack_nframes_t frames), (client, frames));
198 DECL_FUNCTION(jack_nframes_t, jack_frame_time, (const jack_client_t *client), (client));
199 DECL_FUNCTION(jack_nframes_t, jack_last_frame_time, (const jack_client_t *client), (client));
200 DECL_FUNCTION(float, jack_cpu_load, (jack_client_t *client), (client));
201 DECL_FUNCTION(pthread_t, jack_client_thread_id, (jack_client_t *client), (client));
202 DECL_VOID_FUNCTION(jack_set_error_function, (print_function fun), (fun));
203 DECL_VOID_FUNCTION(jack_set_info_function, (print_function fun), (fun));
205 DECL_FUNCTION(float, jack_get_max_delayed_usecs, (jack_client_t *client), (client));
206 DECL_FUNCTION(float, jack_get_xrun_delayed_usecs, (jack_client_t *client), (client));
207 DECL_VOID_FUNCTION(jack_reset_max_delayed_usecs, (jack_client_t *client), (client));
209 DECL_FUNCTION(int, jack_release_timebase, (jack_client_t *client), (client));
210 DECL_FUNCTION(int, jack_set_sync_callback, (jack_client_t *client, JackSyncCallback sync_callback, void *arg), (client, sync_callback, arg));
211 DECL_FUNCTION(int, jack_set_sync_timeout, (jack_client_t *client, jack_time_t timeout), (client, timeout));
212 DECL_FUNCTION(int, jack_set_timebase_callback, (jack_client_t *client,
213 int conditional,
214 JackTimebaseCallback timebase_callback,
215 void *arg), (client, conditional, timebase_callback, arg));
216 DECL_FUNCTION(int, jack_transport_locate, (jack_client_t *client, jack_nframes_t frame), (client, frame));
217 DECL_FUNCTION(jack_transport_state_t, jack_transport_query, (const jack_client_t *client, jack_position_t *pos), (client, pos));
218 DECL_FUNCTION(jack_nframes_t, jack_get_current_transport_frame, (const jack_client_t *client), (client));
219 DECL_FUNCTION(int, jack_transport_reposition, (jack_client_t *client, jack_position_t *pos), (client, pos));
220 DECL_VOID_FUNCTION(jack_transport_start, (jack_client_t *client), (client));
221 DECL_VOID_FUNCTION(jack_transport_stop, (jack_client_t *client), (client));
222 DECL_VOID_FUNCTION(jack_get_transport_info, (jack_client_t *client, jack_transport_info_t *tinfo), (client,tinfo));
223 DECL_VOID_FUNCTION(jack_set_transport_info, (jack_client_t *client, jack_transport_info_t *tinfo), (client,tinfo));
225 DECL_FUNCTION(int, jack_client_real_time_priority, (jack_client_t* client), (client));
226 DECL_FUNCTION(int, jack_client_max_real_time_priority, (jack_client_t* client), (client));
227 DECL_FUNCTION(int, jack_acquire_real_time_scheduling, (pthread_t thread, int priority), (thread, priority));
228 DECL_FUNCTION(int, jack_client_create_thread, (jack_client_t* client,
229 pthread_t *thread,
230 int priority,
231 int realtime, // boolean
232 thread_routine routine,
233 void *arg), (client, thread, priority, realtime, routine, arg));
234 DECL_FUNCTION(int, jack_drop_real_time_scheduling, (pthread_t thread), (thread));
236 DECL_FUNCTION(int, jack_client_stop_thread, (jack_client_t* client, pthread_t thread), (client, thread));
237 DECL_FUNCTION(int, jack_client_kill_thread, (jack_client_t* client, pthread_t thread), (client, thread));
238 #ifndef WIN32
239 DECL_VOID_FUNCTION(jack_set_thread_creator, (jack_thread_creator_t jtc), (jtc));
240 #endif
241 DECL_FUNCTION(char *, jack_get_internal_client_name, (jack_client_t *client, jack_intclient_t intclient), (client, intclient));
242 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));
244 DECL_FUNCTION(jack_intclient_t, jack_internal_client_load, (jack_client_t *client,
245 const char *client_name,
246 jack_options_t options,
247 jack_status_t *status
248 , ...), (client, client_name, options, status, ...));
250 DECL_FUNCTION(jack_status_t, jack_internal_client_unload, (jack_client_t *client, jack_intclient_t intclient), (client, intclient));
251 DECL_VOID_FUNCTION(jack_free, (void* ptr), (ptr));
253 // MIDI
255 DECL_FUNCTION(jack_nframes_t, jack_midi_get_event_count, (void* port_buffer), (port_buffer));
256 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)) ;
257 DECL_VOID_FUNCTION(jack_midi_clear_buffer, (void* port_buffer), (port_buffer));
258 DECL_FUNCTION(size_t, jack_midi_max_event_size, (void* port_buffer), (port_buffer));
259 DECL_FUNCTION(jack_midi_data_t*, jack_midi_event_reserve, (void* port_buffer, jack_nframes_t time, size_t data_size), (port_buffer, time, data_size));
260 DECL_FUNCTION(int, jack_midi_event_write, (void* port_buffer, jack_nframes_t time, const jack_midi_data_t* data, size_t data_size), (port_buffer, time, data, data_size));
261 DECL_FUNCTION(jack_nframes_t, jack_midi_get_lost_event_count, (void* port_buffer), (port_buffer));