NAME

Peta::MIDI::Event - a MIDI message as an event: its name and fields

VERSION

version 0.2610180

SYNOPSIS

my $event = Peta::MIDI::Event->new([ 0x91, 60, 100 ], 0.25);
$event->name;           # note_on
$event->channel;        # 1
$event->as_arrayref;    # [ 'note_on', 1, 60, 100 ]
$event->bytes;          # "\x91\x3c\x64"

DESCRIPTION

The events of Peta::MIDI::Decoder and Peta::MIDI::Encoder, as MIDI::Stream names them (MIDI::Event's names in brackets), with their fields in order:

note_off, note_on   channel note velocity    (a note on of velocity 0 is a note off)
polytouch           channel note pressure    (key_after_touch)
control_change      channel control value
program_change      channel program          (patch_change)
aftertouch          channel pressure         (channel_after_touch)
pitch_bend          channel value            (pitch_wheel_change; -8192 .. 8191)
sysex               msg                      (sysex_f0; the bytes between F0 and F7)
timecode            byte
song_position       position                 (0 .. 16383)
song_select         song
tune_request, eox (sysex_f7), clock, start, continue, stop,
active_sensing, system_reset (no fields)

METHODS

new

new(\@message, $dt): the event of a whole message (its bytes as numbers), $dt the seconds since the one before.

name, status, message, dt, bytes

The event's name, its status byte, its bytes as numbers, the seconds since the message before, and its bytes as a string (a system exclusive message's whole, F0 to F7).

channel, note, velocity, pressure, control, value, program, msg, byte, position, song

The fields; undef where the event has none.

as_arrayref, as_hashref, TO_JSON

[ name, fields in order ]; { name, field = value }> (also as JSON).

FUNCTIONS

status_byte, status_name

status_byte($name): a name's status byte (channel 0); status_name($status): a status byte's name.

keys_for

keys_for($name): the fields of events of a name, in order.

message_length

message_length($status): the length of a message with its status byte; 0 where it is as long as it is (system exclusive).

split_bytes, combine_bytes

split_bytes($value): a value of 14 bits as (lsb, msb); combine_bytes($lsb, $msb) back.

name_to_midi_event, name_from_midi_event

MIDI::Event's names (patch_change, pitch_wheel_change, key_after_touch, channel_after_touch, sysex_f0, sysex_f7) and back; other names as they are.

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.