Skip to content

Instantly share code, notes, and snippets.

@ology
Last active March 11, 2025 06:56
Show Gist options
  • Save ology/af38c6c03556bdd978e9c96764621625 to your computer and use it in GitHub Desktop.
Save ology/af38c6c03556bdd978e9c96764621625 to your computer and use it in GitHub Desktop.
WIP: Score ... So far: Silence! :D
sub score ($dt, $event) {
my ($ev, $chan, $note, $vel) = $event->@*;
if ($ev eq 'control_change' && $note == 26 && $vel == 127) { # record
$recording = 1;
log_it(recording => 'on');
}
elsif ($ev eq 'control_change' && $note == 25 && $vel == 127) { # play
log_it(playing => 'on');
if (!$playing && @$events) {
warn __PACKAGE__,' L',__LINE__,' ',,"HELLO?\n";
my $part = sub {
my (%args) = @_;
$args{score}->n('qn', $_) for @{ $args{events} };
};
MIDI::RtMidi::ScorePlayer->new(
device => $rtc->_midi_out,
score => $score,
common => { score => $score, events => $events },
parts => [ $part ],
sleep => 0,
infinite => 0,
# dump => 1,
)->play_async->retain;
warn __PACKAGE__,' L',__LINE__,' ',,"WTF?\n";
}
$playing = 1;
}
elsif ($ev eq 'control_change' && $note == 24 && $vel == 127) { # stop
log_it(recording => 'off');
log_it(playing => 'off');
$recording = 0;
$playing = 0;
}
if ($ev eq 'note_on' && $recording) {
push @$events, $note;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment