// bpm2 @cid "ABPa"; @name "bpm"; @dbname "ABPa"; @category "Unfiled"; @licon1 "bpmbig.bmp"; @sicon1 "bpmsmall.bmp"; int resx = 60; int resy = 120; int resh = 14; int resw = 40; drawReset(){ textattr(0,1,0); text(resx+10,resy+1,"reset"); frame(1,resx,resy,resx+resw,resy+resh,4); } inReset(int x, int y){ if(y < resy) return false; if(y > resy+resh) return false; if(x < resx) return false; if(x > resx + resw) return false; return true; } inInfo(int x, int y){ if(y > 12) return false; if(x < 148) return false; return true; } drawCnt(int cnt){ string c; textattr(0,1,0); if(cnt != 0) { c = "s"; } text(60,90, (cnt+1)+" tap"+c+" "); } drawAvg(string s){ textattr(2,1,0); text(50,30,s+" "); } drawLast(string s){ textattr(0,1,0); text(60,70,"last: "+s+" "); } main(){ int e,oldtime, cnt; float r; int starttime; string bmpinfo; cnt = -1; graph_on(); title("bpm"); drawReset(); bmpinfo="0c1f82044628618018e18618618614f22041f8"; bitmap(148,0,bmpinfo); drawAvg(" --.-- bpm"); bitmap(120,156,"280a008a800068ecc2864eaacaaa88ae6aeacaa64a"); while(e = event(1)){ if(e==2){ //pendown if( (!inReset(penx(),peny())) && (! inInfo(penx(),peny())) ) { r = 6000.0 / ((ticks()-oldtime)); oldtime = ticks(); cnt++; drawCnt(cnt); if(cnt > 0) { drawAvg(format((6000.0/(ticks()-starttime)*cnt) ,3)+" bpm"); drawLast(format(r,3)); } else { if(cnt == 0){ starttime = ticks(); oldtime = ticks(); } }//end cnt=0 } // end in tap region else { //at top of screen //reset or info if(inReset(penx(),peny())){ cnt = -1; starttime = ticks(); oldtime = ticks(); drawCnt(cnt); drawAvg(" --.-- bpm"); drawLast("--"); } if(inInfo(penx(),peny())){ alert("bpm by kirk israel\n\ntap anywhere to record beats.\n\nEMAIL-ME-WARE: please drop me a line at kisrael@alienbill.com"); } } }//end if tap }//end while }