Skip to content

Commit

Permalink
support multiple nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoxor committed Jun 15, 2024
1 parent a22e78b commit fbf427a
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions src/renderer/logic/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}) {
Expand Down

0 comments on commit fbf427a

Please sign in to comment.