Control Surface new-input
MIDI Control Surface library for Arduino
Cable.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 
13 class Cable {
14  public:
21  explicit constexpr Cable(uint8_t zeroBasedCable)
23 
29  constexpr uint8_t getRaw() const { return zeroBasedCable; }
30 
36  constexpr uint8_t getOneBased() const { return zeroBasedCable + 1; }
37 
44  static constexpr Cable createCable(uint8_t oneBasedCable) {
45  return Cable{uint8_t(oneBasedCable - 1)};
46  }
47 
54  constexpr bool operator==(const Cable &rhs) const {
55  return this->zeroBasedCable == rhs.zeroBasedCable;
56  }
57 
64  constexpr bool operator!=(const Cable &rhs) const {
65  return this->zeroBasedCable != rhs.zeroBasedCable;
66  }
67 
74  Cable &operator+=(uint8_t rhs) {
75  this->zeroBasedCable += rhs;
76  return *this;
77  }
78 
85  Cable operator+(uint8_t rhs) const {
86  Cable copy = *this;
87  copy += rhs;
88  return copy;
89  }
90 
97  Cable &operator-=(uint8_t rhs) {
98  this->zeroBasedCable -= rhs;
99  return *this;
100  }
101 
108  Cable operator-(uint8_t rhs) const {
109  Cable copy = *this;
110  copy -= rhs;
111  return copy;
112  }
113 
114  private:
115  uint8_t zeroBasedCable : 4;
116 };
117 
134 
135 Print &operator<<(Print &, Cable);
136 
constexpr Cable CABLE_7
Definition: Cable.hpp:124
constexpr Cable CABLE_13
Definition: Cable.hpp:130
constexpr Cable CABLE_5
Definition: Cable.hpp:122
constexpr Cable CABLE_12
Definition: Cable.hpp:129
constexpr Cable CABLE_14
Definition: Cable.hpp:131
constexpr Cable CABLE_10
Definition: Cable.hpp:127
constexpr Cable CABLE_16
Definition: Cable.hpp:133
constexpr Cable CABLE_9
Definition: Cable.hpp:126
constexpr Cable CABLE_11
Definition: Cable.hpp:128
constexpr Cable CABLE_3
Definition: Cable.hpp:120
constexpr Cable CABLE_8
Definition: Cable.hpp:125
constexpr Cable CABLE_1
Definition: Cable.hpp:118
constexpr Cable CABLE_6
Definition: Cable.hpp:123
constexpr Cable CABLE_2
Definition: Cable.hpp:119
constexpr Cable CABLE_4
Definition: Cable.hpp:121
constexpr Cable CABLE_15
Definition: Cable.hpp:132
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
A type-safe class for MIDI USB Cable numbers.
Definition: Cable.hpp:13
static constexpr Cable createCable(uint8_t oneBasedCable)
Create a cable.
Definition: Cable.hpp:44
uint8_t zeroBasedCable
Definition: Cable.hpp:115
constexpr bool operator==(const Cable &rhs) const
Check if two cables are the same.
Definition: Cable.hpp:54
constexpr bool operator!=(const Cable &rhs) const
Check if two cables are the different.
Definition: Cable.hpp:64
Cable operator-(uint8_t rhs) const
Subtract an offset from a cable.
Definition: Cable.hpp:108
constexpr uint8_t getOneBased() const
Get the cable as an integer.
Definition: Cable.hpp:36
constexpr Cable(uint8_t zeroBasedCable)
Create a MIDI Cable object.
Definition: Cable.hpp:21
constexpr uint8_t getRaw() const
Get the cable as an integer.
Definition: Cable.hpp:29
Cable & operator-=(uint8_t rhs)
Subtract an offset.
Definition: Cable.hpp:97
Cable & operator+=(uint8_t rhs)
Add an offset.
Definition: Cable.hpp:74
Cable operator+(uint8_t rhs) const
Add an offset to a cable.
Definition: Cable.hpp:85
Print & operator<<(Print &os, Quaternion e)
Printing.
Definition: Quaternion.cpp:28