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.

319 lines
9.0KB

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