Audio plugin host https://kx.studio/carla
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.

375 lines
11KB

  1. /*
  2. * Carla JACK API for external applications
  3. * Copyright (C) 2016-2017 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #include "libjack.hpp"
  18. CARLA_BACKEND_USE_NAMESPACE
  19. // --------------------------------------------------------------------------------------------------------------------
  20. CARLA_EXPORT
  21. jack_port_t* jack_port_register(jack_client_t* client, const char* port_name, const char* port_type,
  22. unsigned long flags, unsigned long buffer_size)
  23. {
  24. carla_stdout("%s(%p, %s, %s, 0x%lx, %lu)", __FUNCTION__, client, port_name, port_type, flags, buffer_size);
  25. JackClientState* const jclient = (JackClientState*)client;
  26. CARLA_SAFE_ASSERT_RETURN(jclient != nullptr, nullptr);
  27. CARLA_SAFE_ASSERT_RETURN(port_name != nullptr && port_name[0] != '\0', nullptr);
  28. CARLA_SAFE_ASSERT_RETURN(port_type != nullptr && port_type[0] != '\0', nullptr);
  29. const JackServerState& jserver(jclient->server);
  30. if (std::strcmp(port_type, JACK_DEFAULT_AUDIO_TYPE) == 0)
  31. {
  32. if (flags & JackPortIsInput)
  33. {
  34. const std::size_t index = jclient->audioIns.count();
  35. JackPortState* const port = new JackPortState(jclient->name, port_name, index, flags,
  36. false, false, index < jserver.numAudioIns);
  37. const CarlaMutexLocker cms(jclient->mutex);
  38. jclient->audioIns.append(port);
  39. return (jack_port_t*)port;
  40. }
  41. if (flags & JackPortIsOutput)
  42. {
  43. const std::size_t index = jclient->audioOuts.count();
  44. JackPortState* const port = new JackPortState(jclient->name, port_name, index, flags,
  45. false, false, index < jserver.numAudioOuts);
  46. const CarlaMutexLocker cms(jclient->mutex);
  47. jclient->audioOuts.append(port);
  48. return (jack_port_t*)port;
  49. }
  50. carla_stderr2("Invalid port flags '%x'", flags);
  51. return nullptr;
  52. }
  53. if (std::strcmp(port_type, JACK_DEFAULT_MIDI_TYPE) == 0)
  54. {
  55. if (flags & JackPortIsInput)
  56. {
  57. const std::size_t index = jclient->midiIns.count();
  58. JackPortState* const port = new JackPortState(jclient->name, port_name, index, flags,
  59. true, false, index < jserver.numMidiIns);
  60. const CarlaMutexLocker cms(jclient->mutex);
  61. jclient->midiIns.append(port);
  62. return (jack_port_t*)port;
  63. }
  64. if (flags & JackPortIsOutput)
  65. {
  66. const std::size_t index = jclient->midiOuts.count();
  67. JackPortState* const port = new JackPortState(jclient->name, port_name, index, flags,
  68. true, false, index < jserver.numMidiOuts);
  69. const CarlaMutexLocker cms(jclient->mutex);
  70. jclient->midiOuts.append(port);
  71. return (jack_port_t*)port;
  72. }
  73. carla_stderr2("Invalid port flags '%x'", flags);
  74. return nullptr;
  75. }
  76. carla_stderr2("Invalid port type '%s'", port_type);
  77. return nullptr;
  78. }
  79. CARLA_EXPORT
  80. int jack_port_unregister(jack_client_t* client, jack_port_t* port)
  81. {
  82. carla_stdout("%s(%p, %p)", __FUNCTION__, client, port);
  83. JackClientState* const jclient = (JackClientState*)client;
  84. CARLA_SAFE_ASSERT_RETURN(jclient != nullptr, 1);
  85. JackPortState* const jport = (JackPortState*)port;
  86. CARLA_SAFE_ASSERT_RETURN(jport != nullptr, 1);
  87. CARLA_SAFE_ASSERT_RETURN(! jport->isSystem, 1);
  88. const CarlaMutexLocker cms(jclient->mutex);
  89. if (jport->isMidi)
  90. {
  91. if (jport->flags & JackPortIsInput)
  92. {
  93. CARLA_SAFE_ASSERT_RETURN(jclient->midiIns.removeOne(jport), 1);
  94. return 0;
  95. }
  96. if (jport->flags & JackPortIsOutput)
  97. {
  98. CARLA_SAFE_ASSERT_RETURN(jclient->midiOuts.removeOne(jport), 1);
  99. return 0;
  100. }
  101. }
  102. else
  103. {
  104. if (jport->flags & JackPortIsInput)
  105. {
  106. CARLA_SAFE_ASSERT_RETURN(jclient->audioIns.removeOne(jport), 1);
  107. return 0;
  108. }
  109. if (jport->flags & JackPortIsOutput)
  110. {
  111. CARLA_SAFE_ASSERT_RETURN(jclient->audioOuts.removeOne(jport), 1);
  112. return 0;
  113. }
  114. }
  115. carla_stderr2("Invalid port on unregister");
  116. return 1;
  117. }
  118. CARLA_EXPORT
  119. void* jack_port_get_buffer(jack_port_t* port, jack_nframes_t)
  120. {
  121. JackPortState* const jport = (JackPortState*)port;
  122. CARLA_SAFE_ASSERT_RETURN(jport != nullptr, nullptr);
  123. return jport->buffer;
  124. }
  125. // --------------------------------------------------------------------------------------------------------------------
  126. CARLA_EXPORT
  127. jack_uuid_t jack_port_uuid(const jack_port_t* port)
  128. {
  129. carla_stdout("%s(%p)", __FUNCTION__, port);
  130. return 0;
  131. }
  132. CARLA_EXPORT
  133. const char* jack_port_name(const jack_port_t* port)
  134. {
  135. carla_stdout("%s(%p)", __FUNCTION__, port);
  136. JackPortState* const jport = (JackPortState*)port;
  137. CARLA_SAFE_ASSERT_RETURN(jport != nullptr, nullptr);
  138. return jport->fullname;
  139. }
  140. CARLA_EXPORT
  141. const char* jack_port_short_name(const jack_port_t* port)
  142. {
  143. carla_stdout("%s(%p)", __FUNCTION__, port);
  144. JackPortState* const jport = (JackPortState*)port;
  145. CARLA_SAFE_ASSERT_RETURN(jport != nullptr, nullptr);
  146. return jport->name;
  147. }
  148. CARLA_EXPORT
  149. int jack_port_flags(const jack_port_t* port)
  150. {
  151. carla_stdout("%s(%p)", __FUNCTION__, port);
  152. JackPortState* const jport = (JackPortState*)port;
  153. CARLA_SAFE_ASSERT_RETURN(jport != nullptr, 0);
  154. return jport->flags;
  155. }
  156. CARLA_EXPORT
  157. const char* jack_port_type(const jack_port_t* port)
  158. {
  159. carla_stdout("%s(%p)", __FUNCTION__, port);
  160. JackPortState* const jport = (JackPortState*)port;
  161. CARLA_SAFE_ASSERT_RETURN(jport != nullptr, nullptr);
  162. static const char* const kAudioType = JACK_DEFAULT_AUDIO_TYPE;
  163. static const char* const kMidiType = JACK_DEFAULT_MIDI_TYPE;
  164. return jport->isMidi ? kMidiType : kAudioType;
  165. }
  166. CARLA_EXPORT
  167. uint32_t jack_port_type_id(const jack_port_t* port)
  168. {
  169. carla_stdout("%s(%p)", __FUNCTION__, port);
  170. JackPortState* const jport = (JackPortState*)port;
  171. CARLA_SAFE_ASSERT_RETURN(jport != nullptr, 0);
  172. return jport->isMidi ? 1 : 0;
  173. }
  174. // --------------------------------------------------------------------------------------------------------------------
  175. CARLA_EXPORT
  176. int jack_port_is_mine(const jack_client_t*, const jack_port_t* port)
  177. {
  178. JackPortState* const jport = (JackPortState*)port;
  179. CARLA_SAFE_ASSERT_RETURN(jport != nullptr, 0);
  180. return jport->isSystem ? 0 : 1;
  181. }
  182. CARLA_EXPORT
  183. int jack_port_connected(const jack_port_t* port)
  184. {
  185. JackPortState* const jport = (JackPortState*)port;
  186. CARLA_SAFE_ASSERT_RETURN(jport != nullptr, 0);
  187. return jport->isConnected ? 1 : 0;
  188. }
  189. CARLA_EXPORT
  190. int jack_port_connected_to(const jack_port_t* port, const char* port_name)
  191. {
  192. carla_stderr2("%s(%p, %s)", __FUNCTION__, port, port_name);
  193. return 1;
  194. }
  195. // --------------------------------------------------------------------------------------------------------------------
  196. CARLA_EXPORT
  197. const char** jack_port_get_connections (const jack_port_t* port)
  198. {
  199. carla_stderr2("%s(%p)", __FUNCTION__, port);
  200. return nullptr;
  201. }
  202. CARLA_EXPORT
  203. const char** jack_port_get_all_connections(const jack_client_t* client, const jack_port_t* port)
  204. {
  205. carla_stderr2("%s(%p, %p)", __FUNCTION__, client, port);
  206. return nullptr;
  207. }
  208. // --------------------------------------------------------------------------------------------------------------------
  209. CARLA_EXPORT
  210. int jack_port_tie(jack_port_t* src, jack_port_t* dst)
  211. {
  212. carla_stderr2("%s(%p, %p)", __FUNCTION__, src, dst);
  213. return ENOSYS;
  214. }
  215. CARLA_EXPORT
  216. int jack_port_untie(jack_port_t* port)
  217. {
  218. carla_stderr2("%s(%p)", __FUNCTION__, port);
  219. return ENOSYS;
  220. }
  221. // --------------------------------------------------------------------------------------------------------------------
  222. CARLA_EXPORT
  223. int jack_port_set_name(jack_port_t *port, const char *port_name)
  224. {
  225. carla_stderr2("%s(%p, %s)", __FUNCTION__, port, port_name);
  226. return ENOSYS;
  227. }
  228. CARLA_EXPORT
  229. int jack_port_rename(jack_client_t* client, jack_port_t *port, const char *port_name)
  230. {
  231. carla_stderr2("%s(%p, %p, %s)", __FUNCTION__, client, port, port_name);
  232. return ENOSYS;
  233. }
  234. CARLA_EXPORT
  235. int jack_port_set_alias(jack_port_t* port, const char* alias)
  236. {
  237. carla_stderr2("%s(%p, %s)", __FUNCTION__, port, alias);
  238. return ENOSYS;
  239. }
  240. CARLA_EXPORT
  241. int jack_port_unset_alias(jack_port_t* port, const char* alias)
  242. {
  243. carla_stderr2("%s(%p, %s)", __FUNCTION__, port, alias);
  244. return ENOSYS;
  245. }
  246. CARLA_EXPORT
  247. int jack_port_get_aliases(const jack_port_t*, char* aliases[2])
  248. {
  249. aliases[0] = aliases[1] = nullptr;
  250. return 0;
  251. }
  252. // --------------------------------------------------------------------------------------------------------------------
  253. //int jack_port_request_monitor (jack_port_t *port, int onoff) JACK_OPTIONAL_WEAK_EXPORT;
  254. //int jack_port_request_monitor_by_name (jack_client_t *client,
  255. // const char *port_name, int onoff) JACK_OPTIONAL_WEAK_EXPORT;
  256. //int jack_port_ensure_monitor (jack_port_t *port, int onoff) JACK_OPTIONAL_WEAK_EXPORT;
  257. //int jack_port_monitoring_input (jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT;
  258. // --------------------------------------------------------------------------------------------------------------------
  259. CARLA_EXPORT
  260. int jack_connect(jack_client_t* client, const char* a, const char* b)
  261. {
  262. carla_stderr2("%s(%p, %s. %s)", __FUNCTION__, client, a, b);
  263. return 0;
  264. }
  265. CARLA_EXPORT
  266. int jack_disconnect(jack_client_t* client, const char* a, const char* b)
  267. {
  268. carla_stderr2("%s(%p, %s. %s)", __FUNCTION__, client, a, b);
  269. return 0;
  270. }
  271. CARLA_EXPORT
  272. int jack_port_disconnect(jack_client_t* client, jack_port_t* port)
  273. {
  274. carla_stderr2("%s(%p, %p)", __FUNCTION__, client, port);
  275. return 0;
  276. }
  277. // --------------------------------------------------------------------------------------------------------------------
  278. CARLA_EXPORT
  279. int jack_port_name_size(void)
  280. {
  281. return STR_MAX;
  282. }
  283. // int jack_port_type_size(void) JACK_OPTIONAL_WEAK_EXPORT;
  284. //size_t jack_port_type_get_buffer_size (jack_client_t *client, const char *port_type) JACK_WEAK_EXPORT;
  285. // --------------------------------------------------------------------------------------------------------------------