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.

131 lines
5.9KB

  1. /*
  2. * Carla Bridge OSC
  3. * Copyright (C) 2011-2014 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. // -----------------------------------------------------------------------
  47. class CarlaBridgeOsc
  48. {
  49. public:
  50. CarlaBridgeOsc(CarlaBridgeClient* const client);
  51. ~CarlaBridgeOsc();
  52. void init(const char* const url);
  53. void idle() const;
  54. void close();
  55. // -------------------------------------------------------------------
  56. bool isControlRegistered() const noexcept
  57. {
  58. return (fControlData.target != nullptr);
  59. }
  60. const CarlaOscData& getControlData() const noexcept
  61. {
  62. return fControlData;
  63. }
  64. const char* getServerPath() const noexcept
  65. {
  66. return fServerPath;
  67. }
  68. // -------------------------------------------------------------------
  69. private:
  70. CarlaBridgeClient* const kClient;
  71. CarlaOscData fControlData;
  72. CarlaString fName;
  73. CarlaString fServerPath;
  74. lo_server fServer;
  75. // -------------------------------------------------------------------
  76. int handleMessage(const char* const path, const int argc, const lo_arg* const* const argv, const char* const types, const lo_message msg);
  77. int handleMsgConfigure(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  78. int handleMsgControl(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  79. int handleMsgProgram(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  80. int handleMsgMidiProgram(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  81. int handleMsgMidi(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  82. int handleMsgUpdateURL(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  83. int handleMsgShow();
  84. int handleMsgHide();
  85. int handleMsgQuit();
  86. #ifdef BRIDGE_LV2
  87. int handleMsgLv2AtomTransfer(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  88. int handleMsgLv2UridMap(CARLA_BRIDGE_OSC_HANDLE_ARGS);
  89. #endif
  90. // -------------------------------------------------------------------
  91. static int osc_message_handler(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* userData)
  92. {
  93. return ((CarlaBridgeOsc*)userData)->handleMessage(path, argc, argv, types, msg);
  94. }
  95. static void osc_error_handler(int num, const char* msg, const char* path)
  96. {
  97. carla_stderr("CarlaBridgeOsc::osc_error_handler(%i, \"%s\", \"%s\")", num, msg, path);
  98. }
  99. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaBridgeOsc)
  100. };
  101. // -----------------------------------------------------------------------
  102. CARLA_BRIDGE_END_NAMESPACE
  103. #endif // CARLA_BRIDGE_OSC_HPP_INCLUDED