This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
MIDIInputElement.hpp
Go to the documentation of this file.
1 /* ✔ */
2 
3 #pragma once
4 
7 
9 
16  protected:
17  MIDIInputElement() {} // not used, only for virtual inheritance
25 
26  public:
27  virtual ~MIDIInputElement() = default;
28 
30  virtual void begin() {}
31 
33  virtual void reset() {}
34 
36  virtual void update() {}
37 
39  bool updateWith(const ChannelMessageMatcher &midimsg) {
40  MIDICNChannelAddress target = getTarget(midimsg);
41  if (!this->match(target))
42  return false;
43  DEBUGFN(F("MIDI message matches"));
44  if (!updateImpl(midimsg, target))
45  return false;
46  DEBUGFN(F("Updated"));
47  return true;
48  }
49 
50  private:
52  virtual bool updateImpl(const ChannelMessageMatcher &midimsg,
53  const MIDICNChannelAddress &target) = 0;
54 
63  virtual MIDICNChannelAddress
64  getTarget(const ChannelMessageMatcher &midimsg) const {
65  return {int8_t(midimsg.data1), Channel(midimsg.channel), midimsg.CN};
66  }
67 
75  virtual bool match(const MIDICNChannelAddress &target) const {
76  return MIDICNChannelAddress::matchSingle(this->address, target);
77  }
78 
79  protected:
81 };
82 
ChannelMessageMatcher::CN
uint8_t CN
Definition: ChannelMessageMatcher.hpp:22
MIDIInputElement::~MIDIInputElement
virtual ~MIDIInputElement()=default
Channel
A type-safe class for MIDI channels.
Definition: Channel.hpp:13
MIDIInputElement::reset
virtual void reset()
Reset the input element to its initial state.
Definition: MIDIInputElement.hpp:33
MIDIInputElement::begin
virtual void begin()
Initialize the input element.
Definition: MIDIInputElement.hpp:30
MIDIInputElement::MIDIInputElement
MIDIInputElement()
Definition: MIDIInputElement.hpp:17
MIDIInputElement::match
virtual bool match(const MIDICNChannelAddress &target) const
Check if the address of the incoming MIDI message matches an address of this element.
Definition: MIDIInputElement.hpp:75
MIDICNChannelAddress.hpp
MIDIInputElement::updateWith
bool updateWith(const ChannelMessageMatcher &midimsg)
Receive a new MIDI message and update the internal state.
Definition: MIDIInputElement.hpp:39
ChannelMessageMatcher
Struct for easily matching MIDI messages.
Definition: ChannelMessageMatcher.hpp:10
ChannelMessageMatcher.hpp
MIDIInputElement::update
virtual void update()
Update the value of the input element. Used for decaying VU meters etc.
Definition: MIDIInputElement.hpp:36
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: NamespaceSettings.hpp:9
MIDICNChannelAddress
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
Definition: MIDICNChannelAddress.hpp:82
DEBUGFN
#define DEBUGFN(x)
Definition: Debug.hpp:164
MIDIInputElement::updateImpl
virtual bool updateImpl(const ChannelMessageMatcher &midimsg, const MIDICNChannelAddress &target)=0
Update the internal state with the new MIDI message.
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: NamespaceSettings.hpp:10
ChannelMessageMatcher::channel
uint8_t channel
Definition: ChannelMessageMatcher.hpp:19
ChannelMessageMatcher::data1
uint8_t data1
Definition: ChannelMessageMatcher.hpp:20
MIDIInputElement::getTarget
virtual MIDICNChannelAddress getTarget(const ChannelMessageMatcher &midimsg) const
Extract the target address from a MIDI message.
Definition: MIDIInputElement.hpp:64
MIDICNChannelAddress::matchSingle
static bool matchSingle(const MIDICNChannelAddress &toMatch, const MIDICNChannelAddress &base)
Check if two addresses match.
Definition: MIDICNChannelAddress.cpp:43
MIDIInputElement::address
const MIDICNChannelAddress address
Definition: MIDIInputElement.hpp:80
MIDIInputElement
A class for objects that listen for incoming MIDI events.
Definition: MIDIInputElement.hpp:15
MIDIInputElement::MIDIInputElement
MIDIInputElement(const MIDICNChannelAddress &address)
Create a new MIDIInputElement that listens on the given address.
Definition: MIDIInputElement.hpp:24
MIDI_Notes::F
constexpr int8_t F
Definition: Notes.hpp:23