Collection of tools useful for audio production
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.

342 lines
9.9KB

  1. /*
  2. * Carla common OSC code
  3. * Copyright (C) 2012 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * 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 COPYING file
  16. */
  17. #ifndef CARLA_OSC_INCLUDES_H
  18. #define CARLA_OSC_INCLUDES_H
  19. #include "carla_includes.h"
  20. #include <cstdint>
  21. #include <cstdlib>
  22. #include <cstring>
  23. #include <lo/lo.h>
  24. struct CarlaOscData {
  25. const char* path;
  26. lo_address source;
  27. lo_address target;
  28. CarlaOscData()
  29. : path(nullptr),
  30. source(nullptr),
  31. target(nullptr) {}
  32. };
  33. static inline
  34. void osc_clear_data(CarlaOscData* const oscData)
  35. {
  36. CARLA_ASSERT(oscData);
  37. qDebug("osc_clear_data(path:\"%s\")", oscData->path);
  38. if (oscData->path)
  39. free((void*)oscData->path);
  40. if (oscData->source)
  41. lo_address_free(oscData->source);
  42. if (oscData->target)
  43. lo_address_free(oscData->target);
  44. oscData->path = nullptr;
  45. oscData->source = nullptr;
  46. oscData->target = nullptr;
  47. }
  48. static inline
  49. void osc_send_configure(const CarlaOscData* const oscData, const char* const key, const char* const value)
  50. {
  51. CARLA_ASSERT(oscData && oscData->path);
  52. CARLA_ASSERT(key);
  53. CARLA_ASSERT(value);
  54. qDebug("osc_send_configure(path:\"%s\", \"%s\", \"%s\")", oscData->path, key, value);
  55. if (oscData->target)
  56. {
  57. char targetPath[strlen(oscData->path)+11];
  58. strcpy(targetPath, oscData->path);
  59. strcat(targetPath, "/configure");
  60. lo_send(oscData->target, targetPath, "ss", key, value);
  61. }
  62. }
  63. static inline
  64. void osc_send_control(const CarlaOscData* const oscData, const int32_t index, const float value)
  65. {
  66. CARLA_ASSERT(oscData && oscData->path);
  67. CARLA_ASSERT(index != -1);
  68. qDebug("osc_send_control(path:\"%s\", %i, %f)", oscData->path, index, value);
  69. if (oscData->target)
  70. {
  71. char targetPath[strlen(oscData->path)+9];
  72. strcpy(targetPath, oscData->path);
  73. strcat(targetPath, "/control");
  74. lo_send(oscData->target, targetPath, "if", index, value);
  75. }
  76. }
  77. static inline
  78. void osc_send_program(const CarlaOscData* const oscData, const int32_t index)
  79. {
  80. CARLA_ASSERT(oscData && oscData->path);
  81. CARLA_ASSERT(index >= 0);
  82. qDebug("osc_send_program(path:\"%s\", %i)", oscData->path, index);
  83. if (oscData->target)
  84. {
  85. char targetPath[strlen(oscData->path)+9];
  86. strcpy(targetPath, oscData->path);
  87. strcat(targetPath, "/program");
  88. lo_send(oscData->target, targetPath, "i", index);
  89. }
  90. }
  91. static inline
  92. void osc_send_program(const CarlaOscData* const oscData, const int32_t bank, const int32_t program)
  93. {
  94. CARLA_ASSERT(oscData && oscData->path);
  95. CARLA_ASSERT(program >= 0 && program < 128);
  96. CARLA_ASSERT(bank >= 0);
  97. qDebug("osc_send_program(path:\"%s\", %i, %i)", oscData->path, bank, program);
  98. if (oscData->target)
  99. {
  100. char targetPath[strlen(oscData->path)+9];
  101. strcpy(targetPath, oscData->path);
  102. strcat(targetPath, "/program");
  103. lo_send(oscData->target, targetPath, "ii", bank, program);
  104. }
  105. }
  106. static inline
  107. void osc_send_midi_program(const CarlaOscData* const oscData, const int32_t index)
  108. {
  109. CARLA_ASSERT(oscData && oscData->path);
  110. CARLA_ASSERT(index >= 0);
  111. qDebug("osc_send_midi_program(path:\"%s\", %i)", oscData->path, index);
  112. if (oscData->target)
  113. {
  114. char targetPath[strlen(oscData->path)+14];
  115. strcpy(targetPath, oscData->path);
  116. strcat(targetPath, "/midi_program");
  117. lo_send(oscData->target, targetPath, "i", index);
  118. }
  119. }
  120. static inline
  121. void osc_send_midi_program(const CarlaOscData* const oscData, const int32_t bank, const int32_t program)
  122. {
  123. CARLA_ASSERT(oscData && oscData->path);
  124. CARLA_ASSERT(program >= 0 && program < 128);
  125. CARLA_ASSERT(bank >= 0);
  126. qDebug("osc_send_midi_program(path:\"%s\", %i, %i)", oscData->path, bank, program);
  127. if (oscData->target)
  128. {
  129. char targetPath[strlen(oscData->path)+14];
  130. strcpy(targetPath, oscData->path);
  131. strcat(targetPath, "/midi_program");
  132. lo_send(oscData->target, targetPath, "ii", bank, program);
  133. }
  134. }
  135. static inline
  136. void osc_send_midi(const CarlaOscData* const oscData, const uint8_t buf[4])
  137. {
  138. CARLA_ASSERT(oscData && oscData->path);
  139. CARLA_ASSERT(buf[0] == 0);
  140. CARLA_ASSERT(buf[1] != 0);
  141. qDebug("osc_send_midi(path:\"%s\", 0x%X, %03u, %03u)", oscData->path, buf[1], buf[2], buf[3]);
  142. if (oscData->target)
  143. {
  144. char targetPath[strlen(oscData->path)+6];
  145. strcpy(targetPath, oscData->path);
  146. strcat(targetPath, "/midi");
  147. lo_send(oscData->target, targetPath, "m", buf);
  148. }
  149. }
  150. static inline
  151. void osc_send_sample_rate(const CarlaOscData* const oscData, const float sampleRate)
  152. {
  153. CARLA_ASSERT(oscData && oscData->path);
  154. CARLA_ASSERT(sampleRate > 0.0f);
  155. qDebug("osc_send_sample_rate(path:\"%s\", %f)", oscData->path, sampleRate);
  156. if (oscData->target)
  157. {
  158. char targetPath[strlen(oscData->path)+12];
  159. strcpy(targetPath, oscData->path);
  160. strcat(targetPath, "/sample_rate");
  161. lo_send(oscData->target, targetPath, "f", sampleRate);
  162. }
  163. }
  164. #ifdef BUILD_BRIDGE
  165. static inline
  166. void osc_send_update(const CarlaOscData* const oscData, const char* const url)
  167. {
  168. CARLA_ASSERT(oscData && oscData->path);
  169. CARLA_ASSERT(url);
  170. qDebug("osc_send_update(path:\"%s\", \"%s\")", oscData->path, url);
  171. if (oscData->target)
  172. {
  173. char targetPath[strlen(oscData->path)+8];
  174. strcpy(targetPath, oscData->path);
  175. strcat(targetPath, "/update");
  176. lo_send(oscData->target, targetPath, "s", url);
  177. }
  178. }
  179. static inline
  180. void osc_send_exiting(const CarlaOscData* const oscData)
  181. {
  182. CARLA_ASSERT(oscData && oscData->path);
  183. qDebug("osc_send_exiting(path:\"%s\")", oscData->path);
  184. if (oscData->target)
  185. {
  186. char targetPath[strlen(oscData->path)+9];
  187. strcpy(targetPath, oscData->path);
  188. strcat(targetPath, "/exiting");
  189. lo_send(oscData->target, targetPath, "");
  190. }
  191. }
  192. #else
  193. static inline
  194. void osc_send_show(const CarlaOscData* const oscData)
  195. {
  196. CARLA_ASSERT(oscData && oscData->path);
  197. qDebug("osc_send_show(path:\"%s\")", oscData->path);
  198. if (oscData->target)
  199. {
  200. char targetPath[strlen(oscData->path)+6];
  201. strcpy(targetPath, oscData->path);
  202. strcat(targetPath, "/show");
  203. lo_send(oscData->target, targetPath, "");
  204. }
  205. }
  206. static inline
  207. void osc_send_hide(const CarlaOscData* const oscData)
  208. {
  209. CARLA_ASSERT(oscData && oscData->path);
  210. qDebug("osc_send_hide(path:\"%s\")", oscData->path);
  211. if (oscData->target)
  212. {
  213. char targetPath[strlen(oscData->path)+6];
  214. strcpy(targetPath, oscData->path);
  215. strcat(targetPath, "/hide");
  216. lo_send(oscData->target, targetPath, "");
  217. }
  218. }
  219. static inline
  220. void osc_send_quit(const CarlaOscData* const oscData)
  221. {
  222. CARLA_ASSERT(oscData && oscData->path);
  223. qDebug("osc_send_quit(path:\"%s\")", oscData->path);
  224. if (oscData->target)
  225. {
  226. char targetPath[strlen(oscData->path)+6];
  227. strcpy(targetPath, oscData->path);
  228. strcat(targetPath, "/quit");
  229. lo_send(oscData->target, targetPath, "");
  230. }
  231. }
  232. #endif
  233. #ifdef BUILD_BRIDGE_PLUGIN
  234. static inline
  235. void osc_send_bridge_update(const CarlaOscData* const oscData, const char* const url)
  236. {
  237. CARLA_ASSERT(oscData && oscData->path);
  238. CARLA_ASSERT(url);
  239. qDebug("osc_send_bridge_update(path:\"%s\", \"%s\")", oscData->path, url);
  240. if (oscData->target)
  241. {
  242. char targetPath[strlen(oscData->path)+15];
  243. strcpy(targetPath, oscData->path);
  244. strcat(targetPath, "/bridge_update");
  245. lo_send(oscData->target, targetPath, "s", url);
  246. }
  247. }
  248. static inline
  249. void osc_send_bridge_error(const CarlaOscData* const oscData, const char* const error)
  250. {
  251. CARLA_ASSERT(oscData && oscData->path);
  252. CARLA_ASSERT(error);
  253. qDebug("osc_send_bridge_error(path:\"%s\", \"%s\")", oscData->path, error);
  254. if (oscData->target)
  255. {
  256. char targetPath[strlen(oscData->path)+14];
  257. strcpy(targetPath, oscData->path);
  258. strcat(targetPath, "/bridge_error");
  259. lo_send(oscData->target, targetPath, "s", error);
  260. }
  261. }
  262. #endif
  263. static inline
  264. void osc_send_lv2_transfer_atom(const CarlaOscData* const oscData, const int32_t portIndex, const char* const typeStr, const char* const atomBuf)
  265. {
  266. CARLA_ASSERT(oscData && oscData->path);
  267. CARLA_ASSERT(portIndex >= 0);
  268. CARLA_ASSERT(typeStr);
  269. CARLA_ASSERT(atomBuf);
  270. qDebug("osc_send_lv2_transfer_atom(path:\"%s\", %i, \"%s\", \"%s\")", oscData->path, portIndex, typeStr, atomBuf);
  271. if (oscData->target)
  272. {
  273. char targetPath[strlen(oscData->path)+19];
  274. strcpy(targetPath, oscData->path);
  275. strcat(targetPath, "/lv2_atom_transfer");
  276. lo_send(oscData->target, targetPath, "iss", portIndex, typeStr, atomBuf);
  277. }
  278. }
  279. static inline
  280. void osc_send_lv2_transfer_event(const CarlaOscData* const oscData, const int32_t portIndex, const char* const typeStr, const char* const atomBuf)
  281. {
  282. CARLA_ASSERT(oscData && oscData->path);
  283. CARLA_ASSERT(portIndex >= 0);
  284. CARLA_ASSERT(typeStr);
  285. CARLA_ASSERT(atomBuf);
  286. qDebug("osc_send_lv2_transfer_event(path:\"%s\", %i, \"%s\", \"%s\")", oscData->path, portIndex, typeStr, atomBuf);
  287. if (oscData->target)
  288. {
  289. char targetPath[strlen(oscData->path)+20];
  290. strcpy(targetPath, oscData->path);
  291. strcat(targetPath, "/lv2_event_transfer");
  292. lo_send(oscData->target, targetPath, "iss", portIndex, typeStr, atomBuf);
  293. }
  294. }
  295. #endif // CARLA_OSC_INCLUDES_H