NAME
MIDI::RtController - Control your MIDI controller
VERSION
version 0.0405
SYNOPSIS
use MIDI::RtController ();
my $rtc = MIDI::RtController->new(
input => 'input-MIDI-device',
output => 'output-MIDI-device',
);
sub filter_notes {
my ($note) = @_;
return $note, $note + 7, $note + 12;
}
sub filter_tone {
my ($delta_time, $event) = @_; # 2 required filter arguments
my ($ev, $channel, $note, $vel) = $event->@*;
my @notes = filter_notes($note);
$rtc->send_it([ $ev, $channel, $_, $vel ]) for @notes;
return 0;
}
# respond to specific events:
$rtc->add_filter('filter_tone', $_, \&filter_tone)
for qw(note_on note_off);
# Or:
$rtc->add_filter('filter_tone', [qw(note_on note_off)], \&filter_tone);
# respond to all events:
$rtc->add_filter(
'echo',
all => sub {
my ($dt, $event) = @_;
print "dt: $dt, ev: ", join( ', ', @$event ), "\n"
unless $event->[0] eq 'clock';
return 0;
}
);
# add other stuff to the $rtc->loop...
$rtc->run;
DESCRIPTION
MIDI::RtController
allows you to control your MIDI controller using plug-in filters.
ATTRIBUTES
verbose
$verbose = $rtc->verbose;
Show progress.
input
$input = $rtc->input;
Return the MIDI input port.
output
$output = $rtc->output;
Return the MIDI output port.
loop
$loop = $rtc->loop;
Return the IO::Async::Loop.
filters
$filters = $rtc->filters;
Return or set the filters.
METHODS
new
$rtc = MIDI::RtController->new(%attributes);
Create a new MIDI::RtController
object given the above attributes.
add_filter
$rtc->add_filter($name, $event_type, $action);
Add a named filter, defined by the CODE reference action for an event_type like note_on
or note_off
. An ARRAY reference of event types like: [qw(note_on note_off)]
may also be given.
The special event type all
may also be used to refer to any controller event (e.g. note_on
, control_change
, pitch_wheel_change
, etc.).
send_it
$rtc->send_it($event);
Send a MIDI event to the output port, where the MIDI event is an ARRAY reference like, ['note_on', 0, 40, 107]
or ['control_change', 0, 1, 24]
, etc.
delay_send
$rtc->delay_send($delay_time, $event);
Send a MIDI event to the output port when the delay_time (in seconds) expires.
run
$rtc->run;
Run the asynchronous loop!
THANK YOU
This code would not exist without the help of CPAN's JBARRETT (John Barrett AKA fuzzix).
SEE ALSO
The eg/*.pl example programs
AUTHOR
Gene Boggs <gene.boggs@gmail.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2025 by Gene Boggs.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.