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.

1950 lines
62KB

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