4 #include <AH/STL/cstdint>
5 #include <AH/STL/limits>
6 #include <AH/STL/utility>
9 #include <Settings/NamespaceSettings.hpp>
17 reinterpret_cast<
MIDIStaller *>(std::numeric_limits<std::uintptr_t>::
max());
107 void connectSourcePipe(
MIDI_Pipe *source);
109 void disconnectSourcePipes();
139 void disconnectSourcePipesShallow();
511 template <
class Message>
522 template <
class Message>
644 template <
size_t N,
class Pipe = MIDI_Pipe>
651 FATAL_ERROR(F(
"Not enough pipes available"), 0x2459);
662 template <
size_t N,
class Pipe>
665 return source >> pipe_fact.
getNext();
668 template <
size_t N,
class Pipe>
671 template <
size_t N,
class Pipe>
674 return pipe_fact.
getNext() >> sink;
677 template <
size_t N,
class Pipe>
680 template <
size_t N,
class Pipe>
683 return sink << pipe_fact.
getNext();
686 template <
size_t N,
class Pipe>
689 return pipe_fact.
getNext() << source;
696 return pipe_fact.
getNext() | sinksource;
703 return sinksource | pipe_fact.
getNext();
MIDIStaller *const eternal_stall
#define BEGIN_CS_NAMESPACE
#define AH_DIAGNOSTIC_POP()
#define AH_DIAGNOSTIC_WERROR()
Class that routes MIDI messages from a MIDI_Source to a MIDI_Sink.
MIDI_Sink * getSink()
Get the immediate sink of this pipe.
MIDI_Pipe * getThroughIn()
Get the pipe connected to the “through” input of this pipe.
void acceptMIDIfromSource(Message msg)
Accept a MIDI message from the source, forward it to the “through” output if necessary,...
MIDI_Sink * getFinalSink() override
Get the sink this pipe eventually sinks to, following the chain recursively.
MIDI_Pipe & operator=(MIDI_Pipe &&)=delete
Move assignment.
bool hasSink() const
Check if this pipe is connected to a sink.
void sourceMIDItoSink(Message msg)
Send the given MIDI message to the sink of this pipe.
const char * getStallerName() const
Get the name of any staller.
MIDI_Pipe(MIDI_Pipe &&)=delete
Move constructor.
MIDIStaller * getStaller() const
Get any staller: returns getSinkStaller() if it's not null, getThroughStaller() otherwise.
virtual void mapForwardMIDI(SysExMessage msg)
Function that maps, edits or filters MIDI messages, and then forwards them to the sink of the pipe.
bool disconnect(MIDI_Pipe &)=delete
void connectSource(MIDI_Source *source)
Set the source pointer to point to the given source.
MIDIStaller * getThroughStaller() const
Get the staller (cause of the stall) that causes the “through” output of this pipe to be stalled.
MIDI_Pipe * getThroughOut()
Get the pipe connected to the “through” output of this pipe.
MIDI_Pipe(const MIDI_Pipe &)=delete
Copy constructor (copying not allowed).
virtual void mapForwardMIDI(RealTimeMessage msg)
Function that maps, edits or filters MIDI messages, and then forwards them to the sink of the pipe.
void sinkMIDIfromPipe(SysCommonMessage msg) override
Called when data arrives from an upstream pipe connected to our “through” input, this function forwar...
virtual void mapForwardMIDI(SysCommonMessage msg)
Function that maps, edits or filters MIDI messages, and then forwards them to the sink of the pipe.
void unstallDownstream(MIDIStaller *cause, MIDI_Source *stallsrc) override
Undoes the stalling by stallDownstream.
bool hasSource() const
Check if this pipe is connected to a source.
void stallDownstream(MIDIStaller *cause, MIDI_Source *stallsrc) override
Stall this pipe and all other pipes further downstream (following the path of the sink and the “throu...
bool hasThroughOut() const
Check if this pipe has a “through” output that sends all incoming messages from the input (source) to...
MIDIStaller * through_staller
MIDI_Source * getInitialSource() override
Get the original source that sources to this pipe, following the chain recursively.
void connectSink(MIDI_Sink *sink)
Set the sink pointer to point to the given sink.
const char * getSinkStallerName() const
Get the name of the staller (cause of the stall) that causes the sink of this pipe to be stalled.
void sinkMIDIfromPipe(RealTimeMessage msg) override
Called when data arrives from an upstream pipe connected to our “through” input, this function forwar...
bool isStalled() const
Check if this pipe is stalled.
MIDI_Pipe & operator=(const MIDI_Pipe &)=delete
Copy assignment (copying not allowed).
MIDIStaller * sink_staller
virtual ~MIDI_Pipe()
Destructor.
const char * getThroughStallerName() const
Get the name of the staller (cause of the stall) that causes the “through” output of this pipe to be ...
MIDIStaller * getSinkStaller() const
Get the staller (cause of the stall) that causes the sink of this pipe to be stalled.
void unstallUpstream(MIDIStaller *cause, MIDI_Sink *stallsrc) override
Undoes the stalling by stallUpstream.
void disconnect()
Disconnect this pipe from all other pipes, sources and sinks.
bool disconnect(TrueMIDI_Sink &sink)
Disconnect the given sink from this pipe.
void sinkMIDIfromPipe(ChannelMessage msg) override
Called when data arrives from an upstream pipe connected to our “through” input, this function forwar...
virtual void mapForwardMIDI(ChannelMessage msg)
Function that maps, edits or filters MIDI messages, and then forwards them to the sink of the pipe.
MIDI_Source * getSource()
Get the immediate source of this pipe.
void handleStallers() const
Give the code that is stalling the MIDI pipe the opportunity to do its job and unstall the pipe.
void disconnectSink()
Set the sink pointer to null.
bool hasThroughIn() const
Check if this pipe has a “through” input that merges all messages from another pipe into the output (...
MIDI_Pipe()=default
Default constructor.
bool throughIsUnstalledOrStalledBy(MIDIStaller *cause)
Returns true if this pipe is either not stalled at all, or if the pipe is stalled by the given stalle...
void disconnectSource()
Set the source pointer to null.
bool disconnect(TrueMIDI_Source &source)
Disconnect the given source from this pipe.
bool sinkIsUnstalledOrStalledBy(MIDIStaller *cause)
Returns true if this pipe is either not stalled at all, or if the pipe is stalled by the given stalle...
void sinkMIDIfromPipe(SysExMessage msg) override
Called when data arrives from an upstream pipe connected to our “through” input, this function forwar...
void stallUpstream(MIDIStaller *cause, MIDI_Sink *stallsrc) override
Stall this pipe and all other pipes further upstream (following the path of the "trough" input).
Receives MIDI messages from a MIDI pipe.
virtual void sinkMIDIfromPipe(RealTimeMessage)=0
Accept an incoming MIDI Real-Time message.
void connectSourcePipe(MIDI_Pipe *source)
Fully connect a source pipe to this sink.
virtual void stallDownstream(MIDIStaller *, MIDI_Source *)
Base case for recursive stall function.
MIDI_Sink & operator=(const MIDI_Sink &)=delete
Copy assignment (copying not allowed).
virtual MIDI_Sink * getFinalSink()
Base case for recursive function.
bool disconnect(MIDI_Pipe &)=delete
MIDI_Sink(const MIDI_Sink &)=delete
Copy constructor (copying not allowed).
friend void swap(MIDI_Sink &a, MIDI_Sink &b)
virtual void unstallDownstream(MIDIStaller *, MIDI_Source *)
Base case for recursive un-stall function.
virtual void sinkMIDIfromPipe(SysCommonMessage)=0
Accept an incoming MIDI System Common message.
MIDI_Sink()=default
Default constructor.
virtual void sinkMIDIfromPipe(ChannelMessage)=0
Accept an incoming MIDI Channel message.
virtual void sinkMIDIfromPipe(SysExMessage)=0
Accept an incoming MIDI System Exclusive message.
bool hasSourcePipe() const
Check if this sink is connected to a source pipe.
MIDI_Pipe * getSourcePipe()
Get a pointer to the pipe this sink is connected to, or nullptr if not connected.
Class that can send MIDI messages to a MIDI pipe.
MIDI_Source & operator=(const MIDI_Source &)=delete
Copy assignment (copying not allowed).
MIDI_Pipe * getSinkPipe()
Get a pointer to the pipe this source is connected to, or nullptr if not connected.
const char * getStallerName() const
Get the name of whatever is causing this MIDI source to be stalled.
void connectSinkPipe(MIDI_Pipe *sink)
Fully connect a sink pipe to this source.
virtual ~MIDI_Source()
Destructor.
MIDIStaller * getStaller() const
Get a pointer to whatever is causing this MIDI source to be stalled.
bool disconnect(MIDI_Pipe &)=delete
MIDI_Source()=default
Default constructor.
void sourceMIDItoPipe(ChannelMessage)
Send a MIDI Channel Message down the pipe.
void stall(MIDIStaller *cause=eternal_stall)
Stall this MIDI source.
virtual MIDI_Source * getInitialSource()
Base case for recursive function.
virtual void stallUpstream(MIDIStaller *, MIDI_Sink *)
Base case for recursive stall function.
bool isStalled() const
Check if this source can write to the sinks it connects to.
static void swap(MIDI_Source &a, MIDI_Source &b)
void disconnectSinkPipesShallow()
Disconnect only the first pipe connected to this source.
bool disconnect(TrueMIDI_Sink &sink)
Disconnect the given sink from this source.
void disconnectSinkPipes()
Disconnect all sink pipes that this source sinks to (recursively).
void handleStallers() const
Give the code that is stalling the MIDI sink pipes the opportunity to do its job and un-stall the pip...
virtual void unstallUpstream(MIDIStaller *, MIDI_Sink *)
Base case for recursive un-stall function.
MIDI_Source(const MIDI_Source &)=delete
Copy constructor (copying not allowed).
bool hasSinkPipe() const
Check if this source is connected to a sink pipe.
void unstall(MIDIStaller *cause=eternal_stall)
Un-stall the pipes connected to this source, so other sources are allowed to send again.
#define FATAL_ERROR(msg, errc)
Print the error message and error code, and stop the execution.
constexpr auto max(const T &a, const U &b) -> decltype(a< b ? b :a)
Return the larger of two numbers/objects.
TrueMIDI_SinkSource & operator|(BidirectionalMIDI_Pipe &pipe, TrueMIDI_SinkSource &sinksource)
Connect a pipe to a sink+source (pipe | source+sink).
MIDI_Pipe & operator>>(TrueMIDI_Source &source, MIDI_Pipe &pipe)
Connect a source to a pipe (source >> pipe).
std::pair< MIDI_Pipe, MIDI_Pipe > BidirectionalMIDI_Pipe
A bidirectional pipe consists of two unidirectional pipes.
Print & operator<<(Print &os, Quaternion e)
Printing.
Struct that can cause a MIDI_Pipe to be stalled.
Class that produces multiple MIDI_Pipes.
const Pipe & operator[](size_t i) const
Pipe & operator[](size_t i)
A struct that is both a TrueMIDI_Sink and a TrueMIDI_Source.