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