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::KeySignature - MIDI Key Signature messages.

SYNOPSIS

  use MIDI::XML::KeySignature;
  $Key_Sig = MIDI::XML::KeySignature->new();
  $Key_Sig->delta(768);
  $Key_Sig->fifths(2);
  $Key_Sig->mode(0);
  @event = $Key_Sig->as_event();
  $midi_track = MIDI::Track->new();
  push( @{$midi_track->events_r},\@event;
  @xml = $Key_Sig->as_MidiXML();
  print join("\n",@xml);

DESCRIPTION

MIDI::XML::KeySignature is a class encapsulating MIDI Key Signature meta messages. A Key Signature message includes either a delta time or absolute time as implemented by MIDI::XML::Message and the MIDI Key Signature event encoded in 5 bytes as follows:

0xFF 0x59 0x02 0xss 0xmm

ss = number of sharps (+) or flats (-)

mm = mode, 0 = Major, 1 = minor

EXPORT

None.

METHODS AND ATTRIBUTES

$Key_Sig = MIDI::XML::KeySignature->new()

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

$Key_Sig = MIDI::XML::KeySignature->new($event);

Creates a new KeySignature object initialized with the values of a MIDI::Event key_signature array.

$delta_time = $Key_Sig->delta() or $Key_Sig->delta($delta_time);

Returns the message time as a delta time or undef if it is an absolute time. Optionally sets the message time to the specified delta time. To avoid contradictory times, the absolute time is set to undef when a delta time is set.

This functionality is provided by the MIDI::XML::Message base class.

$absolute_time = $Key_Sig->absolute() or $Key_Sig->absolute($absolute_time);

Returns the message time as an absolute time or undef if it is a delta time. Optionally sets the message time to the specified absolute time. To avoid contradictory times, the delta time is set to undef when an absolute time is set. The absolute time should be zero according to the specification.

This functionality is provided by the MIDI::XML::Message base class.

$time = $Key_Sig->time();

Returns the message time, absolute or delta, whichever was last set.

This functionality is provided by the MIDI::XML::Message base class.

$fifths = $Key_Sig->fifths() or $Key_Sig->fifths($fifths);

Returns and optionally sets the number of fifths on the circle of fifths from C Major or A minor to the given key. This is equal to the number sharps or flats.

$mode = $Key_Sig->mode() or $Key_Sig->mode($mode);

Returns and optionally sets the mode.

$ordinal = $Key_Sig->ordinal();

Returns a value to be used to order events that occur at the same time.

@event = $Key_Sig->as_event();

Returns a MIDI::Event key_signature array initialized with the values of the KeySignature object. MIDI::Event does not expect absolute times and will interpret them as delta times. Calling this method when the time is absolute will not generate a warning or error but it is unlikely that the results will be satisfactory.

@xml = $Key_Sig->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">

RAVINGS

This Key Signature meta event present difficulties in encoding key signatures for music in other that Ionian (Major) and Aeolian (minor) modes. I have adopted the practice of identifying those modes having a Major third (Ionian, Lydian, Mixolydian) as Major and those having a minor third (Aeolian, Dorian, Phrygian, Locrian) as minor. Thus Mixolydian on G is encoded as G Major, Dorian on D as D minor.

AUTHOR

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

SEE ALSO

MIDI::Event.

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.