Skip to content

jbarrett/MIDI-RtMidi-FFI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MIDI::RtMidi::FFI

Perl bindings for Gary P. Scavone's RtMidi library, realtime MIDI input/output across Linux, Macintosh OS X, and Windows.

MIDI::RtMidi::FFI::Device is included - this adds an OO interface, plus support for RPN/NRPN, 14-bit CC control change, convenience methods for port management, and decoding / encoding of MIDI messages in a friendly, human-readable format.

Installing

With cpanminus:

$ cpanm MIDI::RtMidi::FFI

Using

use MIDI::RtMidi::FFI::Device;

# Create a new device instance
my $device = RtMidiOut->new;

# Open a "virtual port" - this is a virtual MIDI device which may be
# connected to directly from external synths and software.
# This is unsupported on Windows.
$device->open_virtual_port( 'foo' );

# An alternative to opening a virtual port is connecting to an available
# MIDI device on your system, such as a loopback device, or virtual or
# hardware synth. Your device must be connected to some sort of synth to
# make noise.
$device->open_port_by_name( qr/wavetable|loopmidi|timidity|fluid/i );

# Now that a port is open we can start to send MIDI messages, such as
# this annoying sequence
while ( 1 ) {
    # Send Middle C (0x3C) to channel 0, strong velocity (0x7A)
    $device->note_on( 0x00, 0x3C, 0x7A );
    
    # Send a random control change value to Channel 0, CC 1
    $device->cc( 0x00, 0x01, int rand( 128 ) );
    
    sleep 1;
    
    # Stop playing Middle C on channel 0
    $device->note_off( 0x00, 0x40 );
    
    sleep 1;
}

Complete documentation for the current version may be found on the MIDI::RtMidi::FFI::Device MetaCPAN page. There are also a number of examples.

Help! I don't hear anything!

RtMidi requires a hardware or software synth to play music. If your system lacks one of these, try FluidSynth or TiMidity++. Specific instructions for your system should be easily found.

VirtualMIDISynth can be used on Windows if you wish to use soundfonts beyond the default GS Wavetable.

Bugs, Feedback

Open an issue or start a discussion!

Copyright, License

This software is copyright (c) 2024 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.

About

Perl bindings for RtMidi

Resources

Stars

Watchers

Forks

Packages

No packages published