I wanted to tap out a beat and find out how many beats per minute it is, and a quick glance turned up nothing too good for Mac OS X (though I am sure I'd seen something like it before); so, as I am wont to do, I wrote my own. Just run it in the terminal, tap out your rhythm. It only calculates for the last five beats (modify to your pleasure ...).
print "Hit '.' for each beat. Hit '.' to start, and
$| = 1;
my @times;
1 until getc();
push @times, time();
while (my $c = getc()) {
push @times, time();
printf "\rBPM: %d\n", ($#times * 60) / ($times[-1] - $times[0]);
shift @times while @times > 4;
last if $c eq "\n";
}
BEGIN {
system 'stty', '-icanon', 'eol', "\cA";
}
END {
system 'stty', 'icanon', 'eol', "\c@";
}
Re:bpm inspector
pudge on 2004-05-01T02:13:52
Yeah, that's the one. I was looking at some others that didn't do what I wanted. Thanks! But mine's smaller.:-) I could make mine set the value, too, with less than 10 more lines of code. But I don't think I will, unless someone wants me to, since I don't care about that.
Re:until
pudge on 2004-05-01T06:27:57
It's been there a "while". HA!
Seriously, as long as I can remember. I dunno.Only about 16 years ago
vsergu on 2004-05-01T20:33:52
It's been there from the beginning. From the perl 1.0 man page:
If the word while is replaced by the word until, the sense of the test is reversed, but the conditional is still tested before the first iteration.