xxxxxxxxxx
274
let TL = TotalSerialism.Translate;
let TF = TotalSerialism.Transform;
let Gn = TotalSerialism.Generative;
TL.setRoot('D');
TL.setScale('dorian');
let s1, s2;
let sound1, sound2;
let isActive = true;
function setup(){
s1 = createSlider(0, 1, 0.5, 0);
s2 = createSlider(0, 1, 0.5, 0);
console.log(TF.unique(TL.toScale(Gn.spread(36))))
console.log(TL.getSettings())
// sound1 = new Smear(-1);
// sound2 = new Smear(1);
// sound1 = new Squiggle(0);
// sound2 = new Squiggle(1);
// sound1 = new Mosaic(-1);
// sound2 = new Mosaic(1);
sound1 = new Paint(0);
// sound2 = new Paint(1);
// sound1 = new Glass(0);
// sound1.dispose();
// sound2.dispose();
userStartAudio();
}
function draw(){
sound1.update(s1.value());
// sound2.update(s2.value());
if (isActive){
outputVolume(1, 5);
} else {
outputVolume(0.25, 5);
}
}
function Glass(out){
this.osc = new p5.Oscillator(1, 'triangle');
this.osc.disconnect();
this.osc.start();
this.lfo = new p5.Oscillator(0.5, 'triangle');
this.lfo.disconnect();
this.lfo.start();
this.lfo.scale(-1,1,0,1);
this.osc.amp(this.lfo);
this.filter = new p5.Filter();
this.filter.process(this.osc);
this.filter.freq(1000);
this.filter.disconnect();
this.adsr = new p5.Envelope(0.001, 1, 0.4, 0);
// this.adsr.setADSR(0.001, 0.5, 0, 0);
this.delay = new p5.Delay();
this.delay.process(this.filter, 0.3123, 0.5)
this.delay.drywet(0.5);
this.notes = [2,4,5,7,9,11,12,14,16,17,19,21,23,24,26,28,29,31,33,35,36];
this.detune = 0;
this.note = (time) => {
let note = this.notes[int(Math.random()*this.notes.length)];
// let i = this.loop.iterations % this.phrase.length;
// let note = this.phrase[i];
let f = midiToFreq(note + 48);
this.osc.freq(f, 0, time);
this.lfo.freq(f * (this.detune + 0.5), 0, time);
this.adsr.triggerAttack(this.osc, time);
}
this.loop = new p5.SoundLoop(this.note, 1);
this.loop.start();
this.phrase = [];
this.update = (v) => {
this.detune = v * 0.5;
this.loop.interval = (1-v) * 0.5 + 0.1;
this.filter.freq(midiToFreq(v*30+60))
// this.phrase = TL.toScale(Gn.spread(8, 48, 50+(v*36)));
// this.loop.interval = (1-v)*0.05+0.231;
// this.adsr.setADSR(0.001, (1-v)*0.4+0.05, 0, 0);
}
// this.value = (v) => {
// }
this.dispose = () => {
let nodes = [this.osc, this.filter, this.adsr];
for (let i=0; i<nodes.length; i++){
nodes[i].disconnect();
nodes[i].dispose();
}
}
}
function Paint(p){
this.superSaw = Array(3);
this.sum = new p5.Gain();
this.lfo = new p5.Pulse(1, 0.9);
this.filter = new p5.Filter();
this.reverb = new p5.Reverb(3, 2);
// this.drive = new p5.Distortion();
// this.delay = new p5.Delay();
this.lfo.start();
this.lfo.disconnect();
this.lfo.freq(7);
this.lfo.scale(-1,1,0,1);
for (i=0; i<this.superSaw.length; i++){
this.superSaw[i] = new p5.Oscillator('sawtooth');
this.superSaw[i].freq(60);
this.superSaw[i].pan(p);
this.superSaw[i].start();
this.superSaw[i].disconnect();
this.superSaw[i].amp(this.lfo);
this.sum.setInput(this.superSaw[i]);
// this.drive.process(this.oscBank[i], 0.005);
}
this.sum.disconnect();
this.filter.process(this.sum);
this.filter.freq(1500);
this.filter.disconnect();
this.reverb.process(this.filter);
this.reverb.drywet(0.5)
this.update = (v) => {
for (i=0; i<this.superSaw.length; i++){
let freq = midiToFreq(50 + ((i-1)*(v*0.4+0.01)));
this.superSaw[i].freq(freq, 1);
}
this.filter.freq(midiToFreq((1-v)*30+70))
this.lfo.freq(sin(PI*2)*5);
}
}
function Mosaic(p){
this.osc = new p5.Oscillator('sine');
this.osc.pan(p);
this.osc.start();
this.osc.disconnect();
this.adsr = new p5.Envelope();
this.adsr.setADSR(0.001, 0.2, 0, 0);
this.drive = new p5.Distortion();
this.drive.process(this.osc, 0.005);
this.drive.disconnect();
this.delay = new p5.Delay();
this.delay.process(this.drive, 0.316, 0.7, 2500);
this.delay.drywet(0.4);
this.note = (time) => {
let i = this.loop.iterations % this.phrase.length;
let note = this.phrase[i];
// console.log(i, note);
this.osc.freq(midiToFreq(note), 0, time);
this.adsr.triggerAttack(this.osc, time);
}
this.loop = new p5.SoundLoop(this.note, 0.231);
this.loop.start();
this.phrase = [];
this.update = (v) => {
this.phrase = TL.toScale(Gn.spread(8, 48, 50+(v*36)));
this.loop.interval = (1-v)*0.05+0.231;
this.adsr.setADSR(0.001, (1-v)*0.4+0.05, 0, 0);
}
this.dispose = () => {
this.loop.stop();
let nodes = [this.osc, this.adsr, this.drive, this.delay];
for (let i in nodes){
nodes[i].disconnect();
nodes[i].dispose();
}
}
}
function Smear(p){
this.noise = new p5.Noise('pink');
this.noise.pan(p);
this.lfo = new p5.Oscillator('sine');
this.drive = new p5.Distortion();
this.filter = new p5.Filter();
this.lfo.start();
this.lfo.freq(1);
this.lfo.scale(-1,1,0,0.8);
this.lfo.disconnect();
this.noise.start();
this.noise.amp(this.lfo);
this.noise.disconnect();
this.drive.process(this.noise, 0.01);
this.drive.disconnect();
this.filter.process(this.drive);
this.filter.freq(500);
this.update = (v) => {
this.lfo.freq(v*8+0.2);
this.filter.freq(midiToFreq(v*60+72));
}
this.dispose = () => {
let nodes = [this.noise, this.lfo, this.drive, this.filter];
for (let i in nodes){
nodes[i].disconnect();
nodes[i].dispose();
}
}
}
function Squiggle(p){
this.oscBank = new Array(3);
this.drive = new p5.Distortion();
// this.delay = new p5.Delay();
this.reverb = new p5.Reverb();
for (i=0; i<this.oscBank.length; i++){
this.oscBank[i] = new p5.Oscillator(1, 'sine');
this.oscBank[i].pan(p);
this.oscBank[i].start();
this.oscBank[i].disconnect();
this.drive.process(this.oscBank[i], 0.002);
}
// this.delay.process(this.drive, 0.1, 0.7);
// this.drive.disconnect();
this.reverb.process(this.drive, 5, 5);
this.update = (v) => {
for (i=0; i<this.oscBank.length; i++){
let f = midiToFreq( cos(v * 4 * PI) * (i-1) * 0.5 + 49)
this.oscBank[i].freq(f, 0.005)
}
this.reverb.amp(v * 6 + 0.5, 0.01);
}
this.update(0);
this.dispose = () => {
let nodes = [this.oscBank, this.drive, this.delay];
for (let i=0; i<nodes.length; i++){
nodes[i].disconnect();
nodes[i].dispose();
}
}
}