xxxxxxxxxx
90
// Variables for the timer
let time;
let pulse = 1500;
let offbeat = 8; // This might need to be adjusted depending on your desired timing
let beat = 4;
let measure = 0;
let cycleCount = 0; // New variable to count cycles for longer sounds
// Sounds
let Abmajor;
let Dbmajor;
let Ebmajor;
let Bbminor;
let longSound1; // New longer sound
let longSound2; // Another new longer sound
function preload() {
Abmajor = loadSound('CAb.mp3');
Dbmajor = loadSound('DAb.mp3');
Ebmajor = loadSound('EBb.mp3');
Bbminor = loadSound('DBb.mp3');
longSound1 = loadSound('long1.mp3'); // Load new longer sound
longSound2 = loadSound('long2.mp3'); // Load another new longer sound
console.log('sounds loaded');
}
function setup() {
background(220);
createCanvas(400, 400);
setBPM(90, 0);
time = millis();
}
function draw() {
let chords = [1, 2, 3, 4];
let passtime = millis() - time;
let playchord = floor(random(1, 5)); // Ensures integer index from 1 to 4
console.log("Time: ", time, " Passtime: ", passtime, " Playchord: ", playchord);
if (passtime > pulse) {
console.log('Pulse reached');
time = millis();
beat++;
console.log('Beat: ', beat);
}
if (beat >= 4) {
switch (playchord) {
case 1:
Abmajor.play();
console.log('Playing: Abmajor');
break;
case 2:
Dbmajor.play();
console.log('Playing: Dbmajor');
break;
case 3:
Ebmajor.play();
console.log('Playing: Ebmajor');
break;
case 4:
Bbminor.play();
console.log('Playing: Bbminor');
break;
}
beat = 0;
measure++;
console.log('Measure: ', measure);
}
if (measure >= 8) {
measure = 0; // Reset measure after every 8 counts
cycleCount++; // Increment the cycle count
console.log('Cycle Count: ', cycleCount);
}
// Play longer sounds every 7 cycles
if (cycleCount >= 7) {
console.log('Playing longer sound on Playchord: ', playchord);
if (playchord === 1) {
longSound1.play(); // Play longer sound
} else if (playchord === 2) {
longSound2.play(); // Play another longer sound
}
cycleCount = 0; // Reset the cycle counter
}
}