Skip to content

Instantly share code, notes, and snippets.

@ology
Last active December 13, 2024 17:12
Show Gist options
  • Save ology/21f7abfa2556cb7241fe571797f631ea to your computer and use it in GitHub Desktop.
Save ology/21f7abfa2556cb7241fe571797f631ea to your computer and use it in GitHub Desktop.
Perl MIDI clock - No dice
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long qw(GetOptions);
use MIDI::RtMidi::FFI::Device ();
use Time::HiRes qw(usleep);
my %opt = (
virtual => 'foo',
named => 'bar',
bpm => 100,
);
GetOptions(\%opt,
'virtual=s',
'named=s',
'bpm=i',
);
my $interval = 60 / ($opt{bpm} * 24) / 100;
my $in = RtMidiIn->new;
my $out = RtMidiOut->new;
$in->ignore_timing( 0 );
$out->open_virtual_port($opt{virtual});
$in->open_port_by_name(qr/$opt{named}/i);
sleep 1;
while (1) {
$out->send_event('clock');
usleep($interval);
}
END {
$out->close_port;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment