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.

141 lines
6.1KB

  1. /*
  2. * Carla Bridge OSC
  3. * Copyright (C) 2011-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 doc/GPL.txt file.
  16. */
  17. #ifndef CARLA_BRIDGE_OSC_HPP_INCLUDED
  18. #define CARLA_BRIDGE_OSC_HPP_INCLUDED
  19. #include "CarlaBridge.hpp"
  20. #include "CarlaOscUtils.hpp"
  21. #include "CarlaString.hpp"
  22. #define CARLA_BRIDGE_OSC_HANDLE_ARGS const int argc, const lo_arg* const* const argv, const char* const types
  23. #define CARLA_BRIDGE_OSC_CHECK_OSC_TYPES(/* argc, types, */ argcToCompare, typesToCompare) \
  24. /* check argument count */ \
  25. if (argc != argcToCompare) \
  26. { \
  27. carla_stderr("CarlaBridgeOsc::%s() - argument count mismatch: %i != %i", __FUNCTION__, argc, argcToCompare); \
  28. return 1; \
  29. } \
  30. if (argc > 0) \
  31. { \
  32. /* check for nullness */ \
  33. if (types == nullptr || typesToCompare == nullptr) \
  34. { \
  35. carla_stderr("CarlaBridgeOsc::%s() - argument types are null", __FUNCTION__); \
  36. return 1; \
  37. } \
  38. /* check argument types */ \
  39. if (std::strcmp(types, typesToCompare) != 0) \
  40. { \
  41. carla_stderr("CarlaBridgeOsc::%s() - argument types mismatch: '%s' != '%s'", __FUNCTION__, types, typesToCompare); \
  42. return 1; \
  43. } \
  44. }
  45. CARLA_BRIDGE_START_NAMESPACE
  46. #if 0
  47. } // Fix editor indentation
  48. #endif
  49. class CarlaBridgeOsc
  50. {
  51. public:
  52. CarlaBridgeOsc(CarlaBridgeClient* const client);
  53. ~CarlaBridgeOsc();
  54. void init(const char* const url);
  55. void idle() const;
  56. void idleWait() const;
  57. void close();
  58. // -------------------------------------------------------------------
  59. bool isControlRegistered() const noexcept
  60. {
  61. return (fControlData.target != nullptr);
  62. }
  63. const CarlaOscData& getControlData() const noexcept
  64. {
  65. return fControlData;
  66. }
  67. const char* getServerPath() const noexcept
  68. {
  69. return fServerPath;
  70. }
  71. // -------------------------------------------------------------------
  72. private:
  73. CarlaBridgeClient* const fClient;
  74. CarlaOscData fControlData;
  75. CarlaString fName;
  76. CarlaString fServerPath;
  77. lo_server fServer;
  78. // -------------------------------------------------------------------
  79. int handleMessage(const char* const path, const int argc, const lo_arg* const* const argv, const char* const types, const lo_message msg);
  80. #ifdef BUILD_BRIDGE_UI
  81. int handleMsgConfigure(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  82. int handleMsgControl(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  83. int handleMsgProgram(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  84. int handleMsgMidiProgram(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  85. int handleMsgMidi(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  86. #endif
  87. int handleMsgShow();
  88. int handleMsgHide();
  89. int handleMsgQuit();
  90. #ifdef BRIDGE_LV2
  91. int handleMsgLv2AtomTransfer(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  92. int handleMsgLv2UridMap(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  93. #endif
  94. #ifdef BUILD_BRIDGE_PLUGIN
  95. int handleMsgPluginSaveNow();
  96. int handleMsgPluginSetParameterMidiChannel(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  97. int handleMsgPluginSetParameterMidiCC(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  98. int handleMsgPluginSetChunk(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  99. int handleMsgPluginSetCustomData(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  100. #endif
  101. // -------------------------------------------------------------------
  102. static void osc_error_handler(int num, const char* msg, const char* path)
  103. {
  104. carla_stderr("CarlaBridgeOsc::osc_error_handler(%i, \"%s\", \"%s\")", num, msg, path);
  105. }
  106. static int osc_message_handler(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* userData)
  107. {
  108. return ((CarlaBridgeOsc*)userData)->handleMessage(path, argc, argv, types, msg);
  109. }
  110. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaBridgeOsc)
  111. };
  112. CARLA_BRIDGE_END_NAMESPACE
  113. #endif // CARLA_BRIDGE_OSC_HPP_INCLUDED