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.

266 lines
7.3KB

  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 <cstring>
  22. #include <lo/lo.h>
  23. struct CarlaOscData {
  24. const char* path;
  25. lo_address source;
  26. lo_address target;
  27. };
  28. static inline
  29. void osc_clear_data(CarlaOscData* const oscData)
  30. {
  31. Q_ASSERT(oscData);
  32. qDebug("osc_clear_data(path:\"%s\")", oscData->path);
  33. if (oscData->path)
  34. free((void*)oscData->path);
  35. if (oscData->source)
  36. lo_address_free(oscData->source);
  37. if (oscData->target)
  38. lo_address_free(oscData->target);
  39. oscData->path = nullptr;
  40. oscData->source = nullptr;
  41. oscData->target = nullptr;
  42. }
  43. static inline
  44. void osc_send_configure(const CarlaOscData* const oscData, const char* const key, const char* const value)
  45. {
  46. Q_ASSERT(oscData && oscData->path);
  47. Q_ASSERT(key);
  48. Q_ASSERT(value);
  49. qDebug("osc_send_configure(path:\"%s\", \"%s\", \"%s\")", oscData->path, key, value);
  50. if (oscData->target)
  51. {
  52. char targetPath[strlen(oscData->path)+11];
  53. strcpy(targetPath, oscData->path);
  54. strcat(targetPath, "/configure");
  55. lo_send(oscData->target, targetPath, "ss", key, value);
  56. }
  57. }
  58. static inline
  59. void osc_send_control(const CarlaOscData* const oscData, const int32_t index, const float value)
  60. {
  61. Q_ASSERT(oscData && oscData->path);
  62. Q_ASSERT(index >= 0);
  63. qDebug("osc_send_control(path:\"%s\", %i, %f)", oscData->path, index, value);
  64. if (oscData->target)
  65. {
  66. char targetPath[strlen(oscData->path)+9];
  67. strcpy(targetPath, oscData->path);
  68. strcat(targetPath, "/control");
  69. lo_send(oscData->target, targetPath, "if", index, value);
  70. }
  71. }
  72. static inline
  73. void osc_send_program(const CarlaOscData* const oscData, const int32_t index)
  74. {
  75. Q_ASSERT(oscData && oscData->path);
  76. Q_ASSERT(index >= 0);
  77. qDebug("osc_send_program(path:\"%s\", %i)", oscData->path, index);
  78. if (oscData->target)
  79. {
  80. char targetPath[strlen(oscData->path)+9];
  81. strcpy(targetPath, oscData->path);
  82. strcat(targetPath, "/program");
  83. lo_send(oscData->target, targetPath, "i", index);
  84. }
  85. }
  86. static inline
  87. void osc_send_program(const CarlaOscData* const oscData, const int32_t bank, const int32_t program)
  88. {
  89. Q_ASSERT(oscData && oscData->path);
  90. Q_ASSERT(program >= 0);
  91. Q_ASSERT(bank >= 0);
  92. qDebug("osc_send_program(path:\"%s\", %i, %i)", oscData->path, bank, program);
  93. if (oscData->target)
  94. {
  95. char targetPath[strlen(oscData->path)+9];
  96. strcpy(targetPath, oscData->path);
  97. strcat(targetPath, "/program");
  98. lo_send(oscData->target, targetPath, "ii", bank, program);
  99. }
  100. }
  101. static inline
  102. void osc_send_midi_program(const CarlaOscData* const oscData, const int32_t index)
  103. {
  104. Q_ASSERT(oscData && oscData->path);
  105. Q_ASSERT(index >= 0);
  106. qDebug("osc_send_midi_program(path:\"%s\", %i)", oscData->path, index);
  107. if (oscData->target)
  108. {
  109. char targetPath[strlen(oscData->path)+14];
  110. strcpy(targetPath, oscData->path);
  111. strcat(targetPath, "/midi_program");
  112. lo_send(oscData->target, targetPath, "i", index);
  113. }
  114. }
  115. static inline
  116. void osc_send_midi(const CarlaOscData* const oscData, const uint8_t buf[4])
  117. {
  118. Q_ASSERT(oscData && oscData->path);
  119. Q_ASSERT(buf[0] == 0);
  120. Q_ASSERT(buf[1] != 0);
  121. qDebug("osc_send_midi(path:\"%s\", 0x%X, %03u, %03u)", oscData->path, buf[1], buf[2], buf[3]);
  122. if (oscData->target)
  123. {
  124. char targetPath[strlen(oscData->path)+6];
  125. strcpy(targetPath, oscData->path);
  126. strcat(targetPath, "/midi");
  127. lo_send(oscData->target, targetPath, "m", buf);
  128. }
  129. }
  130. #ifdef BUILD_BRIDGE
  131. static inline
  132. void osc_send_update(const CarlaOscData* const oscData, const char* const url)
  133. {
  134. Q_ASSERT(oscData && oscData->path);
  135. Q_ASSERT(url);
  136. qDebug("osc_send_update(path:\"%s\", \"%s\")", oscData->path, url);
  137. if (oscData->target)
  138. {
  139. char targetPath[strlen(oscData->path)+8];
  140. strcpy(targetPath, oscData->path);
  141. strcat(targetPath, "/update");
  142. lo_send(oscData->target, targetPath, "s", url);
  143. }
  144. }
  145. static inline
  146. void osc_send_exiting(const CarlaOscData* const oscData)
  147. {
  148. Q_ASSERT(oscData && oscData->path);
  149. qDebug("osc_send_exiting(path:\"%s\")", oscData->path);
  150. if (oscData->target)
  151. {
  152. char targetPath[strlen(oscData->path)+9];
  153. strcpy(targetPath, oscData->path);
  154. strcat(targetPath, "/exiting");
  155. lo_send(oscData->target, targetPath, "");
  156. }
  157. }
  158. #else
  159. static inline
  160. void osc_send_show(const CarlaOscData* const oscData)
  161. {
  162. Q_ASSERT(oscData && oscData->path);
  163. qDebug("osc_send_show(path:\"%s\")", oscData->path);
  164. if (oscData->target)
  165. {
  166. char targetPath[strlen(oscData->path)+6];
  167. strcpy(targetPath, oscData->path);
  168. strcat(targetPath, "/show");
  169. lo_send(oscData->target, targetPath, "");
  170. }
  171. }
  172. static inline
  173. void osc_send_hide(const CarlaOscData* const oscData)
  174. {
  175. Q_ASSERT(oscData && oscData->path);
  176. qDebug("osc_send_hide(path:\"%s\")", oscData->path);
  177. if (oscData->target)
  178. {
  179. char targetPath[strlen(oscData->path)+6];
  180. strcpy(targetPath, oscData->path);
  181. strcat(targetPath, "/hide");
  182. lo_send(oscData->target, targetPath, "");
  183. }
  184. }
  185. static inline
  186. void osc_send_quit(const CarlaOscData* const oscData)
  187. {
  188. Q_ASSERT(oscData && oscData->path);
  189. qDebug("osc_send_quit(path:\"%s\")", oscData->path);
  190. if (oscData->target)
  191. {
  192. char targetPath[strlen(oscData->path)+6];
  193. strcpy(targetPath, oscData->path);
  194. strcat(targetPath, "/quit");
  195. lo_send(oscData->target, targetPath, "");
  196. }
  197. }
  198. #endif
  199. static inline
  200. void osc_send_lv2_atom_transfer(const CarlaOscData* const oscData /* TODO */)
  201. {
  202. Q_ASSERT(oscData && oscData->path);
  203. qDebug("osc_send_lv2_atom_transfer(path:\"%s\")", oscData->path);
  204. if (oscData->target)
  205. {
  206. char targetPath[strlen(oscData->path)+19];
  207. strcpy(targetPath, oscData->path);
  208. strcat(targetPath, "/lv2_atom_transfer");
  209. lo_send(oscData->target, targetPath, "");
  210. }
  211. }
  212. static inline
  213. void osc_send_lv2_event_transfer(const CarlaOscData* const oscData, const char* const type, const char* const key, const char* const value)
  214. {
  215. Q_ASSERT(oscData && oscData->path);
  216. Q_ASSERT(type);
  217. Q_ASSERT(key);
  218. Q_ASSERT(value);
  219. qDebug("osc_send_lv2_event_transfer(path:\"%s\", \"%s\", \"%s\", \"%s\")", oscData->path, type, key, value);
  220. if (oscData->target)
  221. {
  222. char targetPath[strlen(oscData->path)+20];
  223. strcpy(targetPath, oscData->path);
  224. strcat(targetPath, "/lv2_event_transfer");
  225. lo_send(oscData->target, targetPath, "sss", type, key, value);
  226. }
  227. }
  228. #endif // CARLA_OSC_INCLUDES_H