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.

carla_engine_osc.hpp 7.4KB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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
  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 GPL.txt file
  16. */
  17. #ifndef __CARLA_ENGINE_OSC_HPP__
  18. #define __CARLA_ENGINE_OSC_HPP__
  19. #include "carla_backend.hpp"
  20. #include "carla_juce_utils.hpp"
  21. #include "carla_osc_utils.hpp"
  22. #define CARLA_ENGINE_OSC_HANDLE_ARGS1 CarlaPlugin* const plugin
  23. #define CARLA_ENGINE_OSC_HANDLE_ARGS2 CarlaPlugin* const plugin, const int argc, const lo_arg* const* const argv, const char* const types
  24. #define CARLA_ENGINE_OSC_CHECK_OSC_TYPES(/* argc, types, */ argcToCompare, typesToCompare) \
  25. /* check argument count */ \
  26. if (argc != argcToCompare) \
  27. { \
  28. qCritical("CarlaEngineOsc::%s() - argument count mismatch: %i != %i", __FUNCTION__, argc, argcToCompare); \
  29. return 1; \
  30. } \
  31. if (argc > 0) \
  32. { \
  33. /* check for nullness */ \
  34. if (! (types && typesToCompare)) \
  35. { \
  36. qCritical("CarlaEngineOsc::%s() - argument types are null", __FUNCTION__); \
  37. return 1; \
  38. } \
  39. /* check argument types */ \
  40. if (strcmp(types, typesToCompare) != 0) \
  41. { \
  42. qCritical("CarlaEngineOsc::%s() - argument types mismatch: '%s' != '%s'", __FUNCTION__, types, typesToCompare); \
  43. return 1; \
  44. } \
  45. }
  46. CARLA_BACKEND_START_NAMESPACE
  47. #if 0
  48. } // Fix editor indentation
  49. #endif
  50. class CarlaEngineOsc
  51. {
  52. public:
  53. CarlaEngineOsc(CarlaEngine* const engine);
  54. ~CarlaEngineOsc();
  55. void init(const char* const name);
  56. void idle();
  57. void close();
  58. // -------------------------------------------------------------------
  59. #ifndef BUILD_BRIDGE
  60. bool isControlRegistered() const
  61. {
  62. return bool(m_controlData.target);
  63. }
  64. const CarlaOscData* getControlData() const
  65. {
  66. return &m_controlData;
  67. }
  68. #endif
  69. const char* getServerPathTCP() const
  70. {
  71. return (const char*)m_serverPathTCP;
  72. }
  73. const char* getServerPathUDP() const
  74. {
  75. return (const char*)m_serverPathUDP;
  76. }
  77. // -------------------------------------------------------------------
  78. private:
  79. CarlaEngine* const engine;
  80. char* m_name;
  81. size_t m_nameSize;
  82. lo_server m_serverTCP;
  83. lo_server m_serverUDP;
  84. CarlaString m_serverPathTCP;
  85. CarlaString m_serverPathUDP;
  86. #ifndef BUILD_BRIDGE
  87. CarlaOscData m_controlData; // for carla-control
  88. #endif
  89. // -------------------------------------------------------------------
  90. int handleMessage(const char* const path, const int argc, const lo_arg* const* const argv, const char* const types, const lo_message msg);
  91. #ifndef BUILD_BRIDGE
  92. int handleMsgRegister(const int argc, const lo_arg* const* const argv, const char* const types, const lo_address source);
  93. int handleMsgUnregister();
  94. #endif
  95. int handleMsgUpdate(CARLA_ENGINE_OSC_HANDLE_ARGS2, const lo_address source);
  96. int handleMsgConfigure(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  97. int handleMsgControl(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  98. int handleMsgProgram(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  99. int handleMsgMidi(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  100. int handleMsgExiting(CARLA_ENGINE_OSC_HANDLE_ARGS1);
  101. #ifndef BUILD_BRIDGE
  102. int handleMsgSetActive(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  103. int handleMsgSetDryWet(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  104. int handleMsgSetVolume(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  105. int handleMsgSetBalanceLeft(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  106. int handleMsgSetBalanceRight(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  107. int handleMsgSetParameterValue(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  108. int handleMsgSetParameterMidiCC(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  109. int handleMsgSetParameterMidiChannel(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  110. int handleMsgSetProgram(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  111. int handleMsgSetMidiProgram(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  112. int handleMsgNoteOn(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  113. int handleMsgNoteOff(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  114. int handleMsgBridgeSetInPeak(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  115. int handleMsgBridgeSetOutPeak(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  116. #endif
  117. #ifdef WANT_LV2
  118. int handleMsgLv2AtomTransfer(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  119. int handleMsgLv2EventTransfer(CARLA_ENGINE_OSC_HANDLE_ARGS2);
  120. #endif
  121. // -----------------------------------------------------------------------
  122. static void osc_error_handlerTCP(const int num, const char* const msg, const char* const path)
  123. {
  124. qWarning("CarlaEngineOsc::osc_error_handlerTCP(%i, \"%s\", \"%s\")", num, msg, path);
  125. }
  126. static void osc_error_handlerUDP(const int num, const char* const msg, const char* const path)
  127. {
  128. qWarning("CarlaEngineOsc::osc_error_handlerUDP(%i, \"%s\", \"%s\")", num, msg, path);
  129. }
  130. 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)
  131. {
  132. CARLA_ASSERT(userData);
  133. if (CarlaEngineOsc* const _this_ = (CarlaEngineOsc*)userData)
  134. return _this_->handleMessage(path, argc, argv, types, msg);
  135. return 1;
  136. }
  137. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineOsc)
  138. };
  139. CARLA_BACKEND_END_NAMESPACE
  140. #endif // __CARLA_ENGINE_OSC_HPP__