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.

178 lines
7.0KB

  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 BRIDGE_LV2
  96. void sendOscLv2TransferAtom(const char* const type, const char* const value)
  97. {
  98. Q_ASSERT(m_controlData.target);
  99. if (m_controlData.target)
  100. osc_send_lv2_transfer_atom(&m_controlData, type, value);
  101. }
  102. void sendOscLv2TransferEvent(const char* const type, const char* const value)
  103. {
  104. Q_ASSERT(m_controlData.target);
  105. if (m_controlData.target)
  106. osc_send_lv2_transfer_event(&m_controlData, type, value);
  107. }
  108. #endif
  109. // -------------------------------------------------------------------
  110. protected:
  111. int handleMessage(const char* const path, const int argc, const lo_arg* const* const argv, const char* const types, const lo_message msg);
  112. int handleMsgConfigure(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  113. int handleMsgControl(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  114. int handleMsgProgram(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  115. int handleMsgMidiProgram(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  116. int handleMsgMidi(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  117. int handleMsgShow();
  118. int handleMsgHide();
  119. int handleMsgQuit();
  120. #ifdef BRIDGE_LV2
  121. int handleMsgLv2TransferAtom(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  122. int handleMsgLv2TransferEvent(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  123. #endif
  124. // -------------------------------------------------------------------
  125. private:
  126. CarlaClient* const client;
  127. const char* m_serverPath;
  128. lo_server_thread m_serverThread;
  129. CarlaOscData m_controlData;
  130. char* m_name;
  131. size_t m_nameSize;
  132. // -------------------------------------------------------------------
  133. 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)
  134. {
  135. CarlaOsc* const _this_ = (CarlaOsc*)user_data;
  136. return _this_->handleMessage(path, argc, argv, types, msg);
  137. }
  138. };
  139. /**@}*/
  140. CARLA_BRIDGE_END_NAMESPACE
  141. #endif // CARLA_BRIDGE_OSC_H