-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGridRoll.cpp
165 lines (144 loc) · 3.61 KB
/
GridRoll.cpp
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include "GridRoll.h"
#include "Input.h"
GridRoll::GridRoll() {
BlockSize = 16;
BlockWidth = 16;
BlockHeight = 12;
DeleteAll();
Base = 60;
Ch = Mea = 0;
x = 50;
y = 50;
}
// そのチャンネル内のMidiメッセージを一意に扱うためのidを作る
int getID(int Mea, int bit, int note) {
int Reso = 120; // 分解能
return (Mea * 16 + bit) * 128 * Reso + note;
}
void GridRoll::SetMidiEvent(int bit, int note, int val) {
int gate;
// Noteが無い場所にはGateを登録しない
switch (val) {
case -1:
gate = -1;
break;
case 0:// 全音符
gate = 1920;
break;
case 1:// 2分音符
gate = 960;
break;
case 2:// 4分音符
gate = 480;
break;
case 3:// 8分音符
gate = 240;
break;
case 4:// 16分音符
gate = 120;
break;
}
int id = getID(Mea, bit, note);
auto itr = midiEvent[Ch].find(id);
if (itr != midiEvent[Ch].end()) { // 登録されている場合の処理
return;
}
else { // 登録されていない場合の処理
midiEvent[Ch][id] = MidiEvent(Ch, Mea, bit, note, gate, 100);
}
}
void GridRoll::Update(int mea, int ch) {
Mea = mea;
Ch = ch;
static int mx, my;
int dx = 50;
int dy = 50;
Input::Mouse(&mx, &my);
// 左クリックで登録
//if (Input::MouseL() > 0) {
// int ex = (mx - dx) / BlockSize;
// int ey = BlockHeight - (my - dy) / BlockSize;
// int eey = (my - dy) / BlockSize;
// if (0 <= ex && ex < BlockWidth) {
// // 上のGrid
// if (0 <= ey && ey <= BlockHeight) {
// SetMidiEvent(ex, ey + Base, 4);
// }
// // 下のGrid
// /*else if (BlockHeight+1 < eey && eey < BlockHeight + 7) {
// SetMidiEvent(ex, eey - BlockHeight - 2);
// }*/
// }
//}
// 右クリックで削除
/*if (Input::MouseR() > 0) {
int ex = (mx - dx) / BlockSize;
if (ex < 0 || ex > BlockWidth) {}
else {
Note[Ch][Mea][ex] = -1;
TransRealGate(ex, -1);
}
}*/
}
void GridRoll::Save(FILE *fp) {
}
void GridRoll::Load(FILE *fp) {
}
void GridRoll::DeleteOnePhrase() {
midiEvent[Ch].clear();
}
void GridRoll::DeleteAll() {
for (int i = 0; i < 16; ++i) {
midiEvent[i].clear();
}
}
void GridRoll::Copy() {
}
void GridRoll::Paste() {
}
void GridRoll::Draw() const{
// Noteを描画
//int beginid = getID(Mea, 0, 0);
//int endid = getID(Mea + 1, 0, 0);
//for (int i = beginid; i < endid; ++i) {
// auto itr = midiEvent[Ch].find(i);
// if (itr != midiEvent[Ch].end()) { // 登録されている場合
// int n = itr->second.GetNote() - Base; // Baseから何個上の音か?
// if (0 <= n && n < BlockHeight) {
// int x1 = itr->second.GetBit() * BlockSize + x;
// int y1 = itr->second.GetBit() * BlockSize + y;
// double x2 = (double)x1 + BlockSize * itr->second.GetGate() / 120.0;
// int y2 = y1 + BlockSize;
// DrawEdgeBox(x1, y1, (int)x2, y2, GREEN);
// }
// }
//}
/*for (int i = 0; i < BlockWidth; i++) {
for (int j = 0; j <= BlockHeight; j++) {
int n = me[Ch][0].GetNote() - Base;
if (n == BlockHeight - j) {
int x1 = i * BlockSize + x;
int y1 = j * BlockSize + y;
double x2 = (double)x1 + BlockSize * RealGate[Ch][Mea][i] / 120.0;
int y2 = y1 + BlockSize;
MyDx::DrawEdgeBox(x1, y1, (int)x2, y2, MyDx::GREEN);
}
}
}*/
// Gateを描画
/*int ky = y + (BlockHeight+2) * BlockSize;
for (int i = 0; i < BlockWidth; i++) {
for (int j = 0; j < 5; j++) {
if (Gate[Ch][Mea][i] == j) {
MyDx::DrawEdgeBox(i * BlockSize + x, j * BlockSize + ky, (i + 1) * BlockSize + x, (j + 1) * BlockSize + ky, gatecol, MyDx::WHITE);
}
else DrawBox(i * BlockSize + x, j * BlockSize + ky, (i + 1)*BlockSize + x, (j + 1)*BlockSize + ky, MyDx::WHITE, FALSE);
}
}*/
// MidiEvent情報
int i = 0;
for (auto itr = midiEvent[Ch].begin(); itr != midiEvent[Ch].end(); itr++) {
itr->second.Draw(FMX - 200, 50 + 20*i);
i++;
}
}