NAME

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

VERSION

version 0.0115

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)
      deposit  => 'path/prefix-', # optionally make a file after each loop
			vebose   => 0, # show our progress (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.

If you wish to set the patch or channel for a part, do so inside the scope of the coderef that is returned by the part.

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 use FluidSynth like this: fluidsynth -a coreaudio -m coremidi -g 1.0 some-soundfont.sf2 Also, you can use Timidity. You can also use a digital audio workstation (DAW) like Logic, with a software synth track selected. If you wish, you can get General MIDI via "DLSMusicDevice" within a DAW. To do this, you will need a soundfont in ~/Library/Audio/Sounds/Banks/ and DLSMusicDevice open in your DAW with the soundfont selected.

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 are the eg/* files in this distribution.

Also check out the t/01-methods.t file for basic usage.

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)