Thanks a lot GoToLoop!
Your explanation about numeric conversions was a ray of light in the dark, thanks a lot, clear and right to the point.
So what follows is a new release with your suggestions inside or, at least, what I understood from your suggestions
!
THis new clock now is alive and ticking, thanks to the Minim library.
Just one more thing: minim seems to be picky wiith aiff (and wav) files. The file as downloaded from www.freesound.org was not understood at all by it, while working with other programs including Quicktime. Just reading it in Audacity and saving without modifications made the magic. Any idea about this? I found another guy in this forum had the same issue.
Here is the new clock and thank you all here for the help! By the way, which is the magic to have the source treated as source, as I saw in other discussions?
-------------------------------------------------------------------
// Analog Clock
// by Angelo Caruso
//
// Sound file
//
http://www.freesound.org/people/gherat/sounds/139635/
// Thanks to gherat
import ddf.minim.*;
int frameSec = 24;
int maxX = 500, maxY = 500;
int centX = maxX/2, centY = maxX/2;
PImage bg;
int mediumGrey = 180;
int oldsec;
Minim minim;
AudioSample player;
void setup() {
// Init System
size(maxX, maxY);
frameRate(frameSec);
smooth();
background(mediumGrey);
// Design the clock background
clockBackground();
bg=get();
//Try sound
minim= new Minim(this);
player = minim.loadSample("Clock.aiff");
oldsec=second();
}
void draw() {
//Redraw the Clock Static part
// with suggestions by GoToLoop
int h,sec;
final float hdeg, mdeg, sdeg;
background(bg);
//What time is it?
if ((h=hour()) > 12) h-=12;
hdeg=h/12f*360;
mdeg=minute()*6;
sec=second();
sdeg=sec*6;
// Draw ShortHand
drawHand(int(hdeg), 'h');
// Draw LongHand
drawHand(int(mdeg), 'm');
// Draw vlongHand
drawHand(int(sdeg), 's');
if (sec!=oldsec) {
player.trigger();
oldsec=sec;
}
}
void drawHand (int degree, char hand) {
float teta, len=0.0;
int x, y;
teta=radians(degree-90);
if(hand=='h') {
stroke(250,0,0);
strokeWeight(80);
point(centX,centY);
strokeWeight(20);
len=130;
}
if(hand=='m') {
stroke(0,250,0);
strokeWeight(60);
point(centX,centY);
strokeWeight(15);
len=150;
}
if(hand=='s') {
stroke(0,0,250);
strokeWeight(30);
point(centX,centY);
strokeWeight(5);
len=180;
}
x=int(centX+len*cos(teta));
y=int(centY+len*sin(teta));
line(centX, centY, x, y);
// player.trigger();
}
void clockBackground() {
fill(225);
ellipse(centX, centY, 400, 400);
strokeWeight(60);
stroke(200);
point(centX,centY);
strokeWeight(35);
stroke(50,50,250);
point(centX+180,centY);
point(centX,centY+180);
point(centX-180,centY);
point(centX,centY-180);
}
void stop() {
player.close();
super.stop();
}
-------------------------------------------------------------------