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 7.7KB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 "CarlaMutex.hpp"
  22. #include "CarlaString.hpp"
  23. #define CARLA_ENGINE_OSC_HANDLE_ARGS1 CarlaPlugin* const plugin
  24. #define CARLA_ENGINE_OSC_HANDLE_ARGS2 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. #if 0
  49. } // Fix editor indentation
  50. #endif
  51. class CarlaEngineOsc
  52. {
  53. public:
  54. CarlaEngineOsc(CarlaEngine* const engine);
  55. ~CarlaEngineOsc();
  56. void init(const char* const name);
  57. void close();
  58. // -------------------------------------------------------------------
  59. const char* getServerPathTCP() const noexcept
  60. {
  61. return fServerPathTCP.getBuffer();
  62. }
  63. const char* getServerPathUDP() const noexcept
  64. {
  65. return fServerPathUDP.getBuffer();
  66. }
  67. // -------------------------------------------------------------------
  68. #ifndef BUILD_BRIDGE
  69. bool isControlRegistered() const noexcept
  70. {
  71. return (fControlData.target != nullptr);
  72. }
  73. const CarlaOscData* getControlData() const noexcept
  74. {
  75. return &fControlData;
  76. }
  77. #endif
  78. // -------------------------------------------------------------------
  79. private:
  80. CarlaEngine* const fEngine;
  81. CarlaString fName;
  82. CarlaString fServerPathTCP;
  83. CarlaString fServerPathUDP;
  84. lo_server_thread fServerTCP;
  85. lo_server_thread fServerUDP;
  86. #ifndef BUILD_BRIDGE
  87. CarlaOscData fControlData; // for carla-control
  88. CarlaCriticalSection _cs;
  89. #endif
  90. // -------------------------------------------------------------------
  91. 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);
  92. #ifndef BUILD_BRIDGE
  93. int handleMsgRegister(const bool isTCP, const int argc, const lo_arg* const* const argv, const char* const types, const lo_address source);
  94. int handleMsgUnregister();
  95. #endif
  96. int handleMsgUpdate(CARLA_ENGINE_OSC_HANDLE_ARGS2, const lo_address source);
  97. int handleMsgConfigure(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  98. int handleMsgControl(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  99. int handleMsgProgram(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  100. int handleMsgMidi(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  101. int handleMsgExiting(CARLA_ENGINE_OSC_HANDLE_ARGS1);
  102. #ifndef BUILD_BRIDGE
  103. int handleMsgSetActive(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  104. int handleMsgSetDryWet(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  105. int handleMsgSetVolume(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  106. int handleMsgSetBalanceLeft(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  107. int handleMsgSetBalanceRight(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  108. int handleMsgSetPanning(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  109. int handleMsgSetParameterValue(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  110. int handleMsgSetParameterMidiCC(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  111. int handleMsgSetParameterMidiChannel(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  112. int handleMsgSetProgram(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  113. int handleMsgSetMidiProgram(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  114. int handleMsgNoteOn(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  115. int handleMsgNoteOff(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  116. #endif
  117. #ifdef WANT_LV2
  118. int handleMsgLv2AtomTransfer(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  119. int handleMsgLv2UridMap(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  120. #endif
  121. // -----------------------------------------------------------------------
  122. static void osc_error_handler_TCP(int num, const char* msg, const char* path)
  123. {
  124. carla_stderr("CarlaEngineOsc::osc_error_handler_TCP(%i, \"%s\", \"%s\")", num, msg, path);
  125. }
  126. static void osc_error_handler_UDP(int num, const char* msg, const char* path)
  127. {
  128. carla_stderr("CarlaEngineOsc::osc_error_handler_UDP(%i, \"%s\", \"%s\")", num, msg, path);
  129. }
  130. static int osc_message_handler_TCP(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* userData)
  131. {
  132. return ((CarlaEngineOsc*)userData)->handleMessage(true, path, argc, argv, types, msg);
  133. }
  134. static int osc_message_handler_UDP(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* userData)
  135. {
  136. return ((CarlaEngineOsc*)userData)->handleMessage(false, path, argc, argv, types, msg);
  137. }
  138. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineOsc)
  139. };
  140. CARLA_BACKEND_END_NAMESPACE
  141. #endif // CARLA_ENGINE_OSC_HPP_INCLUDED