Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# stk::MidiFileIn Class Reference

A standard MIDI file reading/parsing class. More...

`#include <MidiFileIn.h>`

Inheritance diagram for stk::MidiFileIn:

List of all members.

## Public Member Functions
| MidiFileIn (std::string fileName)
| Default constructor.
| ~MidiFileIn ()
| Class destructor.
int | getFileFormat () const
| Return the MIDI file format (0, 1, or 2).
unsigned int | getNumberOfTracks () const
| Return the number of tracks in the MIDI file.
int | getDivision () const
| Return the MIDI file division value from the file header.
void | rewindTrack (unsigned int track=0)
| Move the specified track event reader to the beginning of its track.
double | getTickSeconds (unsigned int track=0)
| Get the current value, in seconds, of delta-time ticks for the specified track.
unsigned long | getNextEvent (std::vector< unsigned char > *event, unsigned int track=0)
| Fill the user-provided vector with the next event in the specified track and return the event delta-time in ticks.
unsigned long | getNextMidiEvent (std::vector< unsigned char > *midiEvent, unsigned int track=0)
| Fill the user-provided vector with the next MIDI channel event in the specified track and return the event delta time in ticks.

## Detailed Description

A standard MIDI file reading/parsing class.

This class can be used to read events from a standard MIDI file. Event bytes are copied to a C++ vector and must be subsequently interpreted by the user. The function getNextMidiEvent() skips meta and sysex events, returning only MIDI channel messages. Event delta-times are returned in the form of "ticks" and a function is provided to determine the current "seconds per tick". Tempo changes are internally tracked by the class and reflected in the values returned by the function getTickSeconds().

by Gary P. Scavone, 2003 - 2010.

## Constructor & Destructor Documentation

stk::MidiFileIn::MidiFileIn | ( | std::string | fileName | ) |

Default constructor.

If an error occurs while opening or parsing the file header, an StkError exception will be thrown.

## Member Function Documentation

int stk::MidiFileIn::getDivision | ( |  | ) | const

Return the MIDI file division value from the file header.

Note that this value must be "parsed" in accordance with the MIDI File Specification. In particular, if the MSB is set, the file uses time-code representations for delta-time values.

void stk::MidiFileIn::rewindTrack | ( | unsigned int | track = `0` | ) |

Move the specified track event reader to the beginning of its track.

The relevant track tempo value is reset as well. If an invalid track number is specified, an StkError exception will be thrown.

double stk::MidiFileIn::getTickSeconds | ( | unsigned int | track = `0` | ) |

Get the current value, in seconds, of delta-time ticks for the specified track.

This value can change as events are read (via "Set Tempo" Meta-Events). Therefore, one should call this function after every call to getNextEvent() or getNextMidiEvent(). If an invalid track number is specified, an StkError exception will be thrown.

unsigned long stk::MidiFileIn::getNextEvent | ( | std::vector< unsigned char > * | event,
|  | unsigned int | track = `0` |
| ) |  |  |

Fill the user-provided vector with the next event in the specified track and return the event delta-time in ticks.

MIDI File events consist of a delta time and a sequence of event bytes. This function returns the delta-time value and writes the subsequent event bytes directly to the event vector. The user must parse the event bytes in accordance with the MIDI File Specification. All returned MIDI channel events are complete ... a status byte is provided even when running status is used in the file. If the track has reached its end, no bytes will be written and the event vector size will be zero. If an invalid track number is specified or an error occurs while reading the file, an StkError exception will be thrown.

unsigned long stk::MidiFileIn::getNextMidiEvent | ( | std::vector< unsigned char > * | midiEvent,
|  | unsigned int | track = `0` |
| ) |  |  |

Fill the user-provided vector with the next MIDI channel event in the specified track and return the event delta time in ticks.

All returned MIDI events are complete ... a status byte is provided even when running status is used in the file. Meta and sysex events in the track are skipped though "Set Tempo" events are properly parsed for use by the getTickSeconds() function. If the track has reached its end, no bytes will be written and the event vector size will be zero. If an invalid track number is specified or an error occurs while reading the file, an StkError exception will be thrown.

The documentation for this class was generated from the following file:

- MidiFileIn.h

The Synthesis ToolKit in C++ (STK)
©1995-2010 Perry R. Cook and Gary P. Scavone. All Rights Reserved.