NAME

MIDI::RtMidi::FFI - Perl bindings for RtMidi.

VERSION

version 0.03

SYNOPSIS

use MIDI::RtMidi::FFI ':all';
use MIDI::Event;

my $device = rtmidi_out_create( RTMIDI_API_UNIX_JACK, 'perl-jack' );
my $port_count = rtmidi_get_port_count( $device );
my $synth_port = grep {
    rtmidi_get_port_name( $device, $_ ) =~ /synth/i
} 0..($port_count-1);

rtmidi_open_port( $device, $synth_port, 'my synth' );
rtmidi_out_send_message(
    $device,
    ${ MIDI::Event::encode([[ note_on => 0, 0, 0x40, 0x5a ]], { never_add_eot => 1 }) }
);

DESCRIPTION

RtMidi provides a common API for realtime MIDI input/output supporting ALSA, JACK, CoreMIDI and Windows Multimedia.

MIDI::RtMidi::FFI provides a more-or-less direct binding to RtMidi's C Interface. MIDI::RtMidi::FFI requires librtmidi v4.0.0, though will possibly work with later versions.

This is alpha software. Expect crashes, memory issues and possible API changes.

Check out MIDI::RtMidi::FFI::Device for an OO interface to this module.

ENUMS

RtMidiApi

RTMIDI_API_UNSPECIFIED, RTMIDI_API_MACOSX_CORE, RTMIDI_API_LINUX_ALSA, RTMIDI_API_UNIX_JACK, RTMIDI_API_WINDOWS_MM, RTMIDI_API_RTMIDI_DUMMY, RTMIDI_API_NUM

RtMidiErrorType

RTMIDI_ERROR_WARNING, RTMIDI_ERROR_DEBUG_WARNING, RTMIDI_ERROR_UNSPECIFIED, RTMIDI_ERROR_NO_DEVICES_FOUND, RTMIDI_ERROR_INVALID_DEVICE, RTMIDI_ERROR_MEMORY_ERROR, RTMIDI_ERROR_INVALID_PARAMETER, RTMIDI_ERROR_INVALID_USE, RTMIDI_ERROR_DRIVER_ERROR, RTMIDI_ERROR_SYSTEM_ERROR, RTMIDI_ERROR_THREAD_ERROR

FUNCTIONS

rtmidi_get_compiled_api

rtmidi_get_compiled_api( $return_apis );
rtmidi_get_compiled_api( 1 );

Returns available APIs.

Pass a true value to return an array ref of available APIs as RT_API constants, otherwise a count of available APIs is returned.

rtmidi_api_display_name

rtmidi_api_display_name( $api );

From v4.0.0. Returns the associated display name for a RTMIDI_API constant.

rtmidi_api_name

rtmidi_api_name( $api );

From v4.0.0. Returns the associated name for a given RTMIDI_API constant.

rtmidi_compiled_api_by_name

rtmidi_compiled_api_by_name( $name );

From v4.0.0. Returns the associated RTMIDI_API constant for a given name.

rtmidi_open_port

rtmidi_open_port( $device, $port, $name );

Open a MIDI port.

rtmidi_open_virtual_port

rtmidi_open_virtual_port( $device, $name );

Creates a virtual MIDI port to which other software applications can connect.

rtmidi_close_port

rtmidi_close_port( $device );

Close a MIDI connection.

rtmidi_get_port_count

rtmidi_get_port_count( $device );

Return the number of available MIDI ports.

rtmidi_get_port_name

rtmidi_get_port_name( $device, $port );

Return the name for the specified MIDI input port number.

rtmidi_in_create_default

rtmidi_in_create_default();

Create a default MIDI in device with no initial values.

rtmidi_in_create

rtmidi_in_create( $api, $name, $queuesize );

Create a MIDI in device with initial values.

rtmidi_in_free

rtmidi_in_free( $device );

Free the given MIDI in device.

This currently skips delegating device deletion to librtmidi -- it just closes the port.

rtmidi_in_get_current_api

rtmidi_in_get_current_api( $device );

Return the RTMIDI_API constant for the given device.

rtmidi_in_set_callback

rtmidi_in_set_callback( $device, $coderef, $data );

Set a callback function to be invoked for incoming MIDI messages.

Your callback receives the timestamp of the event, the message and the data you set while defining the callback. Due to the way params are packed, this data can only be a simple scalar, not a reference.

NB This is not recommended in the current implementation. If a message arrives while the callback is already running, your program will segfault!

rtmidi_in_cancel_callback

rtmidi_in_cancel_callback( $device );

Cancel use of the current callback function (if one exists).

rtmidi_in_ignore_types

rtmidi_in_ignore_types( $device, $ignore_sysex, $ignore_timing, $ignore_sensing );

Specify whether certain MIDI message types should be queued or ignored during input.

rtmidi_out_create_default

rtmidi_out_create_default();

Create a default MIDI out device with no initial values.

rtmidi_out_create

rtmidi_out_create( $api, $name );

Create a MIDI out device with initial values.

rtmidi_out_free

rtmidi_out_free( $device );

Free the given MIDI out device.

This currently skips delegating device deletion to librtmidi -- it just closes the port.

rtmidi_out_get_current_api

rtmidi_out_get_current_api( $device );

Return the RTMIDI_API constant for the given device.

rtmidi_out_send_message

rtmidi_out_send_message( $device, $message );

Send a single message out an open MIDI output port.

SEE ALSO

RtMidi

Alien::RtMidi

MIDI::RtMidi::FFI::Device

MIDI::ALSA

Win32API::MIDI

Mac::CoreMIDI

MIDI::Music

MIDI::Realtime

AUTHOR

John Barrett, <john@jbrt.org>

CONTRIBUTING

https://github.com/jbarrett/MIDI-RtMidi-FFI

All comments and contributions welcome.

BUGS AND SUPPORT

Please direct all requests to https://github.com/jbarrett/MIDI-RtMidi-FFI/issues

COPYRIGHT

Copyright 2019-2021 John Barrett.

LICENSE

This application is free software; you can redistribute it and/or modify it under the same terms as Perl itself.