From fbf427a3d519be3f8303c25fc4249b1e1fcad24f Mon Sep 17 00:00:00 2001 From: Geoxor <34042825+Geoxor@users.noreply.github.com> Date: Sat, 15 Jun 2024 06:31:53 +0300 Subject: [PATCH] support multiple nodes --- src/renderer/logic/audio.ts | 47 ++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/src/renderer/logic/audio.ts b/src/renderer/logic/audio.ts index 44eb95a0..86d43b0a 100644 --- a/src/renderer/logic/audio.ts +++ b/src/renderer/logic/audio.ts @@ -79,35 +79,38 @@ export class AmethystAudioNode { } public toggleBypass() { - if (this.isBypassed) { - this.connections.forEach(connection => { - const parent = this.getParentNode(); - const child = amethyst.player.nodeManager.nodes.value.find(node => node.properties.id === connection.target); - - // Reconnect this node - child && this.post.connect(child.pre); - parent && parent.post.connect(this.pre); - parent && child && parent.post.disconnect(child.pre); + this.connections.forEach(connection => { + const parents = this.getParentNodes(); + const children = amethyst.player.nodeManager.nodes.value.filter(node => node.properties.id === connection.target); + + if (this.isBypassed) { + // Reconnect children back to this node + children.forEach(child => this.post.connect(child.pre)); + + // Reconnect parents back to this node + parents.forEach(parent => parent.post.connect(this.pre)); + + // Disconnect parents from children + parents.forEach(parent => children.forEach(child => parent.post.disconnect(child.pre))); this.isBypassed = false; - }); - } else { - this.connections.forEach(connection => { - const parent = this.getParentNode(); - const child = amethyst.player.nodeManager.nodes.value.find(node => node.properties.id === connection.target); + } else { + // Disconnect children back to this node + children.forEach(child => this.post.disconnect(child.pre)); - // Bypass (disconnect) this node - child && this.post.disconnect(child.pre); - parent && parent.post.disconnect(this.pre); - parent && child && parent.post.connect(child.pre); + // Disconnect parents back to this node + parents.forEach(parent => parent.post.disconnect(this.pre)); + + // Connect parents from children + parents.forEach(parent => children.forEach(child => parent.post.connect(child.pre))); this.isBypassed = true; - }); - } + } + }); } - public getParentNode(){ - return amethyst.player.nodeManager.nodes.value.find(node => node.connectedTo.some(node => node.properties.id === this.properties.id)); + public getParentNodes(){ + return amethyst.player.nodeManager.nodes.value.filter(node => node.connectedTo.some(node => node.properties.id === this.properties.id)); } public updatePosition(newPosition: {x: number, y: number}) {