The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

115 lines
4.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. bool PluginDescription::isDuplicateOf (const PluginDescription& other) const noexcept
  21. {
  22. const auto tie = [] (const PluginDescription& d)
  23. {
  24. return std::tie (d.fileOrIdentifier, d.deprecatedUid, d.uniqueId);
  25. };
  26. return tie (*this) == tie (other);
  27. }
  28. static String getPluginDescSuffix (const PluginDescription& d, int uid)
  29. {
  30. return "-" + String::toHexString (d.fileOrIdentifier.hashCode())
  31. + "-" + String::toHexString (uid);
  32. }
  33. bool PluginDescription::matchesIdentifierString (const String& identifierString) const
  34. {
  35. const auto matches = [&] (int uid)
  36. {
  37. return identifierString.endsWithIgnoreCase (getPluginDescSuffix (*this, uid));
  38. };
  39. return matches (uniqueId) || matches (deprecatedUid);
  40. }
  41. String PluginDescription::createIdentifierString() const
  42. {
  43. return pluginFormatName + "-" + name + getPluginDescSuffix (*this, uniqueId);
  44. }
  45. std::unique_ptr<XmlElement> PluginDescription::createXml() const
  46. {
  47. auto e = std::make_unique<XmlElement> ("PLUGIN");
  48. e->setAttribute ("name", name);
  49. if (descriptiveName != name)
  50. e->setAttribute ("descriptiveName", descriptiveName);
  51. e->setAttribute ("format", pluginFormatName);
  52. e->setAttribute ("category", category);
  53. e->setAttribute ("manufacturer", manufacturerName);
  54. e->setAttribute ("version", version);
  55. e->setAttribute ("file", fileOrIdentifier);
  56. e->setAttribute ("uniqueId", String::toHexString (uniqueId));
  57. e->setAttribute ("isInstrument", isInstrument);
  58. e->setAttribute ("fileTime", String::toHexString (lastFileModTime.toMilliseconds()));
  59. e->setAttribute ("infoUpdateTime", String::toHexString (lastInfoUpdateTime.toMilliseconds()));
  60. e->setAttribute ("numInputs", numInputChannels);
  61. e->setAttribute ("numOutputs", numOutputChannels);
  62. e->setAttribute ("isShell", hasSharedContainer);
  63. e->setAttribute ("uid", String::toHexString (deprecatedUid));
  64. return e;
  65. }
  66. bool PluginDescription::loadFromXml (const XmlElement& xml)
  67. {
  68. if (xml.hasTagName ("PLUGIN"))
  69. {
  70. name = xml.getStringAttribute ("name");
  71. descriptiveName = xml.getStringAttribute ("descriptiveName", name);
  72. pluginFormatName = xml.getStringAttribute ("format");
  73. category = xml.getStringAttribute ("category");
  74. manufacturerName = xml.getStringAttribute ("manufacturer");
  75. version = xml.getStringAttribute ("version");
  76. fileOrIdentifier = xml.getStringAttribute ("file");
  77. isInstrument = xml.getBoolAttribute ("isInstrument", false);
  78. lastFileModTime = Time (xml.getStringAttribute ("fileTime").getHexValue64());
  79. lastInfoUpdateTime = Time (xml.getStringAttribute ("infoUpdateTime").getHexValue64());
  80. numInputChannels = xml.getIntAttribute ("numInputs");
  81. numOutputChannels = xml.getIntAttribute ("numOutputs");
  82. hasSharedContainer = xml.getBoolAttribute ("isShell", false);
  83. deprecatedUid = xml.getStringAttribute ("uid").getHexValue32();
  84. uniqueId = xml.getStringAttribute ("uniqueId", "0").getHexValue32();
  85. return true;
  86. }
  87. return false;
  88. }
  89. } // namespace juce