forked from praxis-live/praxiscore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add project module with graph and project parsers and models. (WIP)
- Loading branch information
1 parent
b76cd53
commit cd53826
Showing
12 changed files
with
2,117 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
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,61 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.praxislive</groupId> | ||
<artifactId>praxiscore</artifactId> | ||
<version>6.0.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>praxiscore-project</artifactId> | ||
<packaging>jar</packaging> | ||
<name>PraxisCORE Project</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>praxiscore-api</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>praxiscore-base</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>praxiscore-script</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<version>5.10.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-params</artifactId> | ||
<version>5.10.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<version>5.10.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<compilerArgs> | ||
<arg>-Xlint:all</arg> | ||
</compilerArgs> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
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,11 @@ | ||
|
||
module org.praxislive.project { | ||
|
||
requires transitive org.praxislive.core; | ||
|
||
requires org.praxislive.base; | ||
requires org.praxislive.script; | ||
|
||
exports org.praxislive.project; | ||
|
||
} |
235 changes: 235 additions & 0 deletions
235
praxiscore-project/src/main/java/org/praxislive/project/GraphBuilder.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,235 @@ | ||
/* | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | ||
* | ||
* Copyright 2024 Neil C Smith. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License version 3 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code 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 Lesser General Public License | ||
* version 3 for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License version 3 | ||
* along with this work; if not, see http://www.gnu.org/licenses/ | ||
* | ||
* | ||
* Please visit https://www.praxislive.org if you need additional information or | ||
* have any questions. | ||
*/ | ||
package org.praxislive.project; | ||
|
||
import java.util.ArrayList; | ||
import java.util.LinkedHashMap; | ||
import java.util.LinkedHashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.SequencedMap; | ||
import java.util.SequencedSet; | ||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
import java.util.stream.Stream; | ||
import org.praxislive.core.ComponentAddress; | ||
import org.praxislive.core.ComponentType; | ||
import org.praxislive.core.ControlAddress; | ||
import org.praxislive.core.Value; | ||
|
||
/** | ||
* | ||
*/ | ||
public final class GraphBuilder { | ||
|
||
private GraphBuilder() { | ||
} | ||
|
||
public static Component component(ComponentType type) { | ||
return new Component(type); | ||
} | ||
|
||
public static Component component(GraphElement.Component component) { | ||
return new Component(component); | ||
} | ||
|
||
static Root root(String id, ComponentType type) { | ||
return new Root(id, type); | ||
} | ||
|
||
static Root root(GraphElement.Root root) { | ||
return new Root(root); | ||
} | ||
|
||
static Root syntheticRoot() { | ||
return new Root("", GraphElement.Root.SYNTHETIC); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static sealed abstract class Base<B extends Base<B>> { | ||
|
||
final ComponentType type; | ||
final List<GraphElement.Comment> comments; | ||
final SequencedMap<String, GraphElement.Property> properties; | ||
final SequencedMap<String, GraphElement.Component> children; | ||
final SequencedSet<GraphElement.Connection> connections; | ||
|
||
private Base(ComponentType type) { | ||
this.type = Objects.requireNonNull(type); | ||
comments = new ArrayList<>(); | ||
properties = new LinkedHashMap<>(); | ||
children = new LinkedHashMap<>(); | ||
connections = new LinkedHashSet<>(); | ||
} | ||
|
||
private Base(GraphElement.Component component) { | ||
this(component.type()); | ||
comments.addAll(component.comments()); | ||
properties.putAll(component.properties()); | ||
children.putAll(component.children()); | ||
connections.addAll(component.connections()); | ||
} | ||
|
||
public B child(String id, GraphElement.Component child) { | ||
if (!ComponentAddress.isValidID(id)) { | ||
throw new IllegalArgumentException(id + " is not a valid child ID"); | ||
} | ||
children.put(id, Objects.requireNonNull(child)); | ||
return (B) this; | ||
} | ||
|
||
public B child(String id, ComponentType type, Consumer<Component> constructor) { | ||
Component childBuilder = new Component(type); | ||
constructor.accept(childBuilder); | ||
return child(id, childBuilder.build()); | ||
} | ||
|
||
public B comment(String text) { | ||
comments.add(new GraphElement.Comment(text)); | ||
return (B) this; | ||
} | ||
|
||
public B comment(GraphElement.Comment comment) { | ||
comments.add(Objects.requireNonNull(comment)); | ||
return (B) this; | ||
} | ||
|
||
public B connection(String sourceComponent, String sourcePort, | ||
String targetComponent, String targetPort) { | ||
connections.add(GraphElement.connection(sourceComponent, sourcePort, | ||
targetComponent, targetPort)); | ||
return (B) this; | ||
} | ||
|
||
public B connection(GraphElement.Connection connection) { | ||
connections.add(Objects.requireNonNull(connection)); | ||
return (B) this; | ||
} | ||
|
||
public B property(String id, Value value) { | ||
return property(id, new GraphElement.Property(value)); | ||
} | ||
|
||
public B property(String id, GraphElement.Property property) { | ||
if (!ControlAddress.isValidID(id)) { | ||
throw new IllegalArgumentException(id + " is not a valid property ID"); | ||
} | ||
properties.put(id, Objects.requireNonNull(property)); | ||
return (B) this; | ||
} | ||
|
||
public B clearChildren() { | ||
children.clear(); | ||
return (B) this; | ||
} | ||
|
||
public B clearComments() { | ||
comments.clear(); | ||
return (B) this; | ||
} | ||
|
||
public B clearConnections() { | ||
connections.clear(); | ||
return (B) this; | ||
} | ||
|
||
public B clearProperties() { | ||
properties.clear(); | ||
return (B) this; | ||
} | ||
|
||
public B transformChildren( | ||
Function<Stream<Map.Entry<String, GraphElement.Component>>, List<Map.Entry<String, GraphElement.Component>>> transform) { | ||
var transformed = transform.apply(children.entrySet().stream()); | ||
clearChildren(); | ||
transformed.forEach(c -> child(c.getKey(), c.getValue())); | ||
return (B) this; | ||
} | ||
|
||
public B transformComments( | ||
Function<Stream<GraphElement.Comment>, List<GraphElement.Comment>> transform) { | ||
var transformed = transform.apply(comments.stream()); | ||
clearComments(); | ||
transformed.forEach(c -> comment(c)); | ||
return (B) this; | ||
} | ||
|
||
public B transformConnections( | ||
Function<Stream<GraphElement.Connection>, List<GraphElement.Connection>> transform) { | ||
var transformed = transform.apply(connections.stream()); | ||
clearConnections(); | ||
transformed.forEach(c -> connection(c)); | ||
return (B) this; | ||
} | ||
|
||
public B transformProperties( | ||
Function<Stream<Map.Entry<String, GraphElement.Property>>, List<Map.Entry<String, GraphElement.Property>>> transform) { | ||
var transformed = transform.apply(properties.entrySet().stream()); | ||
clearProperties(); | ||
transformed.forEach(p -> property(p.getKey(), p.getValue())); | ||
return (B) this; | ||
} | ||
|
||
} | ||
|
||
public static final class Component extends Base<Component> { | ||
|
||
private Component(ComponentType type) { | ||
super(type); | ||
} | ||
|
||
private Component(GraphElement.Component component) { | ||
super(component); | ||
} | ||
|
||
public GraphElement.Component build() { | ||
return new GraphElement.Component(type, comments, properties, children, connections); | ||
} | ||
|
||
} | ||
|
||
public static final class Root extends Base<Root> { | ||
|
||
private final String id; | ||
private final List<GraphElement.Command> commands; | ||
|
||
private Root(String id, ComponentType type) { | ||
super(type); | ||
this.id = id; | ||
this.commands = new ArrayList<>(); | ||
} | ||
|
||
private Root(GraphElement.Root root) { | ||
super(root); | ||
this.id = root.id(); | ||
this.commands = new ArrayList<>(root.commands()); | ||
} | ||
|
||
public GraphElement.Root build() { | ||
return new GraphElement.Root(id, type, comments, commands, | ||
properties, children, connections); | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.