You can add input parameters to your ditty by adding the following comment after the declaration of a input parameter:
input.xxx; // value=y, min=y, max=y, step=y
When one or more input parameters are defined, a block with sliders is visible at the left of your ditty.
dittytoy.net/syntax#input-parameters
#dittytoy #tutorial
Log in to post a comment.
// #09 Input Parameters. DittyToy 2022.
// The MIT License.
//
// https://dittytoy.net/ditty/90607d08dc
//
// You can add input parameters to your ditty by adding the following comment after the declaration of a input parameter:
//
// input.xxx; // value=y, min=y, max=y, step=y
//
// When one or more input parameters are defined, a block with sliders is visible at the left of your ditty.
//
// https://dittytoy.net/syntax#input-parameters
//
// melody synth
input.synth0Osc1 = 3; // min=0, max=3, step=1 (Sin, Saw, Square, Tri)
input.synth0Osc1offset = 0; // min=0, max=36, step=0.01
input.synth0Osc1xenv = 0; // min=0, max=1, step=0.01
input.synth0Osc1vol = 0.9; // min=0, max=1, step=0.01
input.synth0Osc2 = 2; // min=0, max=3, step=1 (Sin, Saw, Square, Tri)
input.synth0Osc2offset = 16; // min=0, max=36, step=0.01
input.synth0Osc2xenv = 0; // min=0, max=1, step=0.01
input.synth0Osc2vol = 0.05; // min=0, max=1, step=0.01
input.synth0Osc2det = 0.2; // min=0, max=1, step=0.01
input.synth0NoiseVol = 0; // min=0, max=1, step=0.01
// bass synth
input.synth1Osc1 = 3; // min=0, max=3, step=1 (Sin, Saw, Square, Tri)
input.synth1Osc1offset = 0; // min=0, max=36, step=0.01
input.synth1Osc1xenv = 0; // min=0, max=1, step=0.01
input.synth1Osc1vol = 0.7; // min=0, max=1, step=0.01
input.synth1Osc2 = 0; // min=0, max=3, step=1 (Sin, Saw, Square, Tri)
input.synth1Osc2offset = 0; // min=0, max=36, step=0.01
input.synth1Osc2xenv = 0.3; // min=0, max=1, step=0.01
input.synth1Osc2vol = 0.3; // min=0, max=1, step=0.01
input.synth1Osc2det = 0.2; // min=0, max=1, step=0.01
input.synth1NoiseVol = 0; // min=0, max=1, step=0.01
// tick
input.synth2Osc1 = 3; // min=0, max=3, step=1 (Sin, Saw, Square, Tri)
input.synth2Osc1offset = 0; // min=0, max=36, step=0.01
input.synth2Osc1xenv = 0; // min=0, max=1, step=0.01
input.synth2Osc1vol = 0.1; // min=0, max=1, step=0.01
input.synth2Osc2 = 0; // min=0, max=3, step=1 (Sin, Saw, Square, Tri)
input.synth2Osc2offset = 0; // min=0, max=36, step=0.01
input.synth2Osc2xenv = 1; // min=0, max=1, step=0.01
input.synth2Osc2vol = 0.5; // min=0, max=1, step=0.01
input.synth2Osc2det = 0; // min=0, max=1, step=0.01
input.synth2NoiseVol = 0.1; // min=0, max=1, step=0.01
const oscillators = [
(value) => Math.sin(value * (Math.PI * 2)),
(value) => 2 * (value % 1) - 1,
(value) => (value % 1) < 0.5 ? 1 : -1,
(value) => {
const v = (value % 1) * 4;
return v < 2 ? v - 1 : 3 - v;
}
];
const osc = synth.def(
class {
constructor(options) {
this.phase1 = 0;
this.phase2 = 0;
}
process(note, env, tick, options) {
this.phase1 += midi_to_hz(note + options.osc1offset) * ditty.dt * (env.value ** options.osc1xenv);
this.phase2 += midi_to_hz(note + options.osc2offset) * ditty.dt * (1 + options.osc2det) * (env.value ** options.osc2xenv);
let sample = oscillators[options.osc1](this.phase1) * options.osc1vol;
sample += oscillators[options.osc2](this.phase2) * options.osc2vol;
if (options.noiseVol) {
sample += (2 * Math.random() - 1) * options.noiseVol;
}
return sample * env.value;
}
}, { osc1: 0, osc1offset: 0, osc1xenv: 0, osc1vol: 0.5, osc2: 0, osc2offset: 0, osc2xenv: 0, osc2vol: 0.5, osc2det: 0, noiseVol: 0 }
);
loop( (loopCount) => {
const note = scale(c3, scales.minor_pentatonic, 2).ring(loopCount);
osc.play(note, {
pan: Math.random() * 2 - 1,
attack: 0.02,
amp: 0.5,
osc1: () => input.synth0Osc1,
osc1offset: () => input.synth0Osc1offset,
osc1xenv: () => input.synth0Osc1xenv,
osc1vol: () => input.synth0Osc1vol,
osc2: () => input.synth0Osc2,
osc2offset: () => input.synth0Osc2offset,
osc2xenv: () => input.synth0Osc2xenv,
osc2vol: () => input.synth0Osc2vol,
osc2det: () => input.synth0Osc2det,
noiseVol: () => input.synth0NoiseVol });
sleep(Math.random() < 0.5 ? 0.25 : 0.5);
});
loop( (loopCount) => {
const note = scale(c2, scales.minor_pentatonic, 1).choose();
osc.play(note, {
pan: Math.random() * 2 - 1,
attack: 0.01,
release: 0.5,
osc1: () => input.synth1Osc1,
osc1offset: () => input.synth1Osc1offset,
osc1xenv: () => input.synth1Osc1xenv,
osc1vol: () => input.synth1Osc1vol,
osc2: () => input.synth1Osc2,
osc2offset: () => input.synth1Osc2offset,
osc2xenv: () => input.synth1Osc2xenv,
osc2vol: () => input.synth1Osc2vol,
osc2det: () => input.synth1Osc2det,
noiseVol: () => input.synth1NoiseVol });
sleep(Math.random() < 0.5 ? 0.25 : 0.5);
});
loop( (loopCount) => {
osc.play(c4, {
attack: 0.01,
release: 0.05,
amp: loopCount % 4 == 0 ? 1 : 0.25,
osc1: () => input.synth2Osc1,
osc1offset: () => input.synth2Osc1offset,
osc1xenv: () => input.synth2Osc1xenv,
osc1vol: () => input.synth2Osc1vol,
osc2: () => input.synth2Osc2,
osc2offset: () => input.synth2Osc2offset,
osc2xenv: () => input.synth2Osc2xenv,
osc2vol: () => input.synth2Osc2vol,
osc2det: () => input.synth2Osc2det,
noiseVol: () => input.synth2NoiseVol });
sleep(0.25);
});