Created
March 4, 2025 06:03
-
-
Save ology/e1a8cddfd0eb31a0c79e60f212a4fbaf to your computer and use it in GitHub Desktop.
Trying to make ScorePlayer not block - Grrr!
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
# ... | |
sub score_send ($score) { | |
$loop->add( | |
IO::Async::Timer::Countdown->new( | |
delay => 0, | |
on_expire => sub { $score->play } | |
)->start | |
); | |
} | |
sub drum_part ($note) { | |
# warn __PACKAGE__,' L',__LINE__,' ',,"N: $note\n"; | |
my $part; | |
if ($note == 99) { | |
$part = sub { | |
my (%args) = @_; | |
$args{drummer}->metronome4; | |
}; | |
} | |
else { | |
$part = sub { | |
my (%args) = @_; | |
$args{drummer}->note($args{drummer}->sixtyfourth, $note); | |
}; | |
} | |
return $part; | |
} | |
sub drums ($event) { | |
my ($ev, $channel, $note, $vel) = $event->@*; | |
return 1 unless $ev eq 'note_on'; | |
my $part = drum_part($note); | |
my $d = MIDI::Drummer::Tiny->new(bpm => 100); | |
my $score_player = MIDI::RtMidi::ScorePlayer->new( | |
device => $midi_out, | |
score => $d->score, | |
common => { drummer => $d }, | |
parts => [ $part ], | |
sleep => 0, | |
infinite => 0, | |
# dump => 1, | |
); | |
score_send($score_player); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment