From 8ccad911be98c1c9a6272806446fb64ac090506d Mon Sep 17 00:00:00 2001 From: Stephen Date: Tue, 26 Sep 2023 02:32:25 +0200 Subject: [PATCH] Moves soundstage-player to elements/ --- .../soundstage-instrument.css | 0 .../soundstage-instrument.html | 0 .../soundstage-instrument.js | 0 elements/soundstage-player.js | 2 + .../soundstage-player}/module.js | 24 +++--- elements/sparky/param.js | 84 ------------------- test.html | 6 +- test/tests.css | 28 +++++++ test/tests.js | 53 ++++++++++++ 9 files changed, 98 insertions(+), 99 deletions(-) rename elements/{ => soundstage-instrument}/soundstage-instrument.css (100%) rename elements/{ => soundstage-instrument}/soundstage-instrument.html (100%) rename elements/{ => soundstage-instrument}/soundstage-instrument.js (100%) create mode 100644 elements/soundstage-player.js rename {player => elements/soundstage-player}/module.js (89%) delete mode 100755 elements/sparky/param.js create mode 100755 test/tests.css create mode 100755 test/tests.js diff --git a/elements/soundstage-instrument.css b/elements/soundstage-instrument/soundstage-instrument.css similarity index 100% rename from elements/soundstage-instrument.css rename to elements/soundstage-instrument/soundstage-instrument.css diff --git a/elements/soundstage-instrument.html b/elements/soundstage-instrument/soundstage-instrument.html similarity index 100% rename from elements/soundstage-instrument.html rename to elements/soundstage-instrument/soundstage-instrument.html diff --git a/elements/soundstage-instrument.js b/elements/soundstage-instrument/soundstage-instrument.js similarity index 100% rename from elements/soundstage-instrument.js rename to elements/soundstage-instrument/soundstage-instrument.js diff --git a/elements/soundstage-player.js b/elements/soundstage-player.js new file mode 100644 index 0000000..4eaab86 --- /dev/null +++ b/elements/soundstage-player.js @@ -0,0 +1,2 @@ + +export { default } from './soundstage-player/module.js'; diff --git a/player/module.js b/elements/soundstage-player/module.js similarity index 89% rename from player/module.js rename to elements/soundstage-player/module.js index d901d32..f957af1 100644 --- a/player/module.js +++ b/elements/soundstage-player/module.js @@ -1,16 +1,16 @@ -import Stream, { frames } from '../../fn/modules/stream.js'; -import { formatTime } from '../../fn/modules/time.js'; -import observe from '../../fn/observer/observe.js'; -import Observer from '../../fn/observer/observer.js'; -import delegate from '../../dom/modules/delegate.js'; -import createBoolean from '../../dom/modules/element/create-boolean.js'; -import createTokenList from '../../dom/modules/element/create-token-list.js'; -import element, { getInternals } from '../../dom/modules/element.js'; -import events from '../../dom/modules/events.js'; -import request from '../../dom/modules/request.js'; -import { getSequenceDuration } from '../modules/sequencer/get-duration.js' -import Soundstage from '../modules/soundstage.js'; +import Stream, { frames } from '../../../fn/modules/stream.js'; +import { formatTime } from '../../../fn/modules/time.js'; +import observe from '../../../fn/observer/observe.js'; +import Observer from '../../../fn/observer/observer.js'; +import delegate from '../../../dom/modules/delegate.js'; +import createBoolean from '../../../dom/modules/element/create-boolean.js'; +import createTokenList from '../../../dom/modules/element/create-token-list.js'; +import element, { getInternals } from '../../../dom/modules/element.js'; +import events from '../../../dom/modules/events.js'; +import request from '../../../dom/modules/request.js'; +import { getSequenceDuration } from '../../modules/sequencer/get-duration.js' +import Soundstage from '../../modules/soundstage.js'; export default element('soundstage-player', { diff --git a/elements/sparky/param.js b/elements/sparky/param.js deleted file mode 100755 index 40f3a84..0000000 --- a/elements/sparky/param.js +++ /dev/null @@ -1,84 +0,0 @@ -import { cue, register } from '../../../sparky/module.js'; -import { notify, observe, Target, getPath } from '../../../fn/module.js'; -import { isAudioParam, automato__, getValueAtTime } from '../../module.js'; - -const DEBUG = true;//window.DEBUG; -const assign = Object.assign; -const fadeTime = 0.003; - -function ParamRenderer(node, audioNode, name) { - this.label = "ParamRenderer" - this.node = node; - this.audioNode = audioNode; - this.audioParam = audioNode[name]; - this.audioParamName = name; - - if (DEBUG && !isAudioParam(this.audioParam)) { - throw new Error('Property "' + name + '" is not an AudioParam'); - } - - // Set up param observer - this.unobserve = observe(name, (value) => { - // Param value observers are passed the value of the - // param at the sound output time corresponding to the - // DOM time of the frame + 16ms - this.value = value; - if (this.cued) { return; } - this.cued = true; - cue(this); - }, audioNode, this.audioParam); - - // Immediately notify values. - notify(this.audioNode, name, getValueAtTime(this.audioParam, 0)); - - // Observe node - node.addEventListener('input', (e) => { - const t = this.audioNode.context.currentTime; - automato__(this.audioNode, this.audioParamName, t, 'hold', null, null, notify); - automato__(this.audioNode, this.audioParamName, t + fadeTime, 'linear', e.target.value, null, notify); - //console.log('CHANGE', this.audioParamName, e.target.value) - }); -} - -assign(ParamRenderer.prototype, { - fire: function() { - this.cued = false; - - if (this.node.value !== this.value) { - this.node.value = this.value; - } - - this.renderedValue = this.value; - }, - - stop: function() { - this.unobserve(); - }, - - renderCount: 0 -}); - -register('param', function(node, params) { - const parts = /(?:(.*)\.)?([\w\d-_$]+)$/.exec(params[0]); - const path = parts[1]; - const name = parts[2]; - - var renderer; - - return this.tap((object) => { - // Path is just a property name currently. Todo: if we need it, get - // a proper path. As it is, this is more better (quicker) for the time being. - const target = Target(path ? getPath(path, object) : object); - - if (!target || !target.context) { - throw new Error('fn="param" object at path "' + path + '" not an AudioNode'); - } - - if (!target[name]) { - throw new Error('fn="param" AudioNode has no param "' + name + '"'); - } - - renderer && renderer.stop(); - renderer = new ParamRenderer(node, target, name); - }); -}); diff --git a/test.html b/test.html index dd524e0..94546ba 100755 --- a/test.html +++ b/test.html @@ -2,7 +2,7 @@ Tests - +

@@ -18,7 +18,7 @@