Squeak Class Documentation category index | class index  
 
MIDIFileReader
  category: Sound-Scores
  superclass: Object
  subclasses:

A reader for Standard 1.0 format MIDI files.
MIDI File Types:
type 0 -- one multi-channel track
type 1 -- one or more simultaneous tracks
type 2 -- a number on independent single-track patterns

Instance variables:
stream source of MIDI data
fileType MIDI file type
trackCount number of tracks in file
ticksPerQuarter number of ticks per quarter note for all tracks in this file
tracks collects track data for non-empty tracks
strings collects all strings in the MIDI file
tempoMap nil or a MIDITrack consisting only of tempo change events
trackStream stream on buffer containing track chunk
track track being read
activeEvents notes that have been turned on but not off

instance methods
  chunk reading
  asScore
readHeaderChunk
readMIDIFrom:
readTrackChunk

  private
  guessMissingInstrumentNames
next16BitWord
next32BitWord:
readChunkSize
readChunkType
readVarLengthIntFrom:
report:
riffSkipToMidiChunk
scanForMIDIHeader
splitIntoTracks

  track reading
  endAllNotesAt:
endNote:chan:at:
isTempoTrack:
metaEventAt:
readTrackContents:
readTrackEvents
startNote:vel:chan:at:
trackContainsNotes:

class methods
  as yet unclassified
  playFileNamed:
playStream:
playURLNamed:
scoreFromFileNamed:
scoreFromStream:
scoreFromURL:
standardMIDIInstrumentNames

instance methods
  chunk reading top  
 

asScore


 

readHeaderChunk


 

readMIDIFrom:

Read one or more MIDI tracks from the given binary stream.


 

readTrackChunk


  private top  
 

guessMissingInstrumentNames

Attempt to guess missing instrument names from the first program change in that track.


 

next16BitWord

Read a 16-bit positive integer from the input stream, most significant byte first.


 

next32BitWord:

Read a 32-bit positive integer from the input stream.


 

readChunkSize

Read a 32-bit positive integer from the next 4 bytes, most significant byte first.


 

readChunkType

Read a chunk ID string from the next 4 bytes.


 

readVarLengthIntFrom:

Read a one to four byte positive integer from the given stream, most significant byte first. Use only the lowest seven bits of each byte. The highest bit of a byte is set for all bytes except the last.


 

report:


 

riffSkipToMidiChunk

This file is a RIFF file which may (or may not) contain a MIDI chunk. Thanks to Andreas Raab for this code.


 

scanForMIDIHeader

Scan the first part of this file in search of the MIDI header string 'MThd'. Report an error if it is not found. Otherwise, leave the input stream positioned to the first byte after this string.


 

splitIntoTracks

Split a type zero MIDI file into separate tracks by channel number.


  track reading top  
 

endAllNotesAt:

End of score; end any notes still sounding.


 

endNote:chan:at:


 

isTempoTrack:

Return true if the given event list is non-empty and contains only tempo change events.


 

metaEventAt:

Read a meta event. Event types appear roughly in order of expected frequency.


 

readTrackContents:


 

readTrackEvents

Read the events of the current track.


 

startNote:vel:chan:at:

Record the beginning of a note.


 

trackContainsNotes:

Answer true if the given track contains at least one note event.


class methods
  as yet unclassified top  
 

playFileNamed:


 

playStream:


 

playURLNamed:


 

scoreFromFileNamed:


 

scoreFromStream:


 

scoreFromURL:


 

standardMIDIInstrumentNames

Answer an array of Standard MIDI instrument names.