Control Surface  1.2.0
MIDI Control Surface library for Arduino
MIDIInputElement.hpp
Go to the documentation of this file.
1 /* ✔ */
2 
3 #pragma once
4 
6 #include <Def/MIDIAddress.hpp>
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  MIDIAddress 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 MIDIAddress &target) = 0;
54 
63  virtual MIDIAddress getTarget(const ChannelMessageMatcher &midimsg) const {
64  return {
65  int8_t(midimsg.data1),
66  Channel(midimsg.channel),
67  Cable(midimsg.CN),
68  };
69  }
70 
78  virtual bool match(const MIDIAddress &target) const {
79  return MIDIAddress::matchSingle(this->address, target);
80  }
81 
82  protected:
84 };
85 
ChannelMessageMatcher::data1
uint8_t data1
Definition: ChannelMessageMatcher.hpp:19
Channel
A type-safe class for MIDI channels.
Definition: Channel.hpp:13
MIDIAddress.hpp
MIDIInputElement::reset
virtual void reset()
Reset the input element to its initial state.
Definition: MIDIInputElement.hpp:33
MIDIAddress
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
Definition: MIDIAddress.hpp:91
MIDIInputElement::match
virtual bool match(const MIDIAddress &target) const
Check if the address of the incoming MIDI message matches an address of this element.
Definition: MIDIInputElement.hpp:78
Cable
A type-safe class for MIDI USB Cable numbers.
Definition: Cable.hpp:13
MIDIInputElement::address
const MIDIAddress address
Definition: MIDIInputElement.hpp:83
MIDIInputElement::MIDIInputElement
MIDIInputElement(const MIDIAddress &address)
Create a new MIDIInputElement that listens on the given address.
Definition: MIDIInputElement.hpp:24
MIDIInputElement::updateImpl
virtual bool updateImpl(const ChannelMessageMatcher &midimsg, const MIDIAddress &target)=0
Update the internal state with the new MIDI message.
ChannelMessageMatcher::CN
uint8_t CN
Definition: ChannelMessageMatcher.hpp:21
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
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::begin
virtual void begin()
Initialize the input element.
Definition: MIDIInputElement.hpp:30
MIDIInputElement::MIDIInputElement
MIDIInputElement()
Definition: MIDIInputElement.hpp:17
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
MIDIAddress::matchSingle
static bool matchSingle(const MIDIAddress &toMatch, const MIDIAddress &base)
Check if two addresses match (are equal).
Definition: MIDIAddress.cpp:41
MIDIInputElement::getTarget
virtual MIDIAddress getTarget(const ChannelMessageMatcher &midimsg) const
Extract the target address from a MIDI message.
Definition: MIDIInputElement.hpp:63
MIDI_Notes::F
constexpr int8_t F
Definition: Notes.hpp:23
DEBUGFN
#define DEBUGFN(x)
Print an expression and its function (function name and line number) to the debug output if debugging...
Definition: Debug.hpp:93
MIDIInputElement::update
virtual void update()
Update the value of the input element. Used for decaying VU meters etc.
Definition: MIDIInputElement.hpp:36
ChannelMessageMatcher::channel
Channel channel
Definition: ChannelMessageMatcher.hpp:18
MIDIInputElement::~MIDIInputElement
virtual ~MIDIInputElement()=default
MIDIInputElement
A class for objects that listen for incoming MIDI events.
Definition: MIDIInputElement.hpp:15