This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
Bank.hpp
Go to the documentation of this file.
1 /* ✔ */
2 
3 #pragma once
4 
5 #include <Helpers/Debug.hpp>
6 #include <Helpers/Error.hpp>
7 #include <Helpers/LinkedList.hpp>
9 
11 
12 template <setting_t N>
14 
15 class BankableMIDIOutput;
16 
20 class OutputBank {
21  public:
31  OutputBank(uint8_t tracksPerBank = 1, setting_t initialSelection = 0)
32  : tracksPerBank(tracksPerBank), bankSetting(initialSelection) {
33  if (tracksPerBank == 0)
34  FATAL_ERROR(F("A Bank must have a non-zero number of tracks."),
35  0x4573);
36  }
37 
44  void select(setting_t setting) { bankSetting = setting; }
45 
49  virtual setting_t getSelection() const { return bankSetting; }
50 
55  uint8_t getTracksPerBank() const { return tracksPerBank; }
56 
61  uint8_t getOffset() const { return getSelection() * getTracksPerBank(); }
62 
63  private:
64  uint8_t tracksPerBank;
66 };
67 
76 template <setting_t N>
77 class Bank : public Selectable<N>, public OutputBank {
78  friend class BankableMIDIInput<N>;
79 
80  public:
93 
102  void select(setting_t bankSetting) override;
103 
107  constexpr static uint8_t getNumberOfBanks() { return N; }
108 
109  private:
118  void add(BankableMIDIInput<N> *bankable);
119 
128  void remove(BankableMIDIInput<N> *bankable);
129 
139 };
140 
142 
143 // ---------------------------- Implementations ----------------------------- //
144 
146 
148 
149 template <setting_t N>
151  inputBankables.append(bankable);
152 }
153 
154 template <setting_t N>
156  inputBankables.remove(bankable);
157 }
158 
159 template <setting_t N>
160 void Bank<N>::select(setting_t bankSetting) {
161  bankSetting = this->validateSetting(bankSetting);
162  OutputBank::select(bankSetting);
163  for (BankableMIDIInput<N> &e : inputBankables)
164  e.onBankSettingChange();
165 }
166 
OutputBank
A class for changing the address of BankableMIDIOutputs.
Definition: Bank.hpp:20
Bank
A class that groups Bankable BankableMIDIOutputs and BankableMIDIInputs, and allows the user to chang...
Definition: Bank.hpp:77
Bank::select
void select(setting_t bankSetting) override
Select the given bank setting.
Definition: Bank.hpp:160
OutputBank::getTracksPerBank
uint8_t getTracksPerBank() const
Get the number of tracks per bank.
Definition: Bank.hpp:55
Error.hpp
Selectable.hpp
Bank::inputBankables
DoublyLinkedList< BankableMIDIInput< N > > inputBankables
A linked list of all BankableMIDIInput elements that have been added to this bank,...
Definition: Bank.hpp:138
Selectable
Definition: Selectable.hpp:11
OutputBank::getOffset
uint8_t getOffset() const
Get the offset (number of banks times the index of the selected bank)
Definition: Bank.hpp:61
OutputBank::tracksPerBank
uint8_t tracksPerBank
Definition: Bank.hpp:64
LinkedList.hpp
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: NamespaceSettings.hpp:9
Bank::remove
void remove(BankableMIDIInput< N > *bankable)
Remove a BankableMIDIInput from the bank.
Definition: Bank.hpp:155
OutputBank::select
void select(setting_t setting)
Select the given bank setting.
Definition: Bank.hpp:44
Selectable::initialSelection
setting_t initialSelection
Definition: Selectable.hpp:40
OutputBank::getSelection
virtual setting_t getSelection() const
Get the current bank setting.
Definition: Bank.hpp:49
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: NamespaceSettings.hpp:10
Bank::add
void add(BankableMIDIInput< N > *bankable)
Add a BankableMIDIInput to the bank.
Definition: Bank.hpp:150
FATAL_ERROR
#define FATAL_ERROR(x, e)
Definition: Error.hpp:35
DoublyLinkedList
A class for doubly linked lists.
Definition: LinkedList.hpp:23
setting_t
uint8_t setting_t
The type used for Selectors.
Definition: Def.hpp:63
Debug.hpp
BankableMIDIInput
A base class for all MIDIInputElements that can be banked.
Definition: Bank.hpp:13
OutputBank::bankSetting
setting_t bankSetting
Definition: Bank.hpp:65
OutputBank::OutputBank
OutputBank(uint8_t tracksPerBank=1, setting_t initialSelection=0)
Create a new OutputBank object.
Definition: Bank.hpp:31
BankableMIDIOutput
A base class for all MIDIOutputElements that can be banked.
Definition: BankableMIDIOutput.hpp:84
BankableMIDIInput.hpp
Bank::getNumberOfBanks
constexpr static uint8_t getNumberOfBanks()
Get the number of Banks.
Definition: Bank.hpp:107
Bank::Bank
Bank(uint8_t tracksPerBank=1, setting_t initialSelection=0)
Construct a new Bank object.
Definition: Bank.hpp:90
MIDI_Notes::F
constexpr int8_t F
Definition: Notes.hpp:23