Control Surface  1.2.0
MIDI Control Surface library for Arduino
Bankable/Abstract/MIDIButtons.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include <AH/Hardware/Button.hpp>
6 #include <Def/Def.hpp>
8 
10 
11 namespace Bankable {
12 
22 template <class BankAddress, class Sender, uint8_t NumButtons>
24  protected:
30  MIDIButtons(BankAddress bankAddress,
33  const Sender &sender)
34  : address(bankAddress), buttons{buttons},
36 
37  public:
38  void begin() final override {
39  for (auto &button : buttons)
40  button.begin();
41  }
42  void update() final override {
43  RelativeMIDIAddress offset = {0, 0, 0};
44  for (auto &button : buttons) {
45  AH::Button::State state = button.update();
46  if (state == AH::Button::Falling) {
47  if (!activeButtons)
48  address.lock(); // Don't allow changing of the bank setting
49  MIDIAddress sendAddress = address.getActiveAddress() + offset;
50  sender.sendOn(sendAddress);
51  activeButtons++;
52  } else if (state == AH::Button::Rising) {
53  MIDIAddress sendAddress = address.getActiveAddress() + offset;
54  sender.sendOff(sendAddress);
55  activeButtons--;
56  if (!activeButtons)
57  address.unlock();
58  }
59  offset += incrementAddress;
60  }
61  }
62 
63 #ifdef AH_INDIVIDUAL_BUTTON_INVERT
64  void invert() {
65  for (auto &button : buttons)
66  button.invert();
67  }
68 #endif
69 
70  AH::Button::State getButtonState(size_t index) const {
71  return buttons[index].getState();
72  }
73 
74  private:
75  BankAddress address;
78  uint8_t activeButtons = 0;
79 
80  public:
81  Sender sender;
82 };
83 
84 } // namespace Bankable
85 
MIDIAddress
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
Definition: MIDIAddress.hpp:91
AH::Updatable<>
Bankable::MIDIButtons::MIDIButtons
MIDIButtons(BankAddress bankAddress, const Array< AH::Button, NumButtons > &buttons, const RelativeMIDIAddress &incrementAddress, const Sender &sender)
Construct a new MIDIButtons.
Definition: Bankable/Abstract/MIDIButtons.hpp:30
Bankable
A namespace for MIDI elements that can be added to a Bank, to change their address or channel.
Definition: BankAddresses.hpp:7
Button.hpp
AH::Button::Falling
@ Falling
Input went from high to low (1,0)
Definition: Button.hpp:56
AH::Button::State
State
An enumeration of the different states a button can be in.
Definition: Button.hpp:53
MIDIOutputElement.hpp
RelativeMIDIAddress
A class for saving an offset to a MIDI address.
Definition: MIDIAddress.hpp:64
Def.hpp
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
Bankable::MIDIButtons::getButtonState
AH::Button::State getButtonState(size_t index) const
Definition: Bankable/Abstract/MIDIButtons.hpp:70
Bankable::MIDIButtons::activeButtons
uint8_t activeButtons
Definition: Bankable/Abstract/MIDIButtons.hpp:78
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
Bankable::MIDIButtons::incrementAddress
RelativeMIDIAddress incrementAddress
Definition: Bankable/Abstract/MIDIButtons.hpp:77
Array.hpp
Bankable::MIDIButtons::address
BankAddress address
Definition: Bankable/Abstract/MIDIButtons.hpp:75
AH::Array
An array wrapper for easy copying, comparing, and iterating.
Definition: Array.hpp:36
AH::Button::Rising
@ Rising
Input went from low to high (0,1)
Definition: Button.hpp:57
Bankable::MIDIButtons::sender
Sender sender
Definition: Bankable/Abstract/MIDIButtons.hpp:81
Bankable::MIDIButtons::buttons
Array< AH::Button, NumButtons > buttons
Definition: Bankable/Abstract/MIDIButtons.hpp:76
Bankable::MIDIButtons::begin
void begin() final override
Initialize this updatable.
Definition: Bankable/Abstract/MIDIButtons.hpp:38
BankableAddresses.hpp
Bankable::MIDIButtons::invert
void invert()
Definition: Bankable/Abstract/MIDIButtons.hpp:64
Bankable::MIDIButtons::update
void update() final override
Update this updatable.
Definition: Bankable/Abstract/MIDIButtons.hpp:42
Bankable::MIDIButtons
An abstract class for momentary push buttons that send MIDI events.
Definition: Bankable/Abstract/MIDIButtons.hpp:23