Last active
May 25, 2025 08:33
-
-
Save ology/b693d7999a22d4dffc05b1a0d6a6ce28 to your computer and use it in GitHub Desktop.
Trying to clock from RtMidi
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 clock_it ($self, $device, $dt, $event) { | |
return 0 if $self->running; | |
$self->running(1); | |
$self->rtc->send_it(['start']); | |
$self->rtc->loop->add( | |
IO::Async::Timer::Periodic->new( | |
interval => $self->time_step, | |
on_tick => sub { | |
my ($c) = @_; | |
if ($self->halt) { | |
$self->rtc->send_it(['stop']); | |
$c->stop; | |
$self->running(0); | |
$self->halt(0); | |
} | |
else { | |
$self->rtc->send_it(['clock']); | |
} | |
}, | |
)->start | |
); | |
return $self->continue; | |
} | |
# ... |
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
#!/usr/bin/env perl | |
use curry; | |
use MIDI::RtController (); | |
use MIDI::RtController::Filter::CC (); | |
my $input_name = shift || '49 midi'; | |
my $output_name = shift || 'se-02'; | |
my $filter_name = shift || 'clock_it'; | |
my $controller = MIDI::RtController->new( | |
input => $input_name, | |
output => $output_name, | |
verbose => 1, | |
); | |
my $filter = MIDI::RtController::Filter::CC->new(rtc => $controller); | |
$filter->time_step(60 / (60 * 24)); | |
my $method = "curry::$filter_name"; | |
$controller->add_filter($filter_name, all => $filter->$method); | |
$controller->run; |
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 _open_port($device, $name) { | |
$device->open_port_by_name(qr/\Q$name/i) | |
|| croak "Failed to open port $name"; | |
return $name; | |
} | |
sub _rtmidi_loop ($msg_ch, $midi_ch) { | |
my $midi_in = MIDI::RtMidi::FFI::Device->new(type => 'in'); | |
my $name = _open_port($midi_in, ${ $msg_ch->recv }); | |
$midi_in->set_callback_decoded( | |
sub { | |
my (@event) = @_; | |
my @e = $event[0] eq 'clock' || $event[0] eq 'start' || $event[0] eq 'stop' | |
? ($event[0], 0) : @event[0, 2]; | |
$midi_ch->send([ @e, $name ]) | |
} | |
); # delta-time, event, midi port | |
sleep; | |
} | |
# ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment