|
| 1 | +/* OwlPlug |
| 2 | + * Copyright (C) 2021 Arthur <dropsnorz@gmail.com> |
| 3 | + * |
| 4 | + * This file is part of OwlPlug. |
| 5 | + * |
| 6 | + * OwlPlug is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License version 3 |
| 8 | + * as published by the Free Software Foundation. |
| 9 | + * |
| 10 | + * OwlPlug is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with OwlPlug. If not, see <https://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | + |
| 19 | +package com.owlplug.project.tasks.discovery.studioone; |
| 20 | + |
| 21 | +import com.owlplug.core.utils.PluginUtils; |
| 22 | +import com.owlplug.plugin.model.PluginFormat; |
| 23 | +import com.owlplug.project.model.DawPlugin; |
| 24 | +import java.util.ArrayList; |
| 25 | +import java.util.List; |
| 26 | +import javax.xml.xpath.XPath; |
| 27 | +import javax.xml.xpath.XPathConstants; |
| 28 | +import javax.xml.xpath.XPathExpressionException; |
| 29 | +import javax.xml.xpath.XPathFactory; |
| 30 | +import org.slf4j.Logger; |
| 31 | +import org.slf4j.LoggerFactory; |
| 32 | +import org.w3c.dom.Document; |
| 33 | +import org.w3c.dom.Element; |
| 34 | +import org.w3c.dom.Node; |
| 35 | +import org.w3c.dom.NodeList; |
| 36 | + |
| 37 | +public class StudioOneAudioMixerPluginCollector { |
| 38 | + |
| 39 | + private final Logger log = LoggerFactory.getLogger(this.getClass()); |
| 40 | + |
| 41 | + private Document document; |
| 42 | + |
| 43 | + public StudioOneAudioMixerPluginCollector(Document document) { |
| 44 | + this.document = document; |
| 45 | + } |
| 46 | + |
| 47 | + public List<DawPlugin> collectPlugins() { |
| 48 | + |
| 49 | + ArrayList<DawPlugin> plugins = new ArrayList<>(); |
| 50 | + |
| 51 | + XPath xpath = XPathFactory.newInstance().newXPath(); |
| 52 | + try { |
| 53 | + // Find all FX nodes in the document (all Inserts / channel groups) |
| 54 | + NodeList fxNodes = (NodeList) xpath |
| 55 | + .compile("//Attributes[starts-with(@name, 'FX')]") |
| 56 | + .evaluate(document, XPathConstants.NODESET); |
| 57 | + |
| 58 | + for (int i = 0; i < fxNodes.getLength(); i++) { |
| 59 | + Node node = fxNodes.item(i); |
| 60 | + if (node instanceof Element element) { |
| 61 | + // Filter out empty FX slots by checking for deviceData or ghostData children |
| 62 | + StudioOneDomUtils.DeviceDataAndGhostData data = StudioOneDomUtils.findDeviceDataAndGhostData(element); |
| 63 | + if (data.getDeviceData() == null && data.getGhostData() == null) { |
| 64 | + continue; // Skip empty FX slots |
| 65 | + } |
| 66 | + |
| 67 | + DawPlugin plugin = readPluginElement(element); |
| 68 | + if (plugin != null) { |
| 69 | + plugins.add(plugin); |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + } catch (XPathExpressionException e) { |
| 75 | + log.error("Error extracting plugins from audio mixer", e); |
| 76 | + } |
| 77 | + |
| 78 | + return plugins; |
| 79 | + } |
| 80 | + |
| 81 | + private DawPlugin readPluginElement(Element pluginElement) { |
| 82 | + String pluginName = StudioOneDomUtils.extractPluginName(pluginElement); |
| 83 | + if (pluginName == null || pluginName.isEmpty()) { |
| 84 | + return null; |
| 85 | + } |
| 86 | + |
| 87 | + PluginFormat format = StudioOneDomUtils.extractPluginFormat(pluginElement); |
| 88 | + if (format == null) { |
| 89 | + return null; |
| 90 | + } |
| 91 | + |
| 92 | + // Normalize the plugin name (remove platform suffixes like x64, x32, etc.) |
| 93 | + // This ensures cleaner data in the database and simplifies later queries |
| 94 | + String normalizedName = PluginUtils.absoluteName(pluginName); |
| 95 | + |
| 96 | + DawPlugin plugin = new DawPlugin(); |
| 97 | + plugin.setName(normalizedName); |
| 98 | + plugin.setFormat(format); |
| 99 | + return plugin; |
| 100 | + } |
| 101 | + |
| 102 | +} |
| 103 | + |
0 commit comments