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.

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