| | Comments (0)
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 ...).

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";
    system 'stty', '-icanon', 'eol', "\cA";
    system 'stty', 'icanon', 'eol', "\c@";


Leave a comment

<pudge/*> (pronounced "PudgeGlob") is thousands of posts over many years by Pudge.

"It is the common fate of the indolent to see their rights become a prey to the active. The condition upon which God hath given liberty to man is eternal vigilance; which condition if he break, servitude is at once the consequence of his crime and the punishment of his guilt."

About this Entry

This page contains a single entry by pudge published on April 30, 2004 3:24 PM.

Boston Championships was the previous entry in this site.

Humor is the next entry in this site.

Find recent content on the main index or look in the archives to find all content.