-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add project package and basic ableton parsing logic
- Loading branch information
Showing
8 changed files
with
361 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
owlplug-client/src/main/java/com/owlplug/project/components/ProjectTaskFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
owlplug-client/src/main/java/com/owlplug/project/model/Project.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
owlplug-client/src/main/java/com/owlplug/project/model/ProjectPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
owlplug-client/src/main/java/com/owlplug/project/services/ProjectService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
owlplug-client/src/main/java/com/owlplug/project/tasks/ProjectSyncTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
135 changes: 135 additions & 0 deletions
135
owlplug-client/src/main/java/com/owlplug/project/tasks/discovery/AbletonProjectExplorer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.