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.

2143 lines
73KB

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