diff --git a/com/danitheskunk/skunkworks/audio/nodes/Node.java b/com/danitheskunk/skunkworks/audio/nodes/Node.java new file mode 100644 index 0000000..530bee6 --- /dev/null +++ b/com/danitheskunk/skunkworks/audio/nodes/Node.java @@ -0,0 +1,52 @@ +package com.danitheskunk.skunkworks.audio.nodes; + +import com.danitheskunk.skunkworks.audio.AudioBuffer; + +public abstract class Node { + private int inCount; + private int outCount; + private boolean[] isOutConnected; + private Node[] inConnections; + private int[] inConnectionSlots; + + public Node(int inCount, int outCount) { + this.inCount = inCount; + this.outCount = outCount; + this.isOutConnected = new boolean[outCount]; + this.inConnections = new Node[inCount]; + this.inConnectionSlots = new int[inCount]; + if(outCount > 1) { + throw new RuntimeException("more than one out connection not yet" + + " " + + "allowed, needs handling in getBuffer to only process once"); + } + } + + public static void connect(Node src, int srcSlot, Node dst, int dstSlot) { + if(srcSlot < 0 || srcSlot >= src.outCount) { + throw new RuntimeException("invalid srcSlot"); + } + if(dstSlot < 0 || dstSlot >= dst.inCount) { + throw new RuntimeException("invalid dstSlot"); + } + if(src.isOutConnected[srcSlot]) { + throw new RuntimeException("src node slot already connected"); + } + if(dst.inConnections[dstSlot] != null) { + throw new RuntimeException("dst node slot already connected"); + } + src.isOutConnected[srcSlot] = true; + dst.inConnections[dstSlot] = src; + dst.inConnectionSlots[dstSlot] = srcSlot; + } + + public int getInCount() { + return inCount; + } + + public int getOutCount() { + return outCount; + } + + public abstract AudioBuffer getBuffer(int slot); +}