Skip to content

Instantly share code, notes, and snippets.

@ology
Last active December 12, 2024 23:57
Show Gist options
  • Save ology/458acd5af76907854e2282638ea13466 to your computer and use it in GitHub Desktop.
Save ology/458acd5af76907854e2282638ea13466 to your computer and use it in GitHub Desktop.
Trying to send a MIDI clock with perl
#!/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', #'perl-rtmidi',
named => 'bar', # or 'IAC Driver IAC Bus 1' or 'Logic Pro Virtual In', or anything?
bpm => 100,
);
GetOptions(\%opt,
'virtual=s',
'named=s',
'bpm=i',
);
my $interval = 60 / ($opt{bpm} * 24) / 100;
my $device = RtMidiOut->new;
$device->open_virtual_port($opt{virtual});
$device->open_port_by_name(qr/$opt{named}/);
sleep 1;
while (1) {
$device->send_event('clock');
usleep($interval);
}
END {
$device->close_port;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment