@@ -13,128 +13,47 @@ namespace tracktion { inline namespace engine
13
13
14
14
struct ActiveNoteList
15
15
{
16
- struct NoteState
17
- {
18
- juce::uint16 activeNotes = 0 ;
19
- juce::uint16 pendingOns = 0 ;
20
- juce::uint16 pendingOffs = 0 ;
21
- };
22
-
23
- NoteState noteStates[128 ] = {};
16
+ juce::uint16 activeChannels[128 ] = {};
24
17
25
18
void reset () noexcept
26
19
{
27
- std::memset (noteStates, 0 , sizeof (noteStates));
28
- }
29
-
30
- void clearPendingEvents () noexcept
31
- {
32
- for (auto & state : noteStates)
33
- {
34
- state.pendingOns = 0 ;
35
- state.pendingOffs = 0 ;
36
- }
20
+ std::memset (activeChannels, 0 , sizeof (activeChannels));
37
21
}
38
22
39
23
bool isNoteActive (int channel, int note) const noexcept
40
24
{
41
25
return isValidIndex (channel, note)
42
- && (noteStates[note].activeNotes & (1u << (channel - 1 ))) != 0 ;
43
- }
44
-
45
- bool hasPendingNoteOn (int channel, int note) const noexcept
46
- {
47
- return isValidIndex (channel, note)
48
- && (noteStates[note].pendingOns & (1u << (channel - 1 ))) != 0 ;
49
- }
50
-
51
- bool hasPendingNoteOff (int channel, int note) const noexcept
52
- {
53
- return isValidIndex (channel, note)
54
- && (noteStates[note].pendingOffs & (1u << (channel - 1 ))) != 0 ;
26
+ && (activeChannels[note] & (1u << (channel - 1 ))) != 0 ;
55
27
}
56
28
57
29
void startNote (int channel, int note) noexcept
58
30
{
59
31
if (isValidIndex (channel, note))
60
- noteStates [note]. activeNotes |= (1u << (channel - 1 ));
32
+ activeChannels [note] |= (1u << (channel - 1 ));
61
33
}
62
34
63
35
void clearNote (int channel, int note) noexcept
64
36
{
65
37
if (isValidIndex (channel, note))
66
- noteStates[note].activeNotes &= ~(1u << (channel - 1 ));
67
- }
68
-
69
- void addPendingNoteOn (int channel, int note) noexcept
70
- {
71
- if (isValidIndex (channel, note))
72
- noteStates[note].pendingOns |= (1u << (channel - 1 ));
73
- }
74
-
75
- void addPendingNoteOff (int channel, int note) noexcept
76
- {
77
- if (isValidIndex (channel, note))
78
- noteStates[note].pendingOffs |= (1u << (channel - 1 ));
79
- }
80
-
81
- void applyPendingEvents () noexcept
82
- {
83
- for (auto & state : noteStates)
84
- {
85
- // Apply pending note-offs first
86
- state.activeNotes &= ~state.pendingOffs ;
87
-
88
- // Then apply pending note-ons
89
- state.activeNotes |= state.pendingOns ;
90
-
91
- state.pendingOns = 0 ;
92
- state.pendingOffs = 0 ;
93
- }
38
+ activeChannels[note] &= ~(1u << (channel - 1 ));
94
39
}
95
40
96
41
bool areAnyNotesActive () const noexcept
97
42
{
98
- for (const auto & state : noteStates)
99
- if (state.activeNotes > 0 )
100
- return true ;
101
-
102
- return false ;
103
- }
43
+ juce::uint16 result = 0 ;
104
44
105
- bool areAnyEventsPending () const noexcept
106
- {
107
- for (const auto & state : noteStates)
108
- if (state.pendingOns > 0 || state.pendingOffs > 0 )
109
- return true ;
45
+ for (auto a : activeChannels)
46
+ result |= a;
110
47
111
- return false ;
48
+ return result > 0 ;
112
49
}
113
50
114
51
template <typename Visitor>
115
52
void iterate (Visitor&& v) const noexcept
116
53
{
117
54
for (int note = 0 ; note < 128 ; ++note)
118
55
for (int chan = 0 ; chan < 16 ; ++chan)
119
- if ((noteStates[note].activeNotes & (1u << chan)) != 0 )
120
- v (chan + 1 , note);
121
- }
122
-
123
- template <typename Visitor>
124
- void iteratePendingOns (Visitor&& v) const noexcept
125
- {
126
- for (int note = 0 ; note < 128 ; ++note)
127
- for (int chan = 0 ; chan < 16 ; ++chan)
128
- if ((noteStates[note].pendingOns & (1u << chan)) != 0 )
129
- v (chan + 1 , note);
130
- }
131
-
132
- template <typename Visitor>
133
- void iteratePendingOffs (Visitor&& v) const noexcept
134
- {
135
- for (int note = 0 ; note < 128 ; ++note)
136
- for (int chan = 0 ; chan < 16 ; ++chan)
137
- if ((noteStates[note].pendingOffs & (1u << chan)) != 0 )
56
+ if ((activeChannels[note] & (1u << chan)) != 0 )
138
57
v (chan + 1 , note);
139
58
}
140
59
0 commit comments