mirror of
https://codeberg.org/uzu/strudel
synced 2026-07-23 21:47:16 -04:00
add a function that generates a minimal preset for the currently displayed WAM
This commit is contained in:
@@ -23,6 +23,9 @@ export const getWamInstance = (key) => {
|
||||
let hostInit;
|
||||
// maps wam keys to init promises
|
||||
let instanceInit = {};
|
||||
// maps wam keys to a list of params that are automated
|
||||
let automatedWamParams = {};
|
||||
export const getAutomatedWamParams = () => automatedWamParams;
|
||||
|
||||
// host groups of WAMs can interact with one another, but not directly across groups
|
||||
const hostGroupId = 'strudel';
|
||||
@@ -77,6 +80,13 @@ export const param = register('param', function (param, value, pat) {
|
||||
return pat.addTrigger((time, hap) => {
|
||||
const { wam } = hap.value;
|
||||
const i = getWamInstance(wam);
|
||||
|
||||
// save param automation
|
||||
if (!automatedWamParams[wam]) {
|
||||
automatedWamParams[wam] = {};
|
||||
}
|
||||
automatedWamParams[wam][param] = true;
|
||||
|
||||
i.audioNode.scheduleEvents({
|
||||
time: time,
|
||||
type: 'wam-automation',
|
||||
|
||||
@@ -7,7 +7,7 @@ import React, { useCallback, useLayoutEffect, useRef, useState } from 'react';
|
||||
import { loadedSamples } from './Repl';
|
||||
import { Reference } from './Reference';
|
||||
import { themes, themeColors } from './themes.mjs';
|
||||
import { getWamInstances } from '@strudel.cycles/wam';
|
||||
import { getAutomatedWamParams, getWamInstances } from '@strudel.cycles/wam';
|
||||
|
||||
export function Footer({ context }) {
|
||||
// const [activeFooter, setActiveFooter] = useState('console');
|
||||
@@ -69,6 +69,7 @@ export function Footer({ context }) {
|
||||
if (isZen) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<footer className="bg-lineHighlight z-[20]">
|
||||
<div className="flex justify-between px-2">
|
||||
@@ -208,6 +209,7 @@ export function Footer({ context }) {
|
||||
))}
|
||||
</select>
|
||||
<div id="wam-gui"></div>
|
||||
<button onClick={() => wamPreset()}>preset</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@@ -241,8 +243,17 @@ function linkify(inputText) {
|
||||
return replacedText;
|
||||
}
|
||||
|
||||
let wamGui = null;
|
||||
let displayedWam = null;
|
||||
|
||||
const showWAM = async (e) => {
|
||||
if (displayedWam !== null && wamGui !== null) {
|
||||
displayedWam.destroyGui(wamGui);
|
||||
}
|
||||
|
||||
const wam = getWamInstances()[e.target.value];
|
||||
displayedWam = e.target.value;
|
||||
|
||||
const gui = await wam.createGui();
|
||||
const guiDiv = document.getElementById('wam-gui');
|
||||
guiDiv.innerHTML = '';
|
||||
@@ -257,3 +268,24 @@ const showWAM = async (e) => {
|
||||
guiDiv.appendChild(input);
|
||||
}
|
||||
};
|
||||
|
||||
const wamPreset = async () => {
|
||||
const wam = getWamInstances()[displayedWam];
|
||||
|
||||
const params = await wam.audioNode.getParameterInfo();
|
||||
const values = await wam.audioNode.getParameterValues();
|
||||
|
||||
let preset = {}
|
||||
const automatedParams = getAutomatedWamParams()[displayedWam];
|
||||
|
||||
for (let id of Object.keys(params)) {
|
||||
if (automatedParams[id]) {
|
||||
continue
|
||||
}
|
||||
if (values[id].value.toFixed(6) == params[id].defaultValue.toFixed(6)) {
|
||||
continue
|
||||
}
|
||||
preset[id] = values[id].value;
|
||||
}
|
||||
console.log("preset", preset);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user