Last active
December 13, 2024 17:12
-
-
Save ology/21f7abfa2556cb7241fe571797f631ea to your computer and use it in GitHub Desktop.
Perl MIDI clock - No dice
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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