Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


Public Member Functions | List of all members
stk::MidiFileIn Class Reference

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

#include <MidiFileIn.h>

Inheritance diagram for stk::MidiFileIn:
stk::Stk

Public Member Functions

 MidiFileIn (std::string fileName)
 Default constructor. More...
 
 ~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. More...
 
void rewindTrack (unsigned int track=0)
 Move the specified track event reader to the beginning of its track. More...
 
double getTickSeconds (unsigned int track=0)
 Get the current value, in seconds, of delta-time ticks for the specified track. More...
 
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. More...
 
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. More...
 
- Public Member Functions inherited from stk::Stk
void ignoreSampleRateChange (bool ignore=true)
 A function to enable/disable the automatic updating of class data when the STK sample rate changes. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from stk::Stk
static StkFloat sampleRate (void)
 Static method that returns the current STK sample rate.
 
static void setSampleRate (StkFloat rate)
 Static method that sets the STK sample rate. More...
 
static std::string rawwavePath (void)
 Static method that returns the current rawwave path.
 
static void setRawwavePath (std::string path)
 Static method that sets the STK rawwave path.
 
static void swap16 (unsigned char *ptr)
 Static method that byte-swaps a 16-bit data type.
 
static void swap32 (unsigned char *ptr)
 Static method that byte-swaps a 32-bit data type.
 
static void swap64 (unsigned char *ptr)
 Static method that byte-swaps a 64-bit data type.
 
static void sleep (unsigned long milliseconds)
 Static cross-platform method to sleep for a number of milliseconds.
 
static bool inRange (StkFloat value, StkFloat min, StkFloat max)
 Static method to check whether a value is within a specified range.
 
static void handleError (const char *message, StkError::Type type)
 Static function for error reporting and handling using c-strings.
 
static void handleError (std::string message, StkError::Type type)
 Static function for error reporting and handling using c++ strings.
 
static void showWarnings (bool status)
 Toggle display of WARNING and STATUS messages.
 
static void printErrors (bool status)
 Toggle display of error messages before throwing exceptions.
 
- Static Public Attributes inherited from stk::Stk
static const StkFormat STK_SINT8
 
static const StkFormat STK_SINT16
 
static const StkFormat STK_SINT24
 
static const StkFormat STK_SINT32
 
static const StkFormat STK_FLOAT32
 
static const StkFormat STK_FLOAT64
 
- Protected Member Functions inherited from stk::Stk
 Stk (void)
 Default constructor.
 
virtual ~Stk (void)
 Class destructor.
 
virtual void sampleRateChanged (StkFloat newRate, StkFloat oldRate)
 This function should be implemented in subclasses that depend on the sample rate.
 
void addSampleRateAlert (Stk *ptr)
 Add class pointer to list for sample rate change notification.
 
void removeSampleRateAlert (Stk *ptr)
 Remove class pointer from list for sample rate change notification.
 
void handleError (StkError::Type type) const
 Internal function for error reporting that assumes message in oStream_ variable.
 

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
inline

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.

54 { return division_; };
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:

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