Skip to content

Commit

Permalink
Remove circular reference
Browse files Browse the repository at this point in the history
  • Loading branch information
stephband committed Sep 29, 2023
1 parent 8ccad91 commit 18f4af1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
30 changes: 17 additions & 13 deletions nodes/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,18 @@ output by the `.connect()` and `.disconnect()` methods.
import Privates from '../../fn/modules/privates.js';
import { logGroup, logGroupEnd } from '../modules/print.js';
import { connect, disconnect } from '../modules/connect.js';
import nativeConstructors from '../modules/constructors.js';
import baseConstructors from '../modules/constructors.js';
import Sink from './sink.js';

import Mix from './mix.js';
import SampleSet from './sample-set.js';
import Tone from './tone.js';

const DEBUG = false;//window.DEBUG;
const DEBUG = window.DEBUG && window.DEBUG.soundstage !== false;
const assign = Object.assign;
const define = Object.defineProperties;
const seal = Object.seal;

export const constructors = assign({
mix: Mix,
samples: SampleSet,
tone: Tone,
}, nativeConstructors);
const constructors = assign({
sink: Sink
}, baseConstructors);


function create(type, context, settings, transport) {
const Constructor = constructors[type];
Expand Down Expand Up @@ -140,7 +136,7 @@ function createConnection(nodes, data) {
}

export default function NodeGraph(context, data, transport) {
if (DEBUG) { logGroup('mixin ', 'GraphNode', data.nodes && data.nodes.map((n) => n.type).join(', ')); }
if (window.DEBUG) { logGroup('mixin ', 'GraphNode', data.nodes && data.nodes.map((n) => n.type).join(', ')); }

const privates = Privates(this);
privates.outputId = data.output || 'output' ;
Expand Down Expand Up @@ -210,7 +206,7 @@ export default function NodeGraph(context, data, transport) {
seal(nodes);
data.connections && data.connections.reduce(createConnection, nodes);

if (DEBUG) { logGroupEnd(); }
if (window.DEBUG) { logGroupEnd(); }
}

assign(NodeGraph.prototype, {
Expand Down Expand Up @@ -250,3 +246,11 @@ assign(NodeGraph.prototype, {
return privates.nodes && privates.nodes[id];
}
});

NodeGraph.register = function register(name, constructor) {
if (constructors[name]) {
throw new Error('Soundstage: constructor "' + name+ '" already registered in NodeGraph');
}

constructors[name] = constructor;
};
18 changes: 11 additions & 7 deletions nodes/instrument.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,23 @@ import isDefined from '../../fn/modules/is-defined.js';
import Privates from '../../fn/modules/privates.js';
import { logGroup, logGroupEnd } from './print.js';
import Voice, { defaults as voiceDefaults } from './voice.js';
import NodeGraph, { constructors } from './graph.js';
import Pool from '../modules/pool.js';
import NodeGraph from './graph.js';
import Pool from '../modules/pool.js';
import { assignSettingz__ } from '../modules/assign-settings.js';
import { connect, disconnect } from '../modules/connect.js';

import Mix from './mix.js';
import Samples from './sample-set.js';
import Tone from './tone.js';

const DEBUG = window.DEBUG;
const assign = Object.assign;
const define = Object.defineProperties;

import Sink from './sink.js';
assign(constructors, {
sink: Sink
});
// Register node constructors in NodeGraph
NodeGraph.register('mix', Mix);
NodeGraph.register('samples', Samples);
NodeGraph.register('tone', Tone);

export const config = {
tuning: 440
Expand All @@ -62,7 +66,7 @@ const graph = {
nodes: [
{ id: 'sink', type: 'sink' },
{ id: 'pitch', type: 'constant', data: { offset: 0 } },
{ id: 'detune', type: 'gain', data: { gain: 100 } },
{ id: 'detune', type: 'gain', data: { gain: 100 } },
{ id: 'modulation', type: 'constant', data: { offset: 120 } },
{ id: 'output', type: 'gain', data: {
channelInterpretation: 'speakers',
Expand Down
4 changes: 2 additions & 2 deletions nodes/sample-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ import { requestBuffer } from '../modules/request-buffer.js';
import { requestData } from '../modules/request-data.js';
import { assignSettingz__ } from '../modules/assign-settings.js';
import { fadeInFromTime, fadeOutToTime, releaseAtTime } from '../modules/param.js';
import NodeGraph from './graph.js';
import Playable from '../modules/playable.js';
import NodeGraph from './graph.js';
import Playable from '../modules/playable.js';

const DEBUG = window.DEBUG;
const assign = Object.assign;
Expand Down
2 changes: 1 addition & 1 deletion nodes/voice.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ assign(Voice.prototype, Playable.prototype, NodeGraph.prototype, {

// Start command target
const commands = privates.commands;

console.log(note, frequency, commands);
// Quick out
if (!commands) { return this; }

Expand Down

0 comments on commit 18f4af1

Please sign in to comment.