diff --git a/praxiscore-api/src/main/java/org/praxislive/core/RootHub.java b/praxiscore-api/src/main/java/org/praxislive/core/RootHub.java
index c7065d27..45384f0b 100644
--- a/praxiscore-api/src/main/java/org/praxislive/core/RootHub.java
+++ b/praxiscore-api/src/main/java/org/praxislive/core/RootHub.java
@@ -44,7 +44,7 @@ public interface RootHub extends Lookup.Provider {
/**
* Dispatch a message to another Root.
- *
+ *
* See {@link Root.Controller#submitPacket(org.praxislive.core.Packet)
*
* @param packet message to dispatch
@@ -78,9 +78,8 @@ public static interface ExtensionProvider {
/**
* An interface for RootHub extensions (see {@link ExtensionProvider}) to
- * advertise the services they provide. Use of {@link Component#getInfo()}
- * for this purpose should be considered deprecated.
- *
+ * advertise the services they provide.
+ *
* The Root itself must provide the advertised services. Support for root
* containers to provide services via child components is not yet supported.
*
@@ -88,8 +87,6 @@ public static interface ExtensionProvider {
*/
public static interface ServiceProvider extends Root {
- // ideally this would be part of the ExtensionProvider itself, but breaks
- // too many assumptions in the API
/**
* A list of the services this extension provides. This method will be
* called as the extension Root is installed in the RootHub.
diff --git a/praxiscore-api/src/main/java/org/praxislive/core/services/ComponentFactory.java b/praxiscore-api/src/main/java/org/praxislive/core/services/ComponentFactory.java
index ae961fdf..8be338a2 100644
--- a/praxiscore-api/src/main/java/org/praxislive/core/services/ComponentFactory.java
+++ b/praxiscore-api/src/main/java/org/praxislive/core/services/ComponentFactory.java
@@ -23,7 +23,6 @@
import java.util.Objects;
import java.util.Optional;
-import java.util.function.Supplier;
import java.util.stream.Stream;
import org.praxislive.core.Component;
import org.praxislive.core.ComponentType;
@@ -65,20 +64,6 @@ public interface ComponentFactory {
*/
public Stream rootTypes();
- @Deprecated
- public default MetaData extends Component> getMetaData(ComponentType type) {
- Supplier redirect = () -> componentData(type);
- return new MetaData(redirect) {
- };
- }
-
- @Deprecated
- public default MetaData extends Root> getRootMetaData(ComponentType type) {
- Supplier redirect = () -> rootData(type);
- return new MetaData(redirect) {
- };
- }
-
/**
* Query the data associated with this component type.
*
@@ -86,14 +71,7 @@ public default MetaData extends Root> getRootMetaData(ComponentType type) {
* @return lookup of data
*/
public default Lookup componentData(ComponentType type) {
- var metadata = getMetaData(type);
- if (metadata == null) {
- return null;
- } else if (metadata.redirect != null) {
- return Lookup.EMPTY;
- } else {
- return metadata.getLookup();
- }
+ return Lookup.EMPTY;
}
/**
@@ -103,14 +81,7 @@ public default Lookup componentData(ComponentType type) {
* @return lookup of data
*/
public default Lookup rootData(ComponentType type) {
- var metadata = getRootMetaData(type);
- if (metadata == null) {
- return null;
- } else if (metadata.redirect != null) {
- return Lookup.EMPTY;
- } else {
- return metadata.getLookup();
- }
+ return Lookup.EMPTY;
}
/**
@@ -139,21 +110,6 @@ public default Root createRoot(ComponentType type) throws ComponentInstantiation
throw new ComponentInstantiationException();
}
- @Deprecated
- public default Root createRootComponent(ComponentType type) throws ComponentInstantiationException {
- return createRoot(type);
- }
-
- @Deprecated
- public default Class extends ComponentFactoryService> getFactoryService() {
- return ComponentFactoryService.class;
- }
-
- @Deprecated
- public default Class extends RootFactoryService> getRootFactoryService() {
- return RootFactoryService.class;
- }
-
/**
* Optional service to redirect to for component instantiation. The control
* on the service should follow the same shape as the default
@@ -164,12 +120,7 @@ public default Class extends RootFactoryService> getRootFactoryService() {
* @return optional service redirect
*/
public default Optional componentRedirect() {
- var service = getFactoryService();
- if (service == null || ComponentFactoryService.class.equals(service)) {
- return Optional.empty();
- } else {
- return Optional.of(new Redirect(service, ComponentFactoryService.NEW_INSTANCE));
- }
+ return Optional.empty();
}
/**
@@ -182,104 +133,40 @@ public default Optional componentRedirect() {
* @return optional service redirect
*/
public default Optional rootRedirect() {
- var service = getRootFactoryService();
- if (service == null || RootFactoryService.class.equals(service)) {
- return Optional.empty();
- } else {
- return Optional.of(new Redirect(service, RootFactoryService.NEW_ROOT_INSTANCE));
- }
- }
-
- @Deprecated
- public static abstract class MetaData {
-
- private final Supplier redirect;
-
- public MetaData() {
- this.redirect = null;
- }
-
- private MetaData(Supplier redirect) {
- this.redirect = redirect;
- }
-
- public boolean isDeprecated() {
- return false;
- }
-
- public Optional findReplacement() {
- return Optional.empty();
- }
-
- public Lookup getLookup() {
- return redirect != null ? redirect.get() : Lookup.EMPTY;
- }
-
+ return Optional.empty();
}
/**
* A factory service redirect. See {@link #componentRedirect()} and
* {@link #rootRedirect()}.
*/
- public static final class Redirect {
+ public record Redirect(Class extends Service> service, String control) {
- private final Class extends Service> service;
- private final String control;
+ }
- /**
- * Construct a redirect to the provided service and control.
- *
- * @param service service type to redirect to
- * @param control control on service to redirect to
- */
- public Redirect(Class extends Service> service, String control) {
- this.service = Objects.requireNonNull(service);
- this.control = Objects.requireNonNull(control);
- }
+ /**
+ * Mark a component deprecated (with optional replacement type). An instance
+ * should be added to the metadata lookup associated with the component
+ * type.
+ */
+ public record Deprecated(Optional replacement) {
/**
- * Query the service to redirect to.
- *
- * @return service
+ * Deprecated without replacement.
*/
- public Class extends Service> service() {
- return service;
+ public Deprecated() {
+ this(Optional.empty());
}
/**
- * Query the control on the service to redirect to.
+ * Deprecated with replacement type.
*
- * @return control id
+ * @param replacement replacement type
*/
- public String control() {
- return control;
- }
-
- @Override
- public int hashCode() {
- int hash = 3;
- hash = 97 * hash + Objects.hashCode(this.service);
- hash = 97 * hash + Objects.hashCode(this.control);
- return hash;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- final Redirect other = (Redirect) obj;
- if (!Objects.equals(this.control, other.control)) {
- return false;
- }
- return Objects.equals(this.service, other.service);
+ public Deprecated(ComponentType replacement) {
+ this(Optional.of(replacement));
}
}
+
}
diff --git a/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/AudioBodyContext.java b/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/AudioBodyContext.java
deleted file mode 100644
index 3ee44b28..00000000
--- a/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/AudioBodyContext.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 2020 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.audio.code;
-
-import org.praxislive.code.CodeUtils;
-import org.praxislive.code.ClassBodyContext;
-
-/**
- *
- */
-public class AudioBodyContext extends ClassBodyContext {
-
- public final static String TEMPLATE =
- CodeUtils.load(AudioBodyContext.class, "resources/audio_template.pxj");
-
- private final static String[] IMPORTS = CodeUtils.join(
- CodeUtils.defaultImports(), new String[]{
- "org.jaudiolibs.pipes.*",
- "org.jaudiolibs.pipes.units.*",
- "org.praxislive.audio.code.userapi.*",
- "static org.praxislive.audio.code.userapi.AudioConstants.*"
- });
-
- public AudioBodyContext() {
- super(AudioCodeDelegate.class);
- }
-
- @Override
- public String[] getDefaultImports() {
- return IMPORTS.clone();
- }
-
-}
diff --git a/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/AudioCode.java b/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/AudioCode.java
new file mode 100644
index 00000000..5480c0f0
--- /dev/null
+++ b/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/AudioCode.java
@@ -0,0 +1,59 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2023 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.audio.code;
+
+import java.util.List;
+import java.util.stream.Stream;
+import org.praxislive.code.CodeFactory;
+import org.praxislive.code.CodeUtils;
+
+/**
+ * Audio code utility functions.
+ */
+public class AudioCode {
+
+ private static final List DEFAULT_IMPORTS
+ = Stream.concat(CodeUtils.defaultImports().stream(),
+ Stream.of("org.jaudiolibs.pipes.*",
+ "org.jaudiolibs.pipes.units.*",
+ "org.praxislive.audio.code.userapi.*",
+ "static org.praxislive.audio.code.userapi.AudioConstants.*"))
+ .toList();
+
+ private static final CodeFactory.Base BASE
+ = CodeFactory.base(AudioCodeDelegate.class,
+ DEFAULT_IMPORTS,
+ (task, delegate) -> new AudioCodeContext(new AudioCodeConnector(task, delegate)));
+
+ private AudioCode() {
+
+ }
+
+ /**
+ * Access {@link CodeFactory.Base} for {@link AudioCodeDelegate}.
+ *
+ * @return code factory base for AudioCodeDelegate.
+ */
+ public static CodeFactory.Base base() {
+ return BASE;
+ }
+}
diff --git a/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/AudioCodeConnector.java b/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/AudioCodeConnector.java
index 23ced416..3f6d7930 100644
--- a/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/AudioCodeConnector.java
+++ b/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/AudioCodeConnector.java
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright 2020 Neil C Smith.
+ * Copyright 2023 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
@@ -40,15 +40,20 @@
/**
*
*/
-public class AudioCodeConnector extends CodeConnector {
+public class AudioCodeConnector extends CodeConnector {
private final Class extends AudioCodeDelegate> previousClass;
private final List ins;
private final List outs;
private final List ugens;
-
- public AudioCodeConnector(CodeFactory.Task task,
- D delegate,
+
+ public AudioCodeConnector(CodeFactory.Task task,
+ AudioCodeDelegate delegate) {
+ this(task, delegate, task.getPrevious());
+ }
+
+ public AudioCodeConnector(CodeFactory.Task task,
+ AudioCodeDelegate delegate,
Class extends AudioCodeDelegate> previousClass) {
super(task, delegate);
this.previousClass = previousClass;
@@ -60,12 +65,12 @@ public AudioCodeConnector(CodeFactory.Task task,
@Override
@SuppressWarnings("deprecation")
protected void analyseField(Field field) {
-
+
if (AudioIn.class.isAssignableFrom(field.getType())) {
In in = field.getAnnotation(In.class);
if (in != null) {
- AudioInPort.Descriptor aid =
- AudioInPort.createDescriptor(this, in, field);
+ AudioInPort.Descriptor aid
+ = AudioInPort.createDescriptor(this, in, field);
if (aid != null) {
addPort(aid);
ins.add(aid);
@@ -73,12 +78,12 @@ protected void analyseField(Field field) {
}
}
}
-
+
if (AudioOut.class.isAssignableFrom(field.getType())) {
Out out = field.getAnnotation(Out.class);
if (out != null) {
- AudioOutPort.Descriptor aod =
- AudioOutPort.createDescriptor(this, out, field);
+ AudioOutPort.Descriptor aod
+ = AudioOutPort.createDescriptor(this, out, field);
if (aod != null) {
addPort(aod);
outs.add(aod);
@@ -86,21 +91,21 @@ protected void analyseField(Field field) {
}
}
}
-
- if (field.isAnnotationPresent(UGen.class) &&
- Pipe.class.isAssignableFrom(field.getType())) {
+
+ if (field.isAnnotationPresent(UGen.class)
+ && Pipe.class.isAssignableFrom(field.getType())) {
UGenDescriptor ugd = UGenDescriptor.create(this, field);
if (ugd != null) {
ugens.add(ugd);
return;
}
}
-
+
if (AudioTable.class.isAssignableFrom(field.getType())) {
P p = field.getAnnotation(P.class);
if (p != null) {
- ResourceProperty.Descriptor ipd =
- ResourceProperty.Descriptor.create(this, p, field, TableLoader.getDefault());
+ ResourceProperty.Descriptor ipd
+ = ResourceProperty.Descriptor.create(this, p, field, TableLoader.getDefault());
if (ipd != null) {
addControl(ipd);
if (shouldAddPort(field)) {
@@ -110,24 +115,24 @@ protected void analyseField(Field field) {
}
}
}
-
+
super.analyseField(field);
}
-
+
UGenDescriptor[] extractUGens() {
return ugens.toArray(new UGenDescriptor[ugens.size()]);
}
-
+
AudioInPort.Descriptor[] extractIns() {
return ins.toArray(new AudioInPort.Descriptor[ins.size()]);
}
-
+
AudioOutPort.Descriptor[] extractOuts() {
return outs.toArray(new AudioOutPort.Descriptor[outs.size()]);
}
-
+
Class extends AudioCodeDelegate> getPreviousClass() {
return previousClass;
}
-
+
}
diff --git a/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/AudioCodeContext.java b/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/AudioCodeContext.java
index 5bdf4023..8a72d814 100644
--- a/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/AudioCodeContext.java
+++ b/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/AudioCodeContext.java
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright 2020 Neil C Smith.
+ * Copyright 2023 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
@@ -32,7 +32,7 @@
/**
*
*/
-public class AudioCodeContext extends CodeContext {
+public class AudioCodeContext extends CodeContext {
private final UGenDescriptor[] ugens;
private final AudioInPort.Descriptor[] ins;
@@ -40,7 +40,7 @@ public class AudioCodeContext extends CodeContext connector) {
+ public AudioCodeContext(AudioCodeConnector connector) {
super(connector, true);
ugens = connector.extractUGens();
ins = connector.extractIns();
@@ -48,7 +48,7 @@ public AudioCodeContext(AudioCodeConnector connector) {
}
@Override
- protected void configure(CodeComponent cmp, CodeContext oldCtxt) {
+ protected void configure(CodeComponent cmp, CodeContext oldCtxt) {
super.configure(cmp, oldCtxt);
// audio ins and outs attached in super call because they're ports
for (UGenDescriptor ugd : ugens) {
@@ -62,12 +62,12 @@ protected void hierarchyChanged() {
}
@Override
- protected void starting(ExecutionContext source) {
+ protected void onInit() {
setupDelegate();
}
@Override
- protected void stopping(ExecutionContext source) {
+ protected void onReset() {
resetPorts();
}
@@ -101,7 +101,7 @@ private void updateDelegate() {
getLog().log(LogLevel.ERROR, e, "Exception thrown during update()");
}
}
-
+
private void setupUGens() {
for (UGenDescriptor ugd : ugens) {
Pipe ug = ugd.getUGen();
@@ -109,21 +109,21 @@ private void setupUGens() {
ug.reset();
}
}
-
+
private void setupPorts() {
for (AudioInPort.Descriptor aipd : ins) {
- Utils.disconnectSinks(aipd.getPort().getPipe());
+ Utils.disconnectSinks(aipd.port().getPipe());
}
for (AudioOutPort.Descriptor aopd : outs) {
- AudioOutPort.AudioOutPipe pipe = aopd.getPort().getPipe();
+ AudioOutPort.AudioOutPipe pipe = aopd.port().getPipe();
Utils.disconnectSources(pipe);
pipe.triggerSwitch();
}
}
-
+
private void resetPorts() {
for (AudioOutPort.Descriptor aopd : outs) {
- AudioOutPort.AudioOutPipe pipe = aopd.getPort().getPipe();
+ AudioOutPort.AudioOutPipe pipe = aopd.port().getPipe();
pipe.resetSwitch();
}
}
diff --git a/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/AudioCodeFactory.java b/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/AudioCodeFactory.java
deleted file mode 100644
index 7677010e..00000000
--- a/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/AudioCodeFactory.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 2018 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.audio.code;
-
-import org.praxislive.code.CodeContext;
-import org.praxislive.code.CodeFactory;
-import org.praxislive.core.ComponentType;
-
-/**
- *
- *
- */
-public class AudioCodeFactory extends CodeFactory {
-
- private final static AudioBodyContext ABC = new AudioBodyContext();
-
- public AudioCodeFactory(ComponentType type,
- Class extends AudioCodeDelegate> baseClass,
- String sourceTemplate) {
- super(ABC, type, baseClass, sourceTemplate);
- }
-
- @Override
- public Task task() {
- return new AudioContextCreator();
- }
-
- private class AudioContextCreator extends Task {
-
- private AudioContextCreator() {
- super(AudioCodeFactory.this);
- }
-
- @Override
- protected CodeContext createCodeContext(AudioCodeDelegate delegate) {
- return new AudioCodeContext(
- new AudioCodeConnector(this, delegate, getPrevious()));
- }
-
-
- }
-
-}
diff --git a/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/AudioInPort.java b/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/AudioInPort.java
index f08deef3..10a000fc 100644
--- a/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/AudioInPort.java
+++ b/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/AudioInPort.java
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright 2020 Neil C Smith.
+ * Copyright 2023 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
@@ -31,7 +31,6 @@
import org.praxislive.code.PortDescriptor;
import org.praxislive.code.userapi.AuxIn;
import org.praxislive.code.userapi.In;
-import org.praxislive.core.Port;
import org.praxislive.core.PortInfo;
import org.praxislive.core.types.PMap;
import org.jaudiolibs.pipes.Buffer;
@@ -49,7 +48,7 @@ private AudioInPort(AudioInPipe in) {
super(in);
this.in = in;
}
-
+
AudioInPipe getPipe() {
return in;
}
@@ -81,7 +80,7 @@ protected void process(List list) {
}
- static class Descriptor extends PortDescriptor {
+ static class Descriptor extends PortDescriptor {
private final static PortInfo INFO = PortInfo.create(AudioPort.class, PortInfo.Direction.IN, PMap.EMPTY);
@@ -92,19 +91,16 @@ private Descriptor(String id,
PortDescriptor.Category category,
int index,
Field field) {
- super(id, category, index);
+ super(Descriptor.class, id, category, index);
field.setAccessible(true);
this.field = field;
}
@Override
- public void attach(CodeContext> context, Port previous) {
- if (previous instanceof AudioInPort) {
- port = (AudioInPort) previous;
+ public void attach(CodeContext> context, Descriptor previous) {
+ if (previous != null) {
+ port = previous.port;
} else {
- if (previous != null) {
- previous.disconnectAll();
- }
port = new AudioInPort(new AudioInPipe());
}
try {
@@ -115,12 +111,12 @@ public void attach(CodeContext> context, Port previous) {
}
@Override
- public AudioInPort getPort() {
+ public AudioInPort port() {
return port;
}
@Override
- public PortInfo getInfo() {
+ public PortInfo portInfo() {
return INFO;
}
diff --git a/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/AudioOutPort.java b/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/AudioOutPort.java
index df49489e..a0f740b5 100644
--- a/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/AudioOutPort.java
+++ b/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/AudioOutPort.java
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright 2018 Neil C Smith.
+ * Copyright 2023 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
@@ -31,7 +31,6 @@
import org.praxislive.code.PortDescriptor;
import org.praxislive.code.userapi.AuxOut;
import org.praxislive.code.userapi.Out;
-import org.praxislive.core.Port;
import org.praxislive.core.PortInfo;
import org.praxislive.core.types.PMap;
import org.praxislive.core.services.LogLevel;
@@ -126,7 +125,7 @@ void resetSwitch() {
}
- static class Descriptor extends PortDescriptor {
+ static class Descriptor extends PortDescriptor {
private final static PortInfo INFO = PortInfo.create(AudioPort.class, PortInfo.Direction.OUT, PMap.EMPTY);
@@ -137,19 +136,16 @@ private Descriptor(String id,
PortDescriptor.Category category,
int index,
Field field) {
- super(id, category, index);
+ super(Descriptor.class, id, category, index);
field.setAccessible(true);
this.field = field;
}
@Override
- public void attach(CodeContext> context, Port previous) {
- if (previous instanceof AudioOutPort) {
- port = (AudioOutPort) previous;
+ public void attach(CodeContext> context, Descriptor previous) {
+ if (previous != null) {
+ port = previous.port;
} else {
- if (previous != null) {
- previous.disconnectAll();
- }
port = new AudioOutPort(new AudioOutPipe());
}
port.out.context = context;
@@ -161,12 +157,12 @@ public void attach(CodeContext> context, Port previous) {
}
@Override
- public AudioOutPort getPort() {
+ public AudioOutPort port() {
return port;
}
@Override
- public PortInfo getInfo() {
+ public PortInfo portInfo() {
return INFO;
}
diff --git a/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/UGenDescriptor.java b/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/UGenDescriptor.java
index c4567579..03aa759c 100644
--- a/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/UGenDescriptor.java
+++ b/praxiscore-audio-code/src/main/java/org/praxislive/audio/code/UGenDescriptor.java
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright 2020 Neil C Smith.
+ * Copyright 2023 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
@@ -43,7 +43,7 @@ private UGenDescriptor(Field field, Field previousField, Pipe ugen) {
this.ugen = ugen;
}
- void attach(AudioCodeContext> context, CodeContext> previous) {
+ void attach(AudioCodeContext context, CodeContext> previous) {
if (ugen == null) {
try {
ugen = (Pipe) previousField.get(previous.getDelegate());
diff --git a/praxiscore-audio-components/src/main/java/org/praxislive/audio/components/AudioComponents.java b/praxiscore-audio-components/src/main/java/org/praxislive/audio/components/AudioComponents.java
index bd173727..b620603d 100644
--- a/praxiscore-audio-components/src/main/java/org/praxislive/audio/components/AudioComponents.java
+++ b/praxiscore-audio-components/src/main/java/org/praxislive/audio/components/AudioComponents.java
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright 2018 Neil C Smith.
+ * Copyright 2023 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
@@ -21,16 +21,15 @@
*/
package org.praxislive.audio.components;
+import org.praxislive.audio.code.AudioCode;
import org.praxislive.audio.code.AudioCodeDelegate;
-import org.praxislive.audio.code.AudioCodeFactory;
import org.praxislive.code.AbstractComponentFactory;
-import org.praxislive.core.ComponentType;
import org.praxislive.core.services.ComponentFactory;
import org.praxislive.core.services.ComponentFactoryProvider;
/**
*
- *
+ *
*/
public class AudioComponents implements ComponentFactoryProvider {
@@ -40,24 +39,24 @@ public class AudioComponents implements ComponentFactoryProvider {
public ComponentFactory getFactory() {
return instance;
}
-
+
private static class Factory extends AbstractComponentFactory {
-
+
private Factory() {
build();
}
private void build() {
-
+
// custom
add("audio:custom", AudioCustom.class, AudioCustom.TEMPLATE_PATH);
-
+
add("audio:clock", AudioClock.class, AudioClock.TEMPLATE_PATH);
add("audio:gain", AudioGain.class, AudioGain.TEMPLATE_PATH);
add("audio:osc", AudioOsc.class, AudioOsc.TEMPLATE_PATH);
add("audio:player", AudioPlayer.class, AudioPlayer.TEMPLATE_PATH);
add("audio:looper", AudioLooper.class, AudioLooper.TEMPLATE_PATH);
-
+
add("audio:fx:chorus", AudioFXChorus.class, AudioFXChorus.TEMPLATE_PATH);
add("audio:fx:comb-filter", AudioFXCombFilter.class, AudioFXCombFilter.TEMPLATE_PATH);
add("audio:fx:delay", AudioFXDelay.class, AudioFXDelay.TEMPLATE_PATH);
@@ -65,18 +64,15 @@ private void build() {
add("audio:fx:lfo-delay", AudioFXLFODelay.class, AudioFXLFODelay.TEMPLATE_PATH);
add("audio:fx:overdrive", AudioFXOverdrive.class, AudioFXOverdrive.TEMPLATE_PATH);
add("audio:fx:reverb", AudioFXReverb.class, AudioFXReverb.TEMPLATE_PATH);
-
+
add("audio:analysis:level", AudioLevel.class, AudioLevel.TEMPLATE_PATH);
-
+
}
-
-
+
private void add(String type, Class extends AudioCodeDelegate> cls, String path) {
- add(data(
- new AudioCodeFactory(ComponentType.of(type), cls, source(path))
- ));
+ add(AudioCode.base().create(type, cls, source(path)));
}
-
+
}
-
+
}
diff --git a/praxiscore-base/src/main/java/org/praxislive/base/AbstractComponentFactory.java b/praxiscore-base/src/main/java/org/praxislive/base/AbstractComponentFactory.java
index f05f7f3c..3a8ad172 100644
--- a/praxiscore-base/src/main/java/org/praxislive/base/AbstractComponentFactory.java
+++ b/praxiscore-base/src/main/java/org/praxislive/base/AbstractComponentFactory.java
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright 2020 Neil C Smith.
+ * Copyright 2023 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
@@ -25,7 +25,6 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import java.util.Optional;
import java.util.stream.Stream;
import org.praxislive.core.Component;
import org.praxislive.core.services.ComponentFactory;
@@ -39,8 +38,8 @@
*/
public class AbstractComponentFactory implements ComponentFactory {
- private final Map> componentMap;
- private final Map> rootMap;
+ private final Map componentMap;
+ private final Map rootMap;
protected AbstractComponentFactory() {
componentMap = new LinkedHashMap<>();
@@ -48,23 +47,27 @@ protected AbstractComponentFactory() {
}
@Override
- public Stream componentTypes() {
+ public final Stream componentTypes() {
return componentMap.keySet().stream();
}
@Override
- public Stream rootTypes() {
+ public final Stream rootTypes() {
return rootMap.keySet().stream();
}
@Override
- public Component createComponent(ComponentType type) throws ComponentInstantiationException {
- MetaDataEx extends Component> data = componentMap.get(type);
+ public final Component createComponent(ComponentType type) throws ComponentInstantiationException {
+ Lookup data = componentMap.get(type);
if (data == null) {
throw new IllegalArgumentException();
}
try {
- Class extends Component> cl = data.getComponentClass();
+ Class extends Component> cl = data.findAll(Class.class)
+ .filter(Component.class::isAssignableFrom)
+ .map(cls -> cls.asSubclass(Component.class))
+ .findFirst()
+ .orElseThrow();
return cl.getDeclaredConstructor().newInstance();
} catch (Exception ex) {
throw new ComponentInstantiationException(ex);
@@ -72,26 +75,30 @@ public Component createComponent(ComponentType type) throws ComponentInstantiati
}
@Override
- public Root createRootComponent(ComponentType type) throws ComponentInstantiationException {
- MetaDataEx extends Root> data = rootMap.get(type);
+ public final Root createRoot(ComponentType type) throws ComponentInstantiationException {
+ Lookup data = rootMap.get(type);
if (data == null) {
throw new IllegalArgumentException();
}
try {
- Class extends Root> cl = data.getComponentClass();
- return (Root) cl.getDeclaredConstructor().newInstance();
+ Class extends Root> cl = data.findAll(Class.class)
+ .filter(Root.class::isAssignableFrom)
+ .map(cls -> cls.asSubclass(Root.class))
+ .findFirst()
+ .orElseThrow();
+ return cl.getDeclaredConstructor().newInstance();
} catch (Exception ex) {
throw new ComponentInstantiationException(ex);
}
}
@Override
- public ComponentFactory.MetaData extends Component> getMetaData(ComponentType type) {
+ public final Lookup componentData(ComponentType type) {
return componentMap.get(type);
}
-
+
@Override
- public ComponentFactory.MetaData extends Root> getRootMetaData(ComponentType type) {
+ public final Lookup rootData(ComponentType type) {
return rootMap.get(type);
}
@@ -100,7 +107,7 @@ protected void add(String type, Class extends Component> cls) {
}
protected void add(String type, Data extends Component> info) {
- componentMap.put(ComponentType.of(type), info.toMetaData());
+ componentMap.put(ComponentType.of(type), info.toLookup());
}
protected void addRoot(String type, Class extends Root> cls) {
@@ -108,95 +115,39 @@ protected void addRoot(String type, Class extends Root> cls) {
}
protected void addRoot(String type, Data extends Root> info) {
- rootMap.put(ComponentType.of(type), info.toMetaData());
+ rootMap.put(ComponentType.of(type), info.toLookup());
}
public static Data data(Class cls) {
return new Data<>(cls);
}
- private static class MetaDataEx extends ComponentFactory.MetaData {
-
- private final Class cls;
- private final boolean test;
- private final boolean deprecated;
- private final ComponentType replacement;
- private final Lookup lookup;
-
- private MetaDataEx(Class cls,
- boolean test,
- boolean deprecated,
- ComponentType replacement,
- Lookup lookup) {
- this.cls = cls;
- this.test = test;
- this.deprecated = deprecated;
- this.replacement = replacement;
- this.lookup = lookup;
- }
-
- public Class getComponentClass() {
- return cls;
- }
-
- @Override
- public boolean isDeprecated() {
- return deprecated;
- }
-
- @Override
- public Optional findReplacement() {
- return Optional.ofNullable(replacement);
- }
-
- @Override
- public Lookup getLookup() {
- return lookup == null ? super.getLookup() : lookup;
- }
-
-
-
- }
-
public static class Data {
- private final Class cls;
- private boolean test;
- private boolean deprecated;
- private ComponentType replacement;
- private List