Skip to content

Commit

Permalink
Categorize nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
nahkd123 committed Sep 12, 2023
1 parent 0dbf24e commit 9e3370f
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 4 deletions.
1 change: 1 addition & 0 deletions modules/engine/src/nodes/ADSREnvelopeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export class ADSREnvelopeNode implements INode<ADSREnvelopeNode, ADSR> {
return {
typeId: ADSREnvelopeNode.ID,
label: "ADSR Envelope",
category: "Synthesizing",
createNew(project, context, nodeId) {
return new ADSREnvelopeNode(nodeId, project.workspace.audio);
},
Expand Down
1 change: 1 addition & 0 deletions modules/engine/src/nodes/AudioSourceNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class AudioSourceNode implements INode<AudioSourceNode, AudioSourceNodeDa
return {
typeId: AudioSourceNode.ID,
label: "Audio Source",
category: "Inputs/Outputs",
createNew(project, context, nodeId) {
return new AudioSourceNode(nodeId, project.workspace.audio);
},
Expand Down
1 change: 1 addition & 0 deletions modules/engine/src/nodes/ConstantNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class ConstantNode implements INode<ConstantNode, number> {
return {
typeId: ConstantNode.ID,
label: "Constant",
category: "Inputs/Outputs",
createNew(project, context, nodeId) {
return new ConstantNode(nodeId, project.workspace.audio);
},
Expand Down
1 change: 1 addition & 0 deletions modules/engine/src/nodes/GainNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class GainNode implements INode<GainNode, number> {
return {
typeId: GainNode.ID,
label: "Gain",
category: "Audio Effects",
createNew(project, context, nodeId) {
return new GainNode(nodeId, project.workspace.audio);
},
Expand Down
1 change: 1 addition & 0 deletions modules/engine/src/nodes/INode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export type NodeFromDataFactory<T extends INode<T, TData>, TData> = (
export interface NodeFactory<T extends INode<T, TData>, TData> {
readonly typeId: Identifier;
readonly label: string;
readonly category?: string;
readonly hidden?: boolean;
createNew: NewNodeFactory<T, TData>;
createExisting: NodeFromDataFactory<T, TData>;
Expand Down
1 change: 1 addition & 0 deletions modules/engine/src/nodes/NotesSourceNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class NotesSourceNode implements INode<NotesSourceNode, NotesSourceNodeDa
return {
typeId: NotesSourceNode.ID,
label: "Notes Source",
category: "Inputs/Outputs",
createNew(workspace, context, nodeId) {
return new NotesSourceNode(nodeId);
},
Expand Down
1 change: 1 addition & 0 deletions modules/engine/src/nodes/PluckNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export class PluckNode implements INode<PluckNode, any> {
return {
typeId: PluckNode.ID,
label: "Pluck",
category: "Instruments",
createNew(project, context, nodeId) {
return new PluckNode(nodeId, project.workspace.audio);
},
Expand Down
1 change: 1 addition & 0 deletions modules/engine/src/nodes/SpeakerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class SpeakerNode implements INode<SpeakerNode, any> {
return {
typeId: SpeakerNode.ID,
label: "Speaker Output",
category: "Inputs/Outputs",
createNew(project, context, nodeId) {
return new SpeakerNode(nodeId, context.audioOut);
},
Expand Down
1 change: 1 addition & 0 deletions modules/engine/src/nodes/UnpackNoteNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export class UnpackNoteNode implements INode<UnpackNoteNode, UnpackNoteNodeData>
return {
typeId: UnpackNoteNode.ID,
label: "Unpack Note",
category: "Synthesizing",
createNew(project, context, nodeId) {
return new UnpackNoteNode(nodeId, project.workspace.audio);
},
Expand Down
1 change: 1 addition & 0 deletions modules/engine/src/nodes/group/GroupNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export class GroupNode implements INode<GroupNode, GroupNodeSavedData> {
return {
typeId: GroupNode.ID,
label: "Group",
category: "Specials",
createNew(project, context, nodeId) {
return new GroupNode(nodeId, project.workspace.audio);
},
Expand Down
1 change: 1 addition & 0 deletions modules/engine/src/nodes/oscillators/SineOscillatorNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export class SineOscillatorNode implements INode<SineOscillatorNode, SineOscilla
return {
typeId: SineOscillatorNode.ID,
label: "Sine Oscillator",
category: "Synthesizing",
createNew(project, context, nodeId) {
return new SineOscillatorNode(nodeId, project.workspace.audio);
},
Expand Down
18 changes: 17 additions & 1 deletion modules/ui/src/components/contextmenus/ContextMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ onUnmounted(() => {
<template>
<div class="context-menu" ref="root" :style="{ left: `${props.x}px`, top: `${props.y}px` }">
<div class="content">
<div class="entry" v-for="entry in props.menu">
<div class="entry" v-for="entry in props.menu" :class="{ submenu: !!entry.submenu }">
<div class="label" @click="entryClicked($event, entry)">{{ entry.label }}</div>
</div>
</div>
Expand Down Expand Up @@ -85,10 +85,26 @@ onUnmounted(() => {
line-height: 1.6;
border-radius: 4px;
transition: 0.1s background-color;
white-space: pre;
position: relative;
&:hover {
background-color: #ffffff1f;
}
&.submenu {
padding-right: 16px;
&::after {
content: '';
position: absolute;
right: 4px; top: 50%;
translate: 0 -50%;
border-left: 6px solid #ffffff;
border-top: 6px solid transparent;
border-bottom: 6px solid transparent;
}
}
}
}
}
Expand Down
13 changes: 10 additions & 3 deletions modules/ui/src/components/workspace/nodes/NodesEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,14 @@ function addNode(event: MouseEvent) {
const workspaceBox = workspaceUI?.getBoundingClientRect();
contextMenuX.value = event.pageX - (workspaceBox?.x ?? 0);
contextMenuY.value = event.pageY - (workspaceBox?.y ?? 0);
const entries: ContextMenuEntry[] = [];
const categories: Map<string, ContextMenuEntry[]> = new Map();
getWorkspace().workspace.registries.nodeFactories.forEach((id, factory) => {
if (factory.hidden) return;
let category = categories.get(factory.category ?? "Uncategorized");
if (!category) categories.set(factory.category ?? "Uncategorized", category = []);
entries.push({
category.push({
label: factory.label,
async onClick() {
const createTask = factory.createNew(
Expand All @@ -214,7 +217,11 @@ function addNode(event: MouseEvent) {
},
});
});
contextMenu.value = entries;
contextMenu.value = [...categories.keys()].map(v => ({
label: v,
submenu: categories.get(v) ?? []
}));
}
function nodeClick(event: PointerEvent, cb: (node: INode<any, any>, port?: IPort<any>, portType?: "input" | "output") => any) {
Expand Down

0 comments on commit 9e3370f

Please sign in to comment.