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.

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