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.

171 lines
7.7KB

  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2014 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 "CarlaBackend.h"
  20. #include "CarlaOscUtils.hpp"
  21. #include "CarlaString.hpp"
  22. #define CARLA_ENGINE_OSC_HANDLE_ARGS1 CarlaPlugin* const plugin
  23. #define CARLA_ENGINE_OSC_HANDLE_ARGS2 CarlaPlugin* const plugin, const int argc, const lo_arg* const* const argv, const char* const types
  24. #define CARLA_ENGINE_OSC_CHECK_OSC_TYPES(/* argc, types, */ argcToCompare, typesToCompare) \
  25. /* check argument count */ \
  26. if (argc != argcToCompare) \
  27. { \
  28. carla_stderr("CarlaEngineOsc::%s() - argument count mismatch: %i != %i", __FUNCTION__, argc, argcToCompare); \
  29. return 1; \
  30. } \
  31. if (argc > 0) \
  32. { \
  33. /* check for nullness */ \
  34. if (types == nullptr || typesToCompare == nullptr) \
  35. { \
  36. carla_stderr("CarlaEngineOsc::%s() - argument types are null", __FUNCTION__); \
  37. return 1; \
  38. } \
  39. /* check argument types */ \
  40. if (std::strcmp(types, typesToCompare) != 0) \
  41. { \
  42. carla_stderr("CarlaEngineOsc::%s() - argument types mismatch: '%s' != '%s'", __FUNCTION__, types, typesToCompare); \
  43. return 1; \
  44. } \
  45. }
  46. CARLA_BACKEND_START_NAMESPACE
  47. // -----------------------------------------------------------------------
  48. class CarlaEngineOsc
  49. {
  50. public:
  51. CarlaEngineOsc(CarlaEngine* const engine) noexcept;
  52. ~CarlaEngineOsc() noexcept;
  53. void init(const char* const name) noexcept;
  54. void idle() const noexcept;
  55. void close() noexcept;
  56. // -------------------------------------------------------------------
  57. const char* getServerPathTCP() const noexcept
  58. {
  59. return fServerPathTCP;
  60. }
  61. const char* getServerPathUDP() const noexcept
  62. {
  63. return fServerPathUDP;
  64. }
  65. #ifndef BUILD_BRIDGE
  66. // -------------------------------------------------------------------
  67. bool isControlRegistered() const noexcept
  68. {
  69. return (fControlData.target != nullptr);
  70. }
  71. const CarlaOscData* getControlData() const noexcept
  72. {
  73. return &fControlData;
  74. }
  75. #endif
  76. // -------------------------------------------------------------------
  77. private:
  78. CarlaEngine* const fEngine;
  79. #ifndef BUILD_BRIDGE
  80. CarlaOscData fControlData; // for carla-control
  81. #endif
  82. CarlaString fName;
  83. CarlaString fServerPathTCP;
  84. CarlaString fServerPathUDP;
  85. lo_server fServerTCP;
  86. lo_server fServerUDP;
  87. // -------------------------------------------------------------------
  88. int handleMessage(const bool isTCP, const char* const path, const int argc, const lo_arg* const* const argv, const char* const types, const lo_message msg);
  89. int handleMsgUpdate(CARLA_ENGINE_OSC_HANDLE_ARGS2, const lo_address source);
  90. int handleMsgExiting(CARLA_ENGINE_OSC_HANDLE_ARGS1);
  91. #ifndef BUILD_BRIDGE
  92. int handleMsgRegister(const bool isTCP, const int argc, const lo_arg* const* const argv, const char* const types, const lo_address source);
  93. int handleMsgUnregister();
  94. int handleMsgConfigure(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  95. int handleMsgControl(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  96. int handleMsgProgram(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  97. int handleMsgMidi(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  98. int handleMsgSetActive(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  99. int handleMsgSetDryWet(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  100. int handleMsgSetVolume(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  101. int handleMsgSetBalanceLeft(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  102. int handleMsgSetBalanceRight(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  103. int handleMsgSetPanning(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  104. int handleMsgSetParameterValue(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  105. int handleMsgSetParameterMidiCC(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  106. int handleMsgSetParameterMidiChannel(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  107. int handleMsgSetProgram(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  108. int handleMsgSetMidiProgram(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  109. int handleMsgNoteOn(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  110. int handleMsgNoteOff(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  111. int handleMsgLv2AtomTransfer(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  112. int handleMsgLv2UridMap(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  113. #endif
  114. // -----------------------------------------------------------------------
  115. static void osc_error_handler_TCP(int num, const char* msg, const char* path)
  116. {
  117. carla_stderr("CarlaEngineOsc::osc_error_handler_TCP(%i, \"%s\", \"%s\")", num, msg, path);
  118. }
  119. static void osc_error_handler_UDP(int num, const char* msg, const char* path)
  120. {
  121. carla_stderr("CarlaEngineOsc::osc_error_handler_UDP(%i, \"%s\", \"%s\")", num, msg, path);
  122. }
  123. static int osc_message_handler_TCP(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* userData)
  124. {
  125. return ((CarlaEngineOsc*)userData)->handleMessage(true, path, argc, argv, types, msg);
  126. }
  127. static int osc_message_handler_UDP(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* userData)
  128. {
  129. return ((CarlaEngineOsc*)userData)->handleMessage(false, path, argc, argv, types, msg);
  130. }
  131. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineOsc)
  132. };
  133. // -----------------------------------------------------------------------
  134. CARLA_BACKEND_END_NAMESPACE
  135. #endif // CARLA_ENGINE_OSC_HPP_INCLUDED