The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

MIDI::XML::MIDI - MIDI file/stream data.

SYNOPSIS

  use strict;
  use MIDI::XML::MidiFile;
  use MIDI::XML::Track;
  use MIDI::XML::Parser;
  use XML::Parser;

  use MIDI::Opus;
  use MIDI::Track;
  use MIDI::Event;

  unless (@ARGV) {
  die "Usage: perl test.pl filename\n";
  }

  my $file = shift @ARGV;

  my $opus = MIDI::Opus->new({ 'from_file' => "$file.mid"});
  my $midi=MIDI::XML::MidiFile->new({'from_opus' => $opus});
  my $measures = $midi->measures();
  open XML,">","$file.xml";
  print XML "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; 
  print XML join("\n",$midi->as_MidiXML());
  close XML;
  my $MidiFile = MIDI::XML::Parser->parse_MidiXML("$file.xml");

DESCRIPTION

MIDI::XML::MidiFile is a class for representing a MIDI file. There are methods for the file attribute and a collection containing MIDI::XML::Track objects.

EXPORT

None.

METHODS AND ATTRIBUTES

$obj = MIDI::XML::MidiFile->new()

This creates a new MIDI::XML::MidiFile object.

$format = $MidiFile->format() or $MidiFile->format($format)

Returns or optionally sets the format indicator for the MidiFile object. Valid values are 0, 1, and 2.

$track_count = $MidiFile->track_count() or $MidiFile->track_count($track_count)

Returns or optionally sets the track count for the MidiFile object. This does not necessarilly indicate the number of Track objects contained by the tracks array.

$ticks_per_beat = $MidiFile->ticks_per_beat() or $MidiFile->ticks_per_beat($ticks_per_beat)

Returns or optionally sets the ticks per beat for the MidiFile object. To avoid contradictory values, frame_rate and ticks_per_frame are set to undef when ticks_per_beat is set.

$frame_rate = $MidiFile->frame_rate() or $MidiFile->frame_rate($frame_rate)

Returns or optionally sets the frame rate for the MidiFile object. To avoid contradictory values, ticks_per_beat is set to undef when frame_rate is set.

$ticks_per_frame = $MidiFile->ticks_per_frame() or $MidiFile->ticks_per_frame($ticks_per_frame)

Returns or optionally sets the ticks per frame for the MidiFile object. To avoid contradictory values, ticks_per_beat is set to undef when ticks_per_frame is set.

$timestamp_type = $MidiFile->timestamp_type() or $MidiFile->timestamp_type($timestamp_type)

Returns or optionally sets the format indicator for the MidiFile object. Valid values are Delta and Absolute. This value is only used for the production of MidiXML.

$tracks = $MidiFile->tracks()

Returns an array reference to the tracks contained in the MidiFile object.

$MidiFile->append($Track)

Appends a track to the track array in this MIDI::Xml:MidiFile object.

$MidiFile->from_opus($Opus)

Appends the events in a MIDI::Opus object to the event array in this MIDI::Xml:MidiFile object.

$Midi_opus = $MidiFile->as_midi_opus();

Returns a MIDI:Opus object constructed from this MidiFile object.

$array_ref = $MidiFile->measures() or $MidiFile->measures('refresh');

Returns a reference to an array of measures. If called with any parameter the array is refreshed before the reference is returned.

@xml = $File->as_MidiXML();

Returns an array of elements formatted according to the MidiXML DTD. These elements may be assembled by track into entire documents with the following suggested DOCTYPE declaration:

        <!DOCTYPE MIDI PUBLIC
                "-//Recordare//DTD MusicXML 0.7 MIDI//EN"
                "http://www.musicxml.org/dtds/midixml.dtd">

AUTHOR

Brian M. Ames, <bmames@apk.net>

SEE ALSO

MIDI::Opus, MIDI::XML::Parser.

COPYRIGHT and LICENSE

Copyright 2002 Brian M. Ames. This software may be used under the terms of the GPL and Artistic licenses, the same as Perl itself.