Skip to content

Commit

Permalink
feat: add project package and basic ableton parsing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
DropSnorz committed Oct 8, 2023
1 parent 3c4cde7 commit af00c98
Show file tree
Hide file tree
Showing 8 changed files with 361 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.owlplug.project.services.ProjectService;
import javafx.beans.binding.Bindings;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
Expand All @@ -58,6 +60,8 @@ public class PluginsController extends BaseController {
@Autowired
private PluginService pluginService;
@Autowired
private ProjectService projectService;
@Autowired
private PluginDAO pluginDAO;
@Autowired
private SymlinkDAO symlinkDAO;
Expand All @@ -73,6 +77,8 @@ public class PluginsController extends BaseController {
@FXML
private Button syncButton;
@FXML
private Button projectButton;
@FXML
private Button exportButton;
@FXML
private TreeView<Object> pluginTreeView;
Expand Down Expand Up @@ -167,6 +173,11 @@ public TreeCell<Object> call(TreeView<Object> p) {
pluginService.syncPlugins();
});

projectButton.setOnAction(e -> {
projectService.syncProjects();
});


taskFactory.addSyncPluginsListener(() -> clearAndFillPluginTree());

exportButton.setOnAction(e -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* OwlPlug
* Copyright (C) 2021 Arthur <dropsnorz@gmail.com>
*
* This file is part of OwlPlug.
*
* OwlPlug is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* OwlPlug is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OwlPlug. If not, see <https://www.gnu.org/licenses/>.
*/


package com.owlplug.project.components;

import com.owlplug.core.components.BaseTaskFactory;
import com.owlplug.core.tasks.TaskExecutionContext;
import com.owlplug.project.tasks.ProjectSyncTask;
import org.springframework.stereotype.Component;

@Component
public class ProjectTaskFactory extends BaseTaskFactory {

public TaskExecutionContext createSyncTask() {
return create(new ProjectSyncTask());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* OwlPlug
* Copyright (C) 2021 Arthur <dropsnorz@gmail.com>
*
* This file is part of OwlPlug.
*
* OwlPlug is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* OwlPlug is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OwlPlug. If not, see <https://www.gnu.org/licenses/>.
*/

package com.owlplug.project.model;

import java.util.ArrayList;
import java.util.List;

public class Project {

private String appName;

private List<ProjectPlugin> plugins = new ArrayList<>();

public String getAppName() {
return appName;
}

public void setAppName(String appName) {
this.appName = appName;
}

public List<ProjectPlugin> getPlugins() {
return plugins;
}

public void setPlugins(List<ProjectPlugin> plugins) {
this.plugins = plugins;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* OwlPlug
* Copyright (C) 2021 Arthur <dropsnorz@gmail.com>
*
* This file is part of OwlPlug.
*
* OwlPlug is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* OwlPlug is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OwlPlug. If not, see <https://www.gnu.org/licenses/>.
*/

package com.owlplug.project.model;

public class ProjectPlugin {

private String uid;
private String name;
private String fileName;
private String path;

public String getUid() {
return uid;
}

public void setUid(String uid) {
this.uid = uid;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getFileName() {
return fileName;
}

public void setFileName(String fileName) {
this.fileName = fileName;
}

public String getPath() {
return path;
}

public void setPath(String path) {
this.path = path;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* OwlPlug
* Copyright (C) 2021 Arthur <dropsnorz@gmail.com>
*
* This file is part of OwlPlug.
*
* OwlPlug is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* OwlPlug is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OwlPlug. If not, see <https://www.gnu.org/licenses/>.
*/

package com.owlplug.project.services;

import com.owlplug.core.services.BaseService;
import com.owlplug.project.components.ProjectTaskFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProjectService extends BaseService {

@Autowired
private ProjectTaskFactory taskFactory;

public void syncProjects() {
taskFactory.createSyncTask().schedule();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.owlplug.project.tasks;

import com.owlplug.core.tasks.AbstractTask;
import com.owlplug.core.tasks.TaskResult;
import com.owlplug.project.model.Project;
import com.owlplug.project.model.ProjectPlugin;
import com.owlplug.project.tasks.discovery.AbletonProjectExplorer;
import java.io.File;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ProjectSyncTask extends AbstractTask {

private final Logger log = LoggerFactory.getLogger(this.getClass());

@Override
protected TaskResult call() throws Exception {

log.debug("Starting project sync task");

String path = "C:/Users/arthu/Blend/Lone Wanderer Project/DropSnorz - Lone Wanderer.als";

File sourceFile = new File(path);

AbletonProjectExplorer explorer = new AbletonProjectExplorer();
Project project = explorer.explore(sourceFile);

for (ProjectPlugin p : project.getPlugins()) {
log.debug(p.getName() + " - " + p.getFileName());
}

return success();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/* OwlPlug
* Copyright (C) 2021 Arthur <dropsnorz@gmail.com>
*
* This file is part of OwlPlug.
*
* OwlPlug is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* OwlPlug is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OwlPlug. If not, see <https://www.gnu.org/licenses/>.
*/

package com.owlplug.project.tasks.discovery;

import com.owlplug.project.model.Project;
import com.owlplug.project.model.ProjectPlugin;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.apache.commons.compress.compressors.CompressorException;
import org.apache.commons.compress.compressors.CompressorInputStream;
import org.apache.commons.compress.compressors.CompressorStreamFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public class AbletonProjectExplorer {

public boolean canExploreFile(File file) {
return file.getAbsolutePath().endsWith(".als");
}

public Project explore(File file) {

try {

Document xmlDocument = createDocument(file);
XPath xPath = XPathFactory.newInstance().newXPath();
Project project = new Project();
NodeList abletonNode = (NodeList) xPath.compile("/Ableton").evaluate(xmlDocument, XPathConstants.NODESET);
project.setAppName(abletonNode.item(0).getAttributes().getNamedItem("Creator").getNodeValue());

NodeList vstPlugins = (NodeList) xPath.compile("//PluginDevice/PluginDesc/VstPluginInfo").evaluate(xmlDocument, XPathConstants.NODESET);


for (int i = 0; i < vstPlugins.getLength();i++) {
System.out.println(vstPlugins.item(i).toString());

Node node = vstPlugins.item(i);

if (node instanceof Element element) {
project.getPlugins().add(readPluginElement(element));
}

}
return project;

} catch (XPathExpressionException e) {
e.printStackTrace();
throw new RuntimeException(e);
}

}

private ProjectPlugin readPluginElement(Element pluginElement) {

ProjectPlugin plugin = new ProjectPlugin();
NodeList fileNameNodes = pluginElement.getElementsByTagName("FileName");

if (fileNameNodes.getLength() >= 1) {
plugin.setFileName(fileNameNodes.item(0).getAttributes().getNamedItem("Value").getNodeValue());

}

NodeList nameNodes = pluginElement.getElementsByTagName("PlugName");
if (nameNodes.getLength() >= 1) {
plugin.setName(nameNodes.item(0).getAttributes().getNamedItem("Value").getNodeValue());

}

NodeList uniqueIdNode = pluginElement.getElementsByTagName("UniqueId");
if (uniqueIdNode.getLength() >= 1) {
plugin.setUid(uniqueIdNode.item(0).getAttributes().getNamedItem("Value").getNodeValue());

}

return plugin;
}

private Document createDocument(File file) {

try (InputStream fi = new FileInputStream(file);
InputStream bi = new BufferedInputStream(fi);
CompressorInputStream gzi = new CompressorStreamFactory().createCompressorInputStream(bi);
InputStream bgzi = new BufferedInputStream(gzi)) {

DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = builderFactory.newDocumentBuilder();
return builder.parse(bgzi);

} catch (CompressorException | FileNotFoundException e) {
//TODO: auto-generated
e.printStackTrace();
throw new RuntimeException(e);
} catch (IOException e) {
//TODO: auto-generated
e.printStackTrace();
throw new RuntimeException(e);
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
} catch (SAXException e) {
throw new RuntimeException(e);
}

}

}
Loading

0 comments on commit af00c98

Please sign in to comment.