tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_ActiveNoteList.h
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7
8 Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9*/
10
11namespace tracktion { inline namespace engine
12{
13
15{
16 juce::uint16 activeChannels[128] = {};
17
18 void reset() noexcept
19 {
20 std::memset (activeChannels, 0, sizeof (activeChannels));
21 }
22
23 bool isNoteActive (int channel, int note) const noexcept
24 {
25 return isValidIndex (channel, note)
26 && (activeChannels[note] & (1u << (channel - 1))) != 0;
27 }
28
29 void startNote (int channel, int note) noexcept
30 {
31 if (isValidIndex (channel, note))
32 activeChannels[note] |= (1u << (channel - 1));
33 }
34
35 void clearNote (int channel, int note) noexcept
36 {
37 if (isValidIndex (channel, note))
38 activeChannels[note] &= ~(1u << (channel - 1));
39 }
40
41 bool areAnyNotesActive() const noexcept
42 {
43 juce::uint16 result = 0;
44
45 for (auto a : activeChannels)
46 result |= a;
47
48 return result > 0;
49 }
50
51 template <typename Visitor>
52 void iterate (Visitor&& v) const noexcept
53 {
54 for (int note = 0; note < 128; ++note)
55 for (int chan = 0; chan < 16; ++chan)
56 if ((activeChannels[note] & (1u << chan)) != 0)
57 v (chan + 1, note);
58 }
59
60 static bool isValidIndex (int channel, int note) noexcept
61 {
62 return juce::isPositiveAndBelow (note, 128) && channel > 0 && channel <= 16;
63 }
64};
65
66}} // namespace tracktion { inline namespace engine
T memset(T... args)
unsigned short uint16
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept