Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
Bank.hpp
Go to the documentation of this file.
1/* ✔ */
2
3#pragma once
4
6#include <AH/Debug/Debug.hpp>
7#include <AH/Error/Error.hpp>
9
11
12template <setting_t N>
14
17 public:
28 OutputBank(uint8_t tracksPerBank = 1, setting_t initialSelection = 0,
29 int8_t selectionOffset = 0)
30 : tracksPerBank(tracksPerBank), bankSetting(initialSelection),
32 if (tracksPerBank == 0)
33 FATAL_ERROR(F("A Bank must have a non-zero number of tracks."),
34 0x4573);
35 }
36
41 void select(setting_t setting) { bankSetting = setting; }
42
46 int8_t getSelectionOffset() const { return selectionOffset; }
47
50 uint8_t getTracksPerBank() const { return tracksPerBank; }
51
53 int8_t getOffsetOfSetting(setting_t s) const {
54 return (s + getSelectionOffset()) * getTracksPerBank();
55 }
58 int8_t getOffset() const { return getOffsetOfSetting(getSelection()); }
59
60 private:
64};
65
69 : public DoublyLinkable<BankSettingChangeCallback> {
70 template <setting_t N>
71 friend class Bank;
72
73 private:
81 virtual void onBankSettingChange() {}
82};
83
93template <setting_t NumBanks>
94class Bank : public Selectable<NumBanks>, public OutputBank {
95
96 public:
111
120
122 constexpr static uint8_t getNumberOfBanks() { return NumBanks; }
123
124 public:
130
136
137 private:
143};
144
146
147// ---------------------------- Implementations ----------------------------- //
148
150
151template <setting_t NumBanks>
153 inputBankables.append(bankable);
154}
155
156template <setting_t NumBanks>
158 inputBankables.remove(bankable);
159}
160
161template <setting_t NumBanks>
163 bankSetting = this->validateSetting(bankSetting);
164 OutputBank::select(bankSetting);
165 for (BankSettingChangeCallback &e : inputBankables)
166 e.onBankSettingChange();
167}
168
uint8_t setting_t
The type used for Selectors.
Definition Def.hpp:53
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Callback class for Bankable objects that need to be notified when the active setting of their Bank ch...
Definition Bank.hpp:69
virtual void onBankSettingChange()
A function to be executed each time the bank setting changes.
Definition Bank.hpp:81
A class that groups Bankable MIDI Output Elements and Bankable MIDI Input Elements,...
Definition Bank.hpp:94
static constexpr uint8_t getNumberOfBanks()
Get the number of banks.
Definition Bank.hpp:122
void add(BankSettingChangeCallback *bankable)
Add a Bankable MIDI Input Element to the bank.
Definition Bank.hpp:152
void remove(BankSettingChangeCallback *bankable)
Remove a Bankable MIDI Input Element from the bank.
Definition Bank.hpp:157
void select(setting_t bankSetting) override
Select the given bank setting.
Definition Bank.hpp:162
Bank(uint8_t tracksPerBank=1, setting_t initialSelection=0, int8_t selectionOffset=0)
Construct a new Bank object.
Definition Bank.hpp:107
DoublyLinkedList< BankSettingChangeCallback > inputBankables
A linked list of all Bankable MIDI Input Elements that have been added to this bank,...
Definition Bank.hpp:142
A class that can be inherited from to allow inserting into a DoublyLinkedList.
A class for doubly linked lists.
void append(Node *node)
Append a node to a linked list.
A class for changing the address of BankableMIDIOutputs.
Definition Bank.hpp:16
uint8_t getTracksPerBank() const
Get the number of tracks per bank.
Definition Bank.hpp:50
setting_t getSelection() const
Get the current bank setting (zero-based).
Definition Bank.hpp:44
int8_t getOffset() const
Get the address offset (number of banks times the index of the selected bank after applying the offse...
Definition Bank.hpp:58
OutputBank(uint8_t tracksPerBank=1, setting_t initialSelection=0, int8_t selectionOffset=0)
Create a new OutputBank object.
Definition Bank.hpp:28
uint8_t tracksPerBank
Definition Bank.hpp:61
void select(setting_t setting)
Select the given bank setting.
Definition Bank.hpp:41
int8_t getOffsetOfSetting(setting_t s) const
The same as getOffset, but for a given setting.
Definition Bank.hpp:53
int8_t selectionOffset
Definition Bank.hpp:63
setting_t bankSetting
Definition Bank.hpp:62
int8_t getSelectionOffset() const
Get the offset of the bank setting.
Definition Bank.hpp:46
#define FATAL_ERROR(msg, errc)
Print the error message and error code, and stop the execution.
Definition Error.hpp:57