We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSound,  Music Libraries › if (...) play this song
Page Index Toggle Pages: 1
if (...) play this song (Read 618 times)
if (...) play this song
Jan 30th, 2009, 9:33pm
 
hello, this is my first time using libraries.

i want to play a song only at certain hours of the day. i think i'm almost there, but it's not really working. does anyone know what the problem could be? thank you!


import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;

Minim minim;
AudioPlayer song;

//clock face
PImage img1;

//hands
PImage img2;
PImage img3;
PImage img4;

float s;
float m;
float h;

void setup(){
 size(1000,654);
 smooth();
 img1 = loadImage("face.jpg");
 img2 = loadImage("hours.png");
 img3 = loadImage("minutes.png");
 img4 = loadImage("seconds.png");

 minim = new Minim(this);
 song = minim.loadFile("whateversong.mp3");
 //song.play();
}


void draw(){  

 s = map(second(), 0, 60, 0, TWO_PI) - HALF_PI;
 m = map(minute() + norm(second(), 0, 60), 0, 60, 0, TWO_PI) - PI;
 h = map(hour() + norm(minute(), 0, 60), 0, 24, 0, TWO_PI * 2) - PI;

 //clock face
 image(img1, 0, 0, 1000, 654);

 //hour
 pushMatrix();
 translate(495, 410);
 rotate(h);
 image(img2, -15, -15);
 popMatrix();

 //minute
 pushMatrix();
 translate(495, 410);
 rotate(m);
 image(img3, -16, -16);
 popMatrix();

 //second
 pushMatrix();
 translate(495, 410);
 rotate(s);
 image(img4, -16, -25);
 popMatrix();
 
 audio();
}



void audio(){

if ((m==5) || (m==22) || (m==23) || (m==24) || (m==25)){
 song.play();
 song.close();
 minim.stop();  
 super.stop();
}
else{
minim.stop();
super.stop();
}


}
Page Index Toggle Pages: 1