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.

158 lines
7.2KB

  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 isControlRegistered() const noexcept
  68. {
  69. return (fControlData.target != nullptr);
  70. }
  71. const CarlaOscData* getControlData() const noexcept
  72. {
  73. return &fControlData;
  74. }
  75. // -------------------------------------------------------------------
  76. private:
  77. CarlaEngine* const fEngine;
  78. CarlaOscData fControlData; // for carla-control
  79. CarlaString fName;
  80. CarlaString fServerPathTCP;
  81. CarlaString fServerPathUDP;
  82. lo_server fServerTCP;
  83. lo_server fServerUDP;
  84. // -------------------------------------------------------------------
  85. 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);
  86. int handleMsgRegister(const bool isTCP, const int argc, const lo_arg* const* const argv, const char* const types);
  87. int handleMsgUnregister();
  88. // Internal methods
  89. int handleMsgSetActive(CARLA_ENGINE_OSC_HANDLE_ARGS);
  90. int handleMsgSetDryWet(CARLA_ENGINE_OSC_HANDLE_ARGS);
  91. int handleMsgSetVolume(CARLA_ENGINE_OSC_HANDLE_ARGS);
  92. int handleMsgSetBalanceLeft(CARLA_ENGINE_OSC_HANDLE_ARGS);
  93. int handleMsgSetBalanceRight(CARLA_ENGINE_OSC_HANDLE_ARGS);
  94. int handleMsgSetPanning(CARLA_ENGINE_OSC_HANDLE_ARGS);
  95. int handleMsgSetParameterValue(CARLA_ENGINE_OSC_HANDLE_ARGS);
  96. int handleMsgSetParameterMidiCC(CARLA_ENGINE_OSC_HANDLE_ARGS);
  97. int handleMsgSetParameterMidiChannel(CARLA_ENGINE_OSC_HANDLE_ARGS);
  98. int handleMsgSetProgram(CARLA_ENGINE_OSC_HANDLE_ARGS);
  99. int handleMsgSetMidiProgram(CARLA_ENGINE_OSC_HANDLE_ARGS);
  100. int handleMsgNoteOn(CARLA_ENGINE_OSC_HANDLE_ARGS);
  101. int handleMsgNoteOff(CARLA_ENGINE_OSC_HANDLE_ARGS);
  102. // -----------------------------------------------------------------------
  103. static void osc_error_handler_TCP(int num, const char* msg, const char* path)
  104. {
  105. carla_stderr("CarlaEngineOsc::osc_error_handler_TCP(%i, \"%s\", \"%s\")", num, msg, path);
  106. }
  107. static void osc_error_handler_UDP(int num, const char* msg, const char* path)
  108. {
  109. carla_stderr("CarlaEngineOsc::osc_error_handler_UDP(%i, \"%s\", \"%s\")", num, msg, path);
  110. }
  111. static int osc_message_handler_TCP(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* userData)
  112. {
  113. return ((CarlaEngineOsc*)userData)->handleMessage(true, path, argc, argv, types, msg);
  114. }
  115. static int osc_message_handler_UDP(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* userData)
  116. {
  117. return ((CarlaEngineOsc*)userData)->handleMessage(false, path, argc, argv, types, msg);
  118. }
  119. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineOsc)
  120. };
  121. // -----------------------------------------------------------------------
  122. CARLA_BACKEND_END_NAMESPACE
  123. #endif // HAVE_LIBLO
  124. #endif // CARLA_ENGINE_OSC_HPP_INCLUDED