/
tracktion_MidiChannel.h
59 lines (47 loc) · 1.98 KB
/
tracktion_MidiChannel.h
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
/*
,--. ,--. ,--. ,--.
,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2018
'-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
| | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
`---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
*/
namespace tracktion { inline namespace engine
{
/**
Represents a MIDI channel 1-16, and also contains extra ID bits to encode
info about the event's origin.
*/
struct MidiChannel
{
MidiChannel() = default;
MidiChannel (const MidiChannel&) = default;
MidiChannel& operator= (const MidiChannel&) = default;
// Takes a number 1-16
explicit MidiChannel (int channelNumber1to16) noexcept : channel ((uint8_t) channelNumber1to16)
{
jassert (channelNumber1to16 > 0 && channelNumber1to16 <= 16);
}
explicit MidiChannel (const juce::var& storedChannel) noexcept
: channel ((uint8_t) static_cast<int> (storedChannel))
{
if (! isValid())
channel = 1;
}
static MidiChannel fromChannelOrZero (int channel) noexcept
{
jassert (channel >= 0 && channel <= 16);
MidiChannel m;
m.channel = (uint8_t) channel;
return m;
}
// Returns 1-16 or 0 for invalid
int getChannelNumber() const noexcept { return (int) channel; }
bool isValid() const noexcept { return channel != 0; }
bool operator== (const MidiChannel& other) const noexcept { return channel == other.channel; }
bool operator!= (const MidiChannel& other) const noexcept { return channel != other.channel; }
operator juce::var() const { return juce::var (getChannelNumber()); }
private:
uint8_t channel = 0;
};
}} // namespace tracktion { inline namespace engine