The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

MIDI::RtMidi::FFI - Bindings for librtmidi - Realtime MIDI library

VERSION

version 0.05

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 or later, should work with v5.0.0, and perhaps 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_WEB_MIDI_API, 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_version

    rtmidi_get_version()

Returns the best-guess of the version number of the RtMidi library in use.

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 );

Returns the associated display name for a RTMIDI_API constant.

rtmidi_api_name

    rtmidi_api_name( $api );

Returns the associated name for a given RTMIDI_API constant.

rtmidi_compiled_api_by_name

    rtmidi_compiled_api_by_name( $name );

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 may be connected.

This operation is not supported on Windows.

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.

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 some data you may optionally set while defining the callback. This data-passing functionality acts as a workaround for systems without closure support.

NB RtMidi provides no event loop "runner". A callback may interrupt your program at any time, so it should probably sleep or await input while events are ongoing.

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.

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

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

AUTHOR

John Barrett <john@jbrt.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2023 by John Barrett.

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