Control Surface new-input
MIDI Control Surface library for Arduino
MIDI_Staller.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include <Settings/NamespaceSettings.hpp>
5 #include <AH/STL/utility> // std::forward
6 
8 
10 
12 struct MIDIStaller {
13  virtual ~MIDIStaller() = default;
15  virtual const char *getName() const { return "<?>"; };
18  virtual void handleStall() = 0;
19 
22  static const char *getNameNull(MIDIStaller *s);
23 };
24 
29 template <class Callback>
30 auto makeMIDIStaller(Callback &&callback) -> MIDIStaller * {
31 
32  struct AutoCleanupMIDIStaller : MIDIStaller {
33  AutoCleanupMIDIStaller(Callback &&callback)
34  : callback(std::forward<Callback>(callback)) {}
35 
36  void handleStall() override {
37  callback(this);
38  delete this;
39  }
40 
41  Callback callback;
42  };
43  return new AutoCleanupMIDIStaller(std::forward<Callback>(callback));
44 }
45 
47 
auto makeMIDIStaller(Callback &&callback) -> MIDIStaller *
Allocate a MIDIStaller executes the given callback and deletes itself when MIDIStaller::handleStall i...
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
#define AH_DIAGNOSTIC_POP()
Definition: Warnings.hpp:36
#define AH_DIAGNOSTIC_WERROR()
Definition: Warnings.hpp:35
Struct that can cause a MIDI_Pipe to be stalled.
virtual const char * getName() const
Get the staller's name for debugging purposes.
virtual void handleStall()=0
Call back that should finish any MIDI messages that are in progress, and un-stall the pipe or MIDI so...
virtual ~MIDIStaller()=default