Last active
May 13, 2024 16:31
-
-
Save ology/df7c769f54e427067844af5245298885 to your computer and use it in GitHub Desktop.
perl -wc rt-midi.pl
This file contains 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
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? |
This file contains 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 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