add simple default value versioning
This commit is contained in:
parent
d9214b91b6
commit
2bae6e06c0
2 changed files with 66 additions and 47 deletions
|
|
@ -13,7 +13,6 @@ import { createFilter, gainNode, getCompressor, getWorklet } from './helpers.mjs
|
||||||
import { map } from 'nanostores';
|
import { map } from 'nanostores';
|
||||||
import { logger } from './logger.mjs';
|
import { logger } from './logger.mjs';
|
||||||
import { loadBuffer } from './sampler.mjs';
|
import { loadBuffer } from './sampler.mjs';
|
||||||
import { velocity } from '../core/controls.mjs';
|
|
||||||
|
|
||||||
export const soundMap = map();
|
export const soundMap = map();
|
||||||
|
|
||||||
|
|
@ -25,38 +24,51 @@ export function getSound(s) {
|
||||||
return soundMap.get()[s];
|
return soundMap.get()[s];
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaults = new Map([
|
const defaultDefaultValues = {
|
||||||
['s', 'triangle'],
|
s: 'triangle',
|
||||||
['gain', 0.8],
|
gain: 0.8,
|
||||||
['postgain', 1],
|
postgain: 1,
|
||||||
['density', '.03'],
|
density: '.03',
|
||||||
['ftype', '12db'],
|
ftype: '12db',
|
||||||
['fanchor', 0],
|
fanchor: 0,
|
||||||
['resonance', 1],
|
resonance: 1,
|
||||||
['hresonance', 1],
|
hresonance: 1,
|
||||||
['bandq', 1],
|
bandq: 1,
|
||||||
['channels', [1, 2]],
|
channels: [1, 2],
|
||||||
['phaserdepth', 0.75],
|
phaserdepth: 0.75,
|
||||||
['shapevol', 1],
|
shapevol: 1,
|
||||||
['distortvol', 1],
|
distortvol: 1,
|
||||||
['delay', 0],
|
delay: 0,
|
||||||
['delayfeedback', 0.5],
|
delayfeedback: 0.5,
|
||||||
['delaytime', 0.25],
|
delaytime: 0.25,
|
||||||
['orbit', 1],
|
orbit: 1,
|
||||||
['i', 1],
|
i: 1,
|
||||||
['velocity', 1],
|
velocity: 1,
|
||||||
['fft', 8],
|
fft: 8,
|
||||||
]);
|
};
|
||||||
|
|
||||||
export function setDefault(key, value) {
|
let defaultControls = new Map(Object.entries(defaultDefaultValues));
|
||||||
defaults.set(key, value);
|
|
||||||
|
export function setDefaultValue(key, value) {
|
||||||
|
defaultControls.set(key, value);
|
||||||
}
|
}
|
||||||
|
export function getDefaultValue(key) {
|
||||||
export function setDefaults(defaultsobj) {
|
return defaultControls.get(key);
|
||||||
|
}
|
||||||
|
export function setDefaultValues(defaultsobj) {
|
||||||
Object.keys(defaultsobj).forEach((key) => {
|
Object.keys(defaultsobj).forEach((key) => {
|
||||||
setDefault(key, defaultsobj[key]);
|
setDefaultValue(key, defaultsobj[key]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
export function resetDefaultValues() {
|
||||||
|
defaultControls = new Map(Object.entries(defaultDefaultValues));
|
||||||
|
}
|
||||||
|
export function setVersionDefaults(version) {
|
||||||
|
resetDefaultValues();
|
||||||
|
if (version === '1.0') {
|
||||||
|
setDefaultValue('fanchor', 0.5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const resetLoadedSounds = () => soundMap.set({});
|
export const resetLoadedSounds = () => soundMap.set({});
|
||||||
|
|
||||||
|
|
@ -310,14 +322,14 @@ export const superdough = async (value, t, hapDuration) => {
|
||||||
}
|
}
|
||||||
// destructure
|
// destructure
|
||||||
let {
|
let {
|
||||||
s = defaults.get('s'),
|
s = getDefaultValue('s'),
|
||||||
bank,
|
bank,
|
||||||
source,
|
source,
|
||||||
gain = defaults.get('gain'),
|
gain = getDefaultValue('gain'),
|
||||||
postgain = defaults.get('postgain'),
|
postgain = getDefaultValue('postgain'),
|
||||||
density = defaults.get('density'),
|
density = getDefaultValue('density'),
|
||||||
// filters
|
// filters
|
||||||
fanchor = defaults.get('fanchor'),
|
fanchor = getDefaultValue('fanchor'),
|
||||||
drive = 0.69,
|
drive = 0.69,
|
||||||
// low pass
|
// low pass
|
||||||
cutoff,
|
cutoff,
|
||||||
|
|
@ -326,7 +338,7 @@ export const superdough = async (value, t, hapDuration) => {
|
||||||
lpdecay,
|
lpdecay,
|
||||||
lpsustain,
|
lpsustain,
|
||||||
lprelease,
|
lprelease,
|
||||||
resonance = defaults.get('resonance'),
|
resonance = getDefaultValue('resonance'),
|
||||||
// high pass
|
// high pass
|
||||||
hpenv,
|
hpenv,
|
||||||
hcutoff,
|
hcutoff,
|
||||||
|
|
@ -334,7 +346,7 @@ export const superdough = async (value, t, hapDuration) => {
|
||||||
hpdecay,
|
hpdecay,
|
||||||
hpsustain,
|
hpsustain,
|
||||||
hprelease,
|
hprelease,
|
||||||
hresonance = defaults.get('hresonance'),
|
hresonance = getDefaultValue('hresonance'),
|
||||||
// band pass
|
// band pass
|
||||||
bpenv,
|
bpenv,
|
||||||
bandf,
|
bandf,
|
||||||
|
|
@ -342,36 +354,36 @@ export const superdough = async (value, t, hapDuration) => {
|
||||||
bpdecay,
|
bpdecay,
|
||||||
bpsustain,
|
bpsustain,
|
||||||
bprelease,
|
bprelease,
|
||||||
bandq = defaults.get('bandq'),
|
bandq = getDefaultValue('bandq'),
|
||||||
channels = defaults.get('channels'),
|
channels = getDefaultValue('channels'),
|
||||||
//phaser
|
//phaser
|
||||||
phaser,
|
phaser,
|
||||||
phaserdepth = defaults.get('phaserdepth'),
|
phaserdepth = getDefaultValue('phaserdepth'),
|
||||||
phasersweep,
|
phasersweep,
|
||||||
phasercenter,
|
phasercenter,
|
||||||
//
|
//
|
||||||
coarse,
|
coarse,
|
||||||
crush,
|
crush,
|
||||||
shape,
|
shape,
|
||||||
shapevol = defaults.get('shapevol'),
|
shapevol = getDefaultValue('shapevol'),
|
||||||
distort,
|
distort,
|
||||||
distortvol = defaults.get('distortvol'),
|
distortvol = getDefaultValue('distortvol'),
|
||||||
pan,
|
pan,
|
||||||
vowel,
|
vowel,
|
||||||
delay = defaults.get('delay'),
|
delay = getDefaultValue('delay'),
|
||||||
delayfeedback = defaults.get('delayfeedback'),
|
delayfeedback = getDefaultValue('delayfeedback'),
|
||||||
delaytime = defaults.get('delaytime'),
|
delaytime = getDefaultValue('delaytime'),
|
||||||
orbit = defaults.get('orbit'),
|
orbit = getDefaultValue('orbit'),
|
||||||
room,
|
room,
|
||||||
roomfade,
|
roomfade,
|
||||||
roomlp,
|
roomlp,
|
||||||
roomdim,
|
roomdim,
|
||||||
roomsize,
|
roomsize,
|
||||||
ir,
|
ir,
|
||||||
i = defaults.get('i'),
|
i = getDefaultValue('i'),
|
||||||
velocity = defaults.get('velocity'),
|
velocity = getDefaultValue('velocity'),
|
||||||
analyze, // analyser wet
|
analyze, // analyser wet
|
||||||
fft = defaults.get('fft'), // fftSize 0 - 10
|
fft = getDefaultValue('fft'), // fftSize 0 - 10
|
||||||
compressor: compressorThreshold,
|
compressor: compressorThreshold,
|
||||||
compressorRatio,
|
compressorRatio,
|
||||||
compressorKnee,
|
compressorKnee,
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,13 @@ export function Repl({ embedded = false }) {
|
||||||
window.location.hash = '#' + code2hash(code);
|
window.location.hash = '#' + code2hash(code);
|
||||||
setDocumentTitle(code);
|
setDocumentTitle(code);
|
||||||
const viewingPatternData = getViewingPatternData();
|
const viewingPatternData = getViewingPatternData();
|
||||||
|
try {
|
||||||
|
const metadata = getMetadata(code);
|
||||||
|
setVersionDefaults(metadata.version);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error parsing metadata..');
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
const data = { ...viewingPatternData, code };
|
const data = { ...viewingPatternData, code };
|
||||||
let id = data.id;
|
let id = data.id;
|
||||||
const isExamplePattern = viewingPatternData.collection !== userPattern.collection;
|
const isExamplePattern = viewingPatternData.collection !== userPattern.collection;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue