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.

1774 lines
57KB

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