From 45afcec61580e86d6f9ade8db9c4c3159b60f433 Mon Sep 17 00:00:00 2001 From: Stephen Date: Fri, 29 Sep 2023 16:20:51 +0200 Subject: [PATCH] Give tick context --- nodes/instrument.js | 9 --------- nodes/tick.js | 30 +++++++++++++----------------- nodes/voice.js | 11 +++++++++++ 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/nodes/instrument.js b/nodes/instrument.js index 83cc312..40ac20c 100755 --- a/nodes/instrument.js +++ b/nodes/instrument.js @@ -45,19 +45,10 @@ 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; -// Register node constructors in NodeGraph -NodeGraph.register('mix', Mix); -NodeGraph.register('samples', Samples); -NodeGraph.register('tone', Tone); - export const config = { tuning: 440 }; diff --git a/nodes/tick.js b/nodes/tick.js index 807c313..72f1118 100755 --- a/nodes/tick.js +++ b/nodes/tick.js @@ -29,11 +29,11 @@ A float?? Todo. An AudioParam representing output gain. **/ -import noop from '../../fn/modules/noop.js'; +import noop from '../../fn/modules/noop.js'; import { floatToFrequency, toNoteNumber } from '../../midi/modules/data.js'; import { dB48 } from '../modules/constants.js'; -var assign = Object.assign; +const assign = Object.assign; // Define @@ -47,17 +47,17 @@ export const defaults = { // Tick -export default function Tick(audio, options) { +export default function Tick(context, options) { if (!Tick.prototype.isPrototypeOf(this)) { - return new Tick(audio, options); + return new Tick(context, options); } var settings = assign({}, defaults, options); - var oscillator = audio.createOscillator(); - var filter = audio.createBiquadFilter(); - var gain = audio.createGain(); - var output = audio.createGain(); + var oscillator = context.createOscillator(); + var filter = context.createBiquadFilter(); + var gain = context.createGain(); + var output = context.createGain(); //var merger = audio.createChannelMerger(2); //NodeGraph.call(this, { @@ -117,7 +117,7 @@ export default function Tick(audio, options) { } oscillator.type = 'square'; - oscillator.frequency.setValueAtTime(300, audio.currentTime); + oscillator.frequency.setValueAtTime(300, context.currentTime); oscillator.start(); oscillator.connect(filter); @@ -128,8 +128,8 @@ export default function Tick(audio, options) { //output.connect(merger, 0, 0); //output.connect(merger, 0, 1); - this.gain = output.gain; - + this.context = context; + this.gain = output.gain; this.resonance = settings.resonance; this.decay = settings.decay; //this.gain = settings.gain; @@ -138,12 +138,8 @@ export default function Tick(audio, options) { .start(time, note, velocity) Todo: move parameters to be properties of tick object, echoing other signal generators **/ - this.start = function(time, number, level) { - var frequency = typeof number === 'string' ? - floatToFrequency(440, toNoteNumber(number)) : - floatToFrequency(440, number) ; - - schedule(time || audio.currentTime, frequency, level, this.decay, this.resonance); + this.start = function(time, frequency, level) { + schedule(time || context.currentTime, frequency, level, this.decay, this.resonance); return this; }; diff --git a/nodes/voice.js b/nodes/voice.js index 3088aed..6e2ea1b 100755 --- a/nodes/voice.js +++ b/nodes/voice.js @@ -37,6 +37,17 @@ import { assignSettingz__ } from '../modules/assign-settings.js'; import { floatToFrequency, toNoteNumber } from '../../midi/modules/data.js'; import { create } from '../modules/constructors.js'; +import Mix from './mix.js'; +import Samples from './sample-set.js'; +import Tick from './tick.js'; +import Tone from './tone.js'; + +// Register node constructors in NodeGraph +NodeGraph.register('mix', Mix); +NodeGraph.register('samples', Samples); +NodeGraph.register('tick', Tick); +NodeGraph.register('tone', Tone); + const assign = Object.assign; const define = Object.defineProperties; const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;