00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "JackClient.h"
00022 #include "JackError.h"
00023 #include "JackGraphManager.h"
00024 #include "JackEngineControl.h"
00025 #include "JackClientControl.h"
00026 #include "JackGlobals.h"
00027 #include "JackTime.h"
00028 #include "JackExports.h"
00029 #include <math.h>
00030
00031 using namespace Jack;
00032
00033 #ifdef __cplusplus
00034 extern "C"
00035 {
00036 #endif
00037
00038 EXPORT int jack_client_name_size (void);
00039 EXPORT char* jack_get_client_name (jack_client_t *client);
00040 EXPORT int jack_internal_client_new (const char *client_name,
00041 const char *load_name,
00042 const char *load_init);
00043 EXPORT jack_client_t* my_jack_internal_client_new(const char* client_name);
00044 EXPORT void jack_internal_client_close (const char *client_name);
00045 EXPORT void my_jack_internal_client_close (jack_client_t* client);
00046 EXPORT int jack_is_realtime (jack_client_t *client);
00047 EXPORT void jack_on_shutdown (jack_client_t *client,
00048 void (*function)(void *arg), void *arg);
00049 EXPORT int jack_set_process_callback (jack_client_t *client,
00050 JackProcessCallback process_callback,
00051 void *arg);
00052 EXPORT int jack_set_thread_init_callback (jack_client_t *client,
00053 JackThreadInitCallback thread_init_callback,
00054 void *arg);
00055 EXPORT int jack_set_freewheel_callback (jack_client_t *client,
00056 JackFreewheelCallback freewheel_callback,
00057 void *arg);
00058 EXPORT int jack_set_freewheel(jack_client_t* client, int onoff);
00059 EXPORT int jack_set_buffer_size (jack_client_t *client, jack_nframes_t nframes);
00060 EXPORT int jack_set_buffer_size_callback (jack_client_t *client,
00061 JackBufferSizeCallback bufsize_callback,
00062 void *arg);
00063 EXPORT int jack_set_sample_rate_callback (jack_client_t *client,
00064 JackSampleRateCallback srate_callback,
00065 void *arg);
00066 EXPORT int jack_set_port_registration_callback (jack_client_t *,
00067 JackPortRegistrationCallback
00068 registration_callback, void *arg);
00069 EXPORT int jack_set_graph_order_callback (jack_client_t *,
00070 JackGraphOrderCallback graph_callback,
00071 void *);
00072 EXPORT int jack_set_xrun_callback (jack_client_t *,
00073 JackXRunCallback xrun_callback, void *arg);
00074 EXPORT int jack_activate (jack_client_t *client);
00075 EXPORT int jack_deactivate (jack_client_t *client);
00076 EXPORT jack_port_t * jack_port_register (jack_client_t *client,
00077 const char *port_name,
00078 const char *port_type,
00079 unsigned long flags,
00080 unsigned long buffer_size);
00081 EXPORT int jack_port_unregister (jack_client_t *, jack_port_t *);
00082 EXPORT void * jack_port_get_buffer (jack_port_t *, jack_nframes_t);
00083 EXPORT const char * jack_port_name (const jack_port_t *port);
00084 EXPORT const char * jack_port_short_name (const jack_port_t *port);
00085 EXPORT int jack_port_flags (const jack_port_t *port);
00086 EXPORT const char * jack_port_type (const jack_port_t *port);
00087 EXPORT int jack_port_is_mine (const jack_client_t *, const jack_port_t *port);
00088 EXPORT int jack_port_connected (const jack_port_t *port);
00089 EXPORT int jack_port_connected_to (const jack_port_t *port,
00090 const char *port_name);
00091 EXPORT const char ** jack_port_get_connections (const jack_port_t *port);
00092 EXPORT const char ** jack_port_get_all_connections (const jack_client_t *client,
00093 const jack_port_t *port);
00094 EXPORT int jack_port_tie (jack_port_t *src, jack_port_t *dst);
00095 EXPORT int jack_port_untie (jack_port_t *port);
00096 EXPORT int jack_port_lock (jack_client_t *, jack_port_t *);
00097 EXPORT int jack_port_unlock (jack_client_t *, jack_port_t *);
00098 EXPORT jack_nframes_t jack_port_get_latency (jack_port_t *port);
00099 EXPORT jack_nframes_t jack_port_get_total_latency (jack_client_t *,
00100 jack_port_t *port);
00101 EXPORT void jack_port_set_latency (jack_port_t *, jack_nframes_t);
00102 EXPORT int jack_recompute_total_latencies (jack_client_t*);
00103 EXPORT int jack_port_set_name (jack_port_t *port, const char *port_name);
00104 EXPORT int jack_port_request_monitor (jack_port_t *port, int onoff);
00105 EXPORT int jack_port_request_monitor_by_name (jack_client_t *client,
00106 const char *port_name, int onoff);
00107 EXPORT int jack_port_ensure_monitor (jack_port_t *port, int onoff);
00108 EXPORT int jack_port_monitoring_input (jack_port_t *port);
00109 EXPORT int jack_connect (jack_client_t *,
00110 const char *source_port,
00111 const char *destination_port);
00112 EXPORT int jack_disconnect (jack_client_t *,
00113 const char *source_port,
00114 const char *destination_port);
00115 EXPORT int jack_port_disconnect (jack_client_t *, jack_port_t *);
00116 EXPORT int jack_port_name_size(void);
00117 EXPORT int jack_port_type_size(void);
00118 EXPORT jack_nframes_t jack_get_sample_rate (jack_client_t *);
00119 EXPORT jack_nframes_t jack_get_buffer_size (jack_client_t *);
00120 EXPORT const char ** jack_get_ports (jack_client_t *,
00121 const char *port_name_pattern,
00122 const char *type_name_pattern,
00123 unsigned long flags);
00124 EXPORT jack_port_t * jack_port_by_name (jack_client_t *, const char *port_name);
00125 EXPORT jack_port_t * jack_port_by_id (jack_client_t *client,
00126 jack_port_id_t port_id);
00127 EXPORT int jack_engine_takeover_timebase (jack_client_t *);
00128 EXPORT jack_nframes_t jack_frames_since_cycle_start (const jack_client_t *);
00129 EXPORT jack_nframes_t jack_frame_time (const jack_client_t *);
00130 EXPORT jack_nframes_t jack_last_frame_time (const jack_client_t *client);
00131 EXPORT float jack_cpu_load (jack_client_t *client);
00132 EXPORT pthread_t jack_client_thread_id (jack_client_t *);
00133 EXPORT void jack_set_error_function (void (*func)(const char *));
00134
00135 EXPORT float jack_get_max_delayed_usecs (jack_client_t *client);
00136 EXPORT float jack_get_xrun_delayed_usecs (jack_client_t *client);
00137 EXPORT void jack_reset_max_delayed_usecs (jack_client_t *client);
00138
00139 EXPORT int jack_release_timebase (jack_client_t *client);
00140 EXPORT int jack_set_sync_callback (jack_client_t *client,
00141 JackSyncCallback sync_callback,
00142 void *arg);
00143 EXPORT int jack_set_sync_timeout (jack_client_t *client,
00144 jack_time_t timeout);
00145 EXPORT int jack_set_timebase_callback (jack_client_t *client,
00146 int conditional,
00147 JackTimebaseCallback timebase_callback,
00148 void *arg);
00149 EXPORT int jack_transport_locate (jack_client_t *client,
00150 jack_nframes_t frame);
00151 EXPORT jack_transport_state_t jack_transport_query (const jack_client_t *client,
00152 jack_position_t *pos);
00153 EXPORT jack_nframes_t jack_get_current_transport_frame (const jack_client_t *client);
00154 EXPORT int jack_transport_reposition (jack_client_t *client,
00155 jack_position_t *pos);
00156 EXPORT void jack_transport_start (jack_client_t *client);
00157 EXPORT void jack_transport_stop (jack_client_t *client);
00158 EXPORT void jack_get_transport_info (jack_client_t *client,
00159 jack_transport_info_t *tinfo);
00160 EXPORT void jack_set_transport_info (jack_client_t *client,
00161 jack_transport_info_t *tinfo);
00162
00163 EXPORT int jack_acquire_real_time_scheduling (pthread_t thread, int priority);
00164 EXPORT int jack_client_create_thread (jack_client_t* client,
00165 pthread_t *thread,
00166 int priority,
00167 int realtime,
00168 void *(*start_routine)(void*),
00169 void *arg);
00170 EXPORT int jack_drop_real_time_scheduling (pthread_t thread);
00171
00172 EXPORT char * jack_get_internal_client_name (jack_client_t *client,
00173 jack_intclient_t intclient);
00174 EXPORT jack_intclient_t jack_internal_client_handle (jack_client_t *client,
00175 const char *client_name,
00176 jack_status_t *status);
00177 EXPORT jack_intclient_t jack_internal_client_load (jack_client_t *client,
00178 const char *client_name,
00179 jack_options_t options,
00180 jack_status_t *status, ...);
00181 EXPORT jack_status_t jack_internal_client_unload (jack_client_t *client,
00182 jack_intclient_t intclient);
00183
00184 #ifdef __cplusplus
00185 }
00186 #endif
00187
00188 #ifdef WIN32
00189
00190 inline double rint(double nr)
00191 {
00192 double f = floor(nr);
00193 double c = ceil(nr);
00194 return (((c -nr) >= (nr - f)) ? f : c);
00195 }
00196 #endif
00197
00198 static inline bool CheckPort(jack_port_id_t port_index)
00199 {
00200 return (port_index < PORT_NUM);
00201 }
00202
00203 static inline bool CheckBufferSize(jack_nframes_t buffer_size)
00204 {
00205 return (buffer_size <= BUFFER_SIZE_MAX);
00206 }
00207
00208 static inline void WaitGraphChange()
00209 {
00210 if (GetGraphManager()->IsPendingChange()) {
00211 JackLog("WaitGraphChange...\n");
00212 JackSleep(GetEngineControl()->fPeriodUsecs * 2);
00213 }
00214 }
00215
00216 static void default_jack_error_callback(const char *desc)
00217 {
00218 fprintf(stderr, "%s\n", desc);
00219 }
00220
00221 void (*jack_error_callback)(const char *desc) = &default_jack_error_callback;
00222
00223 EXPORT void jack_set_error_function (void (*func)(const char *))
00224 {
00225 jack_error_callback = func;
00226 }
00227
00228 EXPORT void* jack_port_get_buffer(jack_port_t* port, jack_nframes_t frames)
00229 {
00230 jack_port_id_t myport = (jack_port_id_t)port;
00231 if (!CheckPort(myport)) {
00232 jack_error("jack_port_get_buffer called with an incorrect port %ld", myport);
00233 return NULL;
00234 } else {
00235 return GetGraphManager()->GetBuffer(myport, frames);
00236 }
00237 }
00238
00239 EXPORT const char* jack_port_name(const jack_port_t* port)
00240 {
00241 jack_port_id_t myport = (jack_port_id_t)port;
00242 if (!CheckPort(myport)) {
00243 jack_error("jack_port_name called with an incorrect port %ld", myport);
00244 return NULL;
00245 } else {
00246 return GetGraphManager()->GetPort(myport)->GetName();
00247 }
00248 }
00249
00250 EXPORT const char* jack_port_short_name(const jack_port_t* port)
00251 {
00252 jack_port_id_t myport = (jack_port_id_t)port;
00253 if (!CheckPort(myport)) {
00254 jack_error("jack_port_short_name called with an incorrect port %ld", myport);
00255 return NULL;
00256 } else {
00257 return GetGraphManager()->GetPort(myport)->GetShortName();
00258 }
00259 }
00260
00261 EXPORT int jack_port_flags(const jack_port_t* port)
00262 {
00263 jack_port_id_t myport = (jack_port_id_t)port;
00264 if (!CheckPort(myport)) {
00265 jack_error("jack_port_flags called with an incorrect port %ld", myport);
00266 return -1;
00267 } else {
00268 return GetGraphManager()->GetPort(myport)->Flags();
00269 }
00270 }
00271
00272 EXPORT const char* jack_port_type(const jack_port_t* port)
00273 {
00274 jack_port_id_t myport = (jack_port_id_t)port;
00275 if (!CheckPort(myport)) {
00276 jack_error("jack_port_flags called an incorrect port %ld", myport);
00277 return NULL;
00278 } else {
00279 return GetGraphManager()->GetPort(myport)->Type();
00280 }
00281 }
00282
00283 EXPORT int jack_port_connected(const jack_port_t* port)
00284 {
00285 jack_port_id_t myport = (jack_port_id_t)port;
00286 if (!CheckPort(myport)) {
00287 jack_error("jack_port_connected called with an incorrect port %ld", myport);
00288 return -1;
00289 } else {
00290 WaitGraphChange();
00291 return GetGraphManager()->GetConnectionsNum(myport);
00292 }
00293 }
00294
00295 EXPORT int jack_port_connected_to(const jack_port_t* port, const char* portname)
00296 {
00297 jack_port_id_t myport = (jack_port_id_t)port;
00298 if (!CheckPort(myport)) {
00299 jack_error("jack_port_connected_to called with an incorrect port %ld", myport);
00300 return -1;
00301 } else if (portname == NULL) {
00302 jack_error("jack_port_connected_to called with a NULL port name");
00303 return -1;
00304 } else {
00305 WaitGraphChange();
00306 return GetGraphManager()->ConnectedTo(myport, portname);
00307 }
00308 }
00309
00310 EXPORT int jack_port_tie(jack_port_t* src, jack_port_t* dst)
00311 {
00312 jack_port_id_t mysrc = (jack_port_id_t)src;
00313 if (!CheckPort(mysrc)) {
00314 jack_error("jack_port_tie called with a NULL src port");
00315 return -1;
00316 }
00317 jack_port_id_t mydst = (jack_port_id_t)dst;
00318 if (!CheckPort(mydst)) {
00319 jack_error("jack_port_tie called with a NULL dst port");
00320 return -1;
00321 }
00322 if (GetGraphManager()->GetPort(mysrc)->GetRefNum() != GetGraphManager()->GetPort(mydst)->GetRefNum()) {
00323 jack_error("jack_port_tie called with ports not belonging to the same client");
00324 return -1;
00325 }
00326 return GetGraphManager()->GetPort(mydst)->Tie(mysrc);
00327 }
00328
00329 EXPORT int jack_port_untie(jack_port_t* port)
00330 {
00331 jack_port_id_t myport = (jack_port_id_t)port;
00332 if (!CheckPort(myport)) {
00333 jack_error("jack_port_untie called with an incorrect port %ld", myport);
00334 return -1;
00335 } else {
00336 return GetGraphManager()->GetPort(myport)->UnTie();
00337 }
00338 }
00339
00340 EXPORT jack_nframes_t jack_port_get_latency(jack_port_t* port)
00341 {
00342 jack_port_id_t myport = (jack_port_id_t)port;
00343 if (!CheckPort(myport)) {
00344 jack_error("jack_port_get_latency called with an incorrect port %ld", myport);
00345 return 0;
00346 } else {
00347 WaitGraphChange();
00348 return GetGraphManager()->GetPort(myport)->GetLatency();
00349 }
00350 }
00351
00352 EXPORT void jack_port_set_latency(jack_port_t* port, jack_nframes_t frames)
00353 {
00354 jack_port_id_t myport = (jack_port_id_t)port;
00355 if (!CheckPort(myport)) {
00356 jack_error("jack_port_set_latency called with an incorrect port %ld", myport);
00357 } else {
00358 GetGraphManager()->GetPort(myport)->SetLatency(frames);
00359 }
00360 }
00361
00362 EXPORT int jack_recompute_total_latencies(jack_client_t* ext_client)
00363 {
00364
00365 return 0;
00366 }
00367
00368 EXPORT int jack_port_set_name(jack_port_t* port, const char* name)
00369 {
00370 jack_port_id_t myport = (jack_port_id_t)port;
00371 if (!CheckPort(myport)) {
00372 jack_error("jack_port_set_name called with an incorrect port %ld", myport);
00373 return -1;
00374 } else if (name == NULL) {
00375 jack_error("jack_port_set_name called with a NULL port name");
00376 return -1;
00377 } else {
00378 return GetGraphManager()->GetPort(myport)->SetName(name);
00379 }
00380 }
00381
00382 EXPORT int jack_port_request_monitor(jack_port_t* port, int onoff)
00383 {
00384 jack_port_id_t myport = (jack_port_id_t)port;
00385 if (!CheckPort(myport)) {
00386 jack_error("jack_port_request_monitor called with an incorrect port %ld", myport);
00387 return -1;
00388 } else {
00389 return GetGraphManager()->RequestMonitor(myport, onoff);
00390 }
00391 }
00392
00393 EXPORT int jack_port_request_monitor_by_name(jack_client_t* ext_client, const char* port_name, int onoff)
00394 {
00395 JackClient* client = (JackClient*)ext_client;
00396 if (client == NULL) {
00397 jack_error("jack_port_request_monitor_by_name called with a NULL client");
00398 return -1;
00399 } else {
00400 jack_port_id_t myport = GetGraphManager()->GetPort(port_name);
00401 if (!CheckPort(myport)) {
00402 jack_error("jack_port_request_monitor_by_name called with an incorrect port %s", port_name);
00403 return -1;
00404 } else {
00405 return GetGraphManager()->RequestMonitor(myport, onoff);
00406 }
00407 }
00408 }
00409
00410 EXPORT int jack_port_ensure_monitor(jack_port_t* port, int onoff)
00411 {
00412 jack_port_id_t myport = (jack_port_id_t)port;
00413 if (!CheckPort(myport)) {
00414 jack_error("jack_port_ensure_monitor called with an incorrect port %ld", myport);
00415 return -1;
00416 } else {
00417 return GetGraphManager()->GetPort(myport)->EnsureMonitor(onoff);
00418 }
00419 }
00420
00421 EXPORT int jack_port_monitoring_input(jack_port_t* port)
00422 {
00423 jack_port_id_t myport = (jack_port_id_t)port;
00424 if (!CheckPort(myport)) {
00425 jack_error("jack_port_monitoring_input called with an incorrect port %ld", myport);
00426 return -1;
00427 } else {
00428 return GetGraphManager()->GetPort(myport)->MonitoringInput();
00429 }
00430 }
00431
00432 EXPORT int jack_is_realtime(jack_client_t* ext_client)
00433 {
00434 JackClient* client = (JackClient*)ext_client;
00435 if (client == NULL) {
00436 jack_error("jack_is_realtime called with a NULL client");
00437 return -1;
00438 } else {
00439 return GetEngineControl()->fRealTime;
00440 }
00441 }
00442
00443 EXPORT void jack_on_shutdown(jack_client_t* ext_client, void (*function)(void* arg), void* arg)
00444 {
00445 JackClient* client = (JackClient*)ext_client;
00446 if (client == NULL) {
00447 jack_error("jack_on_shutdown called with a NULL client");
00448 } else {
00449 client->OnShutdown(function, arg);
00450 }
00451 }
00452
00453 EXPORT int jack_set_process_callback(jack_client_t* ext_client, JackProcessCallback callback, void* arg)
00454 {
00455 JackClient* client = (JackClient*)ext_client;
00456 if (client == NULL) {
00457 jack_error("jack_set_process_callback called with a NULL client");
00458 return -1;
00459 } else {
00460 return client->SetProcessCallback(callback, arg);
00461 }
00462 }
00463
00464 EXPORT int jack_set_freewheel_callback(jack_client_t* ext_client, JackFreewheelCallback freewheel_callback, void* arg)
00465 {
00466 JackClient* client = (JackClient*)ext_client;
00467 if (client == NULL) {
00468 jack_error("jack_set_freewheel_callback called with a NULL client");
00469 return -1;
00470 } else {
00471 return client->SetFreewheelCallback(freewheel_callback, arg);
00472 }
00473 }
00474
00475 EXPORT int jack_set_freewheel(jack_client_t* ext_client, int onoff)
00476 {
00477 JackClient* client = (JackClient*)ext_client;
00478 if (client == NULL) {
00479 jack_error("jack_set_freewheel called with a NULL client");
00480 return -1;
00481 } else {
00482 return client->SetFreeWheel(onoff);
00483 }
00484 }
00485
00486 EXPORT int jack_set_buffer_size(jack_client_t* ext_client, jack_nframes_t buffer_size)
00487 {
00488 JackClient* client = (JackClient*)ext_client;
00489 if (client == NULL) {
00490 jack_error("jack_set_buffer_size called with a NULL client");
00491 return -1;
00492 } else if (!CheckBufferSize(buffer_size)) {
00493 return -1;
00494 } else {
00495 return client->SetBufferSize(buffer_size);
00496 }
00497 }
00498
00499 EXPORT int jack_set_buffer_size_callback(jack_client_t* ext_client, JackBufferSizeCallback bufsize_callback, void* arg)
00500 {
00501 JackClient* client = (JackClient*)ext_client;
00502 if (client == NULL) {
00503 jack_error("jack_set_buffer_size_callback called with a NULL client");
00504 return -1;
00505 } else {
00506 return client->SetBufferSizeCallback(bufsize_callback, arg);
00507 }
00508 }
00509
00510 EXPORT int jack_set_sample_rate_callback(jack_client_t* ext_client, JackSampleRateCallback srate_callback, void* arg)
00511 {
00512 JackClient* client = (JackClient*)ext_client;
00513 JackLog("jack_set_sample_rate_callback ext_client %x client %x \n", ext_client, client);
00514 if (client == NULL) {
00515 jack_error("jack_set_sample_rate_callback called with a NULL client");
00516 return -1;
00517 } else {
00518 JackLog("jack_set_sample_rate_callback: deprecated\n");
00519 return -1;
00520 }
00521 }
00522
00523 EXPORT int jack_set_port_registration_callback(jack_client_t* ext_client, JackPortRegistrationCallback registration_callback, void* arg)
00524 {
00525 JackClient* client = (JackClient*)ext_client;
00526 if (client == NULL) {
00527 jack_error("jack_set_port_registration_callback called with a NULL client");
00528 return -1;
00529 } else {
00530 return client->SetPortRegistrationCallback(registration_callback, arg);
00531 }
00532 }
00533
00534 EXPORT int jack_set_graph_order_callback(jack_client_t* ext_client, JackGraphOrderCallback graph_callback, void* arg)
00535 {
00536 JackClient* client = (JackClient*)ext_client;
00537 JackLog("jack_set_graph_order_callback ext_client %x client %x \n", ext_client, client);
00538 if (client == NULL) {
00539 jack_error("jack_set_graph_order_callback called with a NULL client");
00540 return -1;
00541 } else {
00542 return client->SetGraphOrderCallback(graph_callback, arg);
00543 }
00544 }
00545
00546 EXPORT int jack_set_xrun_callback(jack_client_t* ext_client, JackXRunCallback xrun_callback, void* arg)
00547 {
00548 JackClient* client = (JackClient*)ext_client;
00549 if (client == NULL) {
00550 jack_error("jack_set_xrun_callback called with a NULL client");
00551 return -1;
00552 } else {
00553 return client->SetXRunCallback(xrun_callback, arg);
00554 }
00555 }
00556
00557 EXPORT int jack_set_thread_init_callback(jack_client_t* ext_client, JackThreadInitCallback init_callback, void *arg)
00558 {
00559 JackClient* client = (JackClient*)ext_client;
00560 JackLog("jack_set_thread_init_callback ext_client %x client %x \n", ext_client, client);
00561 if (client == NULL) {
00562 jack_error("jack_set_thread_init_callback called with a NULL client");
00563 return -1;
00564 } else {
00565 return client->SetInitCallback(init_callback, arg);
00566 }
00567 }
00568
00569 EXPORT int jack_activate(jack_client_t* ext_client)
00570 {
00571 JackClient* client = (JackClient*)ext_client;
00572 if (client == NULL) {
00573 jack_error("jack_activate called with a NULL client");
00574 return -1;
00575 } else {
00576 return client->Activate();
00577 }
00578 }
00579
00580 EXPORT int jack_deactivate(jack_client_t* ext_client)
00581 {
00582 JackClient* client = (JackClient*)ext_client;
00583 if (client == NULL) {
00584 jack_error("jack_deactivate called with a NULL client");
00585 return -1;
00586 } else {
00587 return client->Deactivate();
00588 }
00589 }
00590
00591 EXPORT jack_port_t* jack_port_register(jack_client_t* ext_client, const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size)
00592 {
00593 JackClient* client = (JackClient*)ext_client;
00594 if (client == NULL) {
00595 jack_error("jack_port_register called with a NULL client");
00596 return NULL;
00597 } else if ((port_name == NULL) || (port_type == NULL)) {
00598 jack_error("jack_port_register called with a NULL port name or a NULL port_type");
00599 return NULL;
00600 } else {
00601 return (jack_port_t *)client->PortRegister(port_name, port_type, flags, buffer_size);
00602 }
00603 }
00604
00605 EXPORT int jack_port_unregister(jack_client_t* ext_client, jack_port_t* port)
00606 {
00607 JackClient* client = (JackClient*)ext_client;
00608 if (client == NULL) {
00609 jack_error("jack_port_unregister called with a NULL client");
00610 return -1;
00611 }
00612 jack_port_id_t myport = (jack_port_id_t)port;
00613 if (!CheckPort(myport)) {
00614 jack_error("jack_port_unregister called with an incorrect port %ld", myport);
00615 return -1;
00616 }
00617 return client->PortUnRegister(myport);
00618 }
00619
00620 EXPORT int jack_port_is_mine(const jack_client_t* ext_client, const jack_port_t* port)
00621 {
00622 JackClient* client = (JackClient*)ext_client;
00623 if (client == NULL) {
00624 jack_error("jack_port_is_mine called with a NULL client");
00625 return -1;
00626 }
00627 jack_port_id_t myport = (jack_port_id_t)port;
00628 if (!CheckPort(myport)) {
00629 jack_error("jack_port_is_mine called with an incorrect port %ld", myport);
00630 return -1;
00631 }
00632 return client->PortIsMine(myport);
00633 }
00634
00635 EXPORT const char** jack_port_get_connections(const jack_port_t* port)
00636 {
00637 jack_port_id_t myport = (jack_port_id_t)port;
00638 if (!CheckPort(myport)) {
00639 jack_error("jack_port_get_connections called with an incorrect port %ld", myport);
00640 return NULL;
00641 } else {
00642 WaitGraphChange();
00643 return GetGraphManager()->GetConnections(myport);
00644 }
00645 }
00646
00647
00648 EXPORT const char** jack_port_get_all_connections(const jack_client_t* ext_client, const jack_port_t* port)
00649 {
00650 JackClient* client = (JackClient*)ext_client;
00651 if (client == NULL) {
00652 jack_error("jack_port_get_all_connections called with a NULL client");
00653 return NULL;
00654 }
00655
00656 jack_port_id_t myport = (jack_port_id_t)port;
00657 if (!CheckPort(myport)) {
00658 jack_error("jack_port_get_all_connections called with an incorrect port %ld", myport);
00659 return NULL;
00660 } else {
00661 WaitGraphChange();
00662 return GetGraphManager()->GetConnections(myport);
00663 }
00664 }
00665
00666
00667 EXPORT int jack_port_lock(jack_client_t* ext_client, jack_port_t* port)
00668 {
00669 JackClient* client = (JackClient*)ext_client;
00670 if (client == NULL) {
00671 jack_error("jack_port_lock called with a NULL client");
00672 return -1;
00673 }
00674
00675 jack_port_id_t myport = (jack_port_id_t)port;
00676 if (!CheckPort(myport)) {
00677 jack_error("jack_port_lock called with an incorrect port %ld", myport);
00678 return -1;
00679 } else {
00680 return (myport && client->PortIsMine(myport)) ? GetGraphManager()->GetPort(myport)->Lock() : -1;
00681 }
00682 }
00683
00684
00685 EXPORT int jack_port_unlock(jack_client_t* ext_client, jack_port_t* port)
00686 {
00687 JackClient* client = (JackClient*)ext_client;
00688 if (client == NULL) {
00689 jack_error("jack_port_unlock called with a NULL client");
00690 return -1;
00691 }
00692
00693 jack_port_id_t myport = (jack_port_id_t)port;
00694 if (!CheckPort(myport)) {
00695 jack_error("jack_port_unlock called with an incorrect port %ld", myport);
00696 return -1;
00697 } else {
00698 return (myport && client->PortIsMine(myport)) ? GetGraphManager()->GetPort(myport)->Unlock() : -1;
00699 }
00700 }
00701
00702 EXPORT jack_nframes_t jack_port_get_total_latency(jack_client_t* ext_client, jack_port_t* port)
00703 {
00704 JackClient* client = (JackClient*)ext_client;
00705 if (client == NULL) {
00706 jack_error("jack_port_get_total_latency called with a NULL client");
00707 return 0;
00708 }
00709
00710 jack_port_id_t myport = (jack_port_id_t)port;
00711 if (!CheckPort(myport)) {
00712 jack_error("jack_port_get_total_latency called with an incorrect port %ld", myport);
00713 return 0;
00714 } else {
00715
00716 WaitGraphChange();
00717 return GetGraphManager()->GetTotalLatency(myport);
00718 }
00719 }
00720
00721 EXPORT int jack_connect(jack_client_t* ext_client, const char* src, const char* dst)
00722 {
00723 JackClient* client = (JackClient*)ext_client;
00724 if (client == NULL) {
00725 jack_error("jack_connect called with a NULL client");
00726 return -1;
00727 } else if ((src == NULL) || (dst == NULL)) {
00728 jack_error("jack_connect called with a NULL port name");
00729 return -1;
00730 } else {
00731 return client->PortConnect(src, dst);
00732 }
00733 }
00734
00735 EXPORT int jack_disconnect(jack_client_t* ext_client, const char* src, const char* dst)
00736 {
00737 JackClient* client = (JackClient*)ext_client;
00738 if (client == NULL) {
00739 jack_error("jack_disconnect called with a NULL client");
00740 return -1;
00741 } else if ((src == NULL) || (dst == NULL)) {
00742 jack_error("jack_connect called with a NULL port name");
00743 return -1;
00744 } else {
00745 return client->PortDisconnect(src, dst);
00746 }
00747 }
00748
00749 EXPORT int jack_port_connect(jack_client_t* ext_client, jack_port_t* src, jack_port_t* dst)
00750 {
00751 JackClient* client = (JackClient*)ext_client;
00752 if (client == NULL) {
00753 jack_error("jack_port_connect called with a NULL client");
00754 return -1;
00755 }
00756 jack_port_id_t mysrc = (jack_port_id_t)src;
00757 if (!CheckPort(mysrc)) {
00758 jack_error("jack_port_connect called with a NULL src port");
00759 return -1;
00760 }
00761 jack_port_id_t mydst = (jack_port_id_t)dst;
00762 if (!CheckPort(mydst)) {
00763 jack_error("jack_port_connect called with a NULL dst port");
00764 return -1;
00765 }
00766 return client->PortConnect(mysrc, mydst);
00767 }
00768
00769 EXPORT int jack_port_disconnect(jack_client_t* ext_client, jack_port_t* src)
00770 {
00771 JackClient* client = (JackClient*)ext_client;
00772 if (client == NULL) {
00773 jack_error("jack_port_disconnect called with a NULL client");
00774 return -1;
00775 }
00776 jack_port_id_t myport = (jack_port_id_t)src;
00777 if (!CheckPort(myport)) {
00778 jack_error("jack_port_disconnect called with an incorrect port %ld", myport);
00779 return -1;
00780 }
00781 return client->PortDisconnect(myport);
00782 }
00783
00784 EXPORT jack_nframes_t jack_get_sample_rate(jack_client_t* ext_client)
00785 {
00786 JackClient* client = (JackClient*)ext_client;
00787 if (client == NULL) {
00788 jack_error("jack_get_sample_rate called with a NULL client");
00789 return 0;
00790 } else {
00791 return GetEngineControl()->fSampleRate;
00792 }
00793 }
00794
00795 EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t* ext_client)
00796 {
00797 JackClient* client = (JackClient*)ext_client;
00798 if (client == NULL) {
00799 jack_error("jack_get_buffer_size called with a NULL client");
00800 return 0;
00801 } else {
00802 return GetEngineControl()->fBufferSize;
00803 }
00804 }
00805
00806 EXPORT const char** jack_get_ports(jack_client_t* ext_client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags)
00807 {
00808 JackClient* client = (JackClient*)ext_client;
00809 if (client == NULL) {
00810 jack_error("jack_get_ports called with a NULL client");
00811 return NULL;
00812 }
00813 return GetGraphManager()->GetPorts(port_name_pattern, type_name_pattern, flags);
00814 }
00815
00816 EXPORT jack_port_t* jack_port_by_name(jack_client_t* ext_client, const char* portname)
00817 {
00818 JackClient* client = (JackClient*)ext_client;
00819 if (client == NULL) {
00820 jack_error("jack_get_ports called with a NULL client");
00821 return 0;
00822 }
00823
00824 if (portname == NULL) {
00825 jack_error("jack_port_by_name called with a NULL port name");
00826 return NULL;
00827 } else {
00828 int res = GetGraphManager()->GetPort(portname);
00829 return (res == NO_PORT) ? NULL : (jack_port_t*)res;
00830 }
00831 }
00832
00833 EXPORT jack_port_t* jack_port_by_id(const jack_client_t* ext_client, jack_port_id_t id)
00834 {
00835
00836 return (jack_port_t*)id;
00837 }
00838
00839 EXPORT int jack_engine_takeover_timebase(jack_client_t* ext_client)
00840 {
00841 JackClient* client = (JackClient*)ext_client;
00842 if (client == NULL) {
00843 jack_error("jack_engine_takeover_timebase called with a NULL client");
00844 return -1;
00845 } else {
00846 jack_error("jack_engine_takeover_timebase : not yet implemented\n");
00847 return 0;
00848 }
00849 }
00850
00851 EXPORT jack_nframes_t jack_frames_since_cycle_start(const jack_client_t* ext_client)
00852 {
00853 JackTimer timer;
00854 GetEngineControl()->ReadFrameTime(&timer);
00855 return (jack_nframes_t) floor((((float)GetEngineControl()->fSampleRate) / 1000000.0f) * (GetMicroSeconds() - timer.fCurrentCallback));
00856 }
00857
00858 EXPORT jack_nframes_t jack_frame_time(const jack_client_t* ext_client)
00859 {
00860 JackClient* client = (JackClient*)ext_client;
00861 if (client == NULL) {
00862 jack_error("jack_frame_time called with a NULL client");
00863 return 0;
00864 } else {
00865 JackTimer timer;
00866 GetEngineControl()->ReadFrameTime(&timer);
00867 if (timer.fInitialized) {
00868 return timer.fFrames +
00869 (long) rint(((double) ((jack_time_t)(GetMicroSeconds() - timer.fCurrentWakeup)) /
00870 ((jack_time_t)(timer.fNextWakeUp - timer.fCurrentWakeup))) * GetEngineControl()->fBufferSize);
00871 } else {
00872 return 0;
00873 }
00874 }
00875 }
00876
00877 EXPORT jack_nframes_t jack_last_frame_time(const jack_client_t* ext_client)
00878 {
00879 JackTimer timer;
00880 GetEngineControl()->ReadFrameTime(&timer);
00881 return timer.fFrames;
00882 }
00883
00884 EXPORT float jack_cpu_load(jack_client_t* ext_client)
00885 {
00886 JackClient* client = (JackClient*)ext_client;
00887 if (client == NULL) {
00888 jack_error("jack_cpu_load called with a NULL client");
00889 return 0.0f;
00890 } else {
00891 return GetEngineControl()->fCPULoad;
00892 }
00893 }
00894
00895 EXPORT pthread_t jack_client_thread_id(jack_client_t* ext_client)
00896 {
00897 JackClient* client = (JackClient*)ext_client;
00898 if (client == NULL) {
00899 jack_error("jack_client_thread_id called with a NULL client");
00900 return (pthread_t)NULL;
00901 } else {
00902 return client->GetThreadID();
00903 }
00904 }
00905
00906 EXPORT char* jack_get_client_name (jack_client_t* ext_client)
00907 {
00908 JackClient* client = (JackClient*)ext_client;
00909 if (client == NULL) {
00910 jack_error("jack_get_client_name called with a NULL client");
00911 return NULL;
00912 } else {
00913 return client->GetClientControl()->fName;
00914 }
00915 }
00916
00917 EXPORT int jack_client_name_size(void)
00918 {
00919 return JACK_CLIENT_NAME_SIZE;
00920 }
00921
00922 EXPORT int jack_port_name_size(void)
00923 {
00924 return JACK_PORT_NAME_SIZE;
00925 }
00926
00927
00928
00929 EXPORT int jack_release_timebase(jack_client_t* ext_client)
00930 {
00931 JackClient* client = (JackClient*)ext_client;
00932 if (client == NULL) {
00933 jack_error("jack_release_timebase called with a NULL client");
00934 return -1;
00935 } else {
00936 return client->ReleaseTimebase();
00937 }
00938 }
00939
00940 EXPORT int jack_set_sync_callback(jack_client_t* ext_client, JackSyncCallback sync_callback, void *arg)
00941 {
00942 JackClient* client = (JackClient*)ext_client;
00943 if (client == NULL) {
00944 jack_error("jack_set_sync_callback called with a NULL client");
00945 return -1;
00946 } else {
00947 return client->SetSyncCallback(sync_callback, arg);
00948 }
00949 }
00950
00951 EXPORT int jack_set_sync_timeout(jack_client_t* ext_client, jack_time_t timeout)
00952 {
00953 JackClient* client = (JackClient*)ext_client;
00954 if (client == NULL) {
00955 jack_error("jack_set_sync_timeout called with a NULL client");
00956 return -1;
00957 } else {
00958 return client->SetSyncTimeout(timeout);
00959 }
00960 }
00961
00962 EXPORT int jack_set_timebase_callback(jack_client_t* ext_client, int conditional, JackTimebaseCallback timebase_callback, void* arg)
00963 {
00964 JackClient* client = (JackClient*)ext_client;
00965 if (client == NULL) {
00966 jack_error("jack_set_timebase_callback called with a NULL client");
00967 return -1;
00968 } else {
00969 return client->SetTimebaseCallback(conditional, timebase_callback, arg);
00970 }
00971 }
00972
00973 EXPORT int jack_transport_locate(jack_client_t* ext_client, jack_nframes_t frame)
00974 {
00975 JackClient* client = (JackClient*)ext_client;
00976 if (client == NULL) {
00977 jack_error("jack_transport_locate called with a NULL client");
00978 return -1;
00979 } else {
00980 return client->TransportLocate(frame);
00981 }
00982 }
00983
00984 EXPORT jack_transport_state_t jack_transport_query(const jack_client_t* ext_client, jack_position_t* pos)
00985 {
00986 JackClient* client = (JackClient*)ext_client;
00987 if (client == NULL) {
00988 jack_error("jack_transport_query called with a NULL client");
00989 return JackTransportStopped;
00990 } else {
00991 return client->TransportQuery(pos);
00992 }
00993 }
00994
00995 EXPORT jack_nframes_t jack_get_current_transport_frame(const jack_client_t* ext_client)
00996 {
00997 JackClient* client = (JackClient*)ext_client;
00998 if (client == NULL) {
00999 jack_error("jack_get_current_transport_frame called with a NULL client");
01000 return 0;
01001 } else {
01002 return client->GetCurrentTransportFrame();
01003 }
01004 }
01005
01006 EXPORT int jack_transport_reposition(jack_client_t* ext_client, jack_position_t* pos)
01007 {
01008 JackClient* client = (JackClient*)ext_client;
01009 if (client == NULL) {
01010 jack_error("jack_transport_reposition called with a NULL client");
01011 return -1;
01012 } else {
01013 return client->TransportReposition(pos);
01014 }
01015 }
01016
01017 EXPORT void jack_transport_start(jack_client_t* ext_client)
01018 {
01019 JackClient* client = (JackClient*)ext_client;
01020 if (client == NULL) {
01021 jack_error("jack_transport_start called with a NULL client");
01022 } else {
01023 client->TransportStart();
01024 }
01025 }
01026
01027 EXPORT void jack_transport_stop(jack_client_t* ext_client)
01028 {
01029 JackClient* client = (JackClient*)ext_client;
01030 if (client == NULL) {
01031 jack_error("jack_transport_stop called with a NULL client");
01032 } else {
01033 client->TransportStop();
01034 }
01035 }
01036
01037
01038
01039 EXPORT void jack_get_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
01040 {
01041 JackLog("jack_get_transport_info : deprecated");
01042 if (tinfo)
01043 memset(tinfo, 0, sizeof(jack_transport_info_t));
01044 }
01045
01046 EXPORT void jack_set_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
01047 {
01048 JackLog("jack_set_transport_info : deprecated");
01049 if (tinfo)
01050 memset(tinfo, 0, sizeof(jack_transport_info_t));
01051 }
01052
01053
01054
01055 EXPORT float jack_get_max_delayed_usecs(jack_client_t* ext_client)
01056 {
01057 JackLog("jack_get_max_delayed_usecs: not yet implemented\n");
01058 return 0.f;
01059 }
01060
01061 EXPORT float jack_get_xrun_delayed_usecs(jack_client_t* ext_client)
01062 {
01063 JackLog("jack_get_xrun_delayed_usecs: not yet implemented\n");
01064 return 0.f;
01065 }
01066
01067 EXPORT void jack_reset_max_delayed_usecs(jack_client_t* ext_client)
01068 {
01069 JackLog("jack_reset_max_delayed_usecs: not yet implemented\n");
01070 }
01071
01072
01073
01074 EXPORT int jack_acquire_real_time_scheduling(pthread_t thread, int priority)
01075 {
01076 JackLog("jack_acquire_real_time_scheduling: not yet implemented\n");
01077 return -1;
01078 }
01079
01080 EXPORT int jack_client_create_thread(jack_client_t* client,
01081 pthread_t *thread,
01082 int priority,
01083 int realtime,
01084 void *(*start_routine)(void*),
01085 void *arg)
01086 {
01087 JackLog("jack_client_create_thread: not yet implemented\n");
01088 return -1;
01089 }
01090
01091 EXPORT int jack_drop_real_time_scheduling(pthread_t thread)
01092 {
01093 JackLog("jack_drop_real_time_scheduling: not yet implemented\n");
01094 return -1;
01095 }
01096
01097
01098
01099 EXPORT char* jack_get_internal_client_name(jack_client_t* ext_client, jack_intclient_t intclient)
01100 {
01101 JackLog("jack_get_internal_client_name: not yet implemented\n");
01102 return "";
01103 }
01104
01105 EXPORT jack_intclient_t jack_internal_client_handle(jack_client_t* ext_client, const char* client_name, jack_status_t* status)
01106 {
01107 JackLog("jack_internal_client_handle: not yet implemented\n");
01108 return 0;
01109 }
01110
01111 EXPORT jack_intclient_t jack_internal_client_load(jack_client_t* ext_client, const char* client_name, jack_options_t options, jack_status_t* status, ...)
01112 {
01113 JackLog("jack_internal_client_load: not yet implemented\n");
01114 return 0;
01115 }
01116
01117 EXPORT jack_status_t jack_internal_client_unload(jack_client_t* ext_client, jack_intclient_t intclient)
01118 {
01119 JackLog("jack_internal_client_unload: not yet implemented\n");
01120 return JackFailure;
01121 }