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.

138 lines
5.9KB

  1. /*
  2. * Carla Bridge OSC
  3. * Copyright (C) 2011-2012 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_BRIDGE_OSC_HPP
  18. #define CARLA_BRIDGE_OSC_HPP
  19. #include "carla_bridge.hpp"
  20. #include "carla_osc_utils.hpp"
  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. /* check argument count */ \
  24. if (argc != argcToCompare) \
  25. { \
  26. qCritical("CarlaBridgeOsc::%s() - argument count mismatch: %i != %i", __FUNCTION__, argc, argcToCompare); \
  27. return 1; \
  28. } \
  29. if (argc > 0) \
  30. { \
  31. /* check for nullness */ \
  32. if (! (types && typesToCompare)) \
  33. { \
  34. qCritical("CarlaBridgeOsc::%s() - argument types are null", __FUNCTION__); \
  35. return 1; \
  36. } \
  37. /* check argument types */ \
  38. if (strcmp(types, typesToCompare) != 0) \
  39. { \
  40. qCritical("CarlaBridgeOsc::%s() - argument types mismatch: '%s' != '%s'", __FUNCTION__, types, typesToCompare); \
  41. return 1; \
  42. } \
  43. }
  44. CARLA_BRIDGE_START_NAMESPACE
  45. #if 0
  46. } // Fix editor indentation
  47. #endif
  48. class CarlaBridgeOsc
  49. {
  50. public:
  51. CarlaBridgeOsc(CarlaBridgeClient* const client);
  52. ~CarlaBridgeOsc();
  53. bool init(const char* const url);
  54. void idle();
  55. void close();
  56. // -------------------------------------------------------------------
  57. bool isControlRegistered() const
  58. {
  59. return bool(m_controlData.target);
  60. }
  61. const CarlaOscData* getControlData() const
  62. {
  63. return &m_controlData;
  64. }
  65. const char* getServerPath() const
  66. {
  67. return m_serverPath;
  68. }
  69. // -------------------------------------------------------------------
  70. private:
  71. CarlaBridgeClient* const client;
  72. char* m_name;
  73. size_t m_nameSize;
  74. lo_server m_server;
  75. char* m_serverPath;
  76. CarlaOscData m_controlData;
  77. // -------------------------------------------------------------------
  78. int handleMessage(const char* const path, const int argc, const lo_arg* const* const argv, const char* const types, const lo_message msg);
  79. int handleMsgConfigure(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  80. int handleMsgControl(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  81. int handleMsgProgram(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  82. int handleMsgMidiProgram(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  83. int handleMsgMidi(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  84. int handleMsgShow();
  85. int handleMsgHide();
  86. int handleMsgQuit();
  87. #ifdef BRIDGE_LV2
  88. int handleMsgLv2TransferAtom(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  89. int handleMsgLv2TransferEvent(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  90. #endif
  91. #ifdef BUILD_BRIDGE_PLUGIN
  92. int handleMsgPluginSaveNow();
  93. int handleMsgPluginSetChunk(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  94. int handleMsgPluginSetCustomData(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  95. #endif
  96. // -------------------------------------------------------------------
  97. static void osc_error_handler(const int num, const char* const msg, const char* const path)
  98. {
  99. qWarning("CarlaBridgeOsc::osc_error_handler(%i, \"%s\", \"%s\")", num, msg, path);
  100. }
  101. 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)
  102. {
  103. CARLA_ASSERT(user_data);
  104. if (CarlaBridgeOsc* const _this_ = (CarlaBridgeOsc*)user_data)
  105. return _this_->handleMessage(path, argc, argv, types, msg);
  106. return 1;
  107. }
  108. };
  109. CARLA_BRIDGE_END_NAMESPACE
  110. #endif // CARLA_BRIDGE_OSC_HPP