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.

CarlaEngineOsc.hpp 9.0KB

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