Skip to content

Commit f42c344

Browse files
committed
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: #232 (comment)
1 parent c2a838d commit f42c344

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

examples/ThruFilterMap/ThruFilterMap.ino

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#include <MIDI.h>
22

3-
using Message = midi::Message<midi::DefaultSettings::SysExMaxSize>;
4-
53
MIDI_CREATE_DEFAULT_INSTANCE();
64

75
/**
@@ -17,7 +15,7 @@ MIDI_CREATE_DEFAULT_INSTANCE();
1715
* allowing to use a keyboard to change patches on a MIDI device.
1816
*/
1917

20-
bool filter(const Message& message)
18+
bool filter(const MIDIMessage& message)
2119
{
2220
if (message.type == midi::NoteOn)
2321
{
@@ -27,10 +25,10 @@ bool filter(const Message& message)
2725
return false;
2826
}
2927

30-
Message map(const Message& message)
28+
MIDIMessage map(const MIDIMessage& message)
3129
{
3230
// Make a copy of the message
33-
Message output(message);
31+
MIDIMessage output(message);
3432
if (message.type == midi::NoteOn)
3533
{
3634
output.type = midi::ProgramChange;

src/serialMIDI.h

+13-7
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class SerialMIDI
5252

5353
public:
5454
static const bool thruActivated = true;
55-
55+
5656
void begin()
5757
{
5858
// Initialise the Serial port
@@ -103,9 +103,12 @@ END_MIDI_NAMESPACE
103103
Example: MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, midi2);
104104
Then call midi2.begin(), midi2.read() etc..
105105
*/
106-
#define MIDI_CREATE_INSTANCE(Type, SerialPort, Name) \
107-
MIDI_NAMESPACE::SerialMIDI<Type> serial##Name(SerialPort);\
108-
MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<Type>> Name((MIDI_NAMESPACE::SerialMIDI<Type>&)serial##Name);
106+
#define MIDI_CREATE_INSTANCE(Type, SerialPort, Name) \
107+
using Name##SerialTransport = MIDI_NAMESPACE::SerialMIDI<Type>; \
108+
using Name##Interface = MIDI_NAMESPACE::MidiInterface<Name##SerialTransport>; \
109+
using Name##Message = Name##Interface::MidiMessage; \
110+
Name##SerialTransport serial##Name(SerialPort); \
111+
Name##Interface Name((Name##SerialTransport&)serial##Name);
109112

110113
#if defined(ARDUINO_SAM_DUE) || defined(USBCON) || defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__)
111114
// Leonardo, Due and other USB boards use Serial1 by default.
@@ -125,6 +128,9 @@ END_MIDI_NAMESPACE
125128
@see DefaultSettings
126129
@see MIDI_CREATE_INSTANCE
127130
*/
128-
#define MIDI_CREATE_CUSTOM_INSTANCE(Type, SerialPort, Name, Settings) \
129-
MIDI_NAMESPACE::SerialMIDI<Type> serial##Name(SerialPort);\
130-
MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<Type>, Settings> Name((MIDI_NAMESPACE::SerialMIDI<Type>&)serial##Name);
131+
#define MIDI_CREATE_CUSTOM_INSTANCE(Type, SerialPort, Name, Settings) \
132+
using Name##SerialTransport = MIDI_NAMESPACE::SerialMIDI<Type>; \
133+
using Name##Interface = MIDI_NAMESPACE::MidiInterface<Name##SerialTransport, Settings>; \
134+
using Name##Message = Name##Interface::MidiMessage; \
135+
Name##SerialTransport serial##Name(SerialPort); \
136+
Name##Interface Name((Name##SerialTransport&)serial##Name);

0 commit comments

Comments
 (0)