MIDIUtil Class Reference

class MIDIFile

A class that represents a full, well-formed MIDI pattern.

This is a container object that contains a header, one or more tracks, and the data associated with a proper and well-formed MIDI pattern.

Calling

MyMIDI = MidiFile(tracks, removeDuplicates=True,  deinterleave=True)

normally

MyMIDI = MidiFile(tracks)


Arguments

  • tracks: The number of tracks this object contains
  • removeDuplicates: If true (the default), the software will remove duplicate events which have been added. For example, two notes at the same channel, time, pitch, and duration would be considered duplicate.
  • deinterleave: If True (the default), overlapping notes (same pitch, same channel) will be modified so that they do not overlap. Otherwise the sequencing software will need to figure out how to interpret NoteOff events upon playback.

Public Functions

addNote(track, channel, pitch,time,duration,volume)

Add notes to the MIDIFile object

Use

MyMIDI.addNotes(track,channel,pitch,time, duration, volume)

Arguments

  • track: The track to which the note is added.
  • channel: the MIDI channel to assign to the note. [Integer, 0-15]
  • pitch: the MIDI pitch number [Integer, 0-127].
  • time: the time (in beats) at which the note sounds [Float].
  • duration: the duration of the note (in beats) [Float].
  • volume: the volume (velocity) of the note. [Integer, 0-127].

addTrackName(track, time,trackName)

Add a track name to a MIDI track.

Use

MyMIDI.addTrackName(track,time,trackName)

Arguments

  • track: The track to which the name is added. [Integer, 0-127].
  • time: The time at which the track name is added, in beats [Float].
  • trackName: The track name. [String].

addTempo(track, time,tempo)

Add a tempo event.

Use

MyMIDI.addTempo(track, time, tempo)

Arguments

  • track: The track to which the event is added. [Integer, 0-127].
  • time: The time at which the event is added, in beats. [Float].
  • tempo: The tempo, in Beats per Minute. [Integer]

 

addProgramChange(track, channel, time, program)

Add a MIDI program change event.

Use

MyMIDI.addProgramChange(track,channel, time, program)

Arguments

  • track: The track to which the event is added. [Integer, 0-127].
  • channel: The channel the event is assigned to. [Integer, 0-15].
  • time: The time at which the event is added, in beats. [Float].
  • program: the program number. [Integer, 0-127].

addControllerEvent(track, channel,time,eventType, paramerter1)

Add a MIDI controller event.

Use

MyMIDI.addControllerEvent(track, channel, time, eventType, parameter1)

Arguments

  • track: The track to which the event is added. [Integer, 0-127].
  • channel: The channel the event is assigned to. [Integer, 0-15].
  • time: The time at which the event is added, in beats. [Float].
  • eventType: the controller event type.
  • parameter1: The event's parameter. The meaning of which varies by event type.

changeNoteTuning(track,  tunings,   sysExChannel=0x7F,  realTime=False,  tuningProgam=0)

Change a note's tuning using sysEx change tuning program.

Use

MyMIDI.changeNoteTuning(track,[tunings],realTime=False, tuningProgram=0)

Arguments

  • track: The track to which the event is added. [Integer, 0-127].
  • tunings: A list of tuples in the form (pitchNumber, frequency).  [[(Integer,Float]]
  • realTime: Boolean which sets the real-time flag. Defaults to false.
  • sysExChannel: do note use (see below).
  • tuningProgram: Tuning program to assign. Defaults to zero. [Integer, 0-127]

In general the sysExChannel should not be changed (parameter will be depreciated).

Also note that many software packages and hardware packages do not implement this standard!

writeFile(fileHandle)

Write the MIDI File.

Use

MyMIDI.writeFile(filehandle)

Arguments

  • filehandle: a file handle that has been opened for binary writing.

addSysEx(track, time, manID, payload)

Add a SysEx event

Use

MyMIDI.addSysEx(track,time,ID,payload)

Arguments

  • track: The track to which the event is added. [Integer, 0-127].
  • time: The time at which the event is added, in beats. [Float].
  • ID: The SysEx ID number
  • payload: the event payload.

Note: This is a low-level MIDI function, so care must be used in constructing the payload. It is recommended that higher-level helper functions be written to wrap this function and construct the payload if a developer finds him or herself using the function heavily.

addUniversalSysEx(track,  time,code, subcode, payload, sysExChannel=0x7F,  realTime=False)

Add a Universal SysEx event.

Use

MyMIDI.addUniversalSysEx(track, time, code, subcode, payload, sysExChannel=0x7f, realTime=False)

Arguments

  • track: The track to which the event is added. [Integer, 0-127].
  • time: The time at which the event is added, in beats. [Float].
  • code: The event code. [Integer]
  • subcode The event sub-code [Integer]
  • payload: The event payload. [Binary string]
  • sysExChannel: The SysEx channel.
  • realTime: Sets the real-time flag. Defaults to zero.

Note: This is a low-level MIDI function, so care must be used in constructing the payload. It is recommended that higher-level helper functions be written to wrap this function and construct the payload if a developer finds him or herself using the function heavily. As an example of such a helper function, see the changeNoteTuning function, both here and in MIDITrack.

~

Return to MIDIUtil