Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,20 @@
use Time::HiRes qw(sleep gettimeofday);
local $| = 1; # autoflush
my $beats_per_minute = shift || 72;
my $beats_per_bar = shift || 4;
my $i = 0;
my $duration = 60 / $beats_per_minute;
my $base_time = gettimeofday() + $duration;
for (my $next_time = $base_time ; ; $next_time += $duration) {
if ($i++ % $beats_per_bar == 0) {
print "\nTICK";
}
else {
print " tick";
}
sleep($next_time - gettimeofday());
}

View file

@ -0,0 +1,35 @@
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
my $active = 0;
my $bpm = 60;
my $x = 100;
my $mw = MainWindow->new;
$mw->title( "Metronome" );
my $c = $mw->Canvas(
)->pack(-fill => 'both', -expand => 1);
$mw->Scale( -orient => 'horizontal', -from => 30, -to => 150,
-variable => \$bpm, -label => 'Beats per Minute',
)->pack(-fill => 'x');
$mw->Button( -text => 'Exit', -command => sub {$mw->destroy},
)->pack(-side => 'right');
$mw->Button( -text => 'Start / Pause', -command => sub {$active ^= 1; tick()},
)->pack(-side => 'right');
$mw->bind('<Configure>' => sub {$x = $c->width >> 2} );
MainLoop;
sub tick
{
$active or return;
# $mw->bell;
$x *= -1;
$c->delete('all');
$c->createLine( $c->width >> 1, $c->height, $c->width / 2 + $x, 30,
-width => 5);
$mw->after( 60_000 / $bpm / 2 => \&tick );
}