22#include "OSLikeStuff/scheduler_api.h"
23#include "definitions_cxx.hpp"
24#include "io/midi/learned_midi.h"
25#include "playback/playback_handler.h"
27struct InterruptsDisabled;
38 void const* source_{
nullptr};
40 MIDISource() =
default;
41 ~MIDISource() =
default;
43 MIDISource(MIDICable
const* cable) : source_(cable) {};
44 MIDISource(MIDIInstrument
const* instrument) : source_(instrument) {};
45 MIDISource(PlaybackHandler
const* handler) : source_(handler) {};
46 MIDISource(MidiFollow
const* follow) : source_(follow) {};
47 MIDISource(MIDIDrum
const* drum) : source_(drum) {};
48 MIDISource(Sound
const* sound) : source_(sound) {};
50 MIDISource(MIDICable
const& cable) : source_(&cable) {};
51 MIDISource(MIDIInstrument
const& instrument) : source_(&instrument) {};
52 MIDISource(MIDIDrum
const& drum) : source_(&drum) {};
53 MIDISource(Sound
const& sound) : source_(&sound) {};
54 MIDISource(MidiFollow
const& follow) : source_(&follow) {};
55 MIDISource(PlaybackHandler
const& handler) : source_(&handler) {};
57 MIDISource(MIDISource
const& other) =
default;
58 MIDISource(MIDISource&& other) =
default;
60 MIDISource& operator=(MIDISource
const& other) =
default;
61 MIDISource& operator=(MIDISource&& other) =
default;
63 bool operator==(MIDISource
const& other)
const {
return source_ == other.source_; }
70 void sendNote(MIDISource source,
bool on, int32_t note, uint8_t velocity, uint8_t channel, int32_t filter);
71 void sendCC(MIDISource source, int32_t channel, int32_t cc, int32_t value, int32_t filter);
72 bool checkIncomingSerialMidi();
73 static void check_incoming_usb();
74 void checkIncomingUsbMidi();
76 void checkIncomingUsbSysex(uint8_t
const* message, int32_t ip, int32_t d, int32_t cable);
78 void sendMidi(MIDISource source, MIDIMessage message, int32_t filter = kMIDIOutputFilterNoMPE,
bool sendUSB =
true);
79 void sendClock(MIDISource source,
bool sendUSB =
true, int32_t howMany = 1);
80 void sendStart(MIDISource source);
81 void sendStop(MIDISource source);
82 void sendPositionPointer(MIDISource source, uint16_t positionPointer);
83 void sendContinue(MIDISource source);
86 void sendUsbMidi(MIDIMessage message, int32_t filter);
87 void sendSerialMidi(MIDIMessage message);
89 void sendPGMChange(MIDISource source, int32_t channel, int32_t pgm, int32_t filter);
90 void sendAllNotesOff(MIDISource source, int32_t channel, int32_t filter);
91 void sendBank(MIDISource source, int32_t channel, int32_t num, int32_t filter);
92 void sendSubBank(MIDISource source, int32_t channel, int32_t num, int32_t filter);
96 void sendPitchBend(MIDISource source, int32_t channel, uint16_t bend, int32_t filter);
98 void sendChannelAftertouch(MIDISource source, int32_t channel, int32_t value, int32_t filter);
100 void sendPolyphonicAftertouch(MIDISource source, int32_t channel, int32_t value, uint8_t noteCode, int32_t filter);
101 bool anythingInOutputBuffer();
106 void setMIDIDue(uint32_t due) { midiDue_ = due; }
110 bool flushDueMIDI(uint32_t now,
const InterruptsDisabled&);
113 void flushAllQueuedMIDI(
const InterruptsDisabled&);
115 bool nextMIDIDue(uint32_t& due);
117 void setupUSBHostReceiveTransfer(int32_t ip, int32_t midiDeviceNum);
118 void flushUSBMIDIOutput();
121 LearnedMIDI globalMIDICommands[kNumGlobalMIDICommands];
124 LearnedMIDI midiFollowChannelType[kNumMIDIFollowChannelTypesIncludingTracks];
125 MIDIFollowFeedbackChannelType midiFollowFeedbackChannelType;
126 uint8_t midiFollowKitRootNote;
127 bool midiFollowDisplayParam;
128 MIDIFollowFeedbackAutomationMode midiFollowFeedbackAutomation;
129 bool midiFollowFeedbackFilter;
130 MIDITakeoverMode midiTakeover;
131 bool midiSelectKitRow;
132 TaskID routine_task_id;
136 uint8_t sysex_fmt_buffer[1024];
147 void midiMessageReceived(MIDICable& cable, uint8_t statusType, uint8_t channel, uint8_t data1, uint8_t data2,
148 uint32_t* timer =
nullptr);
155 void midiSysexReceived(MIDICable& cable, uint8_t* data, int32_t len);
158 uint8_t serialMidiInput[3];
159 uint8_t numSerialMidiInput;
161 bool currentlyReceivingSysExSerial;
163 using EventStackStorage = std::array<MIDISource, 16>;
166 EventStackStorage eventStack_;
168 EventStackStorage::iterator eventStackTop_;
170 int32_t getPotentialNumConnectedUSBMIDIDevices(int32_t ip);
172 void queueMIDI(MIDIMessage message, int32_t filter,
bool sendUSB,
bool sendDIN, uint32_t due);
174 bool flushQueuedMIDI(
bool all, uint32_t now);
177 bool sendOldestQueuedMIDI(
const InterruptsDisabled&);
178 void sendQueuedMIDI(
const QueuedMIDI& queued);
180 uint32_t midiDue_{0};
183extern MidiEngine midiEngine;
184extern bool anythingInUSBOutputBuffer;
188extern uint16_t g_usb_usbmode;
190void usbSendCompleteAsHost(int32_t ip);
191void usbSendCompleteAsPeripheral(int32_t ip);
A MIDI cable connection. Stores all state specific to a given cable and its contained ports and chann...
Definition midi_device.h:96
Definition midi_drum.h:22
Definition midi_instrument.h:38
Definition midi_follow.h:40
Definition playback_handler.h:54
Definition midi_queue.h:38