This repository has been archived by the owner on Sep 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
midi.hpp
70 lines (53 loc) · 1.58 KB
/
midi.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// DO NOT EDIT
// Simple MIDI reader
// Limitations: - only 1 channel (0) per track is supported
// - only format 0 or 1 files supported
// - sysex events not supported
// - Tempo in SMPTE format unsupported.
// - Signature is assumed to be 4/4 time
#ifndef MIDI_HPP
#define MIDI_HPP
#include <cstdint>
#include <string>
#include <istream>
#include "track.hpp"
/** Read MIDI file and parse into a list of tracks.
*/
TrackListType readMIDIFromFile(const std::string & infilename);
/**
*
*/
class MIDIReader{
public:
/** Construct a reader object. */
MIDIReader();
/** Parse from a stream. Returns true on success, false on failure.
* After this successfully completes the tracks are available through
* a call to getAllTracks().
* \param ins input stream to parse from
*/
bool parse(std::istream & ins);
/** Get all the tracks available from a previous call to parse.
*/
TrackListType getAllTracks();
private:
// status of file IO and constraints during parsing
bool status;
// TODO (clwyatt): Add an error message log?
TrackListType tracklist;
void parseHeader(std::istream & ifs);
void parseNextTrack(std::istream & ifs);
struct Header {
int32_t length;
int16_t format;
int16_t n;
int16_t division;
} head;
intmax_t read_variable_length(std::istream & ifs);
int32_t read_big32(std::istream &ifs);
int16_t read_big16(std::istream &ifs);
uint8_t read_byte(std::istream & ifs);
intmax_t read_tempo(std::istream & ifs);
void read_signature(std::istream & ifs);
};
#endif