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.

1744 lines
56KB

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