|
6 | 6 | #include <element/engine.hpp> |
7 | 7 | #include <element/graph.hpp> |
8 | 8 | #include <element/node.hpp> |
| 9 | +#include <element/nodefactory.hpp> |
9 | 10 | #include <element/plugins.hpp> |
10 | 11 | #include <element/services.hpp> |
11 | 12 | #include <element/settings.hpp> |
@@ -35,6 +36,42 @@ static void initializeRootGraphPorts (RootGraph* root, const Node& model) |
35 | 36 | root->setNumPorts (PortType::Midi, ins.size(), true, false); |
36 | 37 | root->setNumPorts (PortType::Midi, outs.size(), false, false); |
37 | 38 | } |
| 39 | + |
| 40 | +/** Scans an unverified plugin and registers it with the known plugins list. |
| 41 | +
|
| 42 | + Handles both JUCE audio plugin formats and Element node providers such |
| 43 | + as CLAP, whose identifiers from the unverified scan are bare file paths. |
| 44 | +
|
| 45 | + @param plugins the plugin manager to verify against. |
| 46 | + @param desc description of the unverified plugin to scan. |
| 47 | + @param out receives the full descriptions produced by the scan. |
| 48 | + @return true if at least one description was found and added. |
| 49 | +*/ |
| 50 | +static bool verifyPlugin (PluginManager& plugins, const PluginDescription& desc, OwnedArray<PluginDescription>& out) |
| 51 | +{ |
| 52 | + auto& list = plugins.getKnownPlugins(); |
| 53 | + |
| 54 | + if (auto* const format = plugins.getAudioPluginFormat (desc.pluginFormatName)) |
| 55 | + { |
| 56 | + list.removeFromBlacklist (desc.fileOrIdentifier); |
| 57 | + list.removeType (desc); |
| 58 | + return list.scanAndAddFile (desc.fileOrIdentifier, false, out, *format); |
| 59 | + } |
| 60 | + |
| 61 | + if (auto* const provider = plugins.getProvider (desc.pluginFormatName)) |
| 62 | + { |
| 63 | + list.removeFromBlacklist (desc.fileOrIdentifier); |
| 64 | + provider->scan (desc.fileOrIdentifier, out); |
| 65 | + for (auto* const d : out) |
| 66 | + { |
| 67 | + list.removeType (*d); |
| 68 | + list.addType (*d); |
| 69 | + } |
| 70 | + return ! out.isEmpty(); |
| 71 | + } |
| 72 | + |
| 73 | + return false; |
| 74 | +} |
38 | 75 | } // namespace detail |
39 | 76 |
|
40 | 77 | struct RootGraphHolder |
@@ -596,12 +633,7 @@ Node EngineService::addPlugin (const PluginDescription& desc, const bool verifie |
596 | 633 | OwnedArray<PluginDescription> plugs; |
597 | 634 | if (! verified) |
598 | 635 | { |
599 | | - auto* format = context().plugins().getAudioPluginFormat (desc.pluginFormatName); |
600 | | - jassert (format != nullptr); |
601 | | - auto& list (context().plugins().getKnownPlugins()); |
602 | | - list.removeFromBlacklist (desc.fileOrIdentifier); |
603 | | - list.removeType (desc); |
604 | | - if (list.scanAndAddFile (desc.fileOrIdentifier, false, plugs, *format)) |
| 636 | + if (detail::verifyPlugin (context().plugins(), desc, plugs)) |
605 | 637 | { |
606 | 638 | context().plugins().saveUserPlugins (context().settings()); |
607 | 639 | } |
@@ -875,12 +907,7 @@ Node EngineService::addPlugin (const Node& graph, const PluginDescription& desc, |
875 | 907 | } |
876 | 908 | else |
877 | 909 | { |
878 | | - auto* format = context().plugins().getAudioPluginFormat (desc.pluginFormatName); |
879 | | - jassert (format != nullptr); |
880 | | - |
881 | | - list.removeFromBlacklist (desc.fileOrIdentifier); |
882 | | - |
883 | | - if (list.scanAndAddFile (desc.fileOrIdentifier, false, plugs, *format)) |
| 910 | + if (detail::verifyPlugin (context().plugins(), desc, plugs)) |
884 | 911 | { |
885 | 912 | context().plugins().saveUserPlugins (context().settings()); |
886 | 913 | } |
|
0 commit comments