diff --git a/index.mjs b/index.mjs index 138298ef6..b2214dcc4 100644 --- a/index.mjs +++ b/index.mjs @@ -15,4 +15,4 @@ export * from './packages/transpiler/index.mjs'; export * from './packages/webaudio/index.mjs'; export * from './packages/webdirt/index.mjs'; export * from './packages/xen/index.mjs'; -export * from './packages/wam/index.mjs'; \ No newline at end of file +export * from './packages/wam/index.mjs'; diff --git a/packages/wam/index.mjs b/packages/wam/index.mjs index 9753fade3..2b5ec37f5 100644 --- a/packages/wam/index.mjs +++ b/packages/wam/index.mjs @@ -1,6 +1,6 @@ -import { register, Pattern, toMidi, valueToMidi } from '@strudel.cycles/core'; +import { register, Pattern, toMidi, valueToMidi } from '@strudel.cycles/core'; import { getAudioContext } from '@strudel.cycles/webaudio'; -import {initializeWamHost} from '@webaudiomodules/sdk' +import { initializeWamHost } from '@webaudiomodules/sdk'; // this is a map of all loaded WebAudioModules let wams = {}; @@ -10,83 +10,84 @@ let wamInstances = {}; export const getWamInstances = () => wamInstances; // has the WAM host been initialized? -let initialized = false +let initialized = false; // host groups of WAMs can interact with one another, but not directly across groups -const hostGroupId = "strudel" +const hostGroupId = 'strudel'; export const loadWAM = async function (name, url, what) { - if (!initialized) { - await initializeWamHost(getAudioContext(), hostGroupId) - initialized = true - } + if (!initialized) { + await initializeWamHost(getAudioContext(), hostGroupId); + initialized = true; + } - if (wamInstances[name]) { - return wamInstances[name] - } - - if (!wams[url]) { - const { default: WAM } = await import( - /* @vite-ignore */ - url); + if (wamInstances[name]) { + return wamInstances[name]; + } - wams[url] = WAM - } - - const instance = new wams[url](hostGroupId, getAudioContext()); - - await instance.initialize() + if (!wams[url]) { + const { default: WAM } = await import( + /* @vite-ignore */ + url + ); - instance.audioNode.connect(getAudioContext().destination); + wams[url] = WAM; + } - wamInstances[name] = instance + const instance = new wams[url](hostGroupId, getAudioContext()); - return instance -} + await instance.initialize(); + + instance.audioNode.connect(getAudioContext().destination); + + wamInstances[name] = instance; + + return instance; +}; export const loadwam = loadWAM; export const loadWam = loadWAM; export const wam = register('wam', function (name, pat) { - return pat.onTrigger((time, hap) => { - let i = wamInstances[name] + return pat.onTrigger((time, hap) => { + let i = wamInstances[name]; - if (!i) { - return - } + if (!i) { + return; + } - let note = toMidi(hap.value.note); - let velocity = hap.context?.velocity ?? 0.75; - let endTime = time + hap.duration.valueOf(); + let note = toMidi(hap.value.note); + let velocity = hap.context?.velocity ?? 0.75; + let endTime = time + hap.duration.valueOf(); - i.audioNode.scheduleEvents({ - type: "wam-midi", - data: {bytes: [0x90, note, velocity]}, - time: time, - }) + i.audioNode.scheduleEvents({ + type: 'wam-midi', + data: { bytes: [0x90, note, velocity] }, + time: time, + }); - i.audioNode.scheduleEvents({ - type: "wam-midi", - data: {bytes: [0x80, note, 0]}, - time: endTime - }) + i.audioNode.scheduleEvents({ + type: 'wam-midi', + data: { bytes: [0x80, note, 0] }, + time: endTime, }); }); +}); export const param = register('param', function (wam, param, pat) { - return pat.onTrigger((time, hap) => { - let i = wamInstances[wam]; - if (!i) { - return; - } - i.audioNode.scheduleEvents({ - time: time, - type: 'wam-automation', - data: { - id: param, - normalized: false, - value: hap.value, - }, - }); - }, false); - }); \ No newline at end of file + return pat.onTrigger((time, hap) => { + let i = wamInstances[wam]; + if (!i) { + return; + } + i.audioNode.scheduleEvents({ + time: time, + type: 'wam-automation', + data: { + id: param, + normalized: false, + value: hap.value, + }, + }); + }, false); +}); diff --git a/website/src/repl/Footer.jsx b/website/src/repl/Footer.jsx index 67a82c60e..e2b073acf 100644 --- a/website/src/repl/Footer.jsx +++ b/website/src/repl/Footer.jsx @@ -201,7 +201,12 @@ export function Footer({ context }) { {activeFooter === 'wams' && (
{Object.keys(getWamInstances()).length} loaded: - +
)} @@ -242,14 +247,13 @@ const showWAM = async (e) => { const guiDiv = document.getElementById('wam-gui'); guiDiv.innerHTML = ''; guiDiv.appendChild(gui); - - const params = await wam.audioNode.getParameterInfo() + + const params = await wam.audioNode.getParameterInfo(); for (let id of Object.keys(params)) { const param = params[id]; const input = document.createElement('div'); - input.innerHTML = `: type ${param.type}, min ${param.minValue}, max ${param.maxValue}` + input.innerHTML = `: type ${param.type}, min ${param.minValue}, max ${param.maxValue}`; guiDiv.appendChild(input); } - -} \ No newline at end of file +}; diff --git a/website/src/repl/Repl.jsx b/website/src/repl/Repl.jsx index a1eea7fa2..9fd53242c 100644 --- a/website/src/repl/Repl.jsx +++ b/website/src/repl/Repl.jsx @@ -46,7 +46,7 @@ const modules = [ import('@strudel.cycles/serial'), import('@strudel.cycles/soundfonts'), import('@strudel.cycles/csound'), - import('@strudel.cycles/wam') + import('@strudel.cycles/wam'), ]; evalScope(