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.

1932 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. return client->Wait(status);
  790. }
  791. }
  792. EXPORT jack_nframes_t jack_cycle_wait(jack_client_t* ext_client)
  793. {
  794. #ifdef __CLIENTDEBUG__
  795. JackLibGlobals::CheckContext();
  796. #endif
  797. JackClient* client = (JackClient*)ext_client;
  798. if (client == NULL) {
  799. jack_error("jack_cycle_wait called with a NULL client");
  800. return 0;
  801. } else {
  802. return client->CycleWait();
  803. }
  804. }
  805. EXPORT void jack_cycle_signal(jack_client_t* ext_client, int status)
  806. {
  807. #ifdef __CLIENTDEBUG__
  808. JackLibGlobals::CheckContext();
  809. #endif
  810. JackClient* client = (JackClient*)ext_client;
  811. if (client == NULL) {
  812. jack_error("jack_cycle_signal called with a NULL client");
  813. } else {
  814. client->CycleSignal(status);
  815. }
  816. }
  817. EXPORT int jack_set_process_thread(jack_client_t* ext_client, JackThreadCallback fun, void *arg)
  818. {
  819. #ifdef __CLIENTDEBUG__
  820. JackLibGlobals::CheckContext();
  821. #endif
  822. JackClient* client = (JackClient*)ext_client;
  823. if (client == NULL) {
  824. jack_error("jack_set_process_thread called with a NULL client");
  825. return -1;
  826. } else {
  827. return client->SetProcessThread(fun, arg);
  828. }
  829. }
  830. EXPORT int jack_set_freewheel_callback(jack_client_t* ext_client, JackFreewheelCallback freewheel_callback, void* arg)
  831. {
  832. #ifdef __CLIENTDEBUG__
  833. JackLibGlobals::CheckContext();
  834. #endif
  835. JackClient* client = (JackClient*)ext_client;
  836. if (client == NULL) {
  837. jack_error("jack_set_freewheel_callback called with a NULL client");
  838. return -1;
  839. } else {
  840. return client->SetFreewheelCallback(freewheel_callback, arg);
  841. }
  842. }
  843. EXPORT int jack_set_freewheel(jack_client_t* ext_client, int onoff)
  844. {
  845. #ifdef __CLIENTDEBUG__
  846. JackLibGlobals::CheckContext();
  847. #endif
  848. JackClient* client = (JackClient*)ext_client;
  849. if (client == NULL) {
  850. jack_error("jack_set_freewheel called with a NULL client");
  851. return -1;
  852. } else {
  853. return client->SetFreeWheel(onoff);
  854. }
  855. }
  856. EXPORT int jack_set_buffer_size(jack_client_t* ext_client, jack_nframes_t buffer_size)
  857. {
  858. #ifdef __CLIENTDEBUG__
  859. JackLibGlobals::CheckContext();
  860. #endif
  861. JackClient* client = (JackClient*)ext_client;
  862. if (client == NULL) {
  863. jack_error("jack_set_buffer_size called with a NULL client");
  864. return -1;
  865. } else if (!CheckBufferSize(buffer_size)) {
  866. return -1;
  867. } else {
  868. return client->SetBufferSize(buffer_size);
  869. }
  870. }
  871. EXPORT int jack_set_buffer_size_callback(jack_client_t* ext_client, JackBufferSizeCallback bufsize_callback, void* arg)
  872. {
  873. #ifdef __CLIENTDEBUG__
  874. JackLibGlobals::CheckContext();
  875. #endif
  876. JackClient* client = (JackClient*)ext_client;
  877. if (client == NULL) {
  878. jack_error("jack_set_buffer_size_callback called with a NULL client");
  879. return -1;
  880. } else {
  881. return client->SetBufferSizeCallback(bufsize_callback, arg);
  882. }
  883. }
  884. EXPORT int jack_set_sample_rate_callback(jack_client_t* ext_client, JackSampleRateCallback srate_callback, void* arg)
  885. {
  886. #ifdef __CLIENTDEBUG__
  887. JackLibGlobals::CheckContext();
  888. #endif
  889. JackClient* client = (JackClient*)ext_client;
  890. if (client == NULL) {
  891. jack_error("jack_set_sample_rate_callback called with a NULL client");
  892. return -1;
  893. } else {
  894. return client->SetSampleRateCallback(srate_callback, arg);
  895. }
  896. }
  897. EXPORT int jack_set_client_registration_callback(jack_client_t* ext_client, JackClientRegistrationCallback registration_callback, void* arg)
  898. {
  899. #ifdef __CLIENTDEBUG__
  900. JackLibGlobals::CheckContext();
  901. #endif
  902. JackClient* client = (JackClient*)ext_client;
  903. if (client == NULL) {
  904. jack_error("jack_set_client_registration_callback called with a NULL client");
  905. return -1;
  906. } else {
  907. return client->SetClientRegistrationCallback(registration_callback, arg);
  908. }
  909. }
  910. EXPORT int jack_set_port_registration_callback(jack_client_t* ext_client, JackPortRegistrationCallback registration_callback, void* arg)
  911. {
  912. #ifdef __CLIENTDEBUG__
  913. JackLibGlobals::CheckContext();
  914. #endif
  915. JackClient* client = (JackClient*)ext_client;
  916. if (client == NULL) {
  917. jack_error("jack_set_port_registration_callback called with a NULL client");
  918. return -1;
  919. } else {
  920. return client->SetPortRegistrationCallback(registration_callback, arg);
  921. }
  922. }
  923. EXPORT int jack_set_port_connect_callback(jack_client_t* ext_client, JackPortConnectCallback portconnect_callback, void* arg)
  924. {
  925. #ifdef __CLIENTDEBUG__
  926. JackLibGlobals::CheckContext();
  927. #endif
  928. JackClient* client = (JackClient*)ext_client;
  929. if (client == NULL) {
  930. jack_error("jack_set_port_connect_callback called with a NULL client");
  931. return -1;
  932. } else {
  933. return client->SetPortConnectCallback(portconnect_callback, arg);
  934. }
  935. }
  936. EXPORT int jack_set_port_rename_callback(jack_client_t* ext_client, JackPortRenameCallback rename_callback, void* arg)
  937. {
  938. #ifdef __CLIENTDEBUG__
  939. JackLibGlobals::CheckContext();
  940. #endif
  941. JackClient* client = (JackClient*)ext_client;
  942. if (client == NULL) {
  943. jack_error("jack_set_port_rename_callback called with a NULL client");
  944. return -1;
  945. } else {
  946. return client->SetPortRenameCallback(rename_callback, arg);
  947. }
  948. }
  949. EXPORT int jack_set_graph_order_callback(jack_client_t* ext_client, JackGraphOrderCallback graph_callback, void* arg)
  950. {
  951. #ifdef __CLIENTDEBUG__
  952. JackLibGlobals::CheckContext();
  953. #endif
  954. JackClient* client = (JackClient*)ext_client;
  955. jack_log("jack_set_graph_order_callback ext_client %x client %x ", ext_client, client);
  956. if (client == NULL) {
  957. jack_error("jack_set_graph_order_callback called with a NULL client");
  958. return -1;
  959. } else {
  960. return client->SetGraphOrderCallback(graph_callback, arg);
  961. }
  962. }
  963. EXPORT int jack_set_xrun_callback(jack_client_t* ext_client, JackXRunCallback xrun_callback, void* arg)
  964. {
  965. #ifdef __CLIENTDEBUG__
  966. JackLibGlobals::CheckContext();
  967. #endif
  968. JackClient* client = (JackClient*)ext_client;
  969. if (client == NULL) {
  970. jack_error("jack_set_xrun_callback called with a NULL client");
  971. return -1;
  972. } else {
  973. return client->SetXRunCallback(xrun_callback, arg);
  974. }
  975. }
  976. EXPORT int jack_set_thread_init_callback(jack_client_t* ext_client, JackThreadInitCallback init_callback, void *arg)
  977. {
  978. #ifdef __CLIENTDEBUG__
  979. JackLibGlobals::CheckContext();
  980. #endif
  981. JackClient* client = (JackClient*)ext_client;
  982. jack_log("jack_set_thread_init_callback ext_client %x client %x ", ext_client, client);
  983. if (client == NULL) {
  984. jack_error("jack_set_thread_init_callback called with a NULL client");
  985. return -1;
  986. } else {
  987. return client->SetInitCallback(init_callback, arg);
  988. }
  989. }
  990. EXPORT int jack_activate(jack_client_t* ext_client)
  991. {
  992. #ifdef __CLIENTDEBUG__
  993. JackLibGlobals::CheckContext();
  994. #endif
  995. JackClient* client = (JackClient*)ext_client;
  996. if (client == NULL) {
  997. jack_error("jack_activate called with a NULL client");
  998. return -1;
  999. } else {
  1000. return client->Activate();
  1001. }
  1002. }
  1003. EXPORT int jack_deactivate(jack_client_t* ext_client)
  1004. {
  1005. #ifdef __CLIENTDEBUG__
  1006. JackLibGlobals::CheckContext();
  1007. #endif
  1008. JackClient* client = (JackClient*)ext_client;
  1009. if (client == NULL) {
  1010. jack_error("jack_deactivate called with a NULL client");
  1011. return -1;
  1012. } else {
  1013. return client->Deactivate();
  1014. }
  1015. }
  1016. 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)
  1017. {
  1018. #ifdef __CLIENTDEBUG__
  1019. JackLibGlobals::CheckContext();
  1020. #endif
  1021. JackClient* client = (JackClient*)ext_client;
  1022. if (client == NULL) {
  1023. jack_error("jack_port_register called with a NULL client");
  1024. return NULL;
  1025. } else if ((port_name == NULL) || (port_type == NULL)) {
  1026. jack_error("jack_port_register called with a NULL port name or a NULL port_type");
  1027. return NULL;
  1028. } else {
  1029. #if defined(__x86_64__) || defined(__ppc64__)
  1030. return (jack_port_t *)((uint64_t)client->PortRegister(port_name, port_type, flags, buffer_size));
  1031. #else
  1032. return (jack_port_t *)client->PortRegister(port_name, port_type, flags, buffer_size);
  1033. #endif
  1034. }
  1035. }
  1036. EXPORT int jack_port_unregister(jack_client_t* ext_client, jack_port_t* port)
  1037. {
  1038. #ifdef __CLIENTDEBUG__
  1039. JackLibGlobals::CheckContext();
  1040. #endif
  1041. JackClient* client = (JackClient*)ext_client;
  1042. if (client == NULL) {
  1043. jack_error("jack_port_unregister called with a NULL client");
  1044. return -1;
  1045. }
  1046. #if defined(__x86_64__) || defined(__ppc64__)
  1047. uint64_t port_aux = (uint64_t)port;
  1048. #else
  1049. uint32_t port_aux = (uint32_t)port;
  1050. #endif
  1051. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1052. if (!CheckPort(myport)) {
  1053. jack_error("jack_port_unregister called with an incorrect port %ld", myport);
  1054. return -1;
  1055. }
  1056. return client->PortUnRegister(myport);
  1057. }
  1058. EXPORT int jack_port_is_mine(const jack_client_t* ext_client, const jack_port_t* port)
  1059. {
  1060. #ifdef __CLIENTDEBUG__
  1061. JackLibGlobals::CheckContext();
  1062. #endif
  1063. JackClient* client = (JackClient*)ext_client;
  1064. if (client == NULL) {
  1065. jack_error("jack_port_is_mine called with a NULL client");
  1066. return -1;
  1067. }
  1068. #if defined(__x86_64__) || defined(__ppc64__)
  1069. uint64_t port_aux = (uint64_t)port;
  1070. #else
  1071. uint32_t port_aux = (uint32_t)port;
  1072. #endif
  1073. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1074. if (!CheckPort(myport)) {
  1075. jack_error("jack_port_is_mine called with an incorrect port %ld", myport);
  1076. return -1;
  1077. }
  1078. return client->PortIsMine(myport);
  1079. }
  1080. EXPORT const char** jack_port_get_connections(const jack_port_t* port)
  1081. {
  1082. #ifdef __CLIENTDEBUG__
  1083. JackLibGlobals::CheckContext();
  1084. #endif
  1085. #if defined(__x86_64__) || defined(__ppc64__)
  1086. uint64_t port_aux = (uint64_t)port;
  1087. #else
  1088. uint32_t port_aux = (uint32_t)port;
  1089. #endif
  1090. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1091. if (!CheckPort(myport)) {
  1092. jack_error("jack_port_get_connections called with an incorrect port %ld", myport);
  1093. return NULL;
  1094. } else {
  1095. WaitGraphChange();
  1096. JackGraphManager* manager = GetGraphManager();
  1097. return (manager ? manager->GetConnections(myport) : NULL);
  1098. }
  1099. }
  1100. // Calling client does not need to "own" the port
  1101. EXPORT const char** jack_port_get_all_connections(const jack_client_t* ext_client, const jack_port_t* port)
  1102. {
  1103. #ifdef __CLIENTDEBUG__
  1104. JackLibGlobals::CheckContext();
  1105. #endif
  1106. JackClient* client = (JackClient*)ext_client;
  1107. if (client == NULL) {
  1108. jack_error("jack_port_get_all_connections called with a NULL client");
  1109. return NULL;
  1110. }
  1111. #if defined(__x86_64__) || defined(__ppc64__)
  1112. uint64_t port_aux = (uint64_t)port;
  1113. #else
  1114. uint32_t port_aux = (uint32_t)port;
  1115. #endif
  1116. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1117. if (!CheckPort(myport)) {
  1118. jack_error("jack_port_get_all_connections called with an incorrect port %ld", myport);
  1119. return NULL;
  1120. } else {
  1121. WaitGraphChange();
  1122. JackGraphManager* manager = GetGraphManager();
  1123. return (manager ? manager->GetConnections(myport) : NULL);
  1124. }
  1125. }
  1126. EXPORT jack_nframes_t jack_port_get_total_latency(jack_client_t* ext_client, jack_port_t* port)
  1127. {
  1128. #ifdef __CLIENTDEBUG__
  1129. JackLibGlobals::CheckContext();
  1130. #endif
  1131. JackClient* client = (JackClient*)ext_client;
  1132. if (client == NULL) {
  1133. jack_error("jack_port_get_total_latency called with a NULL client");
  1134. return 0;
  1135. }
  1136. #if defined(__x86_64__) || defined(__ppc64__)
  1137. uint64_t port_aux = (uint64_t)port;
  1138. #else
  1139. uint32_t port_aux = (uint32_t)port;
  1140. #endif
  1141. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1142. if (!CheckPort(myport)) {
  1143. jack_error("jack_port_get_total_latency called with an incorrect port %ld", myport);
  1144. return 0;
  1145. } else {
  1146. WaitGraphChange();
  1147. JackGraphManager* manager = GetGraphManager();
  1148. if (manager) {
  1149. manager->ComputeTotalLatency(myport);
  1150. return manager->GetPort(myport)->GetTotalLatency();
  1151. } else {
  1152. return 0;
  1153. }
  1154. }
  1155. }
  1156. EXPORT int jack_connect(jack_client_t* ext_client, const char* src, const char* dst)
  1157. {
  1158. #ifdef __CLIENTDEBUG__
  1159. JackLibGlobals::CheckContext();
  1160. #endif
  1161. JackClient* client = (JackClient*)ext_client;
  1162. if (client == NULL) {
  1163. jack_error("jack_connect called with a NULL client");
  1164. return -1;
  1165. } else if ((src == NULL) || (dst == NULL)) {
  1166. jack_error("jack_connect called with a NULL port name");
  1167. return -1;
  1168. } else {
  1169. return client->PortConnect(src, dst);
  1170. }
  1171. }
  1172. EXPORT int jack_disconnect(jack_client_t* ext_client, const char* src, const char* dst)
  1173. {
  1174. #ifdef __CLIENTDEBUG__
  1175. JackLibGlobals::CheckContext();
  1176. #endif
  1177. JackClient* client = (JackClient*)ext_client;
  1178. if (client == NULL) {
  1179. jack_error("jack_disconnect called with a NULL client");
  1180. return -1;
  1181. } else if ((src == NULL) || (dst == NULL)) {
  1182. jack_error("jack_connect called with a NULL port name");
  1183. return -1;
  1184. } else {
  1185. return client->PortDisconnect(src, dst);
  1186. }
  1187. }
  1188. EXPORT int jack_port_disconnect(jack_client_t* ext_client, jack_port_t* src)
  1189. {
  1190. #ifdef __CLIENTDEBUG__
  1191. JackLibGlobals::CheckContext();
  1192. #endif
  1193. JackClient* client = (JackClient*)ext_client;
  1194. if (client == NULL) {
  1195. jack_error("jack_port_disconnect called with a NULL client");
  1196. return -1;
  1197. }
  1198. #if defined(__x86_64__) || defined(__ppc64__)
  1199. uint64_t port_aux = (uint64_t)src;
  1200. #else
  1201. uint32_t port_aux = (uint32_t)src;
  1202. #endif
  1203. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1204. if (!CheckPort(myport)) {
  1205. jack_error("jack_port_disconnect called with an incorrect port %ld", myport);
  1206. return -1;
  1207. }
  1208. return client->PortDisconnect(myport);
  1209. }
  1210. EXPORT jack_nframes_t jack_get_sample_rate(jack_client_t* ext_client)
  1211. {
  1212. #ifdef __CLIENTDEBUG__
  1213. JackLibGlobals::CheckContext();
  1214. #endif
  1215. JackClient* client = (JackClient*)ext_client;
  1216. if (client == NULL) {
  1217. jack_error("jack_get_sample_rate called with a NULL client");
  1218. return 0;
  1219. } else {
  1220. JackEngineControl* control = GetEngineControl();
  1221. return (control ? control->fSampleRate : 0);
  1222. }
  1223. }
  1224. EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t* ext_client)
  1225. {
  1226. #ifdef __CLIENTDEBUG__
  1227. JackLibGlobals::CheckContext();
  1228. #endif
  1229. JackClient* client = (JackClient*)ext_client;
  1230. if (client == NULL) {
  1231. jack_error("jack_get_buffer_size called with a NULL client");
  1232. return 0;
  1233. } else {
  1234. JackEngineControl* control = GetEngineControl();
  1235. return (control ? control->fBufferSize : 0);
  1236. }
  1237. }
  1238. EXPORT const char** jack_get_ports(jack_client_t* ext_client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags)
  1239. {
  1240. #ifdef __CLIENTDEBUG__
  1241. JackLibGlobals::CheckContext();
  1242. #endif
  1243. JackClient* client = (JackClient*)ext_client;
  1244. if (client == NULL) {
  1245. jack_error("jack_get_ports called with a NULL client");
  1246. return NULL;
  1247. }
  1248. JackGraphManager* manager = GetGraphManager();
  1249. return (manager ? manager->GetPorts(port_name_pattern, type_name_pattern, flags) : NULL);
  1250. }
  1251. EXPORT jack_port_t* jack_port_by_name(jack_client_t* ext_client, const char* portname)
  1252. {
  1253. #ifdef __CLIENTDEBUG__
  1254. JackLibGlobals::CheckContext();
  1255. #endif
  1256. JackClient* client = (JackClient*)ext_client;
  1257. if (client == NULL) {
  1258. jack_error("jack_get_ports called with a NULL client");
  1259. return 0;
  1260. }
  1261. if (portname == NULL) {
  1262. jack_error("jack_port_by_name called with a NULL port name");
  1263. return NULL;
  1264. } else {
  1265. JackGraphManager* manager = GetGraphManager();
  1266. if (!manager)
  1267. return NULL;
  1268. int res = manager->GetPort(portname); // returns a port index at least > 1
  1269. #if defined(__x86_64__) || defined(__ppc64__)
  1270. return (res == NO_PORT) ? NULL : (jack_port_t*)((uint64_t)res);
  1271. #else
  1272. return (res == NO_PORT) ? NULL : (jack_port_t*)res;
  1273. #endif
  1274. }
  1275. }
  1276. EXPORT jack_port_t* jack_port_by_id(jack_client_t* ext_client, jack_port_id_t id)
  1277. {
  1278. #ifdef __CLIENTDEBUG__
  1279. JackLibGlobals::CheckContext();
  1280. #endif
  1281. /* jack_port_t* type is actually the port index */
  1282. #if defined(__x86_64__) || defined(__ppc64__)
  1283. return (jack_port_t*)((uint64_t)id);
  1284. #else
  1285. return (jack_port_t*)id;
  1286. #endif
  1287. }
  1288. EXPORT int jack_engine_takeover_timebase(jack_client_t* ext_client)
  1289. {
  1290. #ifdef __CLIENTDEBUG__
  1291. JackLibGlobals::CheckContext();
  1292. #endif
  1293. JackClient* client = (JackClient*)ext_client;
  1294. if (client == NULL) {
  1295. jack_error("jack_engine_takeover_timebase called with a NULL client");
  1296. return -1;
  1297. } else {
  1298. jack_error("jack_engine_takeover_timebase: deprecated\n");
  1299. return 0;
  1300. }
  1301. }
  1302. EXPORT jack_nframes_t jack_frames_since_cycle_start(const jack_client_t* ext_client)
  1303. {
  1304. #ifdef __CLIENTDEBUG__
  1305. JackLibGlobals::CheckContext();
  1306. #endif
  1307. JackTimer timer;
  1308. JackEngineControl* control = GetEngineControl();
  1309. if (control) {
  1310. control->ReadFrameTime(&timer);
  1311. return timer.FramesSinceCycleStart(GetMicroSeconds(), control->fSampleRate);
  1312. } else {
  1313. return 0;
  1314. }
  1315. }
  1316. EXPORT jack_time_t jack_get_time()
  1317. {
  1318. return GetMicroSeconds();
  1319. }
  1320. EXPORT jack_time_t jack_frames_to_time(const jack_client_t* ext_client, jack_nframes_t frames)
  1321. {
  1322. #ifdef __CLIENTDEBUG__
  1323. JackLibGlobals::CheckContext();
  1324. #endif
  1325. JackClient* client = (JackClient*)ext_client;
  1326. if (client == NULL) {
  1327. jack_error("jack_frames_to_time called with a NULL client");
  1328. return 0;
  1329. } else {
  1330. JackTimer timer;
  1331. JackEngineControl* control = GetEngineControl();
  1332. if (control) {
  1333. control->ReadFrameTime(&timer);
  1334. return timer.Frames2Time(frames, control->fBufferSize);
  1335. } else {
  1336. return 0;
  1337. }
  1338. }
  1339. }
  1340. EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t* ext_client, jack_time_t time)
  1341. {
  1342. #ifdef __CLIENTDEBUG__
  1343. JackLibGlobals::CheckContext();
  1344. #endif
  1345. JackClient* client = (JackClient*)ext_client;
  1346. if (client == NULL) {
  1347. jack_error("jack_time_to_frames called with a NULL client");
  1348. return 0;
  1349. } else {
  1350. JackTimer timer;
  1351. JackEngineControl* control = GetEngineControl();
  1352. if (control) {
  1353. control->ReadFrameTime(&timer);
  1354. return timer.Time2Frames(time, control->fBufferSize);
  1355. } else {
  1356. return 0;
  1357. }
  1358. }
  1359. }
  1360. EXPORT jack_nframes_t jack_frame_time(const jack_client_t* ext_client)
  1361. {
  1362. return jack_time_to_frames(ext_client, GetMicroSeconds());
  1363. }
  1364. EXPORT jack_nframes_t jack_last_frame_time(const jack_client_t* ext_client)
  1365. {
  1366. #ifdef __CLIENTDEBUG__
  1367. JackLibGlobals::CheckContext();
  1368. #endif
  1369. JackTimer timer;
  1370. JackEngineControl* control = GetEngineControl();
  1371. if (control) {
  1372. control->ReadFrameTime(&timer);
  1373. return timer.CurFrame();
  1374. } else {
  1375. return 0;
  1376. }
  1377. }
  1378. EXPORT float jack_cpu_load(jack_client_t* ext_client)
  1379. {
  1380. #ifdef __CLIENTDEBUG__
  1381. JackLibGlobals::CheckContext();
  1382. #endif
  1383. JackClient* client = (JackClient*)ext_client;
  1384. if (client == NULL) {
  1385. jack_error("jack_cpu_load called with a NULL client");
  1386. return 0.0f;
  1387. } else {
  1388. JackEngineControl* control = GetEngineControl();
  1389. return (control ? control->fCPULoad : 0.0f);
  1390. }
  1391. }
  1392. EXPORT pthread_t jack_client_thread_id(jack_client_t* ext_client)
  1393. {
  1394. #ifdef __CLIENTDEBUG__
  1395. JackLibGlobals::CheckContext();
  1396. #endif
  1397. JackClient* client = (JackClient*)ext_client;
  1398. if (client == NULL) {
  1399. jack_error("jack_client_thread_id called with a NULL client");
  1400. return (pthread_t)NULL;
  1401. } else {
  1402. return client->GetThreadID();
  1403. }
  1404. }
  1405. EXPORT char* jack_get_client_name(jack_client_t* ext_client)
  1406. {
  1407. #ifdef __CLIENTDEBUG__
  1408. JackLibGlobals::CheckContext();
  1409. #endif
  1410. JackClient* client = (JackClient*)ext_client;
  1411. if (client == NULL) {
  1412. jack_error("jack_get_client_name called with a NULL client");
  1413. return NULL;
  1414. } else {
  1415. return client->GetClientControl()->fName;
  1416. }
  1417. }
  1418. EXPORT int jack_client_name_size(void)
  1419. {
  1420. return JACK_CLIENT_NAME_SIZE;
  1421. }
  1422. EXPORT int jack_port_name_size(void)
  1423. {
  1424. return JACK_PORT_NAME_SIZE;
  1425. }
  1426. EXPORT int jack_port_type_size(void)
  1427. {
  1428. return JACK_PORT_TYPE_SIZE;
  1429. }
  1430. // transport.h
  1431. EXPORT int jack_release_timebase(jack_client_t* ext_client)
  1432. {
  1433. #ifdef __CLIENTDEBUG__
  1434. JackLibGlobals::CheckContext();
  1435. #endif
  1436. JackClient* client = (JackClient*)ext_client;
  1437. if (client == NULL) {
  1438. jack_error("jack_release_timebase called with a NULL client");
  1439. return -1;
  1440. } else {
  1441. return client->ReleaseTimebase();
  1442. }
  1443. }
  1444. EXPORT int jack_set_sync_callback(jack_client_t* ext_client, JackSyncCallback sync_callback, void *arg)
  1445. {
  1446. #ifdef __CLIENTDEBUG__
  1447. JackLibGlobals::CheckContext();
  1448. #endif
  1449. JackClient* client = (JackClient*)ext_client;
  1450. if (client == NULL) {
  1451. jack_error("jack_set_sync_callback called with a NULL client");
  1452. return -1;
  1453. } else {
  1454. return client->SetSyncCallback(sync_callback, arg);
  1455. }
  1456. }
  1457. EXPORT int jack_set_sync_timeout(jack_client_t* ext_client, jack_time_t timeout)
  1458. {
  1459. #ifdef __CLIENTDEBUG__
  1460. JackLibGlobals::CheckContext();
  1461. #endif
  1462. JackClient* client = (JackClient*)ext_client;
  1463. if (client == NULL) {
  1464. jack_error("jack_set_sync_timeout called with a NULL client");
  1465. return -1;
  1466. } else {
  1467. return client->SetSyncTimeout(timeout);
  1468. }
  1469. }
  1470. EXPORT int jack_set_timebase_callback(jack_client_t* ext_client, int conditional, JackTimebaseCallback timebase_callback, void* arg)
  1471. {
  1472. #ifdef __CLIENTDEBUG__
  1473. JackLibGlobals::CheckContext();
  1474. #endif
  1475. JackClient* client = (JackClient*)ext_client;
  1476. if (client == NULL) {
  1477. jack_error("jack_set_timebase_callback called with a NULL client");
  1478. return -1;
  1479. } else {
  1480. return client->SetTimebaseCallback(conditional, timebase_callback, arg);
  1481. }
  1482. }
  1483. EXPORT int jack_transport_locate(jack_client_t* ext_client, jack_nframes_t frame)
  1484. {
  1485. #ifdef __CLIENTDEBUG__
  1486. JackLibGlobals::CheckContext();
  1487. #endif
  1488. JackClient* client = (JackClient*)ext_client;
  1489. if (client == NULL) {
  1490. jack_error("jack_transport_locate called with a NULL client");
  1491. return -1;
  1492. } else {
  1493. client->TransportLocate(frame);
  1494. return 0;
  1495. }
  1496. }
  1497. EXPORT jack_transport_state_t jack_transport_query(const jack_client_t* ext_client, jack_position_t* pos)
  1498. {
  1499. #ifdef __CLIENTDEBUG__
  1500. JackLibGlobals::CheckContext();
  1501. #endif
  1502. JackClient* client = (JackClient*)ext_client;
  1503. if (client == NULL) {
  1504. jack_error("jack_transport_query called with a NULL client");
  1505. return JackTransportStopped;
  1506. } else {
  1507. return client->TransportQuery(pos);
  1508. }
  1509. }
  1510. EXPORT jack_nframes_t jack_get_current_transport_frame(const jack_client_t* ext_client)
  1511. {
  1512. #ifdef __CLIENTDEBUG__
  1513. JackLibGlobals::CheckContext();
  1514. #endif
  1515. JackClient* client = (JackClient*)ext_client;
  1516. if (client == NULL) {
  1517. jack_error("jack_get_current_transport_frame called with a NULL client");
  1518. return 0;
  1519. } else {
  1520. return client->GetCurrentTransportFrame();
  1521. }
  1522. }
  1523. EXPORT int jack_transport_reposition(jack_client_t* ext_client, jack_position_t* pos)
  1524. {
  1525. #ifdef __CLIENTDEBUG__
  1526. JackLibGlobals::CheckContext();
  1527. #endif
  1528. JackClient* client = (JackClient*)ext_client;
  1529. if (client == NULL) {
  1530. jack_error("jack_transport_reposition called with a NULL client");
  1531. return -1;
  1532. } else {
  1533. client->TransportReposition(pos);
  1534. return 0;
  1535. }
  1536. }
  1537. EXPORT void jack_transport_start(jack_client_t* ext_client)
  1538. {
  1539. #ifdef __CLIENTDEBUG__
  1540. JackLibGlobals::CheckContext();
  1541. #endif
  1542. JackClient* client = (JackClient*)ext_client;
  1543. if (client == NULL) {
  1544. jack_error("jack_transport_start called with a NULL client");
  1545. } else {
  1546. client->TransportStart();
  1547. }
  1548. }
  1549. EXPORT void jack_transport_stop(jack_client_t* ext_client)
  1550. {
  1551. #ifdef __CLIENTDEBUG__
  1552. JackLibGlobals::CheckContext();
  1553. #endif
  1554. JackClient* client = (JackClient*)ext_client;
  1555. if (client == NULL) {
  1556. jack_error("jack_transport_stop called with a NULL client");
  1557. } else {
  1558. client->TransportStop();
  1559. }
  1560. }
  1561. // deprecated
  1562. EXPORT void jack_get_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
  1563. {
  1564. jack_error("jack_get_transport_info: deprecated");
  1565. if (tinfo)
  1566. memset(tinfo, 0, sizeof(jack_transport_info_t));
  1567. }
  1568. EXPORT void jack_set_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
  1569. {
  1570. jack_error("jack_set_transport_info: deprecated");
  1571. if (tinfo)
  1572. memset(tinfo, 0, sizeof(jack_transport_info_t));
  1573. }
  1574. // statistics.h
  1575. EXPORT float jack_get_max_delayed_usecs(jack_client_t* ext_client)
  1576. {
  1577. #ifdef __CLIENTDEBUG__
  1578. JackLibGlobals::CheckContext();
  1579. #endif
  1580. JackClient* client = (JackClient*)ext_client;
  1581. if (client == NULL) {
  1582. jack_error("jack_get_max_delayed_usecs called with a NULL client");
  1583. return 0.f;
  1584. } else {
  1585. JackEngineControl* control = GetEngineControl();
  1586. return (control ? control->fMaxDelayedUsecs : 0.f);
  1587. }
  1588. }
  1589. EXPORT float jack_get_xrun_delayed_usecs(jack_client_t* ext_client)
  1590. {
  1591. #ifdef __CLIENTDEBUG__
  1592. JackLibGlobals::CheckContext();
  1593. #endif
  1594. JackClient* client = (JackClient*)ext_client;
  1595. if (client == NULL) {
  1596. jack_error("jack_get_xrun_delayed_usecs called with a NULL client");
  1597. return 0.f;
  1598. } else {
  1599. JackEngineControl* control = GetEngineControl();
  1600. return (control ? control->fXrunDelayedUsecs : 0.f);
  1601. }
  1602. }
  1603. EXPORT void jack_reset_max_delayed_usecs(jack_client_t* ext_client)
  1604. {
  1605. #ifdef __CLIENTDEBUG__
  1606. JackLibGlobals::CheckContext();
  1607. #endif
  1608. JackClient* client = (JackClient*)ext_client;
  1609. if (client == NULL) {
  1610. jack_error("jack_reset_max_delayed_usecs called with a NULL client");
  1611. } else {
  1612. JackEngineControl* control = GetEngineControl();
  1613. control->ResetXRun();
  1614. }
  1615. }
  1616. // thread.h
  1617. EXPORT int jack_client_real_time_priority(jack_client_t* ext_client)
  1618. {
  1619. #ifdef __CLIENTDEBUG__
  1620. JackLibGlobals::CheckContext();
  1621. #endif
  1622. JackClient* client = (JackClient*)ext_client;
  1623. if (client == NULL) {
  1624. jack_error("jack_client_real_time_priority called with a NULL client");
  1625. return -1;
  1626. } else {
  1627. JackEngineControl* control = GetEngineControl();
  1628. return (control->fRealTime) ? control->fClientPriority : -1;
  1629. }
  1630. }
  1631. EXPORT int jack_client_max_real_time_priority(jack_client_t* ext_client)
  1632. {
  1633. #ifdef __CLIENTDEBUG__
  1634. JackLibGlobals::CheckContext();
  1635. #endif
  1636. JackClient* client = (JackClient*)ext_client;
  1637. if (client == NULL) {
  1638. jack_error("jack_client_max_real_time_priority called with a NULL client");
  1639. return -1;
  1640. } else {
  1641. JackEngineControl* control = GetEngineControl();
  1642. return (control->fRealTime) ? control->fMaxClientPriority : -1;
  1643. }
  1644. }
  1645. EXPORT int jack_acquire_real_time_scheduling(pthread_t thread, int priority)
  1646. {
  1647. JackEngineControl* control = GetEngineControl();
  1648. return (control ? JackThread::AcquireRealTimeImp(thread, priority, GetEngineControl()->fPeriod, GetEngineControl()->fComputation, GetEngineControl()->fConstraint) : -1);
  1649. }
  1650. EXPORT int jack_client_create_thread(jack_client_t* client,
  1651. pthread_t *thread,
  1652. int priority,
  1653. int realtime, /* boolean */
  1654. thread_routine routine,
  1655. void *arg)
  1656. {
  1657. return JackThread::StartImp(thread, priority, realtime, routine, arg);
  1658. }
  1659. EXPORT int jack_drop_real_time_scheduling(pthread_t thread)
  1660. {
  1661. return JackThread::DropRealTimeImp(thread);
  1662. }
  1663. EXPORT int jack_client_stop_thread(jack_client_t* client, pthread_t thread)
  1664. {
  1665. return JackThread::StopImp(thread);
  1666. }
  1667. EXPORT int jack_client_kill_thread(jack_client_t* client, pthread_t thread)
  1668. {
  1669. return JackThread::KillImp(thread);
  1670. }
  1671. #ifndef WIN32
  1672. EXPORT void jack_set_thread_creator (jack_thread_creator_t jtc)
  1673. {
  1674. JackGlobals::fJackThreadCreator = jtc;
  1675. }
  1676. #endif
  1677. // intclient.h
  1678. EXPORT int jack_internal_client_new (const char *client_name,
  1679. const char *load_name,
  1680. const char *load_init)
  1681. {
  1682. jack_error("jack_internal_client_new: deprecated");
  1683. return -1;
  1684. }
  1685. EXPORT void jack_internal_client_close (const char *client_name)
  1686. {
  1687. jack_error("jack_internal_client_close: deprecated");
  1688. }
  1689. EXPORT char* jack_get_internal_client_name(jack_client_t* ext_client, jack_intclient_t intclient)
  1690. {
  1691. #ifdef __CLIENTDEBUG__
  1692. JackLibGlobals::CheckContext();
  1693. #endif
  1694. JackClient* client = (JackClient*)ext_client;
  1695. if (client == NULL) {
  1696. jack_error("jack_get_internal_client_name called with a NULL client");
  1697. return NULL;
  1698. } else if (intclient >= CLIENT_NUM) {
  1699. jack_error("jack_get_internal_client_name: incorrect client");
  1700. return NULL;
  1701. } else {
  1702. return client->GetInternalClientName(intclient);
  1703. }
  1704. }
  1705. EXPORT jack_intclient_t jack_internal_client_handle(jack_client_t* ext_client, const char* client_name, jack_status_t* status)
  1706. {
  1707. #ifdef __CLIENTDEBUG__
  1708. JackLibGlobals::CheckContext();
  1709. #endif
  1710. JackClient* client = (JackClient*)ext_client;
  1711. if (client == NULL) {
  1712. jack_error("jack_internal_client_handle called with a NULL client");
  1713. return 0;
  1714. } else {
  1715. jack_status_t my_status;
  1716. if (status == NULL) /* no status from caller? */
  1717. status = &my_status; /* use local status word */
  1718. *status = (jack_status_t)0;
  1719. return client->InternalClientHandle(client_name, status);
  1720. }
  1721. }
  1722. 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)
  1723. {
  1724. #ifdef __CLIENTDEBUG__
  1725. JackLibGlobals::CheckContext();
  1726. #endif
  1727. JackClient* client = (JackClient*)ext_client;
  1728. if (client == NULL) {
  1729. jack_error("jack_internal_client_load called with a NULL client");
  1730. return 0;
  1731. } else {
  1732. jack_varargs_t va;
  1733. jack_status_t my_status;
  1734. if (status == NULL) /* no status from caller? */
  1735. status = &my_status; /* use local status word */
  1736. *status = (jack_status_t)0;
  1737. /* validate parameters */
  1738. if ((options & ~JackLoadOptions)) {
  1739. int my_status1 = *status | (JackFailure | JackInvalidOption);
  1740. *status = (jack_status_t)my_status1;
  1741. return 0;
  1742. }
  1743. /* parse variable arguments */
  1744. jack_varargs_parse(options, ap, &va);
  1745. return client->InternalClientLoad(client_name, options, status, &va);
  1746. }
  1747. }
  1748. EXPORT jack_intclient_t jack_internal_client_load(jack_client_t *client, const char *client_name, jack_options_t options, jack_status_t *status, ...)
  1749. {
  1750. va_list ap;
  1751. va_start(ap, status);
  1752. jack_intclient_t res = jack_internal_client_load_aux(client, client_name, options, status, ap);
  1753. va_end(ap);
  1754. return res;
  1755. }
  1756. EXPORT jack_status_t jack_internal_client_unload(jack_client_t* ext_client, jack_intclient_t intclient)
  1757. {
  1758. #ifdef __CLIENTDEBUG__
  1759. JackLibGlobals::CheckContext();
  1760. #endif
  1761. JackClient* client = (JackClient*)ext_client;
  1762. if (client == NULL) {
  1763. jack_error("jack_internal_client_unload called with a NULL client");
  1764. return (jack_status_t)(JackNoSuchClient | JackFailure);
  1765. } else if (intclient >= CLIENT_NUM) {
  1766. jack_error("jack_internal_client_unload: incorrect client");
  1767. return (jack_status_t)(JackNoSuchClient | JackFailure);
  1768. } else {
  1769. jack_status_t my_status;
  1770. client->InternalClientUnload(intclient, &my_status);
  1771. return my_status;
  1772. }
  1773. }
  1774. EXPORT
  1775. void
  1776. jack_get_version(
  1777. int *major_ptr,
  1778. int *minor_ptr,
  1779. int *micro_ptr,
  1780. int *proto_ptr)
  1781. {
  1782. // FIXME: We need these comming from build system
  1783. *major_ptr = 0;
  1784. *minor_ptr = 0;
  1785. *micro_ptr = 0;
  1786. *proto_ptr = 0;
  1787. }
  1788. EXPORT
  1789. const char *
  1790. jack_get_version_string()
  1791. {
  1792. return VERSION;
  1793. }