4 #include <fltk/Widget.h>
5 #include <fltk/events.h>
10 #include "metronome.h"
16 Metronome::Metronome(int x
, int y
, int w
, int h
, const char* label
= 0) : fltk::Widget(x
, y
, w
, h
, label
) {
28 int Metronome::handle(int event
){
32 void Metronome::draw(){
35 //setcolor(fltk::color(r,g,b));
36 //fillrect(2,2,w()-4,h()-4);
38 setcolor(fltk::WHITE
);
39 int X
= last_beat
%N
*(w()-4)/N
+2;
42 fillrect(X
,2,W
,h()-4);
46 //setcolor(fltk::color(r,g,b));
47 //fillrect(X+W/2-W2/2,h()/2-H2/2,W2,H2);
49 //setcolor(fltk::BLACK);
50 //int C = (getascent()-getdescent())/2;
51 //drawtext(label(),X+W/2-getwidth(label())/2,h()/2+C);
55 //div N is the greatest divisor of N less than or equal to sqrt(N)
58 for(int i
=1; i
<=sqrt(N
); i
++){
69 void Metronome::update(int tick
){
70 int now_beat
= tick
/TICKS_PER_BEAT
;
72 if(now_beat
!= last_beat
){
73 int step
= last_beat
- now_beat
;
77 snprintf(buf
,16,"%d",now_beat
%N
+ plus
);
83 else if(now_beat
%n
== 0){
94 void Metronome::set_N(int zN
){