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.

160 lines
7.2KB

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