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.

283 lines
7.8KB

  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 >= 0);
  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);
  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(const CarlaOscData* const oscData, const uint8_t buf[4])
  118. {
  119. Q_ASSERT(oscData && oscData->path);
  120. Q_ASSERT(buf[0] == 0);
  121. Q_ASSERT(buf[1] != 0);
  122. qDebug("osc_send_midi(path:\"%s\", 0x%X, %03u, %03u)", oscData->path, buf[1], buf[2], buf[3]);
  123. if (oscData->target)
  124. {
  125. char targetPath[strlen(oscData->path)+6];
  126. strcpy(targetPath, oscData->path);
  127. strcat(targetPath, "/midi");
  128. lo_send(oscData->target, targetPath, "m", buf);
  129. }
  130. }
  131. static inline
  132. void osc_send_sample_rate(const CarlaOscData* const oscData, const float sampleRate)
  133. {
  134. Q_ASSERT(oscData && oscData->path);
  135. Q_ASSERT(sampleRate >= 0.0f);
  136. qDebug("osc_send_sample_rate(path:\"%s\", %f)", oscData->path, sampleRate);
  137. if (oscData->target)
  138. {
  139. char targetPath[strlen(oscData->path)+12];
  140. strcpy(targetPath, oscData->path);
  141. strcat(targetPath, "/sample_rate");
  142. lo_send(oscData->target, targetPath, "f", sampleRate);
  143. }
  144. }
  145. #ifdef BUILD_BRIDGE
  146. static inline
  147. void osc_send_update(const CarlaOscData* const oscData, const char* const url)
  148. {
  149. Q_ASSERT(oscData && oscData->path);
  150. Q_ASSERT(url);
  151. qDebug("osc_send_update(path:\"%s\", \"%s\")", oscData->path, url);
  152. if (oscData->target)
  153. {
  154. char targetPath[strlen(oscData->path)+8];
  155. strcpy(targetPath, oscData->path);
  156. strcat(targetPath, "/update");
  157. lo_send(oscData->target, targetPath, "s", url);
  158. }
  159. }
  160. static inline
  161. void osc_send_exiting(const CarlaOscData* const oscData)
  162. {
  163. Q_ASSERT(oscData && oscData->path);
  164. qDebug("osc_send_exiting(path:\"%s\")", oscData->path);
  165. if (oscData->target)
  166. {
  167. char targetPath[strlen(oscData->path)+9];
  168. strcpy(targetPath, oscData->path);
  169. strcat(targetPath, "/exiting");
  170. lo_send(oscData->target, targetPath, "");
  171. }
  172. }
  173. #else
  174. static inline
  175. void osc_send_show(const CarlaOscData* const oscData)
  176. {
  177. Q_ASSERT(oscData && oscData->path);
  178. qDebug("osc_send_show(path:\"%s\")", oscData->path);
  179. if (oscData->target)
  180. {
  181. char targetPath[strlen(oscData->path)+6];
  182. strcpy(targetPath, oscData->path);
  183. strcat(targetPath, "/show");
  184. lo_send(oscData->target, targetPath, "");
  185. }
  186. }
  187. static inline
  188. void osc_send_hide(const CarlaOscData* const oscData)
  189. {
  190. Q_ASSERT(oscData && oscData->path);
  191. qDebug("osc_send_hide(path:\"%s\")", oscData->path);
  192. if (oscData->target)
  193. {
  194. char targetPath[strlen(oscData->path)+6];
  195. strcpy(targetPath, oscData->path);
  196. strcat(targetPath, "/hide");
  197. lo_send(oscData->target, targetPath, "");
  198. }
  199. }
  200. static inline
  201. void osc_send_quit(const CarlaOscData* const oscData)
  202. {
  203. Q_ASSERT(oscData && oscData->path);
  204. qDebug("osc_send_quit(path:\"%s\")", oscData->path);
  205. if (oscData->target)
  206. {
  207. char targetPath[strlen(oscData->path)+6];
  208. strcpy(targetPath, oscData->path);
  209. strcat(targetPath, "/quit");
  210. lo_send(oscData->target, targetPath, "");
  211. }
  212. }
  213. #endif
  214. static inline
  215. void osc_send_lv2_atom_transfer(const CarlaOscData* const oscData /* TODO */)
  216. {
  217. Q_ASSERT(oscData && oscData->path);
  218. qDebug("osc_send_lv2_atom_transfer(path:\"%s\")", oscData->path);
  219. if (oscData->target)
  220. {
  221. char targetPath[strlen(oscData->path)+19];
  222. strcpy(targetPath, oscData->path);
  223. strcat(targetPath, "/lv2_atom_transfer");
  224. lo_send(oscData->target, targetPath, "");
  225. }
  226. }
  227. static inline
  228. void osc_send_lv2_event_transfer(const CarlaOscData* const oscData, const char* const type, const char* const key, const char* const value)
  229. {
  230. Q_ASSERT(oscData && oscData->path);
  231. Q_ASSERT(type);
  232. Q_ASSERT(key);
  233. Q_ASSERT(value);
  234. qDebug("osc_send_lv2_event_transfer(path:\"%s\", \"%s\", \"%s\", \"%s\")", oscData->path, type, key, value);
  235. if (oscData->target)
  236. {
  237. char targetPath[strlen(oscData->path)+20];
  238. strcpy(targetPath, oscData->path);
  239. strcat(targetPath, "/lv2_event_transfer");
  240. lo_send(oscData->target, targetPath, "sss", type, key, value);
  241. }
  242. }
  243. #endif // CARLA_OSC_INCLUDES_H