Lv2Manager.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Lv2Manager.h - Implementation of Lv2Manager class
  3. *
  4. * Copyright (c) 2018-2020 Johannes Lorenz <jlsf2013$users.sourceforge.net, $=@>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #ifndef LV2MANAGER_H
  25. #define LV2MANAGER_H
  26. #include "lmmsconfig.h"
  27. #ifdef LMMS_HAVE_LV2
  28. #include <map>
  29. #include <set>
  30. #include <lilv/lilv.h>
  31. #include "Lv2Basics.h"
  32. #include "Lv2UridCache.h"
  33. #include "Lv2UridMap.h"
  34. #include "Plugin.h"
  35. /*
  36. all Lv2 classes in relation (use our "4 spaces per tab rule" to view):
  37. explanation:
  38. "x = {y z}" means class "x" consists of classes "y" and "z"
  39. (and probably other classes not mentioned)
  40. "x = {y*}" means class "x" references/uses class "y"
  41. core:
  42. Lv2Proc = {LilvInstance}
  43. Lv2ControlBase = {Lv2Proc, Lv2Proc... (2 for mono, 1 for stereo)}
  44. Lv2Manager = {LilvPlugin*, LilvPlugin* ...}
  45. (creates Lv2ControlBase, Lv2ControlBase...)
  46. Lv2FxControls = {Lv2ControlBase}
  47. Lv2Effect = {Effect + Lv2FxControls}
  48. (takes Lv2SubPluginFeatures in ctor)
  49. Lv2Instrument = {Instrument + Lv2ControlBase}
  50. (takes Lv2SubPluginFeatures in ctor)
  51. gui:
  52. Lv2ViewProc = {Lv2Proc*}
  53. Lv2ViewBase = {Lv2ViewProc, Lv2ViewProc...
  54. (2 for mono, 1 for stereo)}
  55. Lv2FxControlDialog = {EffectControlDialog + Lv2ViewBase}
  56. Lv2InsView = {InstrumentView + Lv2ViewBase}
  57. Lv2SubPluginFeatures:
  58. Lv2SubPluginFeatures = {Lv2Manager*}
  59. Lv2Effect::Descriptor = {Lv2SubPluginFeatures}
  60. Lv2Instrument::Descriptor = {Lv2SubPluginFeatures}
  61. */
  62. //! Class to keep track of all LV2 plugins
  63. class Lv2Manager
  64. {
  65. public:
  66. void initPlugins();
  67. Lv2Manager();
  68. ~Lv2Manager();
  69. AutoLilvNode uri(const char* uriStr);
  70. //! Class representing info for one plugin
  71. struct Lv2Info
  72. {
  73. public:
  74. //! use only for std::map internals
  75. Lv2Info() : m_plugin(nullptr) {}
  76. //! ctor used inside Lv2Manager
  77. Lv2Info(const LilvPlugin* plug, Plugin::PluginTypes type, bool valid) :
  78. m_plugin(plug), m_type(type), m_valid(valid) {}
  79. Lv2Info(Lv2Info&& other) = default;
  80. Lv2Info& operator=(Lv2Info&& other) = default;
  81. const LilvPlugin* plugin() const { return m_plugin; }
  82. Plugin::PluginTypes type() const { return m_type; }
  83. bool isValid() const { return m_valid; }
  84. private:
  85. const LilvPlugin* m_plugin;
  86. Plugin::PluginTypes m_type;
  87. bool m_valid = false;
  88. };
  89. //! Return descriptor with URI @p uri or nullptr if none exists
  90. const LilvPlugin *getPlugin(const std::string &uri);
  91. //! Return descriptor with URI @p uri or nullptr if none exists
  92. const LilvPlugin *getPlugin(const QString& uri);
  93. using Lv2InfoMap = std::map<std::string, Lv2Info>;
  94. using Iterator = Lv2InfoMap::iterator;
  95. Iterator begin() { return m_lv2InfoMap.begin(); }
  96. Iterator end() { return m_lv2InfoMap.end(); }
  97. //! strcmp based key comparator for std::set and std::map
  98. struct CmpStr
  99. {
  100. bool operator()(char const *a, char const *b) const;
  101. };
  102. UridMap& uridMap() { return m_uridMap; }
  103. const Lv2UridCache& uridCache() const { return m_uridCache; }
  104. const std::set<const char*, CmpStr>& supportedFeatureURIs() const
  105. {
  106. return m_supportedFeatureURIs;
  107. }
  108. bool isFeatureSupported(const char* featName) const;
  109. AutoLilvNodes findNodes(const LilvNode *subject,
  110. const LilvNode *predicate, const LilvNode *object);
  111. static const std::set<const char*, Lv2Manager::CmpStr>& getPluginBlacklist()
  112. {
  113. return pluginBlacklist;
  114. }
  115. private:
  116. // general data
  117. bool m_debug; //!< if set, debug output will be printed
  118. LilvWorld* m_world;
  119. Lv2InfoMap m_lv2InfoMap;
  120. std::set<const char*, CmpStr> m_supportedFeatureURIs;
  121. // feature data that are common for all Lv2Proc
  122. UridMap m_uridMap;
  123. // URID cache for fast URID access
  124. Lv2UridCache m_uridCache;
  125. // static
  126. static const std::set<const char*, Lv2Manager::CmpStr> pluginBlacklist;
  127. // functions
  128. bool isSubclassOf(const LilvPluginClass *clvss, const char *uriStr);
  129. };
  130. #endif // LMMS_HAVE_LV2
  131. #endif // LV2MANAGER_H