Control Surface  1.1.1
MIDI Control Surface library for Arduino
Channel.hpp
Go to the documentation of this file.
1 /* ✔ */
2 
3 #pragma once
4 
5 #include <stdint.h> // int8_t
6 #include <Settings/NamespaceSettings.hpp>
7 
9 
13 class Channel {
14  public:
21  explicit constexpr Channel(int8_t zeroBasedChannel)
23 
29  constexpr int8_t getRaw() const { return zeroBasedChannel; }
30 
37  static constexpr Channel createChannel(int8_t oneBasedChannel) {
38  return Channel{int8_t(oneBasedChannel - 1)};
39  }
40 
47  constexpr bool operator==(const Channel &rhs) const {
48  return this->zeroBasedChannel == rhs.zeroBasedChannel;
49  }
50 
57  Channel &operator+=(const int8_t rhs) {
58  this->zeroBasedChannel += rhs;
59  return *this;
60  }
61 
68  Channel operator+(const int8_t rhs) const {
69  Channel copy = *this;
70  copy += rhs;
71  return copy;
72  }
73 
80  Channel &operator-=(const int8_t rhs) {
81  this->zeroBasedChannel -= rhs;
82  return *this;
83  }
84 
91  Channel operator-(const int8_t rhs) const {
92  Channel copy = *this;
93  copy -= rhs;
94  return copy;
95  }
96 
97  private:
99 };
100 
107 constexpr Channel operator"" _ch(unsigned long long ch) {
108  return Channel::createChannel(ch);
109 }
110 
111 constexpr Channel CHANNEL_1 = 1_ch;
112 constexpr Channel CHANNEL_2 = 2_ch;
113 constexpr Channel CHANNEL_3 = 3_ch;
114 constexpr Channel CHANNEL_4 = 4_ch;
115 constexpr Channel CHANNEL_5 = 5_ch;
116 constexpr Channel CHANNEL_6 = 6_ch;
117 constexpr Channel CHANNEL_7 = 7_ch;
118 constexpr Channel CHANNEL_8 = 8_ch;
119 constexpr Channel CHANNEL_9 = 9_ch;
120 constexpr Channel CHANNEL_10 = 10_ch;
121 constexpr Channel CHANNEL_11 = 11_ch;
122 constexpr Channel CHANNEL_12 = 12_ch;
123 constexpr Channel CHANNEL_13 = 13_ch;
124 constexpr Channel CHANNEL_14 = 14_ch;
125 constexpr Channel CHANNEL_15 = 15_ch;
126 constexpr Channel CHANNEL_16 = 16_ch;
127 
CHANNEL_13
constexpr Channel CHANNEL_13
Definition: Channel.hpp:123
Channel
A type-safe class for MIDI channels.
Definition: Channel.hpp:13
Channel::createChannel
static constexpr Channel createChannel(int8_t oneBasedChannel)
Create a channel.
Definition: Channel.hpp:37
Channel::operator-
Channel operator-(const int8_t rhs) const
Subtract an offset from a channel.
Definition: Channel.hpp:91
Channel::operator==
constexpr bool operator==(const Channel &rhs) const
Check if two channels are the same.
Definition: Channel.hpp:47
CHANNEL_3
constexpr Channel CHANNEL_3
Definition: Channel.hpp:113
CHANNEL_6
constexpr Channel CHANNEL_6
Definition: Channel.hpp:116
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
Channel::Channel
constexpr Channel(int8_t zeroBasedChannel)
Create a MIDI Channel object.
Definition: Channel.hpp:21
CHANNEL_11
constexpr Channel CHANNEL_11
Definition: Channel.hpp:121
Channel::operator+
Channel operator+(const int8_t rhs) const
Add an offset to a channel.
Definition: Channel.hpp:68
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
CHANNEL_8
constexpr Channel CHANNEL_8
Definition: Channel.hpp:118
CHANNEL_12
constexpr Channel CHANNEL_12
Definition: Channel.hpp:122
CHANNEL_7
constexpr Channel CHANNEL_7
Definition: Channel.hpp:117
CHANNEL_15
constexpr Channel CHANNEL_15
Definition: Channel.hpp:125
CHANNEL_16
constexpr Channel CHANNEL_16
Definition: Channel.hpp:126
CHANNEL_5
constexpr Channel CHANNEL_5
Definition: Channel.hpp:115
CHANNEL_4
constexpr Channel CHANNEL_4
Definition: Channel.hpp:114
Channel::zeroBasedChannel
int8_t zeroBasedChannel
Definition: Channel.hpp:98
CHANNEL_10
constexpr Channel CHANNEL_10
Definition: Channel.hpp:120
CHANNEL_9
constexpr Channel CHANNEL_9
Definition: Channel.hpp:119
Channel::getRaw
constexpr int8_t getRaw() const
Get the channel as an integer.
Definition: Channel.hpp:29
Channel::operator+=
Channel & operator+=(const int8_t rhs)
Add an offset.
Definition: Channel.hpp:57
CHANNEL_14
constexpr Channel CHANNEL_14
Definition: Channel.hpp:124
CHANNEL_2
constexpr Channel CHANNEL_2
Definition: Channel.hpp:112
Channel::operator-=
Channel & operator-=(const int8_t rhs)
Subtract an offset.
Definition: Channel.hpp:80
CHANNEL_1
constexpr Channel CHANNEL_1
Definition: Channel.hpp:111