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.

1988 lines
66KB

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