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.

147 lines
6.2KB

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