Skip to content

Commit

Permalink
CUSTOM serial and MIDI creation MACRO's
Browse files Browse the repository at this point in the history
  • Loading branch information
lathoub committed Jun 4, 2022
1 parent 2d64cc3 commit 28b98cc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
6 changes: 2 additions & 4 deletions examples/CustomBaudRate/CustomBaudRate.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ struct CustomBaudRateSettings : public MIDI_NAMESPACE::DefaultSerialSettings {

#if defined(ARDUINO_SAM_DUE) || defined(USBCON) || defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__)
// Leonardo, Due and other USB boards use Serial1 by default.
MIDI_NAMESPACE::SerialMIDI<HardwareSerial, CustomBaudRateSettings> serialMIDI(Serial1);
MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<HardwareSerial, CustomBaudRateSettings>> MIDI((MIDI_NAMESPACE::SerialMIDI<HardwareSerial, CustomBaudRateSettings>&)serialMIDI);
MIDI_CREATE_CUSTOMSERIAL_INSTANCE(HardwareSerial, Serial1, MIDI, CustomBaudRateSettings)
#else
MIDI_NAMESPACE::SerialMIDI<HardwareSerial, CustomBaudRateSettings> serialMIDI(Serial);
MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<HardwareSerial, CustomBaudRateSettings>> MIDI((MIDI_NAMESPACE::SerialMIDI<HardwareSerial, CustomBaudRateSettings>&)serialMIDI);
MIDI_CREATE_CUSTOMSERIAL_INSTANCE(HardwareSerial, Serial, MIDI, CustomBaudRateSettings)
#endif

void setup() {
Expand Down
18 changes: 16 additions & 2 deletions src/serialMIDI.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ class SerialMIDI

END_MIDI_NAMESPACE

/*! \brief Create an instance of the library attached to a serial port
with overwritten MIDI & Serial Settings
*/
#define MIDI_CREATE_SPECIAL_INSTANCE(Type, SerialPort, Name, CustomMIDISettings, CustomSerialSettings) \
MIDI_NAMESPACE::SerialMIDI<Type, CustomSerialSettings> serial##Name(SerialPort); \
MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<Type, CustomSerialSettings>, CustomMIDISettings> Name((MIDI_NAMESPACE::SerialMIDI<Type, CustomSerialSettings>&)serial##Name);

/*! \brief Create an instance of the library attached to a serial port
with overwritten Serial Settings
*/
#define MIDI_CREATE_CUSTOMSERIAL_INSTANCE(Type, SerialPort, Name, CustomSerialSettings) \
MIDI_NAMESPACE::SerialMIDI<Type, CustomSerialSettings> serial##Name(SerialPort); \
MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<Type, CustomSerialSettings>> Name((MIDI_NAMESPACE::SerialMIDI<Type, CustomSerialSettings>&)serial##Name);

/*! \brief Create an instance of the library attached to a serial port.
You can use HardwareSerial or SoftwareSerial for the serial port.
Example: MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, midi2);
Expand Down Expand Up @@ -125,6 +139,6 @@ END_MIDI_NAMESPACE
@see DefaultSettings
@see MIDI_CREATE_INSTANCE
*/
#define MIDI_CREATE_CUSTOM_INSTANCE(Type, SerialPort, Name, Settings) \
#define MIDI_CREATE_CUSTOM_INSTANCE(Type, SerialPort, Name, CustomMIDISettings) \
MIDI_NAMESPACE::SerialMIDI<Type> serial##Name(SerialPort);\
MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<Type>, Settings> Name((MIDI_NAMESPACE::SerialMIDI<Type>&)serial##Name);
MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<Type>, CustomMIDISettings> Name((MIDI_NAMESPACE::SerialMIDI<Type>&)serial##Name);

0 comments on commit 28b98cc

Please sign in to comment.