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.

170 lines
7.3KB

  1. /*
  2. * Carla Engine OSC
  3. * Copyright (C) 2012-2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * 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 COPYING file
  16. */
  17. #ifndef __CARLA_ENGINE_OSC_HPP__
  18. #define __CARLA_ENGINE_OSC_HPP__
  19. #include "carla_backend.hpp"
  20. #include "carla_osc_utils.hpp"
  21. #define CARLA_ENGINE_OSC_HANDLE_ARGS1 CarlaPlugin* const plugin
  22. #define CARLA_ENGINE_OSC_HANDLE_ARGS2 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. qCritical("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 && typesToCompare)) \
  34. { \
  35. qCritical("CarlaEngineOsc::%s() - argument types are null", __FUNCTION__); \
  36. return 1; \
  37. } \
  38. /* check argument types */ \
  39. if (strcmp(types, typesToCompare) != 0) \
  40. { \
  41. qCritical("CarlaEngineOsc::%s() - argument types mismatch: '%s' != '%s'", __FUNCTION__, types, typesToCompare); \
  42. return 1; \
  43. } \
  44. }
  45. CARLA_BACKEND_START_NAMESPACE
  46. #if 0
  47. } // Fix editor indentation
  48. #endif
  49. class CarlaEngineOsc
  50. {
  51. public:
  52. CarlaEngineOsc(CarlaEngine* const engine);
  53. ~CarlaEngineOsc();
  54. void init(const char* const name);
  55. void idle();
  56. void close();
  57. // -------------------------------------------------------------------
  58. #ifndef BUILD_BRIDGE
  59. bool isControlRegistered() const
  60. {
  61. return bool(m_controlData.target);
  62. }
  63. const CarlaOscData* getControlData() const
  64. {
  65. return &m_controlData;
  66. }
  67. #endif
  68. const char* getServerPathTCP() const
  69. {
  70. return (const char*)m_serverPathTCP;
  71. }
  72. const char* getServerPathUDP() const
  73. {
  74. return (const char*)m_serverPathUDP;
  75. }
  76. // -------------------------------------------------------------------
  77. private:
  78. CarlaEngine* const engine;
  79. char* m_name;
  80. size_t m_nameSize;
  81. lo_server m_serverTCP;
  82. lo_server m_serverUDP;
  83. CarlaString m_serverPathTCP;
  84. CarlaString m_serverPathUDP;
  85. #ifndef BUILD_BRIDGE
  86. CarlaOscData m_controlData; // for carla-control
  87. #endif
  88. // -------------------------------------------------------------------
  89. int handleMessage(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 int argc, const lo_arg* const* const argv, const char* const types, const lo_address source);
  92. int handleMsgUnregister();
  93. #endif
  94. int handleMsgUpdate(CARLA_ENGINE_OSC_HANDLE_ARGS2, const lo_address source);
  95. int handleMsgConfigure(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  96. int handleMsgControl(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  97. int handleMsgProgram(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  98. int handleMsgMidi(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  99. int handleMsgExiting(CARLA_ENGINE_OSC_HANDLE_ARGS1);
  100. #ifndef BUILD_BRIDGE
  101. int handleMsgSetActive(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  102. int handleMsgSetDryWet(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  103. int handleMsgSetVolume(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  104. int handleMsgSetBalanceLeft(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  105. int handleMsgSetBalanceRight(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  106. int handleMsgSetParameterValue(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  107. int handleMsgSetParameterMidiCC(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  108. int handleMsgSetParameterMidiChannel(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  109. int handleMsgSetProgram(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  110. int handleMsgSetMidiProgram(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  111. int handleMsgNoteOn(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  112. int handleMsgNoteOff(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  113. int handleMsgBridgeSetInPeak(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  114. int handleMsgBridgeSetOutPeak(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  115. #endif
  116. #ifdef WANT_LV2
  117. int handleMsgLv2AtomTransfer(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  118. int handleMsgLv2EventTransfer(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  119. #endif
  120. // -----------------------------------------------------------------------
  121. static void osc_error_handlerTCP(const int num, const char* const msg, const char* const path)
  122. {
  123. qWarning("CarlaEngineOsc::osc_error_handlerTCP(%i, \"%s\", \"%s\")", num, msg, path);
  124. }
  125. static void osc_error_handlerUDP(const int num, const char* const msg, const char* const path)
  126. {
  127. qWarning("CarlaEngineOsc::osc_error_handlerUDP(%i, \"%s\", \"%s\")", num, msg, path);
  128. }
  129. static int osc_message_handler(const char* const path, const char* const types, lo_arg** const argv, const int argc, const lo_message msg, void* const userData)
  130. {
  131. CARLA_ASSERT(userData);
  132. if (CarlaEngineOsc* const _this_ = (CarlaEngineOsc*)userData)
  133. return _this_->handleMessage(path, argc, argv, types, msg);
  134. return 1;
  135. }
  136. };
  137. CARLA_BACKEND_END_NAMESPACE
  138. #endif // __CARLA_ENGINE_OSC_HPP__