mirror of
https://codeberg.org/uzu/strudel
synced 2026-07-24 05:57:17 -04:00
fix code style
This commit is contained in:
@@ -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';
|
||||
export * from './packages/wam/index.mjs';
|
||||
|
||||
+61
-60
@@ -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);
|
||||
});
|
||||
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);
|
||||
});
|
||||
|
||||
@@ -201,7 +201,12 @@ export function Footer({ context }) {
|
||||
{activeFooter === 'wams' && (
|
||||
<div className="break-normal w-full px-4 dark:text-white text-stone-900">
|
||||
<span>{Object.keys(getWamInstances()).length} loaded:</span>
|
||||
<select onChange={(e) => showWAM(e)}><option key="--">--</option>{Object.keys(getWamInstances()).map(w => <option key={w}>{w}</option>)}</select>
|
||||
<select onChange={(e) => showWAM(e)}>
|
||||
<option key="--">--</option>
|
||||
{Object.keys(getWamInstances()).map((w) => (
|
||||
<option key={w}>{w}</option>
|
||||
))}
|
||||
</select>
|
||||
<div id="wam-gui"></div>
|
||||
</div>
|
||||
)}
|
||||
@@ -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 = `<label>${id}</label>: type ${param.type}, min ${param.minValue}, max ${param.maxValue}`
|
||||
input.innerHTML = `<label>${id}</label>: type ${param.type}, min ${param.minValue}, max ${param.maxValue}`;
|
||||
guiDiv.appendChild(input);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user