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.

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