Lv2Options.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Lv2Options.h - Lv2Options class
  3. *
  4. * Copyright (c) 2020-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 LV2OPTIONS_H
  25. #define LV2OPTIONS_H
  26. #include "lmmsconfig.h"
  27. #ifdef LMMS_HAVE_LV2
  28. #include <cstdint>
  29. #include <lv2/lv2plug.in/ns/ext/options/options.h>
  30. #include <lv2/lv2plug.in/ns/ext/urid/urid.h>
  31. #include <map>
  32. #include <memory>
  33. #include <set>
  34. #include <vector>
  35. #include "Engine.h"
  36. #include "Lv2Manager.h"
  37. #include "Lv2UridCache.h"
  38. /**
  39. Option container
  40. References all available options for a plugin and maps them to their URIDs.
  41. This class is used per Lv2 processor (justification in Lv2Proc::initMOptions())
  42. The public member functions should be called in descending order:
  43. 1. supportOption: set all supported option URIDs
  44. 2. initOption: initialize options with values
  45. 3. createOptionVectors: create the option vectors required for
  46. the feature
  47. 4. access the latter using feature()
  48. */
  49. class Lv2Options
  50. {
  51. public:
  52. //! Return if an option is supported by LMMS
  53. static bool isOptionSupported(LV2_URID key);
  54. //! Mark option as supported
  55. static void supportOption(LV2_URID key);
  56. //! Initialize an option
  57. template<typename Opt, typename Arg>
  58. void initOption(Lv2UridCache::Id key, Arg&& value,
  59. LV2_Options_Context context = LV2_OPTIONS_INSTANCE,
  60. std::uint32_t subject = 0)
  61. {
  62. const Lv2UridCache& cache = Engine::getLv2Manager()->uridCache();
  63. initOption(cache[key], sizeof(Opt), cache[Lv2UridCache::IdForType<Opt>::value],
  64. std::make_shared<Opt>(std::forward<Arg>(value)), context, subject);
  65. }
  66. //! Fill m_options and m_optionPointers with all options
  67. void createOptionVectors();
  68. //! Return the feature
  69. const LV2_Options_Option* feature() const
  70. {
  71. return m_options.data();
  72. }
  73. private:
  74. //! Initialize an option internally
  75. void initOption(LV2_URID key,
  76. uint32_t size,
  77. LV2_URID type,
  78. std::shared_ptr<void> value,
  79. LV2_Options_Context context = LV2_OPTIONS_INSTANCE,
  80. uint32_t subject = 0);
  81. //! options that are supported by every processor
  82. static std::set<LV2_URID> s_supportedOptions;
  83. //! options + data, ordered by URID
  84. std::map<LV2_URID, LV2_Options_Option> m_optionByUrid;
  85. //! option storage
  86. std::vector<LV2_Options_Option> m_options;
  87. //! option value storage
  88. std::map<LV2_URID, std::shared_ptr<void>> m_optionValues;
  89. };
  90. #endif // LMMS_HAVE_LV2
  91. #endif // LV2OPTIONS_H