Last active
March 11, 2025 20:35
-
-
Save ology/c0f5b7f253fc9988a10a057b78f7fb33 to your computer and use it in GitHub Desktop.
Controller play with mostly correct timing!
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
elsif ($ev eq 'control_change' && $note == 25 && $vel == 127) { # play | |
log_it(recording => 'off'); | |
$recording = 0; | |
if (!$playing && @$events) { | |
log_it(playing => 'on'); | |
$playing = 1; | |
my $part = sub { | |
my (%args) = @_; | |
my $t = $args{bpm} / 60; # beats per second | |
for my $i (0 .. $args{events}->$#*) { | |
my $x = 1; | |
if ($i <= $args{events}->$#*) { | |
$x = $args{events}->[ $i + 1 ]{dt} * $t; | |
} | |
my $dura = sprintf 'd%d', $x * TICKS; | |
$args{score}->n($dura, $args{events}[$i]{note}); | |
} | |
}; | |
my $score = setup_score(lead_in => 0, bpm => $bpm); | |
MIDI::RtMidi::ScorePlayer->new( | |
device => $rtc->_midi_out, | |
score => $score, | |
common => { score => $score, events => $events, bpm => $bpm }, | |
parts => [ $part ], | |
sleep => 0, | |
infinite => 0, | |
)->play_async->retain; | |
log_it(playing => 'off'); | |
$playing = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment