Audio plugin host https://kx.studio/carla
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.

192 lines
8.9KB

  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2019 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or 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 doc/GPL.txt file.
  16. */
  17. #ifndef CARLA_ENGINE_OSC_HPP_INCLUDED
  18. #define CARLA_ENGINE_OSC_HPP_INCLUDED
  19. #include "CarlaDefines.h"
  20. #ifdef HAVE_LIBLO
  21. #include "CarlaBackend.h"
  22. #include "CarlaJuceUtils.hpp"
  23. #include "CarlaOscUtils.hpp"
  24. #include "CarlaString.hpp"
  25. #define CARLA_ENGINE_OSC_HANDLE_ARGS CarlaPlugin* const plugin, const int argc, const lo_arg* const* const argv, const char* const types
  26. #define CARLA_ENGINE_OSC_CHECK_OSC_TYPES(/* argc, types, */ argcToCompare, typesToCompare) \
  27. /* check argument count */ \
  28. if (argc != argcToCompare) \
  29. { \
  30. carla_stderr("CarlaEngineOsc::%s() - argument count mismatch: %i != %i", __FUNCTION__, argc, argcToCompare); \
  31. return 1; \
  32. } \
  33. if (argc > 0) \
  34. { \
  35. /* check for nullness */ \
  36. if (types == nullptr || typesToCompare == nullptr) \
  37. { \
  38. carla_stderr("CarlaEngineOsc::%s() - argument types are null", __FUNCTION__); \
  39. return 1; \
  40. } \
  41. /* check argument types */ \
  42. if (std::strcmp(types, typesToCompare) != 0) \
  43. { \
  44. carla_stderr("CarlaEngineOsc::%s() - argument types mismatch: '%s' != '%s'", __FUNCTION__, types, typesToCompare); \
  45. return 1; \
  46. } \
  47. }
  48. CARLA_BACKEND_START_NAMESPACE
  49. // -----------------------------------------------------------------------
  50. class CarlaEngineOsc
  51. {
  52. public:
  53. CarlaEngineOsc(CarlaEngine* engine) noexcept;
  54. ~CarlaEngineOsc() noexcept;
  55. void init(const char* name, int tcpPort, int udpPort) noexcept;
  56. void idle() const noexcept;
  57. void close() noexcept;
  58. // -------------------------------------------------------------------
  59. const CarlaString& getServerPathTCP() const noexcept
  60. {
  61. return fServerPathTCP;
  62. }
  63. const CarlaString& getServerPathUDP() const noexcept
  64. {
  65. return fServerPathUDP;
  66. }
  67. // -------------------------------------------------------------------
  68. bool isControlRegisteredForTCP() const noexcept
  69. {
  70. return fControlDataTCP.target != nullptr;
  71. }
  72. bool isControlRegisteredForUDP() const noexcept
  73. {
  74. return fControlDataUDP.target != nullptr;
  75. }
  76. // -------------------------------------------------------------------
  77. // TCP
  78. void sendCallback(EngineCallbackOpcode action, uint pluginId,
  79. int value1, int value2, int value3,
  80. float valuef, const char* valueStr) const noexcept;
  81. void sendPluginInfo(const CarlaPlugin* plugin) const noexcept;
  82. void sendPluginPortCount(const CarlaPlugin* plugin) const noexcept;
  83. void sendPluginParameterInfo(const CarlaPlugin* plugin, uint32_t index) const noexcept;
  84. void sendPluginDataCount(const CarlaPlugin* plugin) const noexcept;
  85. void sendPluginProgramCount(const CarlaPlugin* plugin) const noexcept;
  86. void sendPluginProgram(const CarlaPlugin* plugin, uint32_t index) const noexcept;
  87. void sendPluginMidiProgram(const CarlaPlugin* plugin, uint32_t index) const noexcept;
  88. void sendPluginCustomData(const CarlaPlugin* plugin, uint32_t index) const noexcept;
  89. void sendPluginInternalParameterValues(const CarlaPlugin* plugin) const noexcept;
  90. void sendPing() const noexcept;
  91. void sendResponse(int messageId, const char* error) const noexcept;
  92. void sendExit() const noexcept;
  93. // -------------------------------------------------------------------
  94. // UDP
  95. void sendRuntimeInfo() const noexcept;
  96. void sendParameterValue(uint pluginId, uint32_t index, float value) const noexcept;
  97. void sendPeaks(uint pluginId, const float peaks[4]) const noexcept;
  98. // -------------------------------------------------------------------
  99. private:
  100. CarlaEngine* const fEngine;
  101. // for carla-control
  102. CarlaOscData fControlDataTCP;
  103. CarlaOscData fControlDataUDP;
  104. CarlaString fName;
  105. CarlaString fServerPathTCP;
  106. CarlaString fServerPathUDP;
  107. lo_server fServerTCP;
  108. lo_server fServerUDP;
  109. // -------------------------------------------------------------------
  110. int handleMessage(bool isTCP, const char* path,
  111. int argc, const lo_arg* const* argv, const char* types, lo_message msg);
  112. int handleMsgRegister(bool isTCP, int argc, const lo_arg* const* argv, const char* types);
  113. int handleMsgUnregister(bool isTCP, int argc, const lo_arg* const* argv, const char* types);
  114. int handleMsgControl(const char* method,
  115. int argc, const lo_arg* const* argv, const char* types);
  116. // Internal methods
  117. int handleMsgSetActive(CARLA_ENGINE_OSC_HANDLE_ARGS);
  118. int handleMsgSetDryWet(CARLA_ENGINE_OSC_HANDLE_ARGS);
  119. int handleMsgSetVolume(CARLA_ENGINE_OSC_HANDLE_ARGS);
  120. int handleMsgSetBalanceLeft(CARLA_ENGINE_OSC_HANDLE_ARGS);
  121. int handleMsgSetBalanceRight(CARLA_ENGINE_OSC_HANDLE_ARGS);
  122. int handleMsgSetPanning(CARLA_ENGINE_OSC_HANDLE_ARGS);
  123. int handleMsgSetParameterValue(CARLA_ENGINE_OSC_HANDLE_ARGS);
  124. int handleMsgSetParameterMappedControlIndex(CARLA_ENGINE_OSC_HANDLE_ARGS);
  125. int handleMsgSetParameterMappedRange(CARLA_ENGINE_OSC_HANDLE_ARGS);
  126. int handleMsgSetParameterMidiChannel(CARLA_ENGINE_OSC_HANDLE_ARGS);
  127. int handleMsgSetProgram(CARLA_ENGINE_OSC_HANDLE_ARGS);
  128. int handleMsgSetMidiProgram(CARLA_ENGINE_OSC_HANDLE_ARGS);
  129. int handleMsgNoteOn(CARLA_ENGINE_OSC_HANDLE_ARGS);
  130. int handleMsgNoteOff(CARLA_ENGINE_OSC_HANDLE_ARGS);
  131. // -----------------------------------------------------------------------
  132. static void osc_error_handler_TCP(int num, const char* msg, const char* path)
  133. {
  134. carla_stderr("CarlaEngineOsc::osc_error_handler_TCP(%i, \"%s\", \"%s\")", num, msg, path);
  135. }
  136. static void osc_error_handler_UDP(int num, const char* msg, const char* path)
  137. {
  138. carla_stderr("CarlaEngineOsc::osc_error_handler_UDP(%i, \"%s\", \"%s\")", num, msg, path);
  139. }
  140. static int osc_message_handler_TCP(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* userData)
  141. {
  142. return ((CarlaEngineOsc*)userData)->handleMessage(true, path, argc, argv, types, msg);
  143. }
  144. static int osc_message_handler_UDP(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* userData)
  145. {
  146. return ((CarlaEngineOsc*)userData)->handleMessage(false, path, argc, argv, types, msg);
  147. }
  148. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineOsc)
  149. };
  150. // -----------------------------------------------------------------------
  151. CARLA_BACKEND_END_NAMESPACE
  152. #endif // HAVE_LIBLO
  153. #endif // CARLA_ENGINE_OSC_HPP_INCLUDED