The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

MidiFileIn.h
1#ifndef STK_MIDIFILEIN_H
2#define STK_MIDIFILEIN_H
3
4#include "Stk.h"
5#include <string>
6#include <vector>
7#include <fstream>
8#include <sstream>
9
10namespace stk {
11
12/**********************************************************************/
27/**********************************************************************/
28
29 class MidiFileIn : public Stk
30{
31 public:
33
37 MidiFileIn( std::string fileName );
38
40 ~MidiFileIn();
41
43 int getFileFormat() const { return format_; };
44
46 unsigned int getNumberOfTracks() const { return nTracks_; };
47
49
54 int getDivision() const { return division_; };
55
57
61 void rewindTrack( unsigned int track = 0 );
62
64
71 double getTickSeconds( unsigned int track = 0 );
72
74
86 unsigned long getNextEvent( std::vector<unsigned char> *event, unsigned int track = 0 );
87
89
99 unsigned long getNextMidiEvent( std::vector<unsigned char> *midiEvent, unsigned int track = 0 );
100
101 protected:
102
103 // This protected class function is used for reading variable-length
104 // MIDI file values. It is assumed that this function is called with
105 // the file read pointer positioned at the start of a
106 // variable-length value. The function returns true if the value is
107 // successfully parsed. Otherwise, it returns false.
108 bool readVariableLength( unsigned long *value );
109
110 std::ifstream file_;
111 unsigned int nTracks_;
112 int format_;
113 int division_;
114 bool usingTimeCode_;
115 std::vector<double> tickSeconds_;
116 std::vector<long> trackPointers_;
117 std::vector<long> trackOffsets_;
118 std::vector<long> trackLengths_;
119 std::vector<char> trackStatus_;
120
121 // This structure and the following variables are used to save and
122 // keep track of a format 1 tempo map (and the initial tickSeconds
123 // parameter for formats 0 and 2).
124 struct TempoChange {
125 unsigned long count;
126 double tickSeconds;
127 };
128 std::vector<TempoChange> tempoEvents_;
129 std::vector<unsigned long> trackCounters_;
130 std::vector<unsigned int> trackTempoIndex_;
131};
132
133} // stk namespace
134
135#endif
stk::MidiFileIn
A standard MIDI file reading/parsing class.
Definition MidiFileIn.h:30
stk::MidiFileIn::getNextEvent
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-t...
stk::MidiFileIn::getFileFormat
int getFileFormat() const
Return the MIDI file format (0, 1, or 2).
Definition MidiFileIn.h:43
stk::MidiFileIn::rewindTrack
void rewindTrack(unsigned int track=0)
Move the specified track event reader to the beginning of its track.
stk::MidiFileIn::~MidiFileIn
~MidiFileIn()
Class destructor.
stk::MidiFileIn::getTickSeconds
double getTickSeconds(unsigned int track=0)
Get the current value, in seconds, of delta-time ticks for the specified track.
stk::MidiFileIn::getNextMidiEvent
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 ...
stk::MidiFileIn::getDivision
int getDivision() const
Return the MIDI file division value from the file header.
Definition MidiFileIn.h:54
stk::MidiFileIn::MidiFileIn
MidiFileIn(std::string fileName)
Default constructor.
stk::MidiFileIn::getNumberOfTracks
unsigned int getNumberOfTracks() const
Return the number of tracks in the MIDI file.
Definition MidiFileIn.h:46
stk::Stk
STK base class.
Definition Stk.h:136
stk
The STK namespace.
Definition ADSR.h:6

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