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.

197 lines
9.0KB

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