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.

138 lines
5.9KB

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