NAME

Peta::MIDI::ALSA - a client of the ALSA sequencer, with no library

VERSION

version 0.2610180

SYNOPSIS

my $alsa = Peta::MIDI::ALSA->new(name => 'my program');
my $in   = $alsa->create_port('in', 'in');
my $out  = $alsa->create_port('out', 'out');
my ($synth) = grep { Peta::MIDI::ALSA::writable($_->{cap}) && $_->{client_name} =~ /FLUID/ } $alsa->ports;
$alsa->subscribe($alsa->client . ":$out", $synth->{address});
$alsa->send($out, "\x90\x3c\x64");
for my $message ($alsa->read(1)) {
    my ($bytes, $source, $port) = @$message;
}

DESCRIPTION

The kernel's MIDI router through its device: ports of this client's, the other clients' ports, connections between them, and MIDI bytes in and out. Peta::MIDI::Device is built on it, and so is Peta::Synth::Input.

METHODS

new, client, handle

new(name => ...) (dies where there is no sequencer); this client's number; its file handle (for select or an event loop).

create_port, delete_port

create_port($name, 'in' or 'out'): a port others write to, or read from; its number.

ports, readable, writable

The other clients' ports (also as a function): hashes of address, client, port, client_name, port_name, cap; readable($cap) and writable($cap) say what they can do.

subscribe, unsubscribe

subscribe($sender, $dest): what the sender port gives goes to the dest port (client:port each).

on_announce

on_announce($callback): who hears of ports coming and going, $callback->('start' or 'exit', 'client:port'), once a port of this client's is subscribed to the system's announcements (0:1).

read, send

read($wait): what has come in, as [bytes, source, port], waiting at most $wait seconds. on_announce(sub ($what, $address) {...}): ports coming (start) and going (exit), once a port of this client's is subscribed to the system's announcements (0:1). send($port, $bytes): MIDI messages out of a port of this client's to whoever is connected to it.

AUTHOR

PetaMem s.r.o. <info@petamem.com>

COPYRIGHT

Copyright (c) 2026 PetaMem s.r.o.

LICENSE

This package is free software, dual-licensed under the Artistic License 2.0 and the BSD 2-Clause License. See the LICENSE file of the distribution.