BPM
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 ...).
#!/usr/local/bin/perl
use warnings;
use strict;
use Time::HiRes 'time';
print "Hit '.' for each beat. Hit '.' to start, and <enter> or ^C to end.\n";
print "Keep going until you reach about 10 beats, and are satisfied with the result.\n";
$| = 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@";
}
Leave a comment