Skip to content

Instantly share code, notes, and snippets.

@ology
Last active May 13, 2024 16:31
Show Gist options
  • Save ology/df7c769f54e427067844af5245298885 to your computer and use it in GitHub Desktop.
Save ology/df7c769f54e427067844af5245298885 to your computer and use it in GitHub Desktop.
perl -wc rt-midi.pl
Name "FFI::Platypus::keep" used only once: possible typo at /Users/gene/perl5/perlbrew/perls/perl-5.38.0/lib/5.38.0/XSLoader.pm line 115.
Name "FFI::Platypus::TypeParser::ffi_type" used only once: possible typo at /Users/gene/perl5/perlbrew/perls/perl-5.38.0/lib/5.38.0/XSLoader.pm line 115.
- syntax OK
(in cleanup) Can't use an undefined value as a subroutine reference during global destruction.
# What?
#!/usr/bin/env perl
use strict;
use warnings;
use lib map { "$ENV{HOME}/sandbox/$_/lib" } qw(MIDI-Util);
use MIDI::Util qw(setup_score);
use Data::Dumper::Compact qw(ddc);
use Getopt::Long qw(GetOptions);
use MIDI::RtMidi::FFI::Device;
my %opt = (
port => 'Logic Pro Virtual In',
# port => 'IAC Driver',
# port => 'IAC Bus 1',
# port => 'Bus 1',
);
GetOptions(\%opt,
'port=s',
);
my $score = setup_score();
$score->n('qn', 'C5');
$score->n('qn', 'G4');
$score->n('qn', 'F4');
$score->n('qn', 'C4');
my $events_r = MIDI::Score::score_r_to_events_r($score->{Score});
my $device = RtMidiOut->new;
$device->open_virtual_port($opt{port});
for my $event (@$events_r) {
if ($event->[0] =~ /^(note_\w+)$/) {
my $op = $1;
$device->send_event($op => @{ $event }[3,4,5]);
sleep 1 if $op eq 'note_on';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment