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.

190 lines
9.1KB

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