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.

249 lines
6.7KB

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