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.

1541 lines
49KB

  1. /*
  2. Copyright (C) 2001-2003 Paul Davis
  3. Copyright (C) 2004-2006 Grame
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 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 General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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 "JackExports.h"
  24. #include "JackAPI.h"
  25. #ifdef __APPLE__
  26. #include "JackMachThread.h"
  27. #elif WIN32
  28. #include "JackWinThread.h"
  29. #else
  30. #include "JackPosixThread.h"
  31. #endif
  32. #include <math.h>
  33. #ifdef __CLIENTDEBUG__
  34. #include "JackLibGlobals.h"
  35. #endif
  36. using namespace Jack;
  37. #ifdef __cplusplus
  38. extern "C"
  39. {
  40. #endif
  41. EXPORT jack_client_t * jack_client_open (const char *client_name,
  42. jack_options_t options,
  43. jack_status_t *status, ...);
  44. EXPORT jack_client_t * jack_client_new (const char *client_name);
  45. EXPORT int jack_client_name_size (void);
  46. EXPORT char* jack_get_client_name (jack_client_t *client);
  47. EXPORT int jack_internal_client_new (const char *client_name,
  48. const char *load_name,
  49. const char *load_init);
  50. EXPORT void jack_internal_client_close (const char *client_name);
  51. EXPORT int jack_is_realtime (jack_client_t *client);
  52. EXPORT void jack_on_shutdown (jack_client_t *client,
  53. void (*function)(void *arg), void *arg);
  54. EXPORT int jack_set_process_callback (jack_client_t *client,
  55. JackProcessCallback process_callback,
  56. void *arg);
  57. EXPORT int jack_set_thread_init_callback (jack_client_t *client,
  58. JackThreadInitCallback thread_init_callback,
  59. void *arg);
  60. EXPORT int jack_set_freewheel_callback (jack_client_t *client,
  61. JackFreewheelCallback freewheel_callback,
  62. void *arg);
  63. EXPORT int jack_set_freewheel(jack_client_t* client, int onoff);
  64. EXPORT int jack_set_buffer_size (jack_client_t *client, jack_nframes_t nframes);
  65. EXPORT int jack_set_buffer_size_callback (jack_client_t *client,
  66. JackBufferSizeCallback bufsize_callback,
  67. void *arg);
  68. EXPORT int jack_set_sample_rate_callback (jack_client_t *client,
  69. JackSampleRateCallback srate_callback,
  70. void *arg);
  71. EXPORT int jack_set_client_registration_callback (jack_client_t *,
  72. JackClientRegistrationCallback
  73. registration_callback, void *arg);
  74. EXPORT int jack_set_port_registration_callback (jack_client_t *,
  75. JackPortRegistrationCallback
  76. registration_callback, void *arg);
  77. EXPORT int jack_set_graph_order_callback (jack_client_t *,
  78. JackGraphOrderCallback graph_callback,
  79. void *);
  80. EXPORT int jack_set_xrun_callback (jack_client_t *,
  81. JackXRunCallback xrun_callback, void *arg);
  82. EXPORT int jack_activate (jack_client_t *client);
  83. EXPORT int jack_deactivate (jack_client_t *client);
  84. EXPORT jack_port_t * jack_port_register (jack_client_t *client,
  85. const char *port_name,
  86. const char *port_type,
  87. unsigned long flags,
  88. unsigned long buffer_size);
  89. EXPORT int jack_port_unregister (jack_client_t *, jack_port_t *);
  90. EXPORT void * jack_port_get_buffer (jack_port_t *, jack_nframes_t);
  91. EXPORT const char * jack_port_name (const jack_port_t *port);
  92. EXPORT const char * jack_port_short_name (const jack_port_t *port);
  93. EXPORT int jack_port_flags (const jack_port_t *port);
  94. EXPORT const char * jack_port_type (const jack_port_t *port);
  95. EXPORT int jack_port_is_mine (const jack_client_t *, const jack_port_t *port);
  96. EXPORT int jack_port_connected (const jack_port_t *port);
  97. EXPORT int jack_port_connected_to (const jack_port_t *port,
  98. const char *port_name);
  99. EXPORT const char ** jack_port_get_connections (const jack_port_t *port);
  100. EXPORT const char ** jack_port_get_all_connections (const jack_client_t *client,
  101. const jack_port_t *port);
  102. EXPORT int jack_port_tie (jack_port_t *src, jack_port_t *dst);
  103. EXPORT int jack_port_untie (jack_port_t *port);
  104. EXPORT int jack_port_lock (jack_client_t *, jack_port_t *);
  105. EXPORT int jack_port_unlock (jack_client_t *, jack_port_t *);
  106. EXPORT jack_nframes_t jack_port_get_latency (jack_port_t *port);
  107. EXPORT jack_nframes_t jack_port_get_total_latency (jack_client_t *,
  108. jack_port_t *port);
  109. EXPORT void jack_port_set_latency (jack_port_t *, jack_nframes_t);
  110. EXPORT int jack_recompute_total_latencies (jack_client_t*);
  111. EXPORT int jack_port_set_name (jack_port_t *port, const char *port_name);
  112. EXPORT int jack_port_set_alias (jack_port_t *port, const char *alias);
  113. EXPORT int jack_port_unset_alias (jack_port_t *port, const char *alias);
  114. EXPORT int jack_port_get_aliases (const jack_port_t *port, char* const aliases[2]);
  115. EXPORT int jack_port_request_monitor (jack_port_t *port, int onoff);
  116. EXPORT int jack_port_request_monitor_by_name (jack_client_t *client,
  117. const char *port_name, int onoff);
  118. EXPORT int jack_port_ensure_monitor (jack_port_t *port, int onoff);
  119. EXPORT int jack_port_monitoring_input (jack_port_t *port);
  120. EXPORT int jack_connect (jack_client_t *,
  121. const char *source_port,
  122. const char *destination_port);
  123. EXPORT int jack_disconnect (jack_client_t *,
  124. const char *source_port,
  125. const char *destination_port);
  126. EXPORT int jack_port_disconnect (jack_client_t *, jack_port_t *);
  127. EXPORT int jack_port_name_size(void);
  128. EXPORT int jack_port_type_size(void);
  129. EXPORT jack_nframes_t jack_get_sample_rate (jack_client_t *);
  130. EXPORT jack_nframes_t jack_get_buffer_size (jack_client_t *);
  131. EXPORT const char ** jack_get_ports (jack_client_t *,
  132. const char *port_name_pattern,
  133. const char *type_name_pattern,
  134. unsigned long flags);
  135. EXPORT jack_port_t * jack_port_by_name (jack_client_t *, const char *port_name);
  136. EXPORT jack_port_t * jack_port_by_id (jack_client_t *client,
  137. jack_port_id_t port_id);
  138. EXPORT int jack_engine_takeover_timebase (jack_client_t *);
  139. EXPORT jack_nframes_t jack_frames_since_cycle_start (const jack_client_t *);
  140. EXPORT jack_time_t jack_get_time(const jack_client_t *client);
  141. EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t *client, jack_time_t time);
  142. EXPORT jack_time_t jack_frames_to_time(const jack_client_t *client, jack_nframes_t frames);
  143. EXPORT jack_nframes_t jack_frame_time (const jack_client_t *);
  144. EXPORT jack_nframes_t jack_last_frame_time (const jack_client_t *client);
  145. EXPORT float jack_cpu_load (jack_client_t *client);
  146. EXPORT pthread_t jack_client_thread_id (jack_client_t *);
  147. EXPORT void jack_set_error_function (void (*func)(const char *));
  148. EXPORT float jack_get_max_delayed_usecs (jack_client_t *client);
  149. EXPORT float jack_get_xrun_delayed_usecs (jack_client_t *client);
  150. EXPORT void jack_reset_max_delayed_usecs (jack_client_t *client);
  151. EXPORT int jack_release_timebase (jack_client_t *client);
  152. EXPORT int jack_set_sync_callback (jack_client_t *client,
  153. JackSyncCallback sync_callback,
  154. void *arg);
  155. EXPORT int jack_set_sync_timeout (jack_client_t *client,
  156. jack_time_t timeout);
  157. EXPORT int jack_set_timebase_callback (jack_client_t *client,
  158. int conditional,
  159. JackTimebaseCallback timebase_callback,
  160. void *arg);
  161. EXPORT int jack_transport_locate (jack_client_t *client,
  162. jack_nframes_t frame);
  163. EXPORT jack_transport_state_t jack_transport_query (const jack_client_t *client,
  164. jack_position_t *pos);
  165. EXPORT jack_nframes_t jack_get_current_transport_frame (const jack_client_t *client);
  166. EXPORT int jack_transport_reposition (jack_client_t *client,
  167. jack_position_t *pos);
  168. EXPORT void jack_transport_start (jack_client_t *client);
  169. EXPORT void jack_transport_stop (jack_client_t *client);
  170. EXPORT void jack_get_transport_info (jack_client_t *client,
  171. jack_transport_info_t *tinfo);
  172. EXPORT void jack_set_transport_info (jack_client_t *client,
  173. jack_transport_info_t *tinfo);
  174. EXPORT int jack_acquire_real_time_scheduling (pthread_t thread, int priority);
  175. EXPORT int jack_client_create_thread (jack_client_t* client,
  176. pthread_t *thread,
  177. int priority,
  178. int realtime, // boolean
  179. void *(*start_routine)(void*),
  180. void *arg);
  181. EXPORT int jack_drop_real_time_scheduling (pthread_t thread);
  182. EXPORT char * jack_get_internal_client_name (jack_client_t *client,
  183. jack_intclient_t intclient);
  184. EXPORT jack_intclient_t jack_internal_client_handle (jack_client_t *client,
  185. const char *client_name,
  186. jack_status_t *status);
  187. EXPORT jack_intclient_t jack_internal_client_load (jack_client_t *client,
  188. const char *client_name,
  189. jack_options_t options,
  190. jack_status_t *status, ...);
  191. EXPORT jack_status_t jack_internal_client_unload (jack_client_t *client,
  192. jack_intclient_t intclient);
  193. #ifdef __cplusplus
  194. }
  195. #endif
  196. #ifdef WIN32
  197. /* missing on Windows : see http://bugs.mysql.com/bug.php?id=15936 */
  198. inline double rint(double nr)
  199. {
  200. double f = floor(nr);
  201. double c = ceil(nr);
  202. return (((c -nr) >= (nr - f)) ? f : c);
  203. }
  204. #endif
  205. static inline bool CheckPort(jack_port_id_t port_index)
  206. {
  207. return (port_index > 0 && port_index < PORT_NUM);
  208. }
  209. static inline bool CheckBufferSize(jack_nframes_t buffer_size)
  210. {
  211. return (buffer_size <= BUFFER_SIZE_MAX);
  212. }
  213. static inline void WaitGraphChange()
  214. {
  215. if (GetGraphManager()->IsPendingChange()) {
  216. JackLog("WaitGraphChange...\n");
  217. JackSleep(GetEngineControl()->fPeriodUsecs * 2);
  218. }
  219. }
  220. static void default_jack_error_callback(const char *desc)
  221. {
  222. fprintf(stderr, "%s\n", desc);
  223. }
  224. void (*jack_error_callback)(const char *desc) = &default_jack_error_callback;
  225. EXPORT void jack_set_error_function (void (*func)(const char *))
  226. {
  227. jack_error_callback = func;
  228. }
  229. EXPORT jack_client_t* jack_client_new(const char* client_name)
  230. {
  231. int options = JackUseExactName;
  232. if (getenv("JACK_START_SERVER") == NULL)
  233. options |= JackNoStartServer;
  234. return jack_client_open(client_name, (jack_options_t)options, NULL);
  235. }
  236. EXPORT void* jack_port_get_buffer(jack_port_t* port, jack_nframes_t frames)
  237. {
  238. #ifdef __CLIENTDEBUG__
  239. JackLibGlobals::CheckContext();
  240. #endif
  241. jack_port_id_t myport = (jack_port_id_t)port;
  242. if (!CheckPort(myport)) {
  243. jack_error("jack_port_get_buffer called with an incorrect port %ld", myport);
  244. return NULL;
  245. } else {
  246. return GetGraphManager()->GetBuffer(myport, frames);
  247. }
  248. }
  249. EXPORT const char* jack_port_name(const jack_port_t* port)
  250. {
  251. #ifdef __CLIENTDEBUG__
  252. JackLibGlobals::CheckContext();
  253. #endif
  254. jack_port_id_t myport = (jack_port_id_t)port;
  255. if (!CheckPort(myport)) {
  256. jack_error("jack_port_name called with an incorrect port %ld", myport);
  257. return NULL;
  258. } else {
  259. return GetGraphManager()->GetPort(myport)->GetName();
  260. }
  261. }
  262. EXPORT const char* jack_port_short_name(const jack_port_t* port)
  263. {
  264. #ifdef __CLIENTDEBUG__
  265. JackLibGlobals::CheckContext();
  266. #endif
  267. jack_port_id_t myport = (jack_port_id_t)port;
  268. if (!CheckPort(myport)) {
  269. jack_error("jack_port_short_name called with an incorrect port %ld", myport);
  270. return NULL;
  271. } else {
  272. return GetGraphManager()->GetPort(myport)->GetShortName();
  273. }
  274. }
  275. EXPORT int jack_port_flags(const jack_port_t* port)
  276. {
  277. #ifdef __CLIENTDEBUG__
  278. JackLibGlobals::CheckContext();
  279. #endif
  280. jack_port_id_t myport = (jack_port_id_t)port;
  281. if (!CheckPort(myport)) {
  282. jack_error("jack_port_flags called with an incorrect port %ld", myport);
  283. return -1;
  284. } else {
  285. return GetGraphManager()->GetPort(myport)->GetFlags();
  286. }
  287. }
  288. EXPORT const char* jack_port_type(const jack_port_t* port)
  289. {
  290. #ifdef __CLIENTDEBUG__
  291. JackLibGlobals::CheckContext();
  292. #endif
  293. jack_port_id_t myport = (jack_port_id_t)port;
  294. if (!CheckPort(myport)) {
  295. jack_error("jack_port_flags called an incorrect port %ld", myport);
  296. return NULL;
  297. } else {
  298. return GetGraphManager()->GetPort(myport)->GetType();
  299. }
  300. }
  301. EXPORT int jack_port_connected(const jack_port_t* port)
  302. {
  303. #ifdef __CLIENTDEBUG__
  304. JackLibGlobals::CheckContext();
  305. #endif
  306. jack_port_id_t myport = (jack_port_id_t)port;
  307. if (!CheckPort(myport)) {
  308. jack_error("jack_port_connected called with an incorrect port %ld", myport);
  309. return -1;
  310. } else {
  311. WaitGraphChange();
  312. return GetGraphManager()->GetConnectionsNum(myport);
  313. }
  314. }
  315. EXPORT int jack_port_connected_to(const jack_port_t* port, const char* portname)
  316. {
  317. #ifdef __CLIENTDEBUG__
  318. JackLibGlobals::CheckContext();
  319. #endif
  320. jack_port_id_t myport = (jack_port_id_t)port;
  321. if (!CheckPort(myport)) {
  322. jack_error("jack_port_connected_to called with an incorrect port %ld", myport);
  323. return -1;
  324. } else if (portname == NULL) {
  325. jack_error("jack_port_connected_to called with a NULL port name");
  326. return -1;
  327. } else {
  328. WaitGraphChange();
  329. return GetGraphManager()->ConnectedTo(myport, portname);
  330. }
  331. }
  332. EXPORT int jack_port_tie(jack_port_t* src, jack_port_t* dst)
  333. {
  334. #ifdef __CLIENTDEBUG__
  335. JackLibGlobals::CheckContext();
  336. #endif
  337. jack_port_id_t mysrc = (jack_port_id_t)src;
  338. if (!CheckPort(mysrc)) {
  339. jack_error("jack_port_tie called with a NULL src port");
  340. return -1;
  341. }
  342. jack_port_id_t mydst = (jack_port_id_t)dst;
  343. if (!CheckPort(mydst)) {
  344. jack_error("jack_port_tie called with a NULL dst port");
  345. return -1;
  346. }
  347. if (GetGraphManager()->GetPort(mysrc)->GetRefNum() != GetGraphManager()->GetPort(mydst)->GetRefNum()) {
  348. jack_error("jack_port_tie called with ports not belonging to the same client");
  349. return -1;
  350. }
  351. return GetGraphManager()->GetPort(mydst)->Tie(mysrc);
  352. }
  353. EXPORT int jack_port_untie(jack_port_t* port)
  354. {
  355. #ifdef __CLIENTDEBUG__
  356. JackLibGlobals::CheckContext();
  357. #endif
  358. jack_port_id_t myport = (jack_port_id_t)port;
  359. if (!CheckPort(myport)) {
  360. jack_error("jack_port_untie called with an incorrect port %ld", myport);
  361. return -1;
  362. } else {
  363. return GetGraphManager()->GetPort(myport)->UnTie();
  364. }
  365. }
  366. EXPORT jack_nframes_t jack_port_get_latency(jack_port_t* port)
  367. {
  368. #ifdef __CLIENTDEBUG__
  369. JackLibGlobals::CheckContext();
  370. #endif
  371. jack_port_id_t myport = (jack_port_id_t)port;
  372. if (!CheckPort(myport)) {
  373. jack_error("jack_port_get_latency called with an incorrect port %ld", myport);
  374. return 0;
  375. } else {
  376. WaitGraphChange();
  377. return GetGraphManager()->GetPort(myport)->GetLatency();
  378. }
  379. }
  380. EXPORT void jack_port_set_latency(jack_port_t* port, jack_nframes_t frames)
  381. {
  382. #ifdef __CLIENTDEBUG__
  383. JackLibGlobals::CheckContext();
  384. #endif
  385. jack_port_id_t myport = (jack_port_id_t)port;
  386. if (!CheckPort(myport)) {
  387. jack_error("jack_port_set_latency called with an incorrect port %ld", myport);
  388. } else {
  389. GetGraphManager()->GetPort(myport)->SetLatency(frames);
  390. }
  391. }
  392. EXPORT int jack_recompute_total_latencies(jack_client_t* ext_client)
  393. {
  394. // The latency computation is done each time jack_port_get_total_latency is called
  395. return 0;
  396. }
  397. EXPORT int jack_port_set_name(jack_port_t* port, const char* name)
  398. {
  399. #ifdef __CLIENTDEBUG__
  400. JackLibGlobals::CheckContext();
  401. #endif
  402. jack_port_id_t myport = (jack_port_id_t)port;
  403. if (!CheckPort(myport)) {
  404. jack_error("jack_port_set_name called with an incorrect port %ld", myport);
  405. return -1;
  406. } else if (name == NULL) {
  407. jack_error("jack_port_set_name called with a NULL port name");
  408. return -1;
  409. } else {
  410. return GetGraphManager()->GetPort(myport)->SetName(name);
  411. }
  412. }
  413. EXPORT int jack_port_set_alias(jack_port_t* port, const char* name)
  414. {
  415. #ifdef __CLIENTDEBUG__
  416. JackLibGlobals::CheckContext();
  417. #endif
  418. jack_port_id_t myport = (jack_port_id_t)port;
  419. if (!CheckPort(myport)) {
  420. jack_error("jack_port_set_alias called with an incorrect port %ld", myport);
  421. return -1;
  422. } else if (name == NULL) {
  423. jack_error("jack_port_set_alias called with a NULL port name");
  424. return -1;
  425. } else {
  426. return GetGraphManager()->GetPort(myport)->SetAlias(name);
  427. }
  428. }
  429. EXPORT int jack_port_unset_alias(jack_port_t* port, const char* name)
  430. {
  431. #ifdef __CLIENTDEBUG__
  432. JackLibGlobals::CheckContext();
  433. #endif
  434. jack_port_id_t myport = (jack_port_id_t)port;
  435. if (!CheckPort(myport)) {
  436. jack_error("jack_port_unset_alias called with an incorrect port %ld", myport);
  437. return -1;
  438. } else if (name == NULL) {
  439. jack_error("jack_port_unset_alias called with a NULL port name");
  440. return -1;
  441. } else {
  442. return GetGraphManager()->GetPort(myport)->UnsetAlias(name);
  443. }
  444. }
  445. EXPORT int jack_port_get_aliases(const jack_port_t* port, char* const aliases[2])
  446. {
  447. #ifdef __CLIENTDEBUG__
  448. JackLibGlobals::CheckContext();
  449. #endif
  450. jack_port_id_t myport = (jack_port_id_t)port;
  451. if (!CheckPort(myport)) {
  452. jack_error("jack_port_get_aliases called with an incorrect port %ld", myport);
  453. return -1;
  454. } else {
  455. return GetGraphManager()->GetPort(myport)->GetAliases(aliases);
  456. }
  457. }
  458. EXPORT int jack_port_request_monitor(jack_port_t* port, int onoff)
  459. {
  460. #ifdef __CLIENTDEBUG__
  461. JackLibGlobals::CheckContext();
  462. #endif
  463. jack_port_id_t myport = (jack_port_id_t)port;
  464. if (!CheckPort(myport)) {
  465. jack_error("jack_port_request_monitor called with an incorrect port %ld", myport);
  466. return -1;
  467. } else {
  468. return GetGraphManager()->RequestMonitor(myport, onoff);
  469. }
  470. }
  471. EXPORT int jack_port_request_monitor_by_name(jack_client_t* ext_client, const char* port_name, int onoff)
  472. {
  473. #ifdef __CLIENTDEBUG__
  474. JackLibGlobals::CheckContext();
  475. #endif
  476. JackClient* client = (JackClient*)ext_client;
  477. if (client == NULL) {
  478. jack_error("jack_port_request_monitor_by_name called with a NULL client");
  479. return -1;
  480. } else {
  481. jack_port_id_t myport = GetGraphManager()->GetPort(port_name);
  482. if (!CheckPort(myport)) {
  483. jack_error("jack_port_request_monitor_by_name called with an incorrect port %s", port_name);
  484. return -1;
  485. } else {
  486. return GetGraphManager()->RequestMonitor(myport, onoff);
  487. }
  488. }
  489. }
  490. EXPORT int jack_port_ensure_monitor(jack_port_t* port, int onoff)
  491. {
  492. #ifdef __CLIENTDEBUG__
  493. JackLibGlobals::CheckContext();
  494. #endif
  495. jack_port_id_t myport = (jack_port_id_t)port;
  496. if (!CheckPort(myport)) {
  497. jack_error("jack_port_ensure_monitor called with an incorrect port %ld", myport);
  498. return -1;
  499. } else {
  500. return GetGraphManager()->GetPort(myport)->EnsureMonitor(onoff);
  501. }
  502. }
  503. EXPORT int jack_port_monitoring_input(jack_port_t* port)
  504. {
  505. #ifdef __CLIENTDEBUG__
  506. JackLibGlobals::CheckContext();
  507. #endif
  508. jack_port_id_t myport = (jack_port_id_t)port;
  509. if (!CheckPort(myport)) {
  510. jack_error("jack_port_monitoring_input called with an incorrect port %ld", myport);
  511. return -1;
  512. } else {
  513. return GetGraphManager()->GetPort(myport)->MonitoringInput();
  514. }
  515. }
  516. EXPORT int jack_is_realtime(jack_client_t* ext_client)
  517. {
  518. #ifdef __CLIENTDEBUG__
  519. JackLibGlobals::CheckContext();
  520. #endif
  521. JackClient* client = (JackClient*)ext_client;
  522. if (client == NULL) {
  523. jack_error("jack_is_realtime called with a NULL client");
  524. return -1;
  525. } else {
  526. return GetEngineControl()->fRealTime;
  527. }
  528. }
  529. EXPORT void jack_on_shutdown(jack_client_t* ext_client, void (*function)(void* arg), void* arg)
  530. {
  531. #ifdef __CLIENTDEBUG__
  532. JackLibGlobals::CheckContext();
  533. #endif
  534. JackClient* client = (JackClient*)ext_client;
  535. if (client == NULL) {
  536. jack_error("jack_on_shutdown called with a NULL client");
  537. } else {
  538. client->OnShutdown(function, arg);
  539. }
  540. }
  541. EXPORT int jack_set_process_callback(jack_client_t* ext_client, JackProcessCallback callback, void* arg)
  542. {
  543. #ifdef __CLIENTDEBUG__
  544. JackLibGlobals::CheckContext();
  545. #endif
  546. JackClient* client = (JackClient*)ext_client;
  547. if (client == NULL) {
  548. jack_error("jack_set_process_callback called with a NULL client");
  549. return -1;
  550. } else {
  551. return client->SetProcessCallback(callback, arg);
  552. }
  553. }
  554. EXPORT int jack_set_freewheel_callback(jack_client_t* ext_client, JackFreewheelCallback freewheel_callback, void* arg)
  555. {
  556. #ifdef __CLIENTDEBUG__
  557. JackLibGlobals::CheckContext();
  558. #endif
  559. JackClient* client = (JackClient*)ext_client;
  560. if (client == NULL) {
  561. jack_error("jack_set_freewheel_callback called with a NULL client");
  562. return -1;
  563. } else {
  564. return client->SetFreewheelCallback(freewheel_callback, arg);
  565. }
  566. }
  567. EXPORT int jack_set_freewheel(jack_client_t* ext_client, int onoff)
  568. {
  569. #ifdef __CLIENTDEBUG__
  570. JackLibGlobals::CheckContext();
  571. #endif
  572. JackClient* client = (JackClient*)ext_client;
  573. if (client == NULL) {
  574. jack_error("jack_set_freewheel called with a NULL client");
  575. return -1;
  576. } else {
  577. return client->SetFreeWheel(onoff);
  578. }
  579. }
  580. EXPORT int jack_set_buffer_size(jack_client_t* ext_client, jack_nframes_t buffer_size)
  581. {
  582. #ifdef __CLIENTDEBUG__
  583. JackLibGlobals::CheckContext();
  584. #endif
  585. JackClient* client = (JackClient*)ext_client;
  586. if (client == NULL) {
  587. jack_error("jack_set_buffer_size called with a NULL client");
  588. return -1;
  589. } else if (!CheckBufferSize(buffer_size)) {
  590. return -1;
  591. } else {
  592. return client->SetBufferSize(buffer_size);
  593. }
  594. }
  595. EXPORT int jack_set_buffer_size_callback(jack_client_t* ext_client, JackBufferSizeCallback bufsize_callback, void* arg)
  596. {
  597. #ifdef __CLIENTDEBUG__
  598. JackLibGlobals::CheckContext();
  599. #endif
  600. JackClient* client = (JackClient*)ext_client;
  601. if (client == NULL) {
  602. jack_error("jack_set_buffer_size_callback called with a NULL client");
  603. return -1;
  604. } else {
  605. return client->SetBufferSizeCallback(bufsize_callback, arg);
  606. }
  607. }
  608. EXPORT int jack_set_sample_rate_callback(jack_client_t* ext_client, JackSampleRateCallback srate_callback, void* arg)
  609. {
  610. #ifdef __CLIENTDEBUG__
  611. JackLibGlobals::CheckContext();
  612. #endif
  613. JackClient* client = (JackClient*)ext_client;
  614. if (client == NULL) {
  615. jack_error("jack_set_sample_rate_callback called with a NULL client");
  616. return -1;
  617. } else {
  618. jack_error("jack_set_sample_rate_callback: deprecated");
  619. return 0;
  620. }
  621. }
  622. EXPORT int jack_set_client_registration_callback(jack_client_t* ext_client, JackClientRegistrationCallback registration_callback, void* arg)
  623. {
  624. #ifdef __CLIENTDEBUG__
  625. JackLibGlobals::CheckContext();
  626. #endif
  627. JackClient* client = (JackClient*)ext_client;
  628. if (client == NULL) {
  629. jack_error("jack_set_client_registration_callback called with a NULL client");
  630. return -1;
  631. } else {
  632. return client->SetClientRegistrationCallback(registration_callback, arg);
  633. }
  634. }
  635. EXPORT int jack_set_port_registration_callback(jack_client_t* ext_client, JackPortRegistrationCallback registration_callback, void* arg)
  636. {
  637. #ifdef __CLIENTDEBUG__
  638. JackLibGlobals::CheckContext();
  639. #endif
  640. JackClient* client = (JackClient*)ext_client;
  641. if (client == NULL) {
  642. jack_error("jack_set_port_registration_callback called with a NULL client");
  643. return -1;
  644. } else {
  645. return client->SetPortRegistrationCallback(registration_callback, arg);
  646. }
  647. }
  648. EXPORT int jack_set_graph_order_callback(jack_client_t* ext_client, JackGraphOrderCallback graph_callback, void* arg)
  649. {
  650. #ifdef __CLIENTDEBUG__
  651. JackLibGlobals::CheckContext();
  652. #endif
  653. JackClient* client = (JackClient*)ext_client;
  654. JackLog("jack_set_graph_order_callback ext_client %x client %x \n", ext_client, client);
  655. if (client == NULL) {
  656. jack_error("jack_set_graph_order_callback called with a NULL client");
  657. return -1;
  658. } else {
  659. return client->SetGraphOrderCallback(graph_callback, arg);
  660. }
  661. }
  662. EXPORT int jack_set_xrun_callback(jack_client_t* ext_client, JackXRunCallback xrun_callback, void* arg)
  663. {
  664. #ifdef __CLIENTDEBUG__
  665. JackLibGlobals::CheckContext();
  666. #endif
  667. JackClient* client = (JackClient*)ext_client;
  668. if (client == NULL) {
  669. jack_error("jack_set_xrun_callback called with a NULL client");
  670. return -1;
  671. } else {
  672. return client->SetXRunCallback(xrun_callback, arg);
  673. }
  674. }
  675. EXPORT int jack_set_thread_init_callback(jack_client_t* ext_client, JackThreadInitCallback init_callback, void *arg)
  676. {
  677. #ifdef __CLIENTDEBUG__
  678. JackLibGlobals::CheckContext();
  679. #endif
  680. JackClient* client = (JackClient*)ext_client;
  681. JackLog("jack_set_thread_init_callback ext_client %x client %x \n", ext_client, client);
  682. if (client == NULL) {
  683. jack_error("jack_set_thread_init_callback called with a NULL client");
  684. return -1;
  685. } else {
  686. return client->SetInitCallback(init_callback, arg);
  687. }
  688. }
  689. EXPORT int jack_activate(jack_client_t* ext_client)
  690. {
  691. #ifdef __CLIENTDEBUG__
  692. JackLibGlobals::CheckContext();
  693. #endif
  694. JackClient* client = (JackClient*)ext_client;
  695. if (client == NULL) {
  696. jack_error("jack_activate called with a NULL client");
  697. return -1;
  698. } else {
  699. return client->Activate();
  700. }
  701. }
  702. EXPORT int jack_deactivate(jack_client_t* ext_client)
  703. {
  704. #ifdef __CLIENTDEBUG__
  705. JackLibGlobals::CheckContext();
  706. #endif
  707. JackClient* client = (JackClient*)ext_client;
  708. if (client == NULL) {
  709. jack_error("jack_deactivate called with a NULL client");
  710. return -1;
  711. } else {
  712. return client->Deactivate();
  713. }
  714. }
  715. 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)
  716. {
  717. #ifdef __CLIENTDEBUG__
  718. JackLibGlobals::CheckContext();
  719. #endif
  720. JackClient* client = (JackClient*)ext_client;
  721. if (client == NULL) {
  722. jack_error("jack_port_register called with a NULL client");
  723. return NULL;
  724. } else if ((port_name == NULL) || (port_type == NULL)) {
  725. jack_error("jack_port_register called with a NULL port name or a NULL port_type");
  726. return NULL;
  727. } else {
  728. return (jack_port_t *)client->PortRegister(port_name, port_type, flags, buffer_size);
  729. }
  730. }
  731. EXPORT int jack_port_unregister(jack_client_t* ext_client, jack_port_t* port)
  732. {
  733. #ifdef __CLIENTDEBUG__
  734. JackLibGlobals::CheckContext();
  735. #endif
  736. JackClient* client = (JackClient*)ext_client;
  737. if (client == NULL) {
  738. jack_error("jack_port_unregister called with a NULL client");
  739. return -1;
  740. }
  741. jack_port_id_t myport = (jack_port_id_t)port;
  742. if (!CheckPort(myport)) {
  743. jack_error("jack_port_unregister called with an incorrect port %ld", myport);
  744. return -1;
  745. }
  746. return client->PortUnRegister(myport);
  747. }
  748. EXPORT int jack_port_is_mine(const jack_client_t* ext_client, const jack_port_t* port)
  749. {
  750. #ifdef __CLIENTDEBUG__
  751. JackLibGlobals::CheckContext();
  752. #endif
  753. JackClient* client = (JackClient*)ext_client;
  754. if (client == NULL) {
  755. jack_error("jack_port_is_mine called with a NULL client");
  756. return -1;
  757. }
  758. jack_port_id_t myport = (jack_port_id_t)port;
  759. if (!CheckPort(myport)) {
  760. jack_error("jack_port_is_mine called with an incorrect port %ld", myport);
  761. return -1;
  762. }
  763. return client->PortIsMine(myport);
  764. }
  765. EXPORT const char** jack_port_get_connections(const jack_port_t* port)
  766. {
  767. #ifdef __CLIENTDEBUG__
  768. JackLibGlobals::CheckContext();
  769. #endif
  770. jack_port_id_t myport = (jack_port_id_t)port;
  771. if (!CheckPort(myport)) {
  772. jack_error("jack_port_get_connections called with an incorrect port %ld", myport);
  773. return NULL;
  774. } else {
  775. WaitGraphChange();
  776. return GetGraphManager()->GetConnections(myport);
  777. }
  778. }
  779. // Calling client does not need to "own" the port
  780. EXPORT const char** jack_port_get_all_connections(const jack_client_t* ext_client, const jack_port_t* port)
  781. {
  782. #ifdef __CLIENTDEBUG__
  783. JackLibGlobals::CheckContext();
  784. #endif
  785. JackClient* client = (JackClient*)ext_client;
  786. if (client == NULL) {
  787. jack_error("jack_port_get_all_connections called with a NULL client");
  788. return NULL;
  789. }
  790. jack_port_id_t myport = (jack_port_id_t)port;
  791. if (!CheckPort(myport)) {
  792. jack_error("jack_port_get_all_connections called with an incorrect port %ld", myport);
  793. return NULL;
  794. } else {
  795. WaitGraphChange();
  796. return GetGraphManager()->GetConnections(myport);
  797. }
  798. }
  799. // Does not use the client parameter
  800. EXPORT int jack_port_lock(jack_client_t* ext_client, jack_port_t* port)
  801. {
  802. #ifdef __CLIENTDEBUG__
  803. JackLibGlobals::CheckContext();
  804. #endif
  805. JackClient* client = (JackClient*)ext_client;
  806. if (client == NULL) {
  807. jack_error("jack_port_lock called with a NULL client");
  808. return -1;
  809. }
  810. jack_port_id_t myport = (jack_port_id_t)port;
  811. if (!CheckPort(myport)) {
  812. jack_error("jack_port_lock called with an incorrect port %ld", myport);
  813. return -1;
  814. } else {
  815. return (myport && client->PortIsMine(myport)) ? GetGraphManager()->GetPort(myport)->Lock() : -1;
  816. }
  817. }
  818. // Does not use the client parameter
  819. EXPORT int jack_port_unlock(jack_client_t* ext_client, jack_port_t* port)
  820. {
  821. #ifdef __CLIENTDEBUG__
  822. JackLibGlobals::CheckContext();
  823. #endif
  824. JackClient* client = (JackClient*)ext_client;
  825. if (client == NULL) {
  826. jack_error("jack_port_unlock called with a NULL client");
  827. return -1;
  828. }
  829. jack_port_id_t myport = (jack_port_id_t)port;
  830. if (!CheckPort(myport)) {
  831. jack_error("jack_port_unlock called with an incorrect port %ld", myport);
  832. return -1;
  833. } else {
  834. return (myport && client->PortIsMine(myport)) ? GetGraphManager()->GetPort(myport)->Unlock() : -1;
  835. }
  836. }
  837. EXPORT jack_nframes_t jack_port_get_total_latency(jack_client_t* ext_client, jack_port_t* port)
  838. {
  839. #ifdef __CLIENTDEBUG__
  840. JackLibGlobals::CheckContext();
  841. #endif
  842. JackClient* client = (JackClient*)ext_client;
  843. if (client == NULL) {
  844. jack_error("jack_port_get_total_latency called with a NULL client");
  845. return 0;
  846. }
  847. jack_port_id_t myport = (jack_port_id_t)port;
  848. if (!CheckPort(myport)) {
  849. jack_error("jack_port_get_total_latency called with an incorrect port %ld", myport);
  850. return 0;
  851. } else {
  852. // The latency computation is done each time
  853. WaitGraphChange();
  854. return GetGraphManager()->GetTotalLatency(myport);
  855. }
  856. }
  857. EXPORT int jack_connect(jack_client_t* ext_client, const char* src, const char* dst)
  858. {
  859. #ifdef __CLIENTDEBUG__
  860. JackLibGlobals::CheckContext();
  861. #endif
  862. JackClient* client = (JackClient*)ext_client;
  863. if (client == NULL) {
  864. jack_error("jack_connect called with a NULL client");
  865. return -1;
  866. } else if ((src == NULL) || (dst == NULL)) {
  867. jack_error("jack_connect called with a NULL port name");
  868. return -1;
  869. } else {
  870. return client->PortConnect(src, dst);
  871. }
  872. }
  873. EXPORT int jack_disconnect(jack_client_t* ext_client, const char* src, const char* dst)
  874. {
  875. #ifdef __CLIENTDEBUG__
  876. JackLibGlobals::CheckContext();
  877. #endif
  878. JackClient* client = (JackClient*)ext_client;
  879. if (client == NULL) {
  880. jack_error("jack_disconnect called with a NULL client");
  881. return -1;
  882. } else if ((src == NULL) || (dst == NULL)) {
  883. jack_error("jack_connect called with a NULL port name");
  884. return -1;
  885. } else {
  886. return client->PortDisconnect(src, dst);
  887. }
  888. }
  889. EXPORT int jack_port_connect(jack_client_t* ext_client, jack_port_t* src, jack_port_t* dst)
  890. {
  891. #ifdef __CLIENTDEBUG__
  892. JackLibGlobals::CheckContext();
  893. #endif
  894. JackClient* client = (JackClient*)ext_client;
  895. if (client == NULL) {
  896. jack_error("jack_port_connect called with a NULL client");
  897. return -1;
  898. }
  899. jack_port_id_t mysrc = (jack_port_id_t)src;
  900. if (!CheckPort(mysrc)) {
  901. jack_error("jack_port_connect called with a NULL src port");
  902. return -1;
  903. }
  904. jack_port_id_t mydst = (jack_port_id_t)dst;
  905. if (!CheckPort(mydst)) {
  906. jack_error("jack_port_connect called with a NULL dst port");
  907. return -1;
  908. }
  909. return client->PortConnect(mysrc, mydst);
  910. }
  911. EXPORT int jack_port_disconnect(jack_client_t* ext_client, jack_port_t* src)
  912. {
  913. #ifdef __CLIENTDEBUG__
  914. JackLibGlobals::CheckContext();
  915. #endif
  916. JackClient* client = (JackClient*)ext_client;
  917. if (client == NULL) {
  918. jack_error("jack_port_disconnect called with a NULL client");
  919. return -1;
  920. }
  921. jack_port_id_t myport = (jack_port_id_t)src;
  922. if (!CheckPort(myport)) {
  923. jack_error("jack_port_disconnect called with an incorrect port %ld", myport);
  924. return -1;
  925. }
  926. return client->PortDisconnect(myport);
  927. }
  928. EXPORT jack_nframes_t jack_get_sample_rate(jack_client_t* ext_client)
  929. {
  930. #ifdef __CLIENTDEBUG__
  931. JackLibGlobals::CheckContext();
  932. #endif
  933. JackClient* client = (JackClient*)ext_client;
  934. if (client == NULL) {
  935. jack_error("jack_get_sample_rate called with a NULL client");
  936. return 0;
  937. } else {
  938. return GetEngineControl()->fSampleRate;
  939. }
  940. }
  941. EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t* ext_client)
  942. {
  943. #ifdef __CLIENTDEBUG__
  944. JackLibGlobals::CheckContext();
  945. #endif
  946. JackClient* client = (JackClient*)ext_client;
  947. if (client == NULL) {
  948. jack_error("jack_get_buffer_size called with a NULL client");
  949. return 0;
  950. } else {
  951. return GetEngineControl()->fBufferSize;
  952. }
  953. }
  954. EXPORT const char** jack_get_ports(jack_client_t* ext_client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags)
  955. {
  956. #ifdef __CLIENTDEBUG__
  957. JackLibGlobals::CheckContext();
  958. #endif
  959. JackClient* client = (JackClient*)ext_client;
  960. if (client == NULL) {
  961. jack_error("jack_get_ports called with a NULL client");
  962. return NULL;
  963. }
  964. return GetGraphManager()->GetPorts(port_name_pattern, type_name_pattern, flags);
  965. }
  966. EXPORT jack_port_t* jack_port_by_name(jack_client_t* ext_client, const char* portname)
  967. {
  968. #ifdef __CLIENTDEBUG__
  969. JackLibGlobals::CheckContext();
  970. #endif
  971. JackClient* client = (JackClient*)ext_client;
  972. if (client == NULL) {
  973. jack_error("jack_get_ports called with a NULL client");
  974. return 0;
  975. }
  976. if (portname == NULL) {
  977. jack_error("jack_port_by_name called with a NULL port name");
  978. return NULL;
  979. } else {
  980. int res = GetGraphManager()->GetPort(portname); // returns a port index at least > 1
  981. return (res == NO_PORT) ? NULL : (jack_port_t*)res;
  982. }
  983. }
  984. EXPORT jack_port_t* jack_port_by_id(jack_client_t* ext_client, jack_port_id_t id)
  985. {
  986. #ifdef __CLIENTDEBUG__
  987. JackLibGlobals::CheckContext();
  988. #endif
  989. /* jack_port_t* type is actually the port index */
  990. return (jack_port_t*)id;
  991. }
  992. EXPORT int jack_engine_takeover_timebase(jack_client_t* ext_client)
  993. {
  994. #ifdef __CLIENTDEBUG__
  995. JackLibGlobals::CheckContext();
  996. #endif
  997. JackClient* client = (JackClient*)ext_client;
  998. if (client == NULL) {
  999. jack_error("jack_engine_takeover_timebase called with a NULL client");
  1000. return -1;
  1001. } else {
  1002. jack_error("jack_engine_takeover_timebase: deprecated\n");
  1003. return 0;
  1004. }
  1005. }
  1006. EXPORT jack_nframes_t jack_frames_since_cycle_start(const jack_client_t* ext_client)
  1007. {
  1008. #ifdef __CLIENTDEBUG__
  1009. JackLibGlobals::CheckContext();
  1010. #endif
  1011. JackTimer timer;
  1012. GetEngineControl()->ReadFrameTime(&timer);
  1013. return (jack_nframes_t) floor((((float)GetEngineControl()->fSampleRate) / 1000000.0f) * (GetMicroSeconds() - timer.fCurrentCallback));
  1014. }
  1015. EXPORT jack_time_t jack_get_time(jack_client_t *client)
  1016. {
  1017. return GetMicroSeconds();
  1018. }
  1019. EXPORT jack_time_t jack_frames_to_time(const jack_client_t* ext_client, jack_nframes_t frames)
  1020. {
  1021. #ifdef __CLIENTDEBUG__
  1022. JackLibGlobals::CheckContext();
  1023. #endif
  1024. JackClient* client = (JackClient*)ext_client;
  1025. if (client == NULL) {
  1026. jack_error("jack_frames_to_time called with a NULL client");
  1027. return 0;
  1028. } else {
  1029. JackTimer timer;
  1030. GetEngineControl()->ReadFrameTime(&timer);
  1031. if (timer.fInitialized) {
  1032. return timer.fCurrentWakeup +
  1033. (long) rint(((double) ((frames - timer.fFrames)) *
  1034. ((jack_time_t)(timer.fNextWakeUp - timer.fCurrentWakeup))) / GetEngineControl()->fBufferSize);
  1035. } else {
  1036. return 0;
  1037. }
  1038. }
  1039. }
  1040. EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t* ext_client, jack_time_t time)
  1041. {
  1042. #ifdef __CLIENTDEBUG__
  1043. JackLibGlobals::CheckContext();
  1044. #endif
  1045. JackClient* client = (JackClient*)ext_client;
  1046. if (client == NULL) {
  1047. jack_error("jack_time_to_frames called with a NULL client");
  1048. return 0;
  1049. } else {
  1050. JackTimer timer;
  1051. GetEngineControl()->ReadFrameTime(&timer);
  1052. if (timer.fInitialized) {
  1053. return timer.fFrames +
  1054. (long) rint(((double) ((time - timer.fCurrentWakeup)) /
  1055. ((jack_time_t)(timer.fNextWakeUp - timer.fCurrentWakeup))) * GetEngineControl()->fBufferSize);
  1056. } else {
  1057. return 0;
  1058. }
  1059. }
  1060. }
  1061. EXPORT jack_nframes_t jack_frame_time(const jack_client_t* ext_client)
  1062. {
  1063. return jack_time_to_frames(ext_client, GetMicroSeconds());
  1064. }
  1065. EXPORT jack_nframes_t jack_last_frame_time(const jack_client_t* ext_client)
  1066. {
  1067. #ifdef __CLIENTDEBUG__
  1068. JackLibGlobals::CheckContext();
  1069. #endif
  1070. JackTimer timer;
  1071. GetEngineControl()->ReadFrameTime(&timer);
  1072. return timer.fFrames;
  1073. }
  1074. EXPORT float jack_cpu_load(jack_client_t* ext_client)
  1075. {
  1076. #ifdef __CLIENTDEBUG__
  1077. JackLibGlobals::CheckContext();
  1078. #endif
  1079. JackClient* client = (JackClient*)ext_client;
  1080. if (client == NULL) {
  1081. jack_error("jack_cpu_load called with a NULL client");
  1082. return 0.0f;
  1083. } else {
  1084. return GetEngineControl()->fCPULoad;
  1085. }
  1086. }
  1087. EXPORT pthread_t jack_client_thread_id(jack_client_t* ext_client)
  1088. {
  1089. #ifdef __CLIENTDEBUG__
  1090. JackLibGlobals::CheckContext();
  1091. #endif
  1092. JackClient* client = (JackClient*)ext_client;
  1093. if (client == NULL) {
  1094. jack_error("jack_client_thread_id called with a NULL client");
  1095. return (pthread_t)NULL;
  1096. } else {
  1097. return client->GetThreadID();
  1098. }
  1099. }
  1100. EXPORT char* jack_get_client_name (jack_client_t* ext_client)
  1101. {
  1102. #ifdef __CLIENTDEBUG__
  1103. JackLibGlobals::CheckContext();
  1104. #endif
  1105. JackClient* client = (JackClient*)ext_client;
  1106. if (client == NULL) {
  1107. jack_error("jack_get_client_name called with a NULL client");
  1108. return NULL;
  1109. } else {
  1110. return client->GetClientControl()->fName;
  1111. }
  1112. }
  1113. EXPORT int jack_client_name_size(void)
  1114. {
  1115. return JACK_CLIENT_NAME_SIZE;
  1116. }
  1117. EXPORT int jack_port_name_size(void)
  1118. {
  1119. return JACK_PORT_NAME_SIZE;
  1120. }
  1121. EXPORT int jack_port_type_size(void)
  1122. {
  1123. return JACK_PORT_TYPE_SIZE;
  1124. }
  1125. // transport.h
  1126. EXPORT int jack_release_timebase(jack_client_t* ext_client)
  1127. {
  1128. #ifdef __CLIENTDEBUG__
  1129. JackLibGlobals::CheckContext();
  1130. #endif
  1131. JackClient* client = (JackClient*)ext_client;
  1132. if (client == NULL) {
  1133. jack_error("jack_release_timebase called with a NULL client");
  1134. return -1;
  1135. } else {
  1136. return client->ReleaseTimebase();
  1137. }
  1138. }
  1139. EXPORT int jack_set_sync_callback(jack_client_t* ext_client, JackSyncCallback sync_callback, void *arg)
  1140. {
  1141. #ifdef __CLIENTDEBUG__
  1142. JackLibGlobals::CheckContext();
  1143. #endif
  1144. JackClient* client = (JackClient*)ext_client;
  1145. if (client == NULL) {
  1146. jack_error("jack_set_sync_callback called with a NULL client");
  1147. return -1;
  1148. } else {
  1149. return client->SetSyncCallback(sync_callback, arg);
  1150. }
  1151. }
  1152. EXPORT int jack_set_sync_timeout(jack_client_t* ext_client, jack_time_t timeout)
  1153. {
  1154. #ifdef __CLIENTDEBUG__
  1155. JackLibGlobals::CheckContext();
  1156. #endif
  1157. JackClient* client = (JackClient*)ext_client;
  1158. if (client == NULL) {
  1159. jack_error("jack_set_sync_timeout called with a NULL client");
  1160. return -1;
  1161. } else {
  1162. return client->SetSyncTimeout(timeout);
  1163. }
  1164. }
  1165. EXPORT int jack_set_timebase_callback(jack_client_t* ext_client, int conditional, JackTimebaseCallback timebase_callback, void* arg)
  1166. {
  1167. #ifdef __CLIENTDEBUG__
  1168. JackLibGlobals::CheckContext();
  1169. #endif
  1170. JackClient* client = (JackClient*)ext_client;
  1171. if (client == NULL) {
  1172. jack_error("jack_set_timebase_callback called with a NULL client");
  1173. return -1;
  1174. } else {
  1175. return client->SetTimebaseCallback(conditional, timebase_callback, arg);
  1176. }
  1177. }
  1178. EXPORT int jack_transport_locate(jack_client_t* ext_client, jack_nframes_t frame)
  1179. {
  1180. #ifdef __CLIENTDEBUG__
  1181. JackLibGlobals::CheckContext();
  1182. #endif
  1183. JackClient* client = (JackClient*)ext_client;
  1184. if (client == NULL) {
  1185. jack_error("jack_transport_locate called with a NULL client");
  1186. return -1;
  1187. } else {
  1188. return client->TransportLocate(frame);
  1189. }
  1190. }
  1191. EXPORT jack_transport_state_t jack_transport_query(const jack_client_t* ext_client, jack_position_t* pos)
  1192. {
  1193. #ifdef __CLIENTDEBUG__
  1194. JackLibGlobals::CheckContext();
  1195. #endif
  1196. JackClient* client = (JackClient*)ext_client;
  1197. if (client == NULL) {
  1198. jack_error("jack_transport_query called with a NULL client");
  1199. return JackTransportStopped;
  1200. } else {
  1201. return client->TransportQuery(pos);
  1202. }
  1203. }
  1204. EXPORT jack_nframes_t jack_get_current_transport_frame(const jack_client_t* ext_client)
  1205. {
  1206. #ifdef __CLIENTDEBUG__
  1207. JackLibGlobals::CheckContext();
  1208. #endif
  1209. JackClient* client = (JackClient*)ext_client;
  1210. if (client == NULL) {
  1211. jack_error("jack_get_current_transport_frame called with a NULL client");
  1212. return 0;
  1213. } else {
  1214. return client->GetCurrentTransportFrame();
  1215. }
  1216. }
  1217. EXPORT int jack_transport_reposition(jack_client_t* ext_client, jack_position_t* pos)
  1218. {
  1219. #ifdef __CLIENTDEBUG__
  1220. JackLibGlobals::CheckContext();
  1221. #endif
  1222. JackClient* client = (JackClient*)ext_client;
  1223. if (client == NULL) {
  1224. jack_error("jack_transport_reposition called with a NULL client");
  1225. return -1;
  1226. } else {
  1227. return client->TransportReposition(pos);
  1228. }
  1229. }
  1230. EXPORT void jack_transport_start(jack_client_t* ext_client)
  1231. {
  1232. #ifdef __CLIENTDEBUG__
  1233. JackLibGlobals::CheckContext();
  1234. #endif
  1235. JackClient* client = (JackClient*)ext_client;
  1236. if (client == NULL) {
  1237. jack_error("jack_transport_start called with a NULL client");
  1238. } else {
  1239. client->TransportStart();
  1240. }
  1241. }
  1242. EXPORT void jack_transport_stop(jack_client_t* ext_client)
  1243. {
  1244. #ifdef __CLIENTDEBUG__
  1245. JackLibGlobals::CheckContext();
  1246. #endif
  1247. JackClient* client = (JackClient*)ext_client;
  1248. if (client == NULL) {
  1249. jack_error("jack_transport_stop called with a NULL client");
  1250. } else {
  1251. client->TransportStop();
  1252. }
  1253. }
  1254. // deprecated
  1255. EXPORT void jack_get_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
  1256. {
  1257. jack_error("jack_get_transport_info: deprecated");
  1258. if (tinfo)
  1259. memset(tinfo, 0, sizeof(jack_transport_info_t));
  1260. }
  1261. EXPORT void jack_set_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
  1262. {
  1263. jack_error("jack_set_transport_info: deprecated");
  1264. if (tinfo)
  1265. memset(tinfo, 0, sizeof(jack_transport_info_t));
  1266. }
  1267. // statistics.h
  1268. EXPORT float jack_get_max_delayed_usecs(jack_client_t* ext_client)
  1269. {
  1270. #ifdef __CLIENTDEBUG__
  1271. JackLibGlobals::CheckContext();
  1272. #endif
  1273. JackLog("jack_get_max_delayed_usecs: not yet implemented\n");
  1274. return 0.f;
  1275. }
  1276. EXPORT float jack_get_xrun_delayed_usecs(jack_client_t* ext_client)
  1277. {
  1278. #ifdef __CLIENTDEBUG__
  1279. JackLibGlobals::CheckContext();
  1280. #endif
  1281. JackLog("jack_get_xrun_delayed_usecs: not yet implemented\n");
  1282. return 0.f;
  1283. }
  1284. EXPORT void jack_reset_max_delayed_usecs(jack_client_t* ext_client)
  1285. {
  1286. #ifdef __CLIENTDEBUG__
  1287. JackLibGlobals::CheckContext();
  1288. #endif
  1289. JackLog("jack_reset_max_delayed_usecs: not yet implemented\n");
  1290. }
  1291. // thread.h
  1292. EXPORT int jack_acquire_real_time_scheduling(pthread_t thread, int priority)
  1293. {
  1294. #ifdef __APPLE__
  1295. return JackMachThread::AcquireRealTimeImp(thread, GetEngineControl()->fPeriod, GetEngineControl()->fComputation, GetEngineControl()->fConstraint);
  1296. #elif WIN32
  1297. return JackWinThread::AcquireRealTimeImp(thread, priority);
  1298. #else
  1299. return JackPosixThread::AcquireRealTimeImp(thread, priority);
  1300. #endif
  1301. }
  1302. EXPORT int jack_client_create_thread(jack_client_t* client,
  1303. pthread_t *thread,
  1304. int priority,
  1305. int realtime, /* boolean */
  1306. void *(*start_routine)(void*),
  1307. void *arg)
  1308. {
  1309. #ifdef __APPLE__
  1310. return JackPosixThread::StartImp(thread, priority, realtime, start_routine, arg);
  1311. #elif WIN32
  1312. return JackWinThread::StartImp(thread, priority, realtime, (ThreadCallback)start_routine, arg);
  1313. #else
  1314. return JackPosixThread::StartImp(thread, priority, realtime, start_routine, arg);
  1315. #endif
  1316. }
  1317. EXPORT int jack_drop_real_time_scheduling(pthread_t thread)
  1318. {
  1319. #ifdef __APPLE__
  1320. return JackMachThread::DropRealTimeImp(thread);
  1321. #elif WIN32
  1322. return JackWinThread::DropRealTimeImp(thread);
  1323. #else
  1324. return JackPosixThread::DropRealTimeImp(thread);
  1325. #endif
  1326. }
  1327. // intclient.h
  1328. EXPORT int jack_internal_client_new (const char *client_name,
  1329. const char *load_name,
  1330. const char *load_init)
  1331. {
  1332. jack_error("jack_internal_client_new: deprecated");
  1333. return -1;
  1334. }
  1335. EXPORT void jack_internal_client_close (const char *client_name)
  1336. {
  1337. jack_error("jack_internal_client_close: deprecated");
  1338. }
  1339. EXPORT char* jack_get_internal_client_name(jack_client_t* ext_client, jack_intclient_t intclient)
  1340. {
  1341. #ifdef __CLIENTDEBUG__
  1342. JackLibGlobals::CheckContext();
  1343. #endif
  1344. JackClient* client = (JackClient*)ext_client;
  1345. if (client == NULL) {
  1346. jack_error("jack_get_internal_client_name called with a NULL client");
  1347. return NULL;
  1348. } else if (intclient < 0 || intclient >= CLIENT_NUM) {
  1349. jack_error("jack_get_internal_client_name: incorrect client");
  1350. return NULL;
  1351. } else {
  1352. return client->GetInternalClientName(intclient);
  1353. }
  1354. }
  1355. EXPORT jack_intclient_t jack_internal_client_handle(jack_client_t* ext_client, const char* client_name, jack_status_t* status)
  1356. {
  1357. #ifdef __CLIENTDEBUG__
  1358. JackLibGlobals::CheckContext();
  1359. #endif
  1360. JackClient* client = (JackClient*)ext_client;
  1361. if (client == NULL) {
  1362. jack_error("jack_internal_client_handle called with a NULL client");
  1363. return 0;
  1364. } else {
  1365. jack_status_t my_status;
  1366. if (status == NULL) /* no status from caller? */
  1367. status = &my_status; /* use local status word */
  1368. *status = (jack_status_t)0;
  1369. return client->InternalClientHandle(client_name, status);
  1370. }
  1371. }
  1372. EXPORT jack_intclient_t jack_internal_client_load(jack_client_t* ext_client, const char* client_name, jack_options_t options, jack_status_t* status, ...)
  1373. {
  1374. #ifdef __CLIENTDEBUG__
  1375. JackLibGlobals::CheckContext();
  1376. #endif
  1377. JackClient* client = (JackClient*)ext_client;
  1378. if (client == NULL) {
  1379. jack_error("jack_internal_client_load called with a NULL client");
  1380. return 0;
  1381. } else {
  1382. va_list ap;
  1383. jack_varargs_t va;
  1384. jack_status_t my_status;
  1385. if (status == NULL) /* no status from caller? */
  1386. status = &my_status; /* use local status word */
  1387. *status = (jack_status_t)0;
  1388. /* validate parameters */
  1389. if ((options & ~JackLoadOptions)) {
  1390. int my_status1 = *status | (JackFailure | JackInvalidOption);
  1391. *status = (jack_status_t)my_status1;
  1392. return 0;
  1393. }
  1394. /* parse variable arguments */
  1395. va_start(ap, status);
  1396. jack_varargs_parse(options, ap, &va);
  1397. va_end(ap);
  1398. return client->InternalClientLoad(client_name, options, status, &va);
  1399. }
  1400. }
  1401. EXPORT jack_status_t jack_internal_client_unload(jack_client_t* ext_client, jack_intclient_t intclient)
  1402. {
  1403. #ifdef __CLIENTDEBUG__
  1404. JackLibGlobals::CheckContext();
  1405. #endif
  1406. JackClient* client = (JackClient*)ext_client;
  1407. if (client == NULL) {
  1408. jack_error("jack_internal_client_unload called with a NULL client");
  1409. return (jack_status_t)(JackNoSuchClient | JackFailure);
  1410. } else if (intclient < 0 || intclient >= CLIENT_NUM) {
  1411. jack_error("jack_internal_client_unload: incorrect client");
  1412. return (jack_status_t)(JackNoSuchClient | JackFailure);
  1413. } else {
  1414. jack_status_t my_status;
  1415. client->InternalClientUnload(intclient, &my_status);
  1416. return my_status;
  1417. }
  1418. }