NAME

MIDI::Realtime - Writes MIDI data to /dev/sequencer in real time

WARNING

This is heavily experimental software and may change at any moment.

Use this software at your own risk. It works fine for me, but could do anything to you, your pets or your computer.

DESCRIPTION

MIDI::Realtime aims to be a handy utility for handing the output, and one day soon, the input of MIDI data.

This module only writes MIDI data at the moment. There are many areas of expansion - for example, timing, and reading MIDI data is yet to be implemented, and people could make subclasses for sending system exclusive data to their particular synthesiser.

Please contact me if you have any ideas for this. In fact, I'd like to hear from you if you get any use out of it at all.

For an example of how I'm using this module, see http://www.slab.org/void/music/

SYNOPSIS

  use MIDI::Realtime;

  my $midi = MIDI::Realtime->new();

  # Play note 47 with maximum velocity on channel 1
  $midi->note(47, 127, 1);

  # Now have some fun with randomness

  my @notes      = (37 .. 50);
  # use all the channels (with extra drums)
  my @channels   = (1 .. 16, 10, 10, 10); 
  my @velocities = (70 .. 100);

  for (0 .. 127) {
    $midi->note($notes[rand(@notes)],
                $channels[rand(@channels)],
                $velocities[rand(@velocities)]
               );

    # Wait for a tenth of a second
    select(undef,undef,undef, 0.10);
  }    

FUNCTIONS

new()
  my $midi = MIDI::Realtime->new(dev => '/dev/sequencer',
                                 midi_device => 0
                                );

This is the object constructor. It has two, optional parameters - 'dev' the device file to be written to (default is '/dev/sequencer'), and 'midi_device' is the MIDI device to use (default is 0).

devices()

Not yet written. Might one day return information about available MIDI devices somehow.

METHODS THAT SEND MIDI

All the following methods return the number of bytes sent - ie 0 if something unexpectedly evil happened.

patch()
  $midi->patch(2);

Sends a patch change request to the MIDI device. Just pass it the new patch number.

song()
  $midi->song(6);

Sends a patch change request to the MIDI device. Just pass it the new song number. This didn't seem to make my synth do what I wanted it to - change 'performance'. My guess is I have to send it sysex data to do that, and that this is just for sequencers. Let me know if you find that this method works for you.

note()
  $midi->note(40, 10, 100)

Takes three parameters. The first is the note number, and must be supplied. The second is the channel number, and defaults to 1. The third is the velocity and defaults to 127.

send_midi_bytes()
  $midi->send_midi_bytes(0x90, 40, 100);

This method sends the given bytes to the MIDI device. It is intended for only internal use and experiments. If you find some nice bytes to send, please let me know, or put it in MIDI::Realtime.pm and send me a patch.

ACCESSOR METHODS

dev(), midi_device()

These two methods return the values that were supplied (or defaulted) when you first called new(). They are read only.

AUTHOR

Alex McLean - alex@slab.org