Skip to content

Instantly share code, notes, and snippets.

@bingos
Last active November 1, 2023 17:41
Show Gist options
  • Save bingos/609cc13bdffe2e3aacce7fe520b29577 to your computer and use it in GitHub Desktop.
Save bingos/609cc13bdffe2e3aacce7fe520b29577 to your computer and use it in GitHub Desktop.
BPM to MS Calculator
#!/usr/bin/env perl
use 5.012;
no crap;
use Math::BigFloat;
sub round {
return Math::BigFloat->new(shift)->bfround(1);
}
my $bpm = shift @ARGV;
$bpm = 120 unless $bpm && $bpm =~ m!^\d+$!;
my $ms = 60000 / $bpm;
say sprintf "Quarter note (one beat):\t%d ms", round( $ms );
say sprintf "Dotted eighth note (3/4):\t%d ms", round( $ms / 4 * 3 );
say sprintf "Eighth note (half beat):\t%d ms", round( $ms / 2 );
say sprintf "Sixteenth note (quarter):\t%d ms", round( $ms / 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment