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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_MidiChannel.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
19{
20 MidiChannel() = default;
21 MidiChannel (const MidiChannel&) = default;
22 MidiChannel& operator= (const MidiChannel&) = default;
23
24 // Takes a number 1-16
25 explicit MidiChannel (int channelNumber1to16) noexcept : channel ((uint8_t) channelNumber1to16)
26 {
27 jassert (channelNumber1to16 > 0 && channelNumber1to16 <= 16);
28 }
29
30 explicit MidiChannel (const juce::var& storedChannel) noexcept
31 : channel ((uint8_t) static_cast<int> (storedChannel))
32 {
33 if (! isValid())
34 channel = 1;
35 }
36
37 static MidiChannel fromChannelOrZero (int channel) noexcept
38 {
39 jassert (channel >= 0 && channel <= 16);
41 m.channel = (uint8_t) channel;
42 return m;
43 }
44
45 // Returns 1-16 or 0 for invalid
46 int getChannelNumber() const noexcept { return (int) channel; }
47
48 bool isValid() const noexcept { return channel != 0; }
49
50 bool operator== (const MidiChannel& other) const noexcept { return channel == other.channel; }
51 bool operator!= (const MidiChannel& other) const noexcept { return channel != other.channel; }
52
53 operator juce::var() const { return juce::var (getChannelNumber()); }
54
55private:
56 uint8_t channel = 0;
57};
58
59}} // namespace tracktion { inline namespace engine
#define jassert(expression)
typedef uint8_t
Represents a MIDI channel 1-16, and also contains extra ID bits to encode info about the event's orig...