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.3KB

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