-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sequ.cxx
78 lines (66 loc) · 1.45 KB
/
Sequ.cxx
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
#include <cstddef>
#include "Utils.hxx"
#include "MIDI.hxx"
#include "Sequ.hxx"
using namespace NVi;
void NVsequencer::seq_start(NVmidiFile &midi)
{
E = new NVseq_event [midi.tracks + 1u];
E[midi.tracks].abstick = 0xFFFFFFFFu;
E[midi.tracks].track = midi.tracks;
for (L = 1; L < midi.tracks; L <<= 1){ }
T = new u16_t [L << 1]; seq_reset(midi);
}
void NVsequencer::seq_reset(NVmidiFile &midi)
{
for (u32_t i = midi.tracks; i < L; ++i)
{
T[i + L] = midi.tracks;
}
for (u16_t i = 0; i < midi.tracks; ++i)
{
if (E[i].get(i, midi))
{
E[i].track = T[L + i] = i;
E[i].abstick = E[i].tick;
}
else
{
T[L + i] = midi.tracks;
warn("Sequ", "发现空轨道: %d", i);
}
}
for (int i = L - 1; i > 0; --i)
{
update(i, T[i << 1], T[i << 1 | 1]);
}
}
void NVsequencer::seq_next(NVmidiFile &midi)
{
int a = T[1], p = L + a;
if (midi.trk_over[a] || !E[a].get(a, midi))
{
T[p] = midi.tracks;
}
else
{
E[a].abstick += E[a].tick;
}
for ( ; (a = p >> 1); p = a)
{
update(a, T[p], T[p ^ 1]);
}
}
const NVseq_event& NVsequencer::event() const
{
return E[T[1]];
}
void NVsequencer::seq_destroy()
{
delete[] T; delete[] E;
T = nullptr; E = nullptr;
}
void NVsequencer::update(int p, int a, int b)
{
T[p] = E[a].abstick < E[b].abstick? a : b;
}