xxxxxxxxxx
117
var instrumental;
var amp;
var myFont;
var jumpButton;
//array
var visualSound = [];
function preload() {
instrumental = loadSound('Moby - Porcelain.mp3',loaded);
myFont = loadFont('Hoefler Text Regular.ttf');
}
function loaded() {
instrumental.play()
}
function setup() {
createCanvas(700, 490);
jumpButton = createButton ('forward >>');
jumpButton.mousePressed(jumpSong);
amp = new p5.Amplitude();
}
function jumpSong (){
//var lan = song.duration ();
instrumental.jump (37);
}
function draw(){
background (52,78,57);
console.log(instrumental.currentTime());
push();
if(instrumental.currentTime() >= 41 && instrumental.currentTime() <= 42){
fill(220,120,57);
}
if(instrumental.currentTime() >= 43.5 && instrumental.currentTime() <= 44.5){
fill(220,120,57);
}
if(instrumental.currentTime() >= 46 && instrumental.currentTime() <= 47){
fill(220,120,57);
}
if(instrumental.currentTime() >= 51 && instrumental.currentTime() <= 51.5){
fill(220,120,57);
}
if(instrumental.currentTime() >= 53.5 && instrumental.currentTime() <= 54){
fill(220,120,57);
}
if(instrumental.currentTime() >= 56 && instrumental.currentTime() <= 56.5){
fill(220,120,57);
}
textSize(90);
textFont(myFont);
text('Hey,',40, 102);
pop();
push();
if(instrumental.currentTime() >= 48.5 && instrumental.currentTime() <= 49){
fill(220,120,57);
}
if(instrumental.currentTime() >= 58.5 && instrumental.currentTime() <= 59.5){
fill(220,120,57);
}
textSize(160);
textFont(myFont);
text('woman,',40, 240);
pop();
push();
if(instrumental.currentTime() >= 49.5 && instrumental.currentTime() <= 50.5){
fill(220,120,57);
}
if(instrumental.currentTime() >= 59.5 && instrumental.currentTime() <= 60.5){
fill(220,120,57);
}
textSize(100);
textFont(myFont);
text('It’s Alright,',45, 370);
pop();
// console.log (instrumental.currentTime() + " " + instrumental.isPlaying())
//visual of the sounds
var vol = amp.getLevel();
visualSound.push(vol);
stroke(220,120,57);
strokeWeight(1.5);
noFill();
//fill (220,120,57);
beginShape();
for (var i = 0; i < visualSound.length; i++){
var y = map (visualSound[i],0, 1, 280,0);
vertex(i,y);
}
endShape();
if (visualSound.length > width){
visualSound.splice(0,1);
}
}