Collection of tools useful for audio production
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.

188 lines
7.2KB

  1. /*
  2. * Carla bridge code
  3. * Copyright (C) 2012 Filipe Coelho <falktx@gmail.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_BRIDGE_OSC_H
  18. #define CARLA_BRIDGE_OSC_H
  19. #include "carla_bridge.h"
  20. #include "carla_osc_includes.h"
  21. #define CARLA_BRIDGE_OSC_HANDLE_ARGS const int argc, const lo_arg* const* const argv, const char* const types
  22. #define CARLA_BRIDGE_OSC_CHECK_OSC_TYPES(/* argc, types, */ argcToCompare, typesToCompare) \
  23. Q_ASSERT(m_serverPath); \
  24. Q_ASSERT(m_serverThread); \
  25. /* check argument count */ \
  26. if (argc != argcToCompare) \
  27. { \
  28. qCritical("CarlaOsc::%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("CarlaOsc::%s() - argument types are null", __FUNCTION__); \
  37. return 1; \
  38. } \
  39. /* check argument types */ \
  40. if (strcmp(types, typesToCompare) != 0) \
  41. { \
  42. qCritical("CarlaOsc::%s() - argument types mismatch: '%s' != '%s'", __FUNCTION__, types, typesToCompare); \
  43. return 1; \
  44. } \
  45. }
  46. CARLA_BRIDGE_START_NAMESPACE
  47. /*!
  48. * @defgroup CarlaBridgeOSC Carla Bridge OSC
  49. *
  50. * The Carla Bridge OSC.
  51. * @{
  52. */
  53. class CarlaOsc
  54. {
  55. public:
  56. CarlaOsc(CarlaClient* const client, const char* const name);
  57. ~CarlaOsc();
  58. bool init(const char* const url);
  59. void close();
  60. // -------------------------------------------------------------------
  61. const CarlaOscData* getControllerData() const
  62. {
  63. return &m_controlData;
  64. }
  65. void sendOscConfigure(const char* const key, const char* const value)
  66. {
  67. Q_ASSERT(m_controlData.target);
  68. if (m_controlData.target)
  69. osc_send_configure(&m_controlData, key, value);
  70. }
  71. void sendOscControl(const int32_t index, const float value)
  72. {
  73. Q_ASSERT(m_controlData.target);
  74. if (m_controlData.target)
  75. osc_send_control(&m_controlData, index, value);
  76. }
  77. void sendOscMidi(const uint8_t midiBuf[4])
  78. {
  79. Q_ASSERT(m_controlData.target);
  80. if (m_controlData.target)
  81. osc_send_midi(&m_controlData, midiBuf);
  82. }
  83. void sendOscUpdate()
  84. {
  85. Q_ASSERT(m_controlData.target);
  86. if (m_controlData.target)
  87. osc_send_update(&m_controlData, m_serverPath);
  88. }
  89. void sendOscExiting()
  90. {
  91. Q_ASSERT(m_controlData.target);
  92. if (m_controlData.target)
  93. osc_send_exiting(&m_controlData);
  94. }
  95. #ifdef BUILD_BRIDGE_PLUGIN
  96. void sendOscBridgeUpdate()
  97. {
  98. Q_ASSERT(m_controlData.target && m_serverPath);
  99. if (m_controlData.target && m_serverPath)
  100. osc_send_bridge_update(&m_controlData, m_serverPath);
  101. }
  102. #endif
  103. #ifdef BRIDGE_LV2
  104. void sendOscLv2TransferAtom(const char* const type, const char* const value)
  105. {
  106. Q_ASSERT(m_controlData.target);
  107. if (m_controlData.target)
  108. osc_send_lv2_transfer_atom(&m_controlData, type, value);
  109. }
  110. void sendOscLv2TransferEvent(const char* const type, const char* const value)
  111. {
  112. Q_ASSERT(m_controlData.target);
  113. if (m_controlData.target)
  114. osc_send_lv2_transfer_event(&m_controlData, type, value);
  115. }
  116. #endif
  117. // -------------------------------------------------------------------
  118. protected:
  119. int handleMessage(const char* const path, const int argc, const lo_arg* const* const argv, const char* const types, const lo_message msg);
  120. int handleMsgConfigure(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  121. int handleMsgControl(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  122. int handleMsgProgram(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  123. int handleMsgMidiProgram(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  124. int handleMsgMidi(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  125. int handleMsgShow();
  126. int handleMsgHide();
  127. int handleMsgQuit();
  128. #ifdef BRIDGE_LV2
  129. int handleMsgLv2TransferAtom(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  130. int handleMsgLv2TransferEvent(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  131. #endif
  132. // -------------------------------------------------------------------
  133. private:
  134. CarlaClient* const client;
  135. const char* m_serverPath;
  136. lo_server_thread m_serverThread;
  137. CarlaOscData m_controlData;
  138. char* m_name;
  139. size_t m_nameSize;
  140. // -------------------------------------------------------------------
  141. 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 user_data)
  142. {
  143. CarlaOsc* const _this_ = (CarlaOsc*)user_data;
  144. return _this_->handleMessage(path, argc, argv, types, msg);
  145. }
  146. };
  147. /**@}*/
  148. CARLA_BRIDGE_END_NAMESPACE
  149. #endif // CARLA_BRIDGE_OSC_H