#!/usr/bin/perl

print <<X unless $#ARGV;

stupid BPM measurement tool von lynX 2005	http://www.euRoClAsh.com

how to use:
    hit ENTER on the first beat (start counting from zero ;))
    then wait 4, 8, 16 or 32 measures (the longer the better)
    and hit ENTER on the first beat again

the tool will show some possible bpm values

X

use Time::HiRes qw( usleep ualarm gettimeofday tv_interval );

while (1) {
	print "\nHIT ENTER TO START: ";
	$in = <stdin>;

	$t0 = [gettimeofday];
	exit if $in =~ /\S/;

	print "HIT ENTER TO STOP: ";
	$in = <stdin>;

	$elapsed = tv_interval ( $t0, [gettimeofday]);

	print <<X;

seconds elapsed: $elapsed

X

#	print "possible bpm: ", 60 / $elapsed, "\n";
#	print "possible bpm: ", 120 / $elapsed, "\n";
#	print "possible bpm: ", 240 / $elapsed, "\n";
	print "possible bpm: ", 480 / $elapsed, "\n";
	print "possible bpm: ", 960 / $elapsed, "\n";
	print "possible bpm: ", 1920 / $elapsed, "\n";
#	print "possible bpm: ", 3840 / $elapsed, "\n";
#	print "possible bpm: ", 7680 / $elapsed, "\n";

	exit if $in =~ /\S/;
}

