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.

152 lines
6.3KB

  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. osc_send_configure(&m_controlData, key, value);
  68. }
  69. void sendOscControl(int32_t index, float value)
  70. {
  71. osc_send_control(&m_controlData, index, value);
  72. }
  73. void sendOscUpdate()
  74. {
  75. osc_send_update(&m_controlData, m_serverPath);
  76. }
  77. void sendOscExiting()
  78. {
  79. osc_send_exiting(&m_controlData);
  80. }
  81. #ifdef BRIDGE_LV2
  82. void sendOscLv2TransferAtom(const char* const type, const char* const value)
  83. {
  84. osc_send_lv2_transfer_atom(&m_controlData, type, value);
  85. }
  86. void sendOscLv2TransferEvent(const char* const type, const char* const value)
  87. {
  88. osc_send_lv2_transfer_event(&m_controlData, type, value);
  89. }
  90. #endif
  91. // -------------------------------------------------------------------
  92. protected:
  93. int handleMessage(const char* const path, const int argc, const lo_arg* const* const argv, const char* const types, const lo_message msg);
  94. int handleMsgConfigure(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  95. int handleMsgControl(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  96. int handleMsgProgram(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  97. int handleMsgMidiProgram(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  98. int handleMsgMidi(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  99. int handleMsgShow();
  100. int handleMsgHide();
  101. int handleMsgQuit();
  102. #ifdef BRIDGE_LV2
  103. int handleMsgLv2TransferAtom(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  104. int handleMsgLv2TransferEvent(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  105. #endif
  106. // -------------------------------------------------------------------
  107. private:
  108. CarlaClient* const client;
  109. const char* m_serverPath;
  110. lo_server_thread m_serverThread;
  111. CarlaOscData m_controlData;
  112. char* m_name;
  113. size_t m_nameSize;
  114. // -------------------------------------------------------------------
  115. 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)
  116. {
  117. CarlaOsc* const _this_ = (CarlaOsc*)user_data;
  118. return _this_->handleMessage(path, argc, argv, types, msg);
  119. }
  120. };
  121. /**@}*/
  122. CARLA_BRIDGE_END_NAMESPACE
  123. #endif // CARLA_BRIDGE_OSC_H