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.

163 lines
4.7KB

  1. /*
  2. * Carla Bridge Client
  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_CLIENT_HPP_INCLUDED
  18. #define CARLA_BRIDGE_CLIENT_HPP_INCLUDED
  19. #include "CarlaBridgeOsc.hpp"
  20. #include "CarlaBridgeToolkit.hpp"
  21. #include "CarlaLibUtils.hpp"
  22. CARLA_BRIDGE_START_NAMESPACE
  23. // -----------------------------------------------------------------------
  24. class CarlaBridgeClient
  25. {
  26. public:
  27. CarlaBridgeClient(const char* const uiTitle);
  28. virtual ~CarlaBridgeClient();
  29. // ---------------------------------------------------------------------
  30. // ui initialization
  31. virtual bool uiInit(const char*, const char* const, const char* const);
  32. virtual void uiIdle() {}
  33. virtual void uiClose();
  34. // ---------------------------------------------------------------------
  35. // ui management
  36. virtual void* getWidget() const = 0;
  37. virtual bool isResizable() const = 0;
  38. // ---------------------------------------------------------------------
  39. // ui processing
  40. virtual void setParameter(const int32_t rindex, const float value) = 0;
  41. virtual void setProgram(const uint32_t index) = 0;
  42. virtual void setMidiProgram(const uint32_t bank, const uint32_t program) = 0;
  43. virtual void noteOn(const uint8_t channel, const uint8_t note, const uint8_t velo) = 0;
  44. virtual void noteOff(const uint8_t channel, const uint8_t note) = 0;
  45. // ---------------------------------------------------------------------
  46. // ui toolkit
  47. void toolkitShow();
  48. void toolkitHide();
  49. void toolkitResize(const int width, const int height);
  50. void toolkitExec(const bool showGui);
  51. void toolkitQuit();
  52. // ---------------------------------------------------------------------
  53. // osc stuff
  54. void oscInit(const char* const url);
  55. bool oscIdle(const bool onlyOnce = false) const;
  56. void oscClose();
  57. bool isOscControlRegistered() const noexcept;
  58. void sendOscUpdate() const;
  59. // ---------------------------------------------------------------------
  60. protected:
  61. void sendOscConfigure(const char* const key, const char* const value) const;
  62. void sendOscControl(const int32_t index, const float value) const;
  63. void sendOscProgram(const uint32_t index) const;
  64. void sendOscMidiProgram(const uint32_t index) const;
  65. void sendOscMidi(const uint8_t midiBuf[4]) const;
  66. void sendOscExiting() const;
  67. #ifdef BRIDGE_LV2
  68. void sendOscLv2AtomTransfer(const uint32_t portIndex, const char* const atomBuf) const;
  69. void sendOscLv2UridMap(const uint32_t urid, const char* const uri) const;
  70. #endif
  71. // ---------------------------------------------------------------------
  72. void* getContainerId();
  73. void* getContainerId2();
  74. // ---------------------------------------------------------------------
  75. bool uiLibOpen(const char* const filename);
  76. bool uiLibClose();
  77. const char* uiLibError();
  78. template<typename Func>
  79. Func uiLibSymbol(const char* const symbol)
  80. {
  81. CARLA_SAFE_ASSERT_RETURN(fUI.lib != nullptr, nullptr);
  82. carla_debug("CarlaBridgeClient::uiLibSymbol(\"%s\")", symbol);
  83. return lib_symbol<Func>(fUI.lib, symbol);
  84. }
  85. // ---------------------------------------------------------------------
  86. private:
  87. CarlaBridgeOsc fOsc;
  88. const CarlaOscData& fOscData;
  89. struct UI {
  90. CarlaBridgeToolkit* const toolkit;
  91. CarlaString filename;
  92. lib_t lib;
  93. bool quit;
  94. UI(CarlaBridgeToolkit* const toolkit_)
  95. : toolkit(toolkit_),
  96. filename(),
  97. lib(nullptr),
  98. quit(false)
  99. {
  100. CARLA_ASSERT(toolkit != nullptr);
  101. }
  102. ~UI()
  103. {
  104. delete toolkit;
  105. }
  106. void init()
  107. {
  108. toolkit->init();
  109. quit = false;
  110. }
  111. void close()
  112. {
  113. quit = true;
  114. toolkit->quit();
  115. }
  116. #ifdef CARLA_PROPER_CPP11_SUPPORT
  117. UI() = delete;
  118. CARLA_DECLARE_NON_COPY_STRUCT(UI)
  119. #endif
  120. } fUI;
  121. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaBridgeClient)
  122. };
  123. // -----------------------------------------------------------------------
  124. CARLA_BRIDGE_END_NAMESPACE
  125. #endif // CARLA_BRIDGE_CLIENT_HPP_INCLUDED