Control Surface disable-pipes
MIDI Control Surface library for Arduino
MIDI_Staller.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Settings/SettingsWrapper.hpp>
4#if !DISABLE_PIPES
5
7#include <Settings/NamespaceSettings.hpp>
8#include <AH/STL/utility> // std::forward
9
11
13
16 virtual ~MIDIStaller() = default;
18 virtual const char *getName() const { return "<?>"; };
21 virtual void handleStall() = 0;
22
25 static const char *getNameNull(MIDIStaller *s);
26};
27
32template <class Callback>
33auto makeMIDIStaller(Callback &&callback) -> MIDIStaller * {
34
35 struct AutoCleanupMIDIStaller : MIDIStaller {
36 AutoCleanupMIDIStaller(Callback &&callback)
37 : callback(std::forward<Callback>(callback)) {}
38
39 void handleStall() override {
40 callback(this);
41 delete this;
42 }
43
44 Callback callback;
45 };
46 return new AutoCleanupMIDIStaller(std::forward<Callback>(callback));
47}
48
50
52
53#else
54
56
57struct MIDIStaller {};
58
60
61#endif
auto makeMIDIStaller(Callback &&callback) -> MIDIStaller *
Allocate a MIDIStaller that executes the given callback and deletes itself when MIDIStaller::handleSt...
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
#define AH_DIAGNOSTIC_POP()
Definition: Warnings.hpp:53
#define AH_DIAGNOSTIC_WERROR()
Definition: Warnings.hpp:52
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