xxxxxxxxxx
let velocity;
let intervalInSeconds;
let tonic;
let tonicName;
let variations = [];
let newVariation = true;
let melody = [];
let melodyIndex = 0;
let numberOfMelodies = 0;
let beat = -1;
let scaleIndex;
let note;
let developmentalTechniques = []
function setup()
{
createCanvas(windowWidth, windowHeight);
colorMode(HSB);
background(0);
textAlign(CENTER)
intervalInSeconds = random(0.2, 0.5);
soundLoop = new p5.SoundLoop(onSoundLoop, intervalInSeconds);
synth = new p5.MonoSynth();
synth.amp(1);
synth.disconnect();
reverb = new p5.Reverb();
reverb.amp(1);
reverb.process(synth, 1.5, 2);
reverb.drywet(0.7);
let chance = round(random(0,6));
//chance = 0;
scale = scaleCollection[chance];
scaleName = scaleNameCollection[chance];
tonic = round(random(0, 11));
//tonic = 0;
tonicName = basicScale[tonic];
let octave = 0;
for (let i = 0; i < 9; i++)
{
for (let u = 0; u < 7; u++)
{
finalScale.push(scale[u] + tonic + octave);
}
octave += 12;
}
for (let i = 0; i < 12; i++)
{
variations.push([]);
}
//generateBar(motive);
//motive = [17, 'p', 'p', 'p']
//developmentalTechniques= [generateBar(variations[0]), inversion(motive, variations[0]), changeThePitch(motive, variation1), conjunction(motive, variation1), truncation(motive, variation1), retrograde(motive, variation1), inversion(motive, variation1), sequence(motive, variation1)]
createRefrain();
}
function onSoundLoop(timeFromNow)
{
if (beat == 7 && increase == true)
{
melodyIndex ++;
melodyIndex %=2;
increase = false;
}
else if (beat != 7)
{
increase = true;
}
beat ++;
beat %= 8;
scaleIndex = melody[melodyIndex][beat]
if (scaleIndex == 'p')
{
note = 'pause';
velocity = -1;
}
else
{
note = chromaticScale[scaleIndex]
velocity = random(0.3, 0.5);
}
bgColor = scaleIndex - ((round((scaleIndex / 12) - 0.5))*12);
background(bgColor*33, 45, 90);
text(note, windowWidth/2, windowHeight/2);
text(tonicName + ' ' + scaleName, 100, 50);
synth.play(note, velocity, timeFromNow, 1/4);
synth.play(note, velocity, timeFromNow, 1/4);
//print('beat: ' + beat);
//print('mI: ' + melodyIndex);
}
function draw()
{
if (melodyIndex == 0 && newVariation == true)
{
//melody.splice(1, 1)
//numberOfMelodies--;
//variations[0] = [];
//generateBar(variations[0]);
newVariation = false;
}
else if (melodyIndex == 1)
{
newVariation = true;
}
soundLoop.start();
}