Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
MIDI_Staller.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Settings/SettingsWrapper.hpp>
4#if !DISABLE_PIPES
5
6#include <AH/STL/utility> // std::forward
7#include <Settings/NamespaceSettings.hpp>
8
10
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
29template <class Callback>
30auto 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
48#else
49
51
52struct MIDIStaller {};
53
55
56#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
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
static const char * getNameNull(MIDIStaller *s)
Get the staller's name for debugging purposes.