Skip to content

Commit

Permalink
Progress on GroupNodes logic
Browse files Browse the repository at this point in the history
  • Loading branch information
maximecb committed Jun 17, 2021
1 parent 0ba1de3 commit 7191b18
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 36 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# NoiseCraft

Browser-based visual programming language and platform for sound synthesis.
Browser-based visual programming language and platform for sound synthesis and music making.
Once NoiseCraft is more functional and stable, it will be open sourced under the GPLv2.
When the app is deployed it will be live at https://noisecraft.app.

Expand Down
66 changes: 31 additions & 35 deletions public/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,15 @@ export class DeleteNodes extends Action
}
}

// Group the selected nodes into a module
/**
* Group the selected nodes into a user-created module
* Currently, the way this works is that the selected nodes will become
* a black box with inputs and outputs corresponding to the nodes/ports it's
* connected to outside the group. Eventually, we will also make it possible
* to rename module input and output ports after the module is created. We
* could make it possible to expose specific knobs inside the group on the
* module's UI.
* */
export class GroupNodes extends Action
{
constructor(nodeIds)
Expand All @@ -488,20 +496,23 @@ export class GroupNodes extends Action
// Create a set from the node ids so we can test membership quickly
let groupSet = new Set(this.nodeIds)

function tupleInList(list, tuple)
function findInList(list, tuple)
{
for (let tuple of list)
for (let idx = 0; idx < list.length; ++idx)
{
if (treeEq(tupleB, tupleA))
return true;
if (treeEq(list[idx], tuple))
return idx;
}

return false;
return -1;
}

// List of source ports we are connected to
let srcPorts = [];

// List of inputs for the group
let ins = [];

// For each node in the group
for (let nodeId of this.nodeIds)
{
Expand All @@ -516,9 +527,11 @@ export class GroupNodes extends Action
let srcPort = node.ins[dstPort];
let [srcNode, portIdx] = srcPort;

if (!groupSet.has(srcNode) && !tupleInList(srcPorts, srcPort))
// If this connection leads to an outside port which we aren't tracking yet
if (!groupSet.has(srcNode) && findInList(srcPorts, srcPort) == -1)
{
srcPorts.push(srcPort);
ins.push({ name: 'in' + ins.length, default: 0 });
}
}
}
Expand All @@ -534,6 +547,10 @@ export class GroupNodes extends Action



// TODO: update connections exiting the group

// TODO: update connections leaving the group




Expand All @@ -545,7 +562,13 @@ export class GroupNodes extends Action
y: Infinity,
ins: {},
params: {},
nodes: {}
nodes: {},
schema: {
ins: ins,
outs: [], // TODO
params: [],
description: 'user-created module'
},
};

// Add the new module node to the state
Expand All @@ -568,33 +591,6 @@ export class GroupNodes extends Action
module.x = Math.min(module.x, node.x);
module.y = Math.min(module.y, node.y);
}


// TODO: update connections exiting the group

// TODO: update connections leaving the group



/*
// For each node in the model
for (let nodeId in model.state.nodes)
{
let nodeState = model.state.nodes[nodeId];
// For each input-side connection
for (let dstPort in nodeState.ins)
{
let [srcId, srcPort] = nodeState.ins[dstPort];
// If the source node is being deleted
if (this.nodeIds.indexOf(srcId) != -1)
{
delete nodeState.ins[dstPort];
}
}
}
*/
}
}

Expand Down

0 comments on commit 7191b18

Please sign in to comment.