feat: Export type definitions when using macros
Types have names prepended by the port name (defaults to `MIDI`), to allow multi-port applications. This allows referencing those types elsewhere in the application, without re-writing the template arguments, and simplifies referencing the underlying Message type, for SoftThru `filter`/`map`function definitions. Proposition & discussion: https://github.com/FortySevenEffects/arduino_midi_library/pull/232#issuecomment-910355200
This commit is contained in:
parent
2fec41ecfe
commit
7bb96f9780
|
|
@ -1,7 +1,5 @@
|
|||
#include <MIDI.h>
|
||||
|
||||
using Message = midi::Message<midi::DefaultSettings::SysExMaxSize>;
|
||||
|
||||
MIDI_CREATE_DEFAULT_INSTANCE();
|
||||
|
||||
/**
|
||||
|
|
@ -17,7 +15,7 @@ MIDI_CREATE_DEFAULT_INSTANCE();
|
|||
* allowing to use a keyboard to change patches on a MIDI device.
|
||||
*/
|
||||
|
||||
bool filter(const Message& message)
|
||||
bool filter(const MIDIMessage& message)
|
||||
{
|
||||
if (message.type == midi::NoteOn)
|
||||
{
|
||||
|
|
@ -27,10 +25,10 @@ bool filter(const Message& message)
|
|||
return false;
|
||||
}
|
||||
|
||||
Message map(const Message& message)
|
||||
MIDIMessage map(const MIDIMessage& message)
|
||||
{
|
||||
// Make a copy of the message
|
||||
Message output(message);
|
||||
MIDIMessage output(message);
|
||||
if (message.type == midi::NoteOn)
|
||||
{
|
||||
output.type = midi::ProgramChange;
|
||||
|
|
|
|||
|
|
@ -103,9 +103,12 @@ END_MIDI_NAMESPACE
|
|||
Example: MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, midi2);
|
||||
Then call midi2.begin(), midi2.read() etc..
|
||||
*/
|
||||
#define MIDI_CREATE_INSTANCE(Type, SerialPort, Name) \
|
||||
MIDI_NAMESPACE::SerialMIDI<Type> serial##Name(SerialPort);\
|
||||
MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<Type>> Name((MIDI_NAMESPACE::SerialMIDI<Type>&)serial##Name);
|
||||
#define MIDI_CREATE_INSTANCE(Type, SerialPort, Name) \
|
||||
using Name##SerialTransport = MIDI_NAMESPACE::SerialMIDI<Type>; \
|
||||
using Name##Interface = MIDI_NAMESPACE::MidiInterface<Name##SerialTransport>; \
|
||||
using Name##Message = Name##Interface::MidiMessage; \
|
||||
Name##SerialTransport serial##Name(SerialPort); \
|
||||
Name##Interface Name((Name##SerialTransport&)serial##Name);
|
||||
|
||||
#if defined(ARDUINO_SAM_DUE) || defined(USBCON) || defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__)
|
||||
// Leonardo, Due and other USB boards use Serial1 by default.
|
||||
|
|
@ -125,6 +128,9 @@ END_MIDI_NAMESPACE
|
|||
@see DefaultSettings
|
||||
@see MIDI_CREATE_INSTANCE
|
||||
*/
|
||||
#define MIDI_CREATE_CUSTOM_INSTANCE(Type, SerialPort, Name, Settings) \
|
||||
MIDI_NAMESPACE::SerialMIDI<Type> serial##Name(SerialPort);\
|
||||
MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<Type>, Settings> Name((MIDI_NAMESPACE::SerialMIDI<Type>&)serial##Name);
|
||||
#define MIDI_CREATE_CUSTOM_INSTANCE(Type, SerialPort, Name, Settings) \
|
||||
using Name##SerialTransport = MIDI_NAMESPACE::SerialMIDI<Type>; \
|
||||
using Name##Interface = MIDI_NAMESPACE::MidiInterface<Name##SerialTransport, Settings>; \
|
||||
using Name##Message = Name##Interface::MidiMessage; \
|
||||
Name##SerialTransport serial##Name(SerialPort); \
|
||||
Name##Interface Name((Name##SerialTransport&)serial##Name);
|
||||
|
|
|
|||
Loading…
Reference in New Issue