This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
Selectable.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Def/Def.hpp>
4 #include <Helpers/Error.hpp>
5 #include <Helpers/Helpers.hpp>
6 #include <stdint.h>
7 
9 
10 template <setting_t N> // TODO: check bounds here?
11 class Selectable {
12  protected:
15 
16  public:
17  virtual void select(setting_t setting) = 0;
18 
20  static_assert(is_unsigned<setting_t>::value,
21  "Error: setting_t should be an unsigned integer type.");
22  if (setting >= N) {
23  ERROR(F("Error: Setting ")
24  << setting
25  << F(" is not less than the number of settings (") << N
26  << ')',
27  0xFFFE);
28  return N - 1;
29  }
30  return setting;
31  }
32 
34 
36  this->initialSelection = validateSetting(initialSelection);
37  }
38 
39  private:
41 };
42 
Selectable::setInitialSelection
void setInitialSelection(setting_t initialSelection)
Definition: Selectable.hpp:35
Selectable::validateSetting
static setting_t validateSetting(setting_t setting)
Definition: Selectable.hpp:19
ERROR
#define ERROR(x, e)
Definition: Error.hpp:27
Error.hpp
Def.hpp
Selectable::getInitialSelection
setting_t getInitialSelection() const
Definition: Selectable.hpp:33
Selectable
Definition: Selectable.hpp:11
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: NamespaceSettings.hpp:9
Selectable::initialSelection
setting_t initialSelection
Definition: Selectable.hpp:40
is_unsigned
A utility class to check whether a given type is unsigned.
Definition: Helpers.hpp:12
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: NamespaceSettings.hpp:10
Selectable::Selectable
Selectable(setting_t initialSelection=0)
Definition: Selectable.hpp:13
Helpers.hpp
setting_t
uint8_t setting_t
The type used for Selectors.
Definition: Def.hpp:63
Selectable::select
virtual void select(setting_t setting)=0
MIDI_Notes::F
constexpr int8_t F
Definition: Notes.hpp:23