jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1939 lines
62KB

  1. /*
  2. Copyright (C) 2001-2003 Paul Davis
  3. Copyright (C) 2004-2008 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.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. #include "JackClient.h"
  17. #include "JackError.h"
  18. #include "JackGraphManager.h"
  19. #include "JackEngineControl.h"
  20. #include "JackClientControl.h"
  21. #include "JackGlobals.h"
  22. #include "JackTime.h"
  23. #include "JackCompilerDeps.h"
  24. #include "JackPortType.h"
  25. #include "JackPlatformPlug.h"
  26. #include <math.h>
  27. #ifdef __CLIENTDEBUG__
  28. #include "JackLibGlobals.h"
  29. #endif
  30. using namespace Jack;
  31. #ifdef __cplusplus
  32. extern "C"
  33. {
  34. #endif
  35. typedef void (*print_function)(const char *);
  36. typedef void *(*thread_routine)(void*);
  37. EXPORT
  38. void
  39. jack_get_version(
  40. int *major_ptr,
  41. int *minor_ptr,
  42. int *micro_ptr,
  43. int *proto_ptr);
  44. EXPORT
  45. const char *
  46. jack_get_version_string();
  47. EXPORT jack_client_t * jack_client_open_aux (const char *client_name,
  48. jack_options_t options,
  49. jack_status_t *status, va_list ap);
  50. EXPORT jack_client_t * jack_client_open (const char *client_name,
  51. jack_options_t options,
  52. jack_status_t *status, ...);
  53. EXPORT jack_client_t * jack_client_new (const char *client_name);
  54. EXPORT int jack_client_name_size (void);
  55. EXPORT char* jack_get_client_name (jack_client_t *client);
  56. EXPORT int jack_internal_client_new (const char *client_name,
  57. const char *load_name,
  58. const char *load_init);
  59. EXPORT void jack_internal_client_close (const char *client_name);
  60. EXPORT int jack_is_realtime (jack_client_t *client);
  61. EXPORT void jack_on_shutdown (jack_client_t *client,
  62. JackShutdownCallback shutdown_callback, void *arg);
  63. EXPORT int jack_set_process_callback (jack_client_t *client,
  64. JackProcessCallback process_callback,
  65. void *arg);
  66. EXPORT jack_nframes_t jack_thread_wait(jack_client_t *client, int status);
  67. // new
  68. EXPORT jack_nframes_t jack_cycle_wait (jack_client_t*);
  69. EXPORT void jack_cycle_signal (jack_client_t*, int status);
  70. EXPORT int jack_set_process_thread(jack_client_t* client, JackThreadCallback fun, void *arg);
  71. EXPORT int jack_set_thread_init_callback (jack_client_t *client,
  72. JackThreadInitCallback thread_init_callback,
  73. void *arg);
  74. EXPORT int jack_set_freewheel_callback (jack_client_t *client,
  75. JackFreewheelCallback freewheel_callback,
  76. void *arg);
  77. EXPORT int jack_set_freewheel(jack_client_t* client, int onoff);
  78. EXPORT int jack_set_buffer_size (jack_client_t *client, jack_nframes_t nframes);
  79. EXPORT int jack_set_buffer_size_callback (jack_client_t *client,
  80. JackBufferSizeCallback bufsize_callback,
  81. void *arg);
  82. EXPORT int jack_set_sample_rate_callback (jack_client_t *client,
  83. JackSampleRateCallback srate_callback,
  84. void *arg);
  85. EXPORT int jack_set_client_registration_callback (jack_client_t *,
  86. JackClientRegistrationCallback
  87. registration_callback, void *arg);
  88. EXPORT int jack_set_port_registration_callback (jack_client_t *,
  89. JackPortRegistrationCallback
  90. registration_callback, void *arg);
  91. EXPORT int jack_set_port_connect_callback (jack_client_t *,
  92. JackPortConnectCallback
  93. connect_callback, void *arg);
  94. EXPORT int jack_set_port_rename_callback (jack_client_t *,
  95. JackPortRenameCallback
  96. rename_callback, void *arg);
  97. EXPORT int jack_set_graph_order_callback (jack_client_t *,
  98. JackGraphOrderCallback graph_callback,
  99. void *);
  100. EXPORT int jack_set_xrun_callback (jack_client_t *,
  101. JackXRunCallback xrun_callback, void *arg);
  102. EXPORT int jack_activate (jack_client_t *client);
  103. EXPORT int jack_deactivate (jack_client_t *client);
  104. EXPORT jack_port_t * jack_port_register (jack_client_t *client,
  105. const char *port_name,
  106. const char *port_type,
  107. unsigned long flags,
  108. unsigned long buffer_size);
  109. EXPORT int jack_port_unregister (jack_client_t *, jack_port_t *);
  110. EXPORT void * jack_port_get_buffer (jack_port_t *, jack_nframes_t);
  111. EXPORT const char * jack_port_name (const jack_port_t *port);
  112. EXPORT const char * jack_port_short_name (const jack_port_t *port);
  113. EXPORT int jack_port_flags (const jack_port_t *port);
  114. EXPORT const char * jack_port_type (const jack_port_t *port);
  115. EXPORT jack_port_type_id_t jack_port_type_id (const jack_port_t *port);
  116. EXPORT int jack_port_is_mine (const jack_client_t *, const jack_port_t *port);
  117. EXPORT int jack_port_connected (const jack_port_t *port);
  118. EXPORT int jack_port_connected_to (const jack_port_t *port,
  119. const char *port_name);
  120. EXPORT const char ** jack_port_get_connections (const jack_port_t *port);
  121. EXPORT const char ** jack_port_get_all_connections (const jack_client_t *client,
  122. const jack_port_t *port);
  123. EXPORT int jack_port_tie (jack_port_t *src, jack_port_t *dst);
  124. EXPORT int jack_port_untie (jack_port_t *port);
  125. EXPORT jack_nframes_t jack_port_get_latency (jack_port_t *port);
  126. EXPORT jack_nframes_t jack_port_get_total_latency (jack_client_t *,
  127. jack_port_t *port);
  128. EXPORT void jack_port_set_latency (jack_port_t *, jack_nframes_t);
  129. EXPORT int jack_recompute_total_latency (jack_client_t*, jack_port_t* port);
  130. EXPORT int jack_recompute_total_latencies (jack_client_t*);
  131. EXPORT int jack_port_set_name (jack_port_t *port, const char *port_name);
  132. EXPORT int jack_port_set_alias (jack_port_t *port, const char *alias);
  133. EXPORT int jack_port_unset_alias (jack_port_t *port, const char *alias);
  134. EXPORT int jack_port_get_aliases (const jack_port_t *port, char* const aliases[2]);
  135. EXPORT int jack_port_request_monitor (jack_port_t *port, int onoff);
  136. EXPORT int jack_port_request_monitor_by_name (jack_client_t *client,
  137. const char *port_name, int onoff);
  138. EXPORT int jack_port_ensure_monitor (jack_port_t *port, int onoff);
  139. EXPORT int jack_port_monitoring_input (jack_port_t *port);
  140. EXPORT int jack_connect (jack_client_t *,
  141. const char *source_port,
  142. const char *destination_port);
  143. EXPORT int jack_disconnect (jack_client_t *,
  144. const char *source_port,
  145. const char *destination_port);
  146. EXPORT int jack_port_disconnect (jack_client_t *, jack_port_t *);
  147. EXPORT int jack_port_name_size(void);
  148. EXPORT int jack_port_type_size(void);
  149. EXPORT jack_nframes_t jack_get_sample_rate (jack_client_t *);
  150. EXPORT jack_nframes_t jack_get_buffer_size (jack_client_t *);
  151. EXPORT const char ** jack_get_ports (jack_client_t *,
  152. const char *port_name_pattern,
  153. const char *type_name_pattern,
  154. unsigned long flags);
  155. EXPORT jack_port_t * jack_port_by_name (jack_client_t *, const char *port_name);
  156. EXPORT jack_port_t * jack_port_by_id (jack_client_t *client,
  157. jack_port_id_t port_id);
  158. EXPORT int jack_engine_takeover_timebase (jack_client_t *);
  159. EXPORT jack_nframes_t jack_frames_since_cycle_start (const jack_client_t *);
  160. EXPORT jack_time_t jack_get_time();
  161. EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t *client, jack_time_t time);
  162. EXPORT jack_time_t jack_frames_to_time(const jack_client_t *client, jack_nframes_t frames);
  163. EXPORT jack_nframes_t jack_frame_time (const jack_client_t *);
  164. EXPORT jack_nframes_t jack_last_frame_time (const jack_client_t *client);
  165. EXPORT float jack_cpu_load (jack_client_t *client);
  166. EXPORT pthread_t jack_client_thread_id (jack_client_t *);
  167. EXPORT void jack_set_error_function (print_function);
  168. EXPORT void jack_set_info_function (print_function);
  169. EXPORT float jack_get_max_delayed_usecs (jack_client_t *client);
  170. EXPORT float jack_get_xrun_delayed_usecs (jack_client_t *client);
  171. EXPORT void jack_reset_max_delayed_usecs (jack_client_t *client);
  172. EXPORT int jack_release_timebase (jack_client_t *client);
  173. EXPORT int jack_set_sync_callback (jack_client_t *client,
  174. JackSyncCallback sync_callback,
  175. void *arg);
  176. EXPORT int jack_set_sync_timeout (jack_client_t *client,
  177. jack_time_t timeout);
  178. EXPORT int jack_set_timebase_callback (jack_client_t *client,
  179. int conditional,
  180. JackTimebaseCallback timebase_callback,
  181. void *arg);
  182. EXPORT int jack_transport_locate (jack_client_t *client,
  183. jack_nframes_t frame);
  184. EXPORT jack_transport_state_t jack_transport_query (const jack_client_t *client,
  185. jack_position_t *pos);
  186. EXPORT jack_nframes_t jack_get_current_transport_frame (const jack_client_t *client);
  187. EXPORT int jack_transport_reposition (jack_client_t *client,
  188. jack_position_t *pos);
  189. EXPORT void jack_transport_start (jack_client_t *client);
  190. EXPORT void jack_transport_stop (jack_client_t *client);
  191. EXPORT void jack_get_transport_info (jack_client_t *client,
  192. jack_transport_info_t *tinfo);
  193. EXPORT void jack_set_transport_info (jack_client_t *client,
  194. jack_transport_info_t *tinfo);
  195. EXPORT int jack_client_real_time_priority (jack_client_t*);
  196. EXPORT int jack_client_max_real_time_priority (jack_client_t*);
  197. EXPORT int jack_acquire_real_time_scheduling (pthread_t thread, int priority);
  198. EXPORT int jack_client_create_thread (jack_client_t* client,
  199. pthread_t *thread,
  200. int priority,
  201. int realtime, // boolean
  202. thread_routine routine,
  203. void *arg);
  204. EXPORT int jack_drop_real_time_scheduling (pthread_t thread);
  205. EXPORT int jack_client_stop_thread (jack_client_t* client, pthread_t thread);
  206. EXPORT int jack_client_kill_thread (jack_client_t* client, pthread_t thread);
  207. #ifndef WIN32
  208. EXPORT void jack_set_thread_creator (jack_thread_creator_t jtc);
  209. #endif
  210. EXPORT char * jack_get_internal_client_name (jack_client_t *client,
  211. jack_intclient_t intclient);
  212. EXPORT jack_intclient_t jack_internal_client_handle (jack_client_t *client,
  213. const char *client_name,
  214. jack_status_t *status);
  215. EXPORT jack_intclient_t jack_internal_client_load (jack_client_t *client,
  216. const char *client_name,
  217. jack_options_t options,
  218. jack_status_t *status, ...);
  219. EXPORT jack_intclient_t jack_internal_client_load_aux (jack_client_t *client,
  220. const char *client_name,
  221. jack_options_t options,
  222. jack_status_t *status, va_list ap);
  223. EXPORT jack_status_t jack_internal_client_unload (jack_client_t *client,
  224. jack_intclient_t intclient);
  225. EXPORT void jack_free(void* ptr);
  226. #ifdef __cplusplus
  227. }
  228. #endif
  229. static inline bool CheckPort(jack_port_id_t port_index)
  230. {
  231. return (port_index > 0 && port_index < PORT_NUM);
  232. }
  233. static inline bool CheckBufferSize(jack_nframes_t buffer_size)
  234. {
  235. return (buffer_size <= BUFFER_SIZE_MAX);
  236. }
  237. static inline void WaitGraphChange()
  238. {
  239. /*
  240. TLS key that is set only in RT thread, so never waits for pending
  241. graph change in RT context (just read the current graph state).
  242. */
  243. if (jack_tls_get(JackGlobals::fRealTime) == NULL) {
  244. JackGraphManager* manager = GetGraphManager();
  245. JackEngineControl* control = GetEngineControl();
  246. assert(manager);
  247. assert(control);
  248. if (manager->IsPendingChange()) {
  249. jack_log("WaitGraphChange...");
  250. JackSleep(int(control->fPeriodUsecs * 1.1f));
  251. }
  252. }
  253. }
  254. EXPORT void jack_set_error_function (print_function func)
  255. {
  256. jack_error_callback = func;
  257. }
  258. EXPORT void jack_set_info_function (print_function func)
  259. {
  260. jack_info_callback = func;
  261. }
  262. EXPORT jack_client_t* jack_client_new(const char* client_name)
  263. {
  264. assert(JackGlobals::fOpenMutex);
  265. JackGlobals::fOpenMutex->Lock();
  266. jack_error("jack_client_new: deprecated");
  267. int options = JackUseExactName;
  268. if (getenv("JACK_START_SERVER") == NULL)
  269. options |= JackNoStartServer;
  270. jack_client_t* res = jack_client_open_aux(client_name, (jack_options_t)options, NULL, NULL);
  271. JackGlobals::fOpenMutex->Unlock();
  272. return res;
  273. }
  274. EXPORT void* jack_port_get_buffer(jack_port_t* port, jack_nframes_t frames)
  275. {
  276. #ifdef __CLIENTDEBUG__
  277. JackLibGlobals::CheckContext();
  278. #endif
  279. #if defined(__x86_64__) || defined(__ppc64__)
  280. uint64_t port_aux = (uint64_t)port;
  281. #else
  282. uint32_t port_aux = (uint32_t)port;
  283. #endif
  284. jack_port_id_t myport = (jack_port_id_t)port_aux;
  285. if (!CheckPort(myport)) {
  286. jack_error("jack_port_get_buffer called with an incorrect port %ld", myport);
  287. return NULL;
  288. } else {
  289. JackGraphManager* manager = GetGraphManager();
  290. return (manager ? manager->GetBuffer(myport, frames) : NULL);
  291. }
  292. }
  293. EXPORT const char* jack_port_name(const jack_port_t* port)
  294. {
  295. #ifdef __CLIENTDEBUG__
  296. JackLibGlobals::CheckContext();
  297. #endif
  298. #if defined(__x86_64__) || defined(__ppc64__)
  299. uint64_t port_aux = (uint64_t)port;
  300. #else
  301. uint32_t port_aux = (uint32_t)port;
  302. #endif
  303. jack_port_id_t myport = (jack_port_id_t)port_aux;
  304. if (!CheckPort(myport)) {
  305. jack_error("jack_port_name called with an incorrect port %ld", myport);
  306. return NULL;
  307. } else {
  308. JackGraphManager* manager = GetGraphManager();
  309. return (manager ? manager->GetPort(myport)->GetName() : NULL);
  310. }
  311. }
  312. EXPORT const char* jack_port_short_name(const jack_port_t* port)
  313. {
  314. #ifdef __CLIENTDEBUG__
  315. JackLibGlobals::CheckContext();
  316. #endif
  317. #if defined(__x86_64__) || defined(__ppc64__)
  318. uint64_t port_aux = (uint64_t)port;
  319. #else
  320. uint32_t port_aux = (uint32_t)port;
  321. #endif
  322. jack_port_id_t myport = (jack_port_id_t)port_aux;
  323. if (!CheckPort(myport)) {
  324. jack_error("jack_port_short_name called with an incorrect port %ld", myport);
  325. return NULL;
  326. } else {
  327. JackGraphManager* manager = GetGraphManager();
  328. return (manager ? manager->GetPort(myport)->GetShortName() : NULL);
  329. }
  330. }
  331. EXPORT int jack_port_flags(const jack_port_t* port)
  332. {
  333. #ifdef __CLIENTDEBUG__
  334. JackLibGlobals::CheckContext();
  335. #endif
  336. #if defined(__x86_64__) || defined(__ppc64__)
  337. uint64_t port_aux = (uint64_t)port;
  338. #else
  339. uint32_t port_aux = (uint32_t)port;
  340. #endif
  341. jack_port_id_t myport = (jack_port_id_t)port_aux;
  342. if (!CheckPort(myport)) {
  343. jack_error("jack_port_flags called with an incorrect port %ld", myport);
  344. return -1;
  345. } else {
  346. JackGraphManager* manager = GetGraphManager();
  347. return (manager ? manager->GetPort(myport)->GetFlags() : -1);
  348. }
  349. }
  350. EXPORT const char* jack_port_type(const jack_port_t* port)
  351. {
  352. #ifdef __CLIENTDEBUG__
  353. JackLibGlobals::CheckContext();
  354. #endif
  355. #if defined(__x86_64__) || defined(__ppc64__)
  356. uint64_t port_aux = (uint64_t)port;
  357. #else
  358. uint32_t port_aux = (uint32_t)port;
  359. #endif
  360. jack_port_id_t myport = (jack_port_id_t)port_aux;
  361. if (!CheckPort(myport)) {
  362. jack_error("jack_port_flags called an incorrect port %ld", myport);
  363. return NULL;
  364. } else {
  365. JackGraphManager* manager = GetGraphManager();
  366. return (manager ? manager->GetPort(myport)->GetType() : NULL);
  367. }
  368. }
  369. EXPORT jack_port_type_id_t jack_port_type_id(const jack_port_t *port)
  370. {
  371. #ifdef __CLIENTDEBUG__
  372. JackLibGlobals::CheckContext();
  373. #endif
  374. #if defined(__x86_64__) || defined(__ppc64__)
  375. uint64_t port_aux = (uint64_t)port;
  376. #else
  377. uint32_t port_aux = (uint32_t)port;
  378. #endif
  379. jack_port_id_t myport = (jack_port_id_t)port_aux;
  380. if (!CheckPort(myport)) {
  381. jack_error("jack_port_type_id called an incorrect port %ld", myport);
  382. return 0;
  383. } else {
  384. JackGraphManager* manager = GetGraphManager();
  385. return (manager ? GetPortTypeId(manager->GetPort(myport)->GetType()) : 0);
  386. }
  387. }
  388. EXPORT int jack_port_connected(const jack_port_t* port)
  389. {
  390. #ifdef __CLIENTDEBUG__
  391. JackLibGlobals::CheckContext();
  392. #endif
  393. #if defined(__x86_64__) || defined(__ppc64__)
  394. uint64_t port_aux = (uint64_t)port;
  395. #else
  396. uint32_t port_aux = (uint32_t)port;
  397. #endif
  398. jack_port_id_t myport = (jack_port_id_t)port_aux;
  399. if (!CheckPort(myport)) {
  400. jack_error("jack_port_connected called with an incorrect port %ld", myport);
  401. return -1;
  402. } else {
  403. WaitGraphChange();
  404. JackGraphManager* manager = GetGraphManager();
  405. return (manager ? manager->GetConnectionsNum(myport) : -1);
  406. }
  407. }
  408. EXPORT int jack_port_connected_to(const jack_port_t* port, const char* port_name)
  409. {
  410. #ifdef __CLIENTDEBUG__
  411. JackLibGlobals::CheckContext();
  412. #endif
  413. #if defined(__x86_64__) || defined(__ppc64__)
  414. uint64_t port_aux = (uint64_t)port;
  415. #else
  416. uint32_t port_aux = (uint32_t)port;
  417. #endif
  418. jack_port_id_t src = (jack_port_id_t)port_aux;
  419. if (!CheckPort(src)) {
  420. jack_error("jack_port_connected_to called with an incorrect port %ld", src);
  421. return -1;
  422. } else if (port_name == NULL) {
  423. jack_error("jack_port_connected_to called with a NULL port name");
  424. return -1;
  425. } else {
  426. WaitGraphChange();
  427. JackGraphManager* manager = GetGraphManager();
  428. jack_port_id_t dst = (manager ? manager->GetPort(port_name) : NO_PORT);
  429. if (dst == NO_PORT) {
  430. jack_error("Unknown destination port port_name = %s", port_name);
  431. return 0;
  432. } else {
  433. return manager->IsConnected(src, dst);
  434. }
  435. }
  436. }
  437. EXPORT int jack_port_tie(jack_port_t* src, jack_port_t* dst)
  438. {
  439. #ifdef __CLIENTDEBUG__
  440. JackLibGlobals::CheckContext();
  441. #endif
  442. #if defined(__x86_64__) || defined(__ppc64__)
  443. uint64_t src_aux = (uint64_t)src;
  444. #else
  445. uint32_t src_aux = (uint32_t)src;
  446. #endif
  447. jack_port_id_t mysrc = (jack_port_id_t)src_aux;
  448. if (!CheckPort(mysrc)) {
  449. jack_error("jack_port_tie called with a NULL src port");
  450. return -1;
  451. }
  452. #if defined(__x86_64__) || defined(__ppc64__)
  453. uint64_t dst_aux = (uint64_t)dst;
  454. #else
  455. uint32_t dst_aux = (uint32_t)dst;
  456. #endif
  457. jack_port_id_t mydst = (jack_port_id_t)dst_aux;
  458. if (!CheckPort(mydst)) {
  459. jack_error("jack_port_tie called with a NULL dst port");
  460. return -1;
  461. }
  462. JackGraphManager* manager = GetGraphManager();
  463. if (manager && manager->GetPort(mysrc)->GetRefNum() != manager->GetPort(mydst)->GetRefNum()) {
  464. jack_error("jack_port_tie called with ports not belonging to the same client");
  465. return -1;
  466. } else {
  467. return manager->GetPort(mydst)->Tie(mysrc);
  468. }
  469. }
  470. EXPORT int jack_port_untie(jack_port_t* port)
  471. {
  472. #ifdef __CLIENTDEBUG__
  473. JackLibGlobals::CheckContext();
  474. #endif
  475. #if defined(__x86_64__) || defined(__ppc64__)
  476. uint64_t port_aux = (uint64_t)port;
  477. #else
  478. uint32_t port_aux = (uint32_t)port;
  479. #endif
  480. jack_port_id_t myport = (jack_port_id_t)port_aux;
  481. if (!CheckPort(myport)) {
  482. jack_error("jack_port_untie called with an incorrect port %ld", myport);
  483. return -1;
  484. } else {
  485. JackGraphManager* manager = GetGraphManager();
  486. return (manager ? manager->GetPort(myport)->UnTie() : -1);
  487. }
  488. }
  489. EXPORT jack_nframes_t jack_port_get_latency(jack_port_t* port)
  490. {
  491. #ifdef __CLIENTDEBUG__
  492. JackLibGlobals::CheckContext();
  493. #endif
  494. #if defined(__x86_64__) || defined(__ppc64__)
  495. uint64_t port_aux = (uint64_t)port;
  496. #else
  497. uint32_t port_aux = (uint32_t)port;
  498. #endif
  499. jack_port_id_t myport = (jack_port_id_t)port_aux;
  500. if (!CheckPort(myport)) {
  501. jack_error("jack_port_get_latency called with an incorrect port %ld", myport);
  502. return 0;
  503. } else {
  504. WaitGraphChange();
  505. JackGraphManager* manager = GetGraphManager();
  506. return (manager ? manager->GetPort(myport)->GetLatency() : 0);
  507. }
  508. }
  509. EXPORT void jack_port_set_latency(jack_port_t* port, jack_nframes_t frames)
  510. {
  511. #ifdef __CLIENTDEBUG__
  512. JackLibGlobals::CheckContext();
  513. #endif
  514. #if defined(__x86_64__) || defined(__ppc64__)
  515. uint64_t port_aux = (uint64_t)port;
  516. #else
  517. uint32_t port_aux = (uint32_t)port;
  518. #endif
  519. jack_port_id_t myport = (jack_port_id_t)port_aux;
  520. if (!CheckPort(myport)) {
  521. jack_error("jack_port_set_latency called with an incorrect port %ld", myport);
  522. } else {
  523. JackGraphManager* manager = GetGraphManager();
  524. if (manager)
  525. manager->GetPort(myport)->SetLatency(frames);
  526. }
  527. }
  528. EXPORT int jack_recompute_total_latency(jack_client_t* ext_client, jack_port_t* port)
  529. {
  530. #ifdef __CLIENTDEBUG__
  531. JackLibGlobals::CheckContext();
  532. #endif
  533. JackClient* client = (JackClient*)ext_client;
  534. #if defined(__x86_64__) || defined(__ppc64__)
  535. uint64_t port_aux = (uint64_t)port;
  536. #else
  537. uint32_t port_aux = (uint32_t)port;
  538. #endif
  539. jack_port_id_t myport = (jack_port_id_t)port_aux;
  540. if (client == NULL) {
  541. jack_error("jack_recompute_total_latencies called with a NULL client");
  542. return -1;
  543. } else if (!CheckPort(myport)) {
  544. jack_error("jack_recompute_total_latencies called with a NULL port");
  545. return -1;
  546. } else {
  547. WaitGraphChange();
  548. JackGraphManager* manager = GetGraphManager();
  549. return (manager ? manager->ComputeTotalLatency(myport) : -1);
  550. }
  551. }
  552. EXPORT int jack_recompute_total_latencies(jack_client_t* ext_client)
  553. {
  554. #ifdef __CLIENTDEBUG__
  555. JackLibGlobals::CheckContext();
  556. #endif
  557. JackClient* client = (JackClient*)ext_client;
  558. if (client == NULL) {
  559. jack_error("jack_recompute_total_latencies called with a NULL client");
  560. return -1;
  561. } else {
  562. WaitGraphChange();
  563. JackGraphManager* manager = GetGraphManager();
  564. return (manager ? manager->ComputeTotalLatencies() : -1);
  565. }
  566. }
  567. /*
  568. This is unsafe if case of concurrent access, and should be "serialized" doing a server call.
  569. */
  570. EXPORT int jack_port_set_name(jack_port_t* port, const char* name)
  571. {
  572. #ifdef __CLIENTDEBUG__
  573. JackLibGlobals::CheckContext();
  574. #endif
  575. #if defined(__x86_64__) || defined(__ppc64__)
  576. uint64_t port_aux = (uint64_t)port;
  577. #else
  578. uint32_t port_aux = (uint32_t)port;
  579. #endif
  580. jack_port_id_t myport = (jack_port_id_t)port_aux;
  581. if (!CheckPort(myport)) {
  582. jack_error("jack_port_set_name called with an incorrect port %ld", myport);
  583. return -1;
  584. } else if (name == NULL) {
  585. jack_error("jack_port_set_name called with a NULL port name");
  586. return -1;
  587. } else {
  588. JackGraphManager* manager = GetGraphManager();
  589. int refnum;
  590. if (manager && ((refnum = manager->GetPort(myport)->GetRefNum()) > 0)) {
  591. JackClient* client = JackGlobals::fClientTable[refnum];
  592. assert(client);
  593. return client->PortRename(myport, name);
  594. } else {
  595. return -1;
  596. }
  597. }
  598. }
  599. EXPORT int jack_port_set_alias(jack_port_t* port, const char* name)
  600. {
  601. #ifdef __CLIENTDEBUG__
  602. JackLibGlobals::CheckContext();
  603. #endif
  604. #if defined(__x86_64__) || defined(__ppc64__)
  605. uint64_t port_aux = (uint64_t)port;
  606. #else
  607. uint32_t port_aux = (uint32_t)port;
  608. #endif
  609. jack_port_id_t myport = (jack_port_id_t)port_aux;
  610. if (!CheckPort(myport)) {
  611. jack_error("jack_port_set_alias called with an incorrect port %ld", myport);
  612. return -1;
  613. } else if (name == NULL) {
  614. jack_error("jack_port_set_alias called with a NULL port name");
  615. return -1;
  616. } else {
  617. JackGraphManager* manager = GetGraphManager();
  618. return (manager ? manager->GetPort(myport)->SetAlias(name) : -1);
  619. }
  620. }
  621. EXPORT int jack_port_unset_alias(jack_port_t* port, const char* name)
  622. {
  623. #ifdef __CLIENTDEBUG__
  624. JackLibGlobals::CheckContext();
  625. #endif
  626. #if defined(__x86_64__) || defined(__ppc64__)
  627. uint64_t port_aux = (uint64_t)port;
  628. #else
  629. uint32_t port_aux = (uint32_t)port;
  630. #endif
  631. jack_port_id_t myport = (jack_port_id_t)port_aux;
  632. if (!CheckPort(myport)) {
  633. jack_error("jack_port_unset_alias called with an incorrect port %ld", myport);
  634. return -1;
  635. } else if (name == NULL) {
  636. jack_error("jack_port_unset_alias called with a NULL port name");
  637. return -1;
  638. } else {
  639. JackGraphManager* manager = GetGraphManager();
  640. return (manager ? manager->GetPort(myport)->UnsetAlias(name) : -1);
  641. }
  642. }
  643. EXPORT int jack_port_get_aliases(const jack_port_t* port, char* const aliases[2])
  644. {
  645. #ifdef __CLIENTDEBUG__
  646. JackLibGlobals::CheckContext();
  647. #endif
  648. #if defined(__x86_64__) || defined(__ppc64__)
  649. uint64_t port_aux = (uint64_t)port;
  650. #else
  651. uint32_t port_aux = (uint32_t)port;
  652. #endif
  653. jack_port_id_t myport = (jack_port_id_t)port_aux;
  654. if (!CheckPort(myport)) {
  655. jack_error("jack_port_get_aliases called with an incorrect port %ld", myport);
  656. return -1;
  657. } else {
  658. JackGraphManager* manager = GetGraphManager();
  659. return (manager ? manager->GetPort(myport)->GetAliases(aliases) : -1);
  660. }
  661. }
  662. EXPORT int jack_port_request_monitor(jack_port_t* port, int onoff)
  663. {
  664. #ifdef __CLIENTDEBUG__
  665. JackLibGlobals::CheckContext();
  666. #endif
  667. #if defined(__x86_64__) || defined(__ppc64__)
  668. uint64_t port_aux = (uint64_t)port;
  669. #else
  670. uint32_t port_aux = (uint32_t)port;
  671. #endif
  672. jack_port_id_t myport = (jack_port_id_t)port_aux;
  673. if (!CheckPort(myport)) {
  674. jack_error("jack_port_request_monitor called with an incorrect port %ld", myport);
  675. return -1;
  676. } else {
  677. JackGraphManager* manager = GetGraphManager();
  678. return (manager ? manager->RequestMonitor(myport, onoff) : -1);
  679. }
  680. }
  681. EXPORT int jack_port_request_monitor_by_name(jack_client_t* ext_client, const char* port_name, int onoff)
  682. {
  683. #ifdef __CLIENTDEBUG__
  684. JackLibGlobals::CheckContext();
  685. #endif
  686. JackClient* client = (JackClient*)ext_client;
  687. if (client == NULL) {
  688. jack_error("jack_port_request_monitor_by_name called with a NULL client");
  689. return -1;
  690. } else {
  691. JackGraphManager* manager = GetGraphManager();
  692. if (!manager)
  693. return -1;
  694. jack_port_id_t myport = manager->GetPort(port_name);
  695. if (!CheckPort(myport)) {
  696. jack_error("jack_port_request_monitor_by_name called with an incorrect port %s", port_name);
  697. return -1;
  698. } else {
  699. return manager->RequestMonitor(myport, onoff);
  700. }
  701. }
  702. }
  703. EXPORT int jack_port_ensure_monitor(jack_port_t* port, int onoff)
  704. {
  705. #ifdef __CLIENTDEBUG__
  706. JackLibGlobals::CheckContext();
  707. #endif
  708. #if defined(__x86_64__) || defined(__ppc64__)
  709. uint64_t port_aux = (uint64_t)port;
  710. #else
  711. uint32_t port_aux = (uint32_t)port;
  712. #endif
  713. jack_port_id_t myport = (jack_port_id_t)port_aux;
  714. if (!CheckPort(myport)) {
  715. jack_error("jack_port_ensure_monitor called with an incorrect port %ld", myport);
  716. return -1;
  717. } else {
  718. JackGraphManager* manager = GetGraphManager();
  719. return (manager ? manager->GetPort(myport)->EnsureMonitor(onoff) : -1);
  720. }
  721. }
  722. EXPORT int jack_port_monitoring_input(jack_port_t* port)
  723. {
  724. #ifdef __CLIENTDEBUG__
  725. JackLibGlobals::CheckContext();
  726. #endif
  727. #if defined(__x86_64__) || defined(__ppc64__)
  728. uint64_t port_aux = (uint64_t)port;
  729. #else
  730. uint32_t port_aux = (uint32_t)port;
  731. #endif
  732. jack_port_id_t myport = (jack_port_id_t)port_aux;
  733. if (!CheckPort(myport)) {
  734. jack_error("jack_port_monitoring_input called with an incorrect port %ld", myport);
  735. return -1;
  736. } else {
  737. JackGraphManager* manager = GetGraphManager();
  738. return (manager ? manager->GetPort(myport)->MonitoringInput() : -1);
  739. }
  740. }
  741. EXPORT int jack_is_realtime(jack_client_t* ext_client)
  742. {
  743. #ifdef __CLIENTDEBUG__
  744. JackLibGlobals::CheckContext();
  745. #endif
  746. JackClient* client = (JackClient*)ext_client;
  747. if (client == NULL) {
  748. jack_error("jack_is_realtime called with a NULL client");
  749. return -1;
  750. } else {
  751. JackEngineControl* control = GetEngineControl();
  752. return (control ? control->fRealTime : -1);
  753. }
  754. }
  755. EXPORT void jack_on_shutdown(jack_client_t* ext_client, JackShutdownCallback callback, void* arg)
  756. {
  757. #ifdef __CLIENTDEBUG__
  758. JackLibGlobals::CheckContext();
  759. #endif
  760. JackClient* client = (JackClient*)ext_client;
  761. if (client == NULL) {
  762. jack_error("jack_on_shutdown called with a NULL client");
  763. } else {
  764. client->OnShutdown(callback, arg);
  765. }
  766. }
  767. EXPORT int jack_set_process_callback(jack_client_t* ext_client, JackProcessCallback callback, void* arg)
  768. {
  769. #ifdef __CLIENTDEBUG__
  770. JackLibGlobals::CheckContext();
  771. #endif
  772. JackClient* client = (JackClient*)ext_client;
  773. if (client == NULL) {
  774. jack_error("jack_set_process_callback called with a NULL client");
  775. return -1;
  776. } else {
  777. return client->SetProcessCallback(callback, arg);
  778. }
  779. }
  780. EXPORT jack_nframes_t jack_thread_wait(jack_client_t* ext_client, int status)
  781. {
  782. #ifdef __CLIENTDEBUG__
  783. JackLibGlobals::CheckContext();
  784. #endif
  785. JackClient* client = (JackClient*)ext_client;
  786. if (client == NULL) {
  787. jack_error("jack_thread_wait called with a NULL client");
  788. return 0;
  789. } else {
  790. jack_error("jack_thread_wait: deprecated, use jack_cycle_wait/jack_cycle_signal");
  791. return 0;
  792. }
  793. }
  794. EXPORT jack_nframes_t jack_cycle_wait(jack_client_t* ext_client)
  795. {
  796. #ifdef __CLIENTDEBUG__
  797. JackLibGlobals::CheckContext();
  798. #endif
  799. JackClient* client = (JackClient*)ext_client;
  800. if (client == NULL) {
  801. jack_error("jack_cycle_wait called with a NULL client");
  802. return 0;
  803. } else {
  804. return client->CycleWait();
  805. }
  806. }
  807. EXPORT void jack_cycle_signal(jack_client_t* ext_client, int status)
  808. {
  809. #ifdef __CLIENTDEBUG__
  810. JackLibGlobals::CheckContext();
  811. #endif
  812. JackClient* client = (JackClient*)ext_client;
  813. if (client == NULL) {
  814. jack_error("jack_cycle_signal called with a NULL client");
  815. } else {
  816. client->CycleSignal(status);
  817. }
  818. }
  819. EXPORT int jack_set_process_thread(jack_client_t* ext_client, JackThreadCallback fun, void *arg)
  820. {
  821. #ifdef __CLIENTDEBUG__
  822. JackLibGlobals::CheckContext();
  823. #endif
  824. JackClient* client = (JackClient*)ext_client;
  825. if (client == NULL) {
  826. jack_error("jack_set_process_thread called with a NULL client");
  827. return -1;
  828. } else {
  829. return client->SetProcessThread(fun, arg);
  830. }
  831. }
  832. EXPORT int jack_set_freewheel_callback(jack_client_t* ext_client, JackFreewheelCallback freewheel_callback, void* arg)
  833. {
  834. #ifdef __CLIENTDEBUG__
  835. JackLibGlobals::CheckContext();
  836. #endif
  837. JackClient* client = (JackClient*)ext_client;
  838. if (client == NULL) {
  839. jack_error("jack_set_freewheel_callback called with a NULL client");
  840. return -1;
  841. } else {
  842. return client->SetFreewheelCallback(freewheel_callback, arg);
  843. }
  844. }
  845. EXPORT int jack_set_freewheel(jack_client_t* ext_client, int onoff)
  846. {
  847. #ifdef __CLIENTDEBUG__
  848. JackLibGlobals::CheckContext();
  849. #endif
  850. JackClient* client = (JackClient*)ext_client;
  851. if (client == NULL) {
  852. jack_error("jack_set_freewheel called with a NULL client");
  853. return -1;
  854. } else {
  855. return client->SetFreeWheel(onoff);
  856. }
  857. }
  858. EXPORT int jack_set_buffer_size(jack_client_t* ext_client, jack_nframes_t buffer_size)
  859. {
  860. #ifdef __CLIENTDEBUG__
  861. JackLibGlobals::CheckContext();
  862. #endif
  863. JackClient* client = (JackClient*)ext_client;
  864. if (client == NULL) {
  865. jack_error("jack_set_buffer_size called with a NULL client");
  866. return -1;
  867. } else if (!CheckBufferSize(buffer_size)) {
  868. return -1;
  869. } else {
  870. return client->SetBufferSize(buffer_size);
  871. }
  872. }
  873. EXPORT int jack_set_buffer_size_callback(jack_client_t* ext_client, JackBufferSizeCallback bufsize_callback, void* arg)
  874. {
  875. #ifdef __CLIENTDEBUG__
  876. JackLibGlobals::CheckContext();
  877. #endif
  878. JackClient* client = (JackClient*)ext_client;
  879. if (client == NULL) {
  880. jack_error("jack_set_buffer_size_callback called with a NULL client");
  881. return -1;
  882. } else {
  883. return client->SetBufferSizeCallback(bufsize_callback, arg);
  884. }
  885. }
  886. EXPORT int jack_set_sample_rate_callback(jack_client_t* ext_client, JackSampleRateCallback srate_callback, void* arg)
  887. {
  888. #ifdef __CLIENTDEBUG__
  889. JackLibGlobals::CheckContext();
  890. #endif
  891. JackClient* client = (JackClient*)ext_client;
  892. if (client == NULL) {
  893. jack_error("jack_set_sample_rate_callback called with a NULL client");
  894. return -1;
  895. } else {
  896. return client->SetSampleRateCallback(srate_callback, arg);
  897. }
  898. }
  899. EXPORT int jack_set_client_registration_callback(jack_client_t* ext_client, JackClientRegistrationCallback registration_callback, void* arg)
  900. {
  901. #ifdef __CLIENTDEBUG__
  902. JackLibGlobals::CheckContext();
  903. #endif
  904. JackClient* client = (JackClient*)ext_client;
  905. if (client == NULL) {
  906. jack_error("jack_set_client_registration_callback called with a NULL client");
  907. return -1;
  908. } else {
  909. return client->SetClientRegistrationCallback(registration_callback, arg);
  910. }
  911. }
  912. EXPORT int jack_set_port_registration_callback(jack_client_t* ext_client, JackPortRegistrationCallback registration_callback, void* arg)
  913. {
  914. #ifdef __CLIENTDEBUG__
  915. JackLibGlobals::CheckContext();
  916. #endif
  917. JackClient* client = (JackClient*)ext_client;
  918. if (client == NULL) {
  919. jack_error("jack_set_port_registration_callback called with a NULL client");
  920. return -1;
  921. } else {
  922. return client->SetPortRegistrationCallback(registration_callback, arg);
  923. }
  924. }
  925. EXPORT int jack_set_port_connect_callback(jack_client_t* ext_client, JackPortConnectCallback portconnect_callback, void* arg)
  926. {
  927. #ifdef __CLIENTDEBUG__
  928. JackLibGlobals::CheckContext();
  929. #endif
  930. JackClient* client = (JackClient*)ext_client;
  931. if (client == NULL) {
  932. jack_error("jack_set_port_connect_callback called with a NULL client");
  933. return -1;
  934. } else {
  935. return client->SetPortConnectCallback(portconnect_callback, arg);
  936. }
  937. }
  938. EXPORT int jack_set_port_rename_callback(jack_client_t* ext_client, JackPortRenameCallback rename_callback, void* arg)
  939. {
  940. #ifdef __CLIENTDEBUG__
  941. JackLibGlobals::CheckContext();
  942. #endif
  943. JackClient* client = (JackClient*)ext_client;
  944. if (client == NULL) {
  945. jack_error("jack_set_port_rename_callback called with a NULL client");
  946. return -1;
  947. } else {
  948. return client->SetPortRenameCallback(rename_callback, arg);
  949. }
  950. }
  951. EXPORT int jack_set_graph_order_callback(jack_client_t* ext_client, JackGraphOrderCallback graph_callback, void* arg)
  952. {
  953. #ifdef __CLIENTDEBUG__
  954. JackLibGlobals::CheckContext();
  955. #endif
  956. JackClient* client = (JackClient*)ext_client;
  957. jack_log("jack_set_graph_order_callback ext_client %x client %x ", ext_client, client);
  958. if (client == NULL) {
  959. jack_error("jack_set_graph_order_callback called with a NULL client");
  960. return -1;
  961. } else {
  962. return client->SetGraphOrderCallback(graph_callback, arg);
  963. }
  964. }
  965. EXPORT int jack_set_xrun_callback(jack_client_t* ext_client, JackXRunCallback xrun_callback, void* arg)
  966. {
  967. #ifdef __CLIENTDEBUG__
  968. JackLibGlobals::CheckContext();
  969. #endif
  970. JackClient* client = (JackClient*)ext_client;
  971. if (client == NULL) {
  972. jack_error("jack_set_xrun_callback called with a NULL client");
  973. return -1;
  974. } else {
  975. return client->SetXRunCallback(xrun_callback, arg);
  976. }
  977. }
  978. EXPORT int jack_set_thread_init_callback(jack_client_t* ext_client, JackThreadInitCallback init_callback, void *arg)
  979. {
  980. #ifdef __CLIENTDEBUG__
  981. JackLibGlobals::CheckContext();
  982. #endif
  983. JackClient* client = (JackClient*)ext_client;
  984. jack_log("jack_set_thread_init_callback ext_client %x client %x ", ext_client, client);
  985. if (client == NULL) {
  986. jack_error("jack_set_thread_init_callback called with a NULL client");
  987. return -1;
  988. } else {
  989. return client->SetInitCallback(init_callback, arg);
  990. }
  991. }
  992. EXPORT int jack_activate(jack_client_t* ext_client)
  993. {
  994. #ifdef __CLIENTDEBUG__
  995. JackLibGlobals::CheckContext();
  996. #endif
  997. JackClient* client = (JackClient*)ext_client;
  998. if (client == NULL) {
  999. jack_error("jack_activate called with a NULL client");
  1000. return -1;
  1001. } else {
  1002. return client->Activate();
  1003. }
  1004. }
  1005. EXPORT int jack_deactivate(jack_client_t* ext_client)
  1006. {
  1007. #ifdef __CLIENTDEBUG__
  1008. JackLibGlobals::CheckContext();
  1009. #endif
  1010. JackClient* client = (JackClient*)ext_client;
  1011. if (client == NULL) {
  1012. jack_error("jack_deactivate called with a NULL client");
  1013. return -1;
  1014. } else {
  1015. return client->Deactivate();
  1016. }
  1017. }
  1018. 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)
  1019. {
  1020. #ifdef __CLIENTDEBUG__
  1021. JackLibGlobals::CheckContext();
  1022. #endif
  1023. JackClient* client = (JackClient*)ext_client;
  1024. if (client == NULL) {
  1025. jack_error("jack_port_register called with a NULL client");
  1026. return NULL;
  1027. } else if ((port_name == NULL) || (port_type == NULL)) {
  1028. jack_error("jack_port_register called with a NULL port name or a NULL port_type");
  1029. return NULL;
  1030. } else {
  1031. #if defined(__x86_64__) || defined(__ppc64__)
  1032. return (jack_port_t *)((uint64_t)client->PortRegister(port_name, port_type, flags, buffer_size));
  1033. #else
  1034. return (jack_port_t *)client->PortRegister(port_name, port_type, flags, buffer_size);
  1035. #endif
  1036. }
  1037. }
  1038. EXPORT int jack_port_unregister(jack_client_t* ext_client, jack_port_t* port)
  1039. {
  1040. #ifdef __CLIENTDEBUG__
  1041. JackLibGlobals::CheckContext();
  1042. #endif
  1043. JackClient* client = (JackClient*)ext_client;
  1044. if (client == NULL) {
  1045. jack_error("jack_port_unregister called with a NULL client");
  1046. return -1;
  1047. }
  1048. #if defined(__x86_64__) || defined(__ppc64__)
  1049. uint64_t port_aux = (uint64_t)port;
  1050. #else
  1051. uint32_t port_aux = (uint32_t)port;
  1052. #endif
  1053. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1054. if (!CheckPort(myport)) {
  1055. jack_error("jack_port_unregister called with an incorrect port %ld", myport);
  1056. return -1;
  1057. }
  1058. return client->PortUnRegister(myport);
  1059. }
  1060. EXPORT int jack_port_is_mine(const jack_client_t* ext_client, const jack_port_t* port)
  1061. {
  1062. #ifdef __CLIENTDEBUG__
  1063. JackLibGlobals::CheckContext();
  1064. #endif
  1065. JackClient* client = (JackClient*)ext_client;
  1066. if (client == NULL) {
  1067. jack_error("jack_port_is_mine called with a NULL client");
  1068. return -1;
  1069. }
  1070. #if defined(__x86_64__) || defined(__ppc64__)
  1071. uint64_t port_aux = (uint64_t)port;
  1072. #else
  1073. uint32_t port_aux = (uint32_t)port;
  1074. #endif
  1075. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1076. if (!CheckPort(myport)) {
  1077. jack_error("jack_port_is_mine called with an incorrect port %ld", myport);
  1078. return -1;
  1079. }
  1080. return client->PortIsMine(myport);
  1081. }
  1082. EXPORT const char** jack_port_get_connections(const jack_port_t* port)
  1083. {
  1084. #ifdef __CLIENTDEBUG__
  1085. JackLibGlobals::CheckContext();
  1086. #endif
  1087. #if defined(__x86_64__) || defined(__ppc64__)
  1088. uint64_t port_aux = (uint64_t)port;
  1089. #else
  1090. uint32_t port_aux = (uint32_t)port;
  1091. #endif
  1092. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1093. if (!CheckPort(myport)) {
  1094. jack_error("jack_port_get_connections called with an incorrect port %ld", myport);
  1095. return NULL;
  1096. } else {
  1097. WaitGraphChange();
  1098. JackGraphManager* manager = GetGraphManager();
  1099. return (manager ? manager->GetConnections(myport) : NULL);
  1100. }
  1101. }
  1102. // Calling client does not need to "own" the port
  1103. EXPORT const char** jack_port_get_all_connections(const jack_client_t* ext_client, const jack_port_t* port)
  1104. {
  1105. #ifdef __CLIENTDEBUG__
  1106. JackLibGlobals::CheckContext();
  1107. #endif
  1108. JackClient* client = (JackClient*)ext_client;
  1109. if (client == NULL) {
  1110. jack_error("jack_port_get_all_connections called with a NULL client");
  1111. return NULL;
  1112. }
  1113. #if defined(__x86_64__) || defined(__ppc64__)
  1114. uint64_t port_aux = (uint64_t)port;
  1115. #else
  1116. uint32_t port_aux = (uint32_t)port;
  1117. #endif
  1118. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1119. if (!CheckPort(myport)) {
  1120. jack_error("jack_port_get_all_connections called with an incorrect port %ld", myport);
  1121. return NULL;
  1122. } else {
  1123. WaitGraphChange();
  1124. JackGraphManager* manager = GetGraphManager();
  1125. return (manager ? manager->GetConnections(myport) : NULL);
  1126. }
  1127. }
  1128. EXPORT jack_nframes_t jack_port_get_total_latency(jack_client_t* ext_client, jack_port_t* port)
  1129. {
  1130. #ifdef __CLIENTDEBUG__
  1131. JackLibGlobals::CheckContext();
  1132. #endif
  1133. JackClient* client = (JackClient*)ext_client;
  1134. if (client == NULL) {
  1135. jack_error("jack_port_get_total_latency called with a NULL client");
  1136. return 0;
  1137. }
  1138. #if defined(__x86_64__) || defined(__ppc64__)
  1139. uint64_t port_aux = (uint64_t)port;
  1140. #else
  1141. uint32_t port_aux = (uint32_t)port;
  1142. #endif
  1143. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1144. if (!CheckPort(myport)) {
  1145. jack_error("jack_port_get_total_latency called with an incorrect port %ld", myport);
  1146. return 0;
  1147. } else {
  1148. WaitGraphChange();
  1149. JackGraphManager* manager = GetGraphManager();
  1150. if (manager) {
  1151. manager->ComputeTotalLatency(myport);
  1152. return manager->GetPort(myport)->GetTotalLatency();
  1153. } else {
  1154. return 0;
  1155. }
  1156. }
  1157. }
  1158. EXPORT int jack_connect(jack_client_t* ext_client, const char* src, const char* dst)
  1159. {
  1160. #ifdef __CLIENTDEBUG__
  1161. JackLibGlobals::CheckContext();
  1162. #endif
  1163. JackClient* client = (JackClient*)ext_client;
  1164. if (client == NULL) {
  1165. jack_error("jack_connect called with a NULL client");
  1166. return -1;
  1167. } else if ((src == NULL) || (dst == NULL)) {
  1168. jack_error("jack_connect called with a NULL port name");
  1169. return -1;
  1170. } else {
  1171. return client->PortConnect(src, dst);
  1172. }
  1173. }
  1174. EXPORT int jack_disconnect(jack_client_t* ext_client, const char* src, const char* dst)
  1175. {
  1176. #ifdef __CLIENTDEBUG__
  1177. JackLibGlobals::CheckContext();
  1178. #endif
  1179. JackClient* client = (JackClient*)ext_client;
  1180. if (client == NULL) {
  1181. jack_error("jack_disconnect called with a NULL client");
  1182. return -1;
  1183. } else if ((src == NULL) || (dst == NULL)) {
  1184. jack_error("jack_connect called with a NULL port name");
  1185. return -1;
  1186. } else {
  1187. return client->PortDisconnect(src, dst);
  1188. }
  1189. }
  1190. EXPORT int jack_port_disconnect(jack_client_t* ext_client, jack_port_t* src)
  1191. {
  1192. #ifdef __CLIENTDEBUG__
  1193. JackLibGlobals::CheckContext();
  1194. #endif
  1195. JackClient* client = (JackClient*)ext_client;
  1196. if (client == NULL) {
  1197. jack_error("jack_port_disconnect called with a NULL client");
  1198. return -1;
  1199. }
  1200. #if defined(__x86_64__) || defined(__ppc64__)
  1201. uint64_t port_aux = (uint64_t)src;
  1202. #else
  1203. uint32_t port_aux = (uint32_t)src;
  1204. #endif
  1205. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1206. if (!CheckPort(myport)) {
  1207. jack_error("jack_port_disconnect called with an incorrect port %ld", myport);
  1208. return -1;
  1209. }
  1210. return client->PortDisconnect(myport);
  1211. }
  1212. EXPORT jack_nframes_t jack_get_sample_rate(jack_client_t* ext_client)
  1213. {
  1214. #ifdef __CLIENTDEBUG__
  1215. JackLibGlobals::CheckContext();
  1216. #endif
  1217. JackClient* client = (JackClient*)ext_client;
  1218. if (client == NULL) {
  1219. jack_error("jack_get_sample_rate called with a NULL client");
  1220. return 0;
  1221. } else {
  1222. JackEngineControl* control = GetEngineControl();
  1223. return (control ? control->fSampleRate : 0);
  1224. }
  1225. }
  1226. EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t* ext_client)
  1227. {
  1228. #ifdef __CLIENTDEBUG__
  1229. JackLibGlobals::CheckContext();
  1230. #endif
  1231. JackClient* client = (JackClient*)ext_client;
  1232. if (client == NULL) {
  1233. jack_error("jack_get_buffer_size called with a NULL client");
  1234. return 0;
  1235. } else {
  1236. JackEngineControl* control = GetEngineControl();
  1237. return (control ? control->fBufferSize : 0);
  1238. }
  1239. }
  1240. EXPORT const char** jack_get_ports(jack_client_t* ext_client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags)
  1241. {
  1242. #ifdef __CLIENTDEBUG__
  1243. JackLibGlobals::CheckContext();
  1244. #endif
  1245. JackClient* client = (JackClient*)ext_client;
  1246. if (client == NULL) {
  1247. jack_error("jack_get_ports called with a NULL client");
  1248. return NULL;
  1249. }
  1250. JackGraphManager* manager = GetGraphManager();
  1251. return (manager ? manager->GetPorts(port_name_pattern, type_name_pattern, flags) : NULL);
  1252. }
  1253. EXPORT jack_port_t* jack_port_by_name(jack_client_t* ext_client, const char* portname)
  1254. {
  1255. #ifdef __CLIENTDEBUG__
  1256. JackLibGlobals::CheckContext();
  1257. #endif
  1258. JackClient* client = (JackClient*)ext_client;
  1259. if (client == NULL) {
  1260. jack_error("jack_get_ports called with a NULL client");
  1261. return 0;
  1262. }
  1263. if (portname == NULL) {
  1264. jack_error("jack_port_by_name called with a NULL port name");
  1265. return NULL;
  1266. } else {
  1267. JackGraphManager* manager = GetGraphManager();
  1268. if (!manager)
  1269. return NULL;
  1270. int res = manager->GetPort(portname); // returns a port index at least > 1
  1271. #if defined(__x86_64__) || defined(__ppc64__)
  1272. return (res == NO_PORT) ? NULL : (jack_port_t*)((uint64_t)res);
  1273. #else
  1274. return (res == NO_PORT) ? NULL : (jack_port_t*)res;
  1275. #endif
  1276. }
  1277. }
  1278. EXPORT jack_port_t* jack_port_by_id(jack_client_t* ext_client, jack_port_id_t id)
  1279. {
  1280. #ifdef __CLIENTDEBUG__
  1281. JackLibGlobals::CheckContext();
  1282. #endif
  1283. /* jack_port_t* type is actually the port index */
  1284. #if defined(__x86_64__) || defined(__ppc64__)
  1285. return (jack_port_t*)((uint64_t)id);
  1286. #else
  1287. return (jack_port_t*)id;
  1288. #endif
  1289. }
  1290. EXPORT int jack_engine_takeover_timebase(jack_client_t* ext_client)
  1291. {
  1292. #ifdef __CLIENTDEBUG__
  1293. JackLibGlobals::CheckContext();
  1294. #endif
  1295. JackClient* client = (JackClient*)ext_client;
  1296. if (client == NULL) {
  1297. jack_error("jack_engine_takeover_timebase called with a NULL client");
  1298. return -1;
  1299. } else {
  1300. jack_error("jack_engine_takeover_timebase: deprecated\n");
  1301. return 0;
  1302. }
  1303. }
  1304. EXPORT jack_nframes_t jack_frames_since_cycle_start(const jack_client_t* ext_client)
  1305. {
  1306. #ifdef __CLIENTDEBUG__
  1307. JackLibGlobals::CheckContext();
  1308. #endif
  1309. JackTimer timer;
  1310. JackEngineControl* control = GetEngineControl();
  1311. if (control) {
  1312. control->ReadFrameTime(&timer);
  1313. return timer.FramesSinceCycleStart(GetMicroSeconds(), control->fSampleRate);
  1314. } else {
  1315. return 0;
  1316. }
  1317. }
  1318. EXPORT jack_time_t jack_get_time()
  1319. {
  1320. return GetMicroSeconds();
  1321. }
  1322. EXPORT jack_time_t jack_frames_to_time(const jack_client_t* ext_client, jack_nframes_t frames)
  1323. {
  1324. #ifdef __CLIENTDEBUG__
  1325. JackLibGlobals::CheckContext();
  1326. #endif
  1327. JackClient* client = (JackClient*)ext_client;
  1328. if (client == NULL) {
  1329. jack_error("jack_frames_to_time called with a NULL client");
  1330. return 0;
  1331. } else {
  1332. JackTimer timer;
  1333. JackEngineControl* control = GetEngineControl();
  1334. if (control) {
  1335. control->ReadFrameTime(&timer);
  1336. return timer.Frames2Time(frames, control->fBufferSize);
  1337. } else {
  1338. return 0;
  1339. }
  1340. }
  1341. }
  1342. EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t* ext_client, jack_time_t time)
  1343. {
  1344. #ifdef __CLIENTDEBUG__
  1345. JackLibGlobals::CheckContext();
  1346. #endif
  1347. JackClient* client = (JackClient*)ext_client;
  1348. if (client == NULL) {
  1349. jack_error("jack_time_to_frames called with a NULL client");
  1350. return 0;
  1351. } else {
  1352. JackTimer timer;
  1353. JackEngineControl* control = GetEngineControl();
  1354. if (control) {
  1355. control->ReadFrameTime(&timer);
  1356. return timer.Time2Frames(time, control->fBufferSize);
  1357. } else {
  1358. return 0;
  1359. }
  1360. }
  1361. }
  1362. EXPORT jack_nframes_t jack_frame_time(const jack_client_t* ext_client)
  1363. {
  1364. return jack_time_to_frames(ext_client, GetMicroSeconds());
  1365. }
  1366. EXPORT jack_nframes_t jack_last_frame_time(const jack_client_t* ext_client)
  1367. {
  1368. #ifdef __CLIENTDEBUG__
  1369. JackLibGlobals::CheckContext();
  1370. #endif
  1371. JackTimer timer;
  1372. JackEngineControl* control = GetEngineControl();
  1373. if (control) {
  1374. control->ReadFrameTime(&timer);
  1375. return timer.CurFrame();
  1376. } else {
  1377. return 0;
  1378. }
  1379. }
  1380. EXPORT float jack_cpu_load(jack_client_t* ext_client)
  1381. {
  1382. #ifdef __CLIENTDEBUG__
  1383. JackLibGlobals::CheckContext();
  1384. #endif
  1385. JackClient* client = (JackClient*)ext_client;
  1386. if (client == NULL) {
  1387. jack_error("jack_cpu_load called with a NULL client");
  1388. return 0.0f;
  1389. } else {
  1390. JackEngineControl* control = GetEngineControl();
  1391. return (control ? control->fCPULoad : 0.0f);
  1392. }
  1393. }
  1394. EXPORT pthread_t jack_client_thread_id(jack_client_t* ext_client)
  1395. {
  1396. #ifdef __CLIENTDEBUG__
  1397. JackLibGlobals::CheckContext();
  1398. #endif
  1399. JackClient* client = (JackClient*)ext_client;
  1400. if (client == NULL) {
  1401. jack_error("jack_client_thread_id called with a NULL client");
  1402. return (pthread_t)NULL;
  1403. } else {
  1404. return client->GetThreadID();
  1405. }
  1406. }
  1407. EXPORT char* jack_get_client_name(jack_client_t* ext_client)
  1408. {
  1409. #ifdef __CLIENTDEBUG__
  1410. JackLibGlobals::CheckContext();
  1411. #endif
  1412. JackClient* client = (JackClient*)ext_client;
  1413. if (client == NULL) {
  1414. jack_error("jack_get_client_name called with a NULL client");
  1415. return NULL;
  1416. } else {
  1417. return client->GetClientControl()->fName;
  1418. }
  1419. }
  1420. EXPORT int jack_client_name_size(void)
  1421. {
  1422. return JACK_CLIENT_NAME_SIZE;
  1423. }
  1424. EXPORT int jack_port_name_size(void)
  1425. {
  1426. return JACK_PORT_NAME_SIZE;
  1427. }
  1428. EXPORT int jack_port_type_size(void)
  1429. {
  1430. return JACK_PORT_TYPE_SIZE;
  1431. }
  1432. // transport.h
  1433. EXPORT int jack_release_timebase(jack_client_t* ext_client)
  1434. {
  1435. #ifdef __CLIENTDEBUG__
  1436. JackLibGlobals::CheckContext();
  1437. #endif
  1438. JackClient* client = (JackClient*)ext_client;
  1439. if (client == NULL) {
  1440. jack_error("jack_release_timebase called with a NULL client");
  1441. return -1;
  1442. } else {
  1443. return client->ReleaseTimebase();
  1444. }
  1445. }
  1446. EXPORT int jack_set_sync_callback(jack_client_t* ext_client, JackSyncCallback sync_callback, void *arg)
  1447. {
  1448. #ifdef __CLIENTDEBUG__
  1449. JackLibGlobals::CheckContext();
  1450. #endif
  1451. JackClient* client = (JackClient*)ext_client;
  1452. if (client == NULL) {
  1453. jack_error("jack_set_sync_callback called with a NULL client");
  1454. return -1;
  1455. } else {
  1456. return client->SetSyncCallback(sync_callback, arg);
  1457. }
  1458. }
  1459. EXPORT int jack_set_sync_timeout(jack_client_t* ext_client, jack_time_t timeout)
  1460. {
  1461. #ifdef __CLIENTDEBUG__
  1462. JackLibGlobals::CheckContext();
  1463. #endif
  1464. JackClient* client = (JackClient*)ext_client;
  1465. if (client == NULL) {
  1466. jack_error("jack_set_sync_timeout called with a NULL client");
  1467. return -1;
  1468. } else {
  1469. return client->SetSyncTimeout(timeout);
  1470. }
  1471. }
  1472. EXPORT int jack_set_timebase_callback(jack_client_t* ext_client, int conditional, JackTimebaseCallback timebase_callback, void* arg)
  1473. {
  1474. #ifdef __CLIENTDEBUG__
  1475. JackLibGlobals::CheckContext();
  1476. #endif
  1477. JackClient* client = (JackClient*)ext_client;
  1478. if (client == NULL) {
  1479. jack_error("jack_set_timebase_callback called with a NULL client");
  1480. return -1;
  1481. } else {
  1482. return client->SetTimebaseCallback(conditional, timebase_callback, arg);
  1483. }
  1484. }
  1485. EXPORT int jack_transport_locate(jack_client_t* ext_client, jack_nframes_t frame)
  1486. {
  1487. #ifdef __CLIENTDEBUG__
  1488. JackLibGlobals::CheckContext();
  1489. #endif
  1490. JackClient* client = (JackClient*)ext_client;
  1491. if (client == NULL) {
  1492. jack_error("jack_transport_locate called with a NULL client");
  1493. return -1;
  1494. } else {
  1495. client->TransportLocate(frame);
  1496. return 0;
  1497. }
  1498. }
  1499. EXPORT jack_transport_state_t jack_transport_query(const jack_client_t* ext_client, jack_position_t* pos)
  1500. {
  1501. #ifdef __CLIENTDEBUG__
  1502. JackLibGlobals::CheckContext();
  1503. #endif
  1504. JackClient* client = (JackClient*)ext_client;
  1505. if (client == NULL) {
  1506. jack_error("jack_transport_query called with a NULL client");
  1507. return JackTransportStopped;
  1508. } else {
  1509. return client->TransportQuery(pos);
  1510. }
  1511. }
  1512. EXPORT jack_nframes_t jack_get_current_transport_frame(const jack_client_t* ext_client)
  1513. {
  1514. #ifdef __CLIENTDEBUG__
  1515. JackLibGlobals::CheckContext();
  1516. #endif
  1517. JackClient* client = (JackClient*)ext_client;
  1518. if (client == NULL) {
  1519. jack_error("jack_get_current_transport_frame called with a NULL client");
  1520. return 0;
  1521. } else {
  1522. return client->GetCurrentTransportFrame();
  1523. }
  1524. }
  1525. EXPORT int jack_transport_reposition(jack_client_t* ext_client, jack_position_t* pos)
  1526. {
  1527. #ifdef __CLIENTDEBUG__
  1528. JackLibGlobals::CheckContext();
  1529. #endif
  1530. JackClient* client = (JackClient*)ext_client;
  1531. if (client == NULL) {
  1532. jack_error("jack_transport_reposition called with a NULL client");
  1533. return -1;
  1534. } else {
  1535. client->TransportReposition(pos);
  1536. return 0;
  1537. }
  1538. }
  1539. EXPORT void jack_transport_start(jack_client_t* ext_client)
  1540. {
  1541. #ifdef __CLIENTDEBUG__
  1542. JackLibGlobals::CheckContext();
  1543. #endif
  1544. JackClient* client = (JackClient*)ext_client;
  1545. if (client == NULL) {
  1546. jack_error("jack_transport_start called with a NULL client");
  1547. } else {
  1548. client->TransportStart();
  1549. }
  1550. }
  1551. EXPORT void jack_transport_stop(jack_client_t* ext_client)
  1552. {
  1553. #ifdef __CLIENTDEBUG__
  1554. JackLibGlobals::CheckContext();
  1555. #endif
  1556. JackClient* client = (JackClient*)ext_client;
  1557. if (client == NULL) {
  1558. jack_error("jack_transport_stop called with a NULL client");
  1559. } else {
  1560. client->TransportStop();
  1561. }
  1562. }
  1563. // deprecated
  1564. EXPORT void jack_get_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
  1565. {
  1566. jack_error("jack_get_transport_info: deprecated");
  1567. if (tinfo)
  1568. memset(tinfo, 0, sizeof(jack_transport_info_t));
  1569. }
  1570. EXPORT void jack_set_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
  1571. {
  1572. jack_error("jack_set_transport_info: deprecated");
  1573. if (tinfo)
  1574. memset(tinfo, 0, sizeof(jack_transport_info_t));
  1575. }
  1576. // statistics.h
  1577. EXPORT float jack_get_max_delayed_usecs(jack_client_t* ext_client)
  1578. {
  1579. #ifdef __CLIENTDEBUG__
  1580. JackLibGlobals::CheckContext();
  1581. #endif
  1582. JackClient* client = (JackClient*)ext_client;
  1583. if (client == NULL) {
  1584. jack_error("jack_get_max_delayed_usecs called with a NULL client");
  1585. return 0.f;
  1586. } else {
  1587. JackEngineControl* control = GetEngineControl();
  1588. return (control ? control->fMaxDelayedUsecs : 0.f);
  1589. }
  1590. }
  1591. EXPORT float jack_get_xrun_delayed_usecs(jack_client_t* ext_client)
  1592. {
  1593. #ifdef __CLIENTDEBUG__
  1594. JackLibGlobals::CheckContext();
  1595. #endif
  1596. JackClient* client = (JackClient*)ext_client;
  1597. if (client == NULL) {
  1598. jack_error("jack_get_xrun_delayed_usecs called with a NULL client");
  1599. return 0.f;
  1600. } else {
  1601. JackEngineControl* control = GetEngineControl();
  1602. return (control ? control->fXrunDelayedUsecs : 0.f);
  1603. }
  1604. }
  1605. EXPORT void jack_reset_max_delayed_usecs(jack_client_t* ext_client)
  1606. {
  1607. #ifdef __CLIENTDEBUG__
  1608. JackLibGlobals::CheckContext();
  1609. #endif
  1610. JackClient* client = (JackClient*)ext_client;
  1611. if (client == NULL) {
  1612. jack_error("jack_reset_max_delayed_usecs called with a NULL client");
  1613. } else {
  1614. JackEngineControl* control = GetEngineControl();
  1615. control->ResetXRun();
  1616. }
  1617. }
  1618. // thread.h
  1619. EXPORT int jack_client_real_time_priority(jack_client_t* ext_client)
  1620. {
  1621. #ifdef __CLIENTDEBUG__
  1622. JackLibGlobals::CheckContext();
  1623. #endif
  1624. JackClient* client = (JackClient*)ext_client;
  1625. if (client == NULL) {
  1626. jack_error("jack_client_real_time_priority called with a NULL client");
  1627. return -1;
  1628. } else {
  1629. JackEngineControl* control = GetEngineControl();
  1630. return (control->fRealTime) ? control->fClientPriority : -1;
  1631. }
  1632. }
  1633. EXPORT int jack_client_max_real_time_priority(jack_client_t* ext_client)
  1634. {
  1635. #ifdef __CLIENTDEBUG__
  1636. JackLibGlobals::CheckContext();
  1637. #endif
  1638. JackClient* client = (JackClient*)ext_client;
  1639. if (client == NULL) {
  1640. jack_error("jack_client_max_real_time_priority called with a NULL client");
  1641. return -1;
  1642. } else {
  1643. JackEngineControl* control = GetEngineControl();
  1644. return (control->fRealTime) ? control->fMaxClientPriority : -1;
  1645. }
  1646. }
  1647. EXPORT int jack_acquire_real_time_scheduling(pthread_t thread, int priority)
  1648. {
  1649. JackEngineControl* control = GetEngineControl();
  1650. return (control ? JackThread::AcquireRealTimeImp(thread, priority, GetEngineControl()->fPeriod, GetEngineControl()->fComputation, GetEngineControl()->fConstraint) : -1);
  1651. }
  1652. EXPORT int jack_client_create_thread(jack_client_t* client,
  1653. pthread_t *thread,
  1654. int priority,
  1655. int realtime, /* boolean */
  1656. thread_routine routine,
  1657. void *arg)
  1658. {
  1659. return JackThread::StartImp(thread, priority, realtime, routine, arg);
  1660. }
  1661. EXPORT int jack_drop_real_time_scheduling(pthread_t thread)
  1662. {
  1663. return JackThread::DropRealTimeImp(thread);
  1664. }
  1665. EXPORT int jack_client_stop_thread(jack_client_t* client, pthread_t thread)
  1666. {
  1667. return JackThread::StopImp(thread);
  1668. }
  1669. EXPORT int jack_client_kill_thread(jack_client_t* client, pthread_t thread)
  1670. {
  1671. return JackThread::KillImp(thread);
  1672. }
  1673. #ifndef WIN32
  1674. EXPORT void jack_set_thread_creator (jack_thread_creator_t jtc)
  1675. {
  1676. JackGlobals::fJackThreadCreator = jtc;
  1677. }
  1678. #endif
  1679. // intclient.h
  1680. EXPORT int jack_internal_client_new (const char *client_name,
  1681. const char *load_name,
  1682. const char *load_init)
  1683. {
  1684. jack_error("jack_internal_client_new: deprecated");
  1685. return -1;
  1686. }
  1687. EXPORT void jack_internal_client_close (const char *client_name)
  1688. {
  1689. jack_error("jack_internal_client_close: deprecated");
  1690. }
  1691. EXPORT char* jack_get_internal_client_name(jack_client_t* ext_client, jack_intclient_t intclient)
  1692. {
  1693. #ifdef __CLIENTDEBUG__
  1694. JackLibGlobals::CheckContext();
  1695. #endif
  1696. JackClient* client = (JackClient*)ext_client;
  1697. if (client == NULL) {
  1698. jack_error("jack_get_internal_client_name called with a NULL client");
  1699. return NULL;
  1700. } else if (intclient >= CLIENT_NUM) {
  1701. jack_error("jack_get_internal_client_name: incorrect client");
  1702. return NULL;
  1703. } else {
  1704. return client->GetInternalClientName(intclient);
  1705. }
  1706. }
  1707. EXPORT jack_intclient_t jack_internal_client_handle(jack_client_t* ext_client, const char* client_name, jack_status_t* status)
  1708. {
  1709. #ifdef __CLIENTDEBUG__
  1710. JackLibGlobals::CheckContext();
  1711. #endif
  1712. JackClient* client = (JackClient*)ext_client;
  1713. if (client == NULL) {
  1714. jack_error("jack_internal_client_handle called with a NULL client");
  1715. return 0;
  1716. } else {
  1717. jack_status_t my_status;
  1718. if (status == NULL) /* no status from caller? */
  1719. status = &my_status; /* use local status word */
  1720. *status = (jack_status_t)0;
  1721. return client->InternalClientHandle(client_name, status);
  1722. }
  1723. }
  1724. EXPORT jack_intclient_t jack_internal_client_load_aux(jack_client_t* ext_client, const char* client_name, jack_options_t options, jack_status_t* status, va_list ap)
  1725. {
  1726. #ifdef __CLIENTDEBUG__
  1727. JackLibGlobals::CheckContext();
  1728. #endif
  1729. JackClient* client = (JackClient*)ext_client;
  1730. if (client == NULL) {
  1731. jack_error("jack_internal_client_load called with a NULL client");
  1732. return 0;
  1733. } else {
  1734. jack_varargs_t va;
  1735. jack_status_t my_status;
  1736. if (status == NULL) /* no status from caller? */
  1737. status = &my_status; /* use local status word */
  1738. *status = (jack_status_t)0;
  1739. /* validate parameters */
  1740. if ((options & ~JackLoadOptions)) {
  1741. int my_status1 = *status | (JackFailure | JackInvalidOption);
  1742. *status = (jack_status_t)my_status1;
  1743. return 0;
  1744. }
  1745. /* parse variable arguments */
  1746. jack_varargs_parse(options, ap, &va);
  1747. return client->InternalClientLoad(client_name, options, status, &va);
  1748. }
  1749. }
  1750. EXPORT jack_intclient_t jack_internal_client_load(jack_client_t *client, const char *client_name, jack_options_t options, jack_status_t *status, ...)
  1751. {
  1752. va_list ap;
  1753. va_start(ap, status);
  1754. jack_intclient_t res = jack_internal_client_load_aux(client, client_name, options, status, ap);
  1755. va_end(ap);
  1756. return res;
  1757. }
  1758. EXPORT jack_status_t jack_internal_client_unload(jack_client_t* ext_client, jack_intclient_t intclient)
  1759. {
  1760. #ifdef __CLIENTDEBUG__
  1761. JackLibGlobals::CheckContext();
  1762. #endif
  1763. JackClient* client = (JackClient*)ext_client;
  1764. if (client == NULL) {
  1765. jack_error("jack_internal_client_unload called with a NULL client");
  1766. return (jack_status_t)(JackNoSuchClient | JackFailure);
  1767. } else if (intclient >= CLIENT_NUM) {
  1768. jack_error("jack_internal_client_unload: incorrect client");
  1769. return (jack_status_t)(JackNoSuchClient | JackFailure);
  1770. } else {
  1771. jack_status_t my_status;
  1772. client->InternalClientUnload(intclient, &my_status);
  1773. return my_status;
  1774. }
  1775. }
  1776. EXPORT
  1777. void
  1778. jack_get_version(
  1779. int *major_ptr,
  1780. int *minor_ptr,
  1781. int *micro_ptr,
  1782. int *proto_ptr)
  1783. {
  1784. // FIXME: We need these comming from build system
  1785. *major_ptr = 0;
  1786. *minor_ptr = 0;
  1787. *micro_ptr = 0;
  1788. *proto_ptr = 0;
  1789. }
  1790. EXPORT
  1791. const char *
  1792. jack_get_version_string()
  1793. {
  1794. return VERSION;
  1795. }
  1796. EXPORT void jack_free(void* ptr)
  1797. {
  1798. free(ptr);
  1799. }