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.

1933 lines
61KB

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