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.

185 lines
8.6KB

  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 char* getServerPathTCP() const noexcept
  59. {
  60. return fServerPathTCP;
  61. }
  62. const char* 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 sendPluginInit(const uint pluginId, const char* const pluginName) const noexcept;
  81. void sendPluginInfo(const CarlaPlugin* const plugin) const noexcept;
  82. void sendPluginPortCount(const CarlaPlugin* const plugin) const noexcept;
  83. void sendPluginParameterInfo(const CarlaPlugin* const plugin, const uint32_t parameterId) const noexcept;
  84. void sendPluginInternalParameterValues(const CarlaPlugin* const plugin) const noexcept;
  85. void sendPing() const noexcept;
  86. void sendExit() const noexcept;
  87. // -------------------------------------------------------------------
  88. // UDP
  89. void sendRuntimeInfo() const noexcept;
  90. void sendParameterValue(const uint pluginId, const uint32_t index, const float value) const noexcept;
  91. void sendPeaks(const uint pluginId, const float peaks[4]) const noexcept;
  92. // -------------------------------------------------------------------
  93. private:
  94. CarlaEngine* const fEngine;
  95. // for carla-control
  96. CarlaOscData fControlDataTCP;
  97. CarlaOscData fControlDataUDP;
  98. CarlaString fName;
  99. CarlaString fServerPathTCP;
  100. CarlaString fServerPathUDP;
  101. lo_server fServerTCP;
  102. lo_server fServerUDP;
  103. // -------------------------------------------------------------------
  104. int handleMessage(const bool isTCP, const char* const path,
  105. const int argc, const lo_arg* const* const argv, const char* const types, const lo_message msg);
  106. int handleMsgRegister(const bool isTCP, const int argc, const lo_arg* const* const argv, const char* const types);
  107. int handleMsgUnregister(const bool isTCP, const int argc, const lo_arg* const* const argv, const char* const types);
  108. int handleMsgControl(const char* const method,
  109. const int argc, const lo_arg* const* const argv, const char* const types);
  110. // Internal methods
  111. int handleMsgSetActive(CARLA_ENGINE_OSC_HANDLE_ARGS);
  112. int handleMsgSetDryWet(CARLA_ENGINE_OSC_HANDLE_ARGS);
  113. int handleMsgSetVolume(CARLA_ENGINE_OSC_HANDLE_ARGS);
  114. int handleMsgSetBalanceLeft(CARLA_ENGINE_OSC_HANDLE_ARGS);
  115. int handleMsgSetBalanceRight(CARLA_ENGINE_OSC_HANDLE_ARGS);
  116. int handleMsgSetPanning(CARLA_ENGINE_OSC_HANDLE_ARGS);
  117. int handleMsgSetParameterValue(CARLA_ENGINE_OSC_HANDLE_ARGS);
  118. int handleMsgSetParameterMidiCC(CARLA_ENGINE_OSC_HANDLE_ARGS);
  119. int handleMsgSetParameterMidiChannel(CARLA_ENGINE_OSC_HANDLE_ARGS);
  120. int handleMsgSetProgram(CARLA_ENGINE_OSC_HANDLE_ARGS);
  121. int handleMsgSetMidiProgram(CARLA_ENGINE_OSC_HANDLE_ARGS);
  122. int handleMsgNoteOn(CARLA_ENGINE_OSC_HANDLE_ARGS);
  123. int handleMsgNoteOff(CARLA_ENGINE_OSC_HANDLE_ARGS);
  124. // -----------------------------------------------------------------------
  125. static void osc_error_handler_TCP(int num, const char* msg, const char* path)
  126. {
  127. carla_stderr("CarlaEngineOsc::osc_error_handler_TCP(%i, \"%s\", \"%s\")", num, msg, path);
  128. }
  129. static void osc_error_handler_UDP(int num, const char* msg, const char* path)
  130. {
  131. carla_stderr("CarlaEngineOsc::osc_error_handler_UDP(%i, \"%s\", \"%s\")", num, msg, path);
  132. }
  133. static int osc_message_handler_TCP(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* userData)
  134. {
  135. return ((CarlaEngineOsc*)userData)->handleMessage(true, path, argc, argv, types, msg);
  136. }
  137. static int osc_message_handler_UDP(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* userData)
  138. {
  139. return ((CarlaEngineOsc*)userData)->handleMessage(false, path, argc, argv, types, msg);
  140. }
  141. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineOsc)
  142. };
  143. // -----------------------------------------------------------------------
  144. CARLA_BACKEND_END_NAMESPACE
  145. #endif // HAVE_LIBLO
  146. #endif // CARLA_ENGINE_OSC_HPP_INCLUDED