-
Notifications
You must be signed in to change notification settings - Fork 0
/
midi.hpp
49 lines (43 loc) · 1.06 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
#pragma once
#include <iostream>
#include <cstdint>
#include <cstring>
#include <vector>
#include <fstream>
#include <algorithm>
class Midi {
private:
uint32_t readBytes(uint16_t);
uint8_t readByte();
void seekg(int32_t);
uint32_t readVarLen();
std::string readStr(uint16_t);
uint32_t swap32(uint32_t) const;
uint16_t swap16(uint16_t) const;
std::ifstream in;
uint32_t pos; // file
float unitOfTime;
struct Track {
struct Note {
bool state;
uint8_t channel;
int8_t key, velocity;
uint32_t startTick, durationTick;
float startTime, durationTime;
};
std::vector<Note> notes;
};
std::vector<Track> tracks;
struct Tempo {
uint32_t tick, tempo;
float time;
};
std::vector<Tempo> tempo_map;
public:
Midi();
~Midi();
bool parse(const char*);
const std::vector<Track>& getTracks() const;
void setUnitOfTime(float);
float getUnitOfTime() const;
};