NAME

MIDI::RtMidi::ScorePlayer - Play a MIDI score in real-time

VERSION

version 0.0108

SYNOPSIS

use MIDI::RtMidi::ScorePlayer ();
use MIDI::Util qw(setup_score);

my $score = setup_score();

my %common = (score => $score, seen => {}, etc => '...',);

sub treble {
    my (%args) = @_;
    ...; # Setup things
    my $treble = sub {
        if ($args{_part} % 2) {
            $args{score}->n('...');
        }
        else {
            $args{score}->r('...');
        }
    };
    return $treble;
}
sub bass {
    ...; # As above but different!
}

MIDI::RtMidi::ScorePlayer->new(
    score    => $score, # required MIDI score object
    parts    => [ \&treble, \&bass ], # required part functions
    common   => \%common, # arguments given to the part functions
    repeats  => 4, # number of repeated synched parts (default: 1)
    sleep    => 2, # number of seconds to sleep between loops (default: 1)
    loop     => 4, # loop limit if finite (default: 1)
    infinite => 0, # loop infinitely (default: 1)
)->play;

DESCRIPTION

MIDI::RtMidi::ScorePlayer plays a MIDI score in real-time.

In order to use this module, create subroutines for simultaneous MIDI parts that take a common hash of named arguments. These parts each return an anonymous subroutine that tells MIDI-perl to build up a score, by adding notes (n()) and rests (r()), etc. These musical operations are described in the MIDI modules, like MIDI::Simple.

Besides being handed the common arguments, each part function gets a handy, increasing _part number, starting at one, which can be used in the part functions.

These parts are synch'd together, given the new parameters that are described in the example above.

Hints

Linux: If your distro does not install a service, you can use timidity in daemon mode: timidity -iAD. Also, FluidSynth is an alternative.

MacOS: You can get General MIDI via DLSMusicDevice within Logic or Garageband. You will need a soundfont containing drum patches in '~/Library/Audio/Sounds/Banks/' and DLSMusicDevice open in Garageband or Logic with this soundfont selected. See the MIDI::RtMidi::FFI::Device docs for more info. Alternatively you can use FluidSynth: fluidsynth -a coreaudio -m coremidi -g 1.0 ~/Music/some-soundfont.sf2. Also, you can use timidity too.

For Windows, this should just work out of the box.

METHODS

new

Instantiate a new MIDI::RtMidi::ScorePlayer object.

play

Play a given MIDI score in real-time.

SEE ALSO

Examples can be found in the eg/* files in this distribution.

MIDI::RtMidi::FFI::Device

MIDI::Util

Time::HiRes

AUTHOR

Gene Boggs <gene.boggs@gmail.com>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2024 by Gene Boggs.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)