-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMIDI.hpp
101 lines (82 loc) · 2.38 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#pragma once
#include <Windows.h>
#include <mmeapi.h>
#pragma comment(lib,"winmm.lib")
inline constexpr DWORD NoteOn(UCHAR ucChannel, UCHAR ucPitch, UCHAR ucVelocity)
{
/*
Status byte : 1001 CCCC
Data byte 1 : 0PPP PPPP
Data byte 2 : 0VVV VVVV
*/
union
{
UCHAR ucRet[4] = {0};
DWORD dwRet;
};
ucRet[0] = 0b1001 << 4 | (0b0000'1111 & ucChannel);
ucRet[1] = 0b0111'1111 & ucPitch;
ucRet[2] = 0b0111'1111 & ucVelocity;
return dwRet;
}
inline constexpr DWORD NoteOff(UCHAR ucChannel, UCHAR ucPitch, UCHAR ucVelocity)
{
/*
Status byte : 1000 CCCC
Data byte 1 : 0PPP PPPP
Data byte 2 : 0VVV VVVV
*/
union
{
UCHAR ucRet[4] = {0};
DWORD dwRet;
};
ucRet[0] = 0b1000'0000 | (0b0000'1111 & ucChannel);
ucRet[1] = 0b0111'1111 & ucPitch;
ucRet[2] = 0b0111'1111 & ucVelocity;
return dwRet;
}
inline constexpr DWORD PitchBend(UCHAR ucChannel, USHORT usBend)
{
/*
Status byte : 1110 CCCC
Data byte 1 : 0LLL LLLL
Data byte 2 : 0MMM MMMM
*/
union
{
UCHAR ucRet[4] = {0};
DWORD dwRet;
};
ucRet[0] = 0b1110'0000 | (0b0000'1111 & ucChannel);
ucRet[1] = 0b0111'1111 & usBend;
ucRet[2] = 0b0111'1111 & usBend >> 7;
return dwRet;
}
inline constexpr DWORD MusicalChange(UCHAR ucChannel, UCHAR ucMusical)
{
/*
Status byte : 1100 CCCC
Data byte 1 : 0MMM MMMM
*/
union
{
UCHAR ucRet[4] = {0};
DWORD dwRet;
};
ucRet[0] = 0b1100'0000 | (0b0000'1111 & ucChannel);
ucRet[1] = 0b0111'1111 & ucMusical;
return dwRet;
}
enum Pitch :UCHAR
{
UD = 0, C8 = 108, B7 = 107, A7s = 106, A7 = 105, G7s = 104, G7 = 103, F7s = 102, F7 = 101, E7 = 100,
D7s = 99, D7 = 98, C7s = 97, C7 = 96, B6 = 95, A6s = 94, A6 = 93, G6s = 92, G6 = 91, F6s = 90, F6 = 89,
E6 = 88, D6s = 87, D6 = 86, C6s = 85, C6 = 84, B5 = 83, A5s = 82, A5 = 81, G5s = 80, G5 = 79, F5s = 78,
F5 = 77, E5 = 76, D5s = 75, D5 = 74, C5s = 73, C5 = 72, B4 = 71, A4s = 70, A4 = 69, G4s = 68, G4 = 67,
F4s = 66, F4 = 65, E4 = 64, D4s = 63, D4 = 62, C4s = 61, C4 = 60, B3 = 59, A3s = 58, A3 = 57, G3s = 56,
G3 = 55, F3s = 54, F3 = 53, E3 = 52, D3s = 51, D3 = 50, C3s = 49, C3 = 48, B2 = 47, A2s = 46, A2 = 45,
G2s = 44, G2 = 43, F2s = 42, F2 = 41, E2 = 40, D2s = 39, D2 = 38, C2s = 37, C2 = 36, B1 = 35, A1s = 34,
A1 = 33, G1s = 32, G1 = 31, F1s = 30, F1 = 29, E1 = 28, D1s = 27, D1 = 26, C1s = 25, C1 = 24, B0 = 23,
A0s = 22, A0 = 21
};