Final Update #3 – The coding part

Having finalized the conceptual part of my project, it’s time to code! Over the break I spent quite some time trying to figure out how to get two preloaded songs mapped out on the slide corresponding to the volume of each track.

Here’s what I have of the sketch so far. I’m adding buttons because this part of my project is due before the pComp part and I won’t have enough of the physical side done in time to present in a few days.

I still need to add images of the album covers fading into each other above the slider to emphasize what’s going on. And if I have time, I’d like to be able to add up to six songs per set. That reminds me I need to get that “Next Set” button working too! A nice background would be nice to have as well.

let playbutton, nextbutton, backbutton;
let slider;
let soundGroupPath1 = ['assets/sounds/BabyDidABadBadThing.wav', 'assets/sounds/LaGrange.wav'];
let soundGroup1 = [];
let soundGroupPath2 = ['assets/sounds/RunThroughTheJungle.mp3', 'assets/sounds/TheOldManDownTheRoad.mp3'];
let soundGroup2 = [];
function preload()
{
for(let i =0; i<soundGroupPath1.length; i ++) {
soundGroup1[i] = loadSound(soundGroupPath1[i])
}
for(let i =0; i<soundGroupPath2.length; i ++) {
soundGroup2[i] = loadSound(soundGroupPath2[i])
}
// album = loadImage('assets/images/BabyDidABadBadThing.jpg');
// album1 = loadImage('assets/images/BoogieChillun.jpg');
}
function setup()
{
createCanvas(350, 300);
background(255);
// slider
slider = createSlider (0, 255, 100);
slider.position(100,100);
// stop sound to prevent it from playing automatically
// soundtrack.stop();
// play button
playbutton = createButton('Play');
playbutton.position(120, 150);
playbutton.mousePressed(playsound);
//next set button
nextbutton = createButton('Next Set');
nextbutton.position(140, 180);
nextbutton.mousePressed(nextsetsound);
// stop button
stopbutton = createButton('Stop');
stopbutton.position(180, 150);
stopbutton.mousePressed(stopsound);
}
function draw()
{
checkSliderAndUpdateSound();
}
function checkSliderAndUpdateSound(){
// console.log(slider.value());
let slidervalue = slider.value();
let volumeOne = map(slidervalue , 0, 255, 0, 0.5);
let volumeTwo = map(slidervalue , 0, 255, 1, 0);
if(soundGroup1[0].isPlaying() == true && soundGroup1[1].isPlaying() == true){
// if(soundGroup1[0].isPlaying() == true ){
soundGroup1[0].setVolume(volumeOne);
soundGroup1[1].setVolume(volumeTwo);
}
if(soundGroup2[0].isPlaying() == true && soundGroup2[1].isPlaying() == true){
soundGroup2[0].setVolume(volumeOne);
soundGroup2[1].setVolume(volumeTwo);
}
}
function playsound()
{
if(soundGroup1[0].isPlaying() == false)
{
for(let i =0; i<soundGroupPath1.length; i ++) {
// soundGroup1[i].play();
soundGroup1[i].loop();
// soundGroup1[i].setVolume(1);
}
}
}
function stopsound()
{
if(soundGroup1[0].isPlaying() == true)
{
for(let i =0; i<soundGroupPath1.length; i ++) {
soundGroup1[i].pause();
}
}
}
function nextsetsound()
{
if(soundGroup1[0].isPlaying() == true)
{
for(let i=0; i<soundGroupPath2.length; i ++) {
soundGroup2[i].loop();
}
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *