Control Surface master
MIDI Control Surface library for Arduino
Channel.hpp
Go to the documentation of this file.
1/* ✔ */
2
3#pragma once
4
5#include <AH/Arduino-Wrapper.h> // Print
6#include <Settings/NamespaceSettings.hpp>
7
9
13class Channel {
14 public:
21 explicit constexpr Channel(uint8_t zeroBasedChannel)
23
29 constexpr uint8_t getRaw() const { return zeroBasedChannel; }
30
36 constexpr uint8_t getOneBased() const { return zeroBasedChannel + 1; }
37
44 static constexpr Channel createChannel(uint8_t oneBasedChannel) {
45 return Channel{uint8_t(oneBasedChannel - 1)};
46 }
47
54 constexpr bool operator==(const Channel &rhs) const {
55 return this->zeroBasedChannel == rhs.zeroBasedChannel;
56 }
57
64 constexpr bool operator!=(const Channel &rhs) const {
65 return this->zeroBasedChannel != rhs.zeroBasedChannel;
66 }
67
74 Channel &operator+=(uint8_t rhs) {
75 this->zeroBasedChannel += rhs;
76 return *this;
77 }
78
85 Channel operator+(uint8_t rhs) const {
86 Channel copy = *this;
87 copy += rhs;
88 return copy;
89 }
90
97 Channel &operator-=(uint8_t rhs) {
98 this->zeroBasedChannel -= rhs;
99 return *this;
100 }
101
108 Channel operator-(uint8_t rhs) const {
109 Channel copy = *this;
110 copy -= rhs;
111 return copy;
112 }
113
114 private:
115 uint8_t zeroBasedChannel : 4;
116};
117
134
135Print &operator<<(Print &, Channel);
136
constexpr Channel CHANNEL_2
Definition: Channel.hpp:119
constexpr Channel CHANNEL_1
Definition: Channel.hpp:118
constexpr Channel CHANNEL_11
Definition: Channel.hpp:128
constexpr Channel CHANNEL_10
Definition: Channel.hpp:127
constexpr Channel CHANNEL_12
Definition: Channel.hpp:129
constexpr Channel CHANNEL_15
Definition: Channel.hpp:132
constexpr Channel CHANNEL_6
Definition: Channel.hpp:123
constexpr Channel CHANNEL_9
Definition: Channel.hpp:126
constexpr Channel CHANNEL_13
Definition: Channel.hpp:130
constexpr Channel CHANNEL_3
Definition: Channel.hpp:120
constexpr Channel CHANNEL_4
Definition: Channel.hpp:121
constexpr Channel CHANNEL_14
Definition: Channel.hpp:131
constexpr Channel CHANNEL_5
Definition: Channel.hpp:122
constexpr Channel CHANNEL_7
Definition: Channel.hpp:124
constexpr Channel CHANNEL_16
Definition: Channel.hpp:133
constexpr Channel CHANNEL_8
Definition: Channel.hpp:125
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
A type-safe class for MIDI channels.
Definition: Channel.hpp:13
uint8_t zeroBasedChannel
Definition: Channel.hpp:115
Channel & operator+=(uint8_t rhs)
Add an offset.
Definition: Channel.hpp:74
constexpr Channel(uint8_t zeroBasedChannel)
Create a MIDI Channel object.
Definition: Channel.hpp:21
Channel operator+(uint8_t rhs) const
Add an offset to a channel.
Definition: Channel.hpp:85
static constexpr Channel createChannel(uint8_t oneBasedChannel)
Create a channel.
Definition: Channel.hpp:44
constexpr uint8_t getOneBased() const
Get the channel as an integer.
Definition: Channel.hpp:36
constexpr bool operator!=(const Channel &rhs) const
Check if two channels are the different.
Definition: Channel.hpp:64
constexpr uint8_t getRaw() const
Get the channel as an integer.
Definition: Channel.hpp:29
Channel & operator-=(uint8_t rhs)
Subtract an offset.
Definition: Channel.hpp:97
Channel operator-(uint8_t rhs) const
Subtract an offset from a channel.
Definition: Channel.hpp:108
constexpr bool operator==(const Channel &rhs) const
Check if two channels are the same.
Definition: Channel.hpp:54
Print & operator<<(Print &os, Quaternion e)
Printing.
Definition: Quaternion.cpp:28