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.

140 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 close();
  57. // -------------------------------------------------------------------
  58. bool isControlRegistered() const noexcept
  59. {
  60. return (fControlData.target != nullptr);
  61. }
  62. const CarlaOscData& getControlData() const noexcept
  63. {
  64. return fControlData;
  65. }
  66. const char* getServerPath() const noexcept
  67. {
  68. return (const char*)fServerPath;
  69. }
  70. // -------------------------------------------------------------------
  71. private:
  72. CarlaBridgeClient* const fClient;
  73. CarlaOscData fControlData;
  74. CarlaString fName;
  75. CarlaString fServerPath;
  76. lo_server fServer;
  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. #ifdef BUILD_BRIDGE_UI
  80. int handleMsgConfigure(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  81. int handleMsgControl(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  82. int handleMsgProgram(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  83. int handleMsgMidiProgram(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  84. int handleMsgMidi(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  85. #endif
  86. int handleMsgShow();
  87. int handleMsgHide();
  88. int handleMsgQuit();
  89. #ifdef BRIDGE_LV2
  90. int handleMsgLv2AtomTransfer(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  91. int handleMsgLv2UridMap(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  92. #endif
  93. #ifdef BUILD_BRIDGE_PLUGIN
  94. int handleMsgPluginSaveNow();
  95. int handleMsgPluginSetParameterMidiChannel(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  96. int handleMsgPluginSetParameterMidiCC(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  97. int handleMsgPluginSetChunk(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  98. int handleMsgPluginSetCustomData(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  99. #endif
  100. // -------------------------------------------------------------------
  101. static void osc_error_handler(int num, const char* msg, const char* path)
  102. {
  103. carla_stderr("CarlaBridgeOsc::osc_error_handler(%i, \"%s\", \"%s\")", num, msg, path);
  104. }
  105. static int osc_message_handler(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* userData)
  106. {
  107. return ((CarlaBridgeOsc*)userData)->handleMessage(path, argc, argv, types, msg);
  108. }
  109. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaBridgeOsc)
  110. };
  111. CARLA_BRIDGE_END_NAMESPACE
  112. #endif // CARLA_BRIDGE_OSC_HPP_INCLUDED