diff --git a/README.md b/README.md index cfd8474..54e23e4 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Arduino USB-MIDI Transport [![arduino-library-badge](https://www.ardu-badge.com/badge/USB-MIDI.svg?)](https://www.ardu-badge.com/USB-MIDI)[![GitHub version](https://badge.fury.io/gh/lathoub%2FArduino-USBMIDI.svg)](https://badge.fury.io/gh/lathoub%2FArduino-USBMIDI) -This library implements the USB-MIDI transport layer for the [FortySevenEffects Arduino MIDI Library](https://github.com/FortySevenEffects/arduino_midi_library) +This library implements the USB-MIDI transport layer for the [FortySevenEffects Arduino MIDI Library](https://github.com/FortySevenEffects/arduino_midi_library) and uses the underlying [Arduino MIDIUSB](https://github.com/arduino-libraries/MIDIUSB) library (so only devices working with MIDIUSB, will work here). ## Installation diff --git a/examples/MIDI_DIN2USB/MIDI_DIN2USB.ino b/examples/MIDI_DIN2USB/MIDI_DIN2USB.ino index bde218c..98f6a0d 100644 --- a/examples/MIDI_DIN2USB/MIDI_DIN2USB.ino +++ b/examples/MIDI_DIN2USB/MIDI_DIN2USB.ino @@ -1,13 +1,7 @@ #include -USING_NAMESPACE_MIDI; - -typedef USBMIDI_NAMESPACE::usbMidiTransport __umt; -typedef MIDI_NAMESPACE::MidiInterface<__umt> __ss; -__umt usbMIDI(0); // cableNr -__ss MIDICoreUSB((__umt&)usbMIDI); - -typedef Message MidiMessage; +USING_NAMESPACE_MIDI +USBMIDI_CREATE_INSTANCE(0, MIDICoreUSB); MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDICoreSerial); // ----------------------------------------------------------------------------- @@ -34,12 +28,12 @@ void loop() // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- -void onUsbMessage(const MidiMessage& message) +void onUsbMessage(const MidiInterface::MidiMessage& message) { MIDICoreSerial.send(message); } -void onSerialMessage(const MidiMessage& message) +void onSerialMessage(const MidiInterface>::MidiMessage& message) { MIDICoreUSB.send(message); -} +} \ No newline at end of file diff --git a/examples/MIDI_DIN2USB_SysEx/MIDI_DIN2USB_SysEx.ino b/examples/MIDI_DIN2USB_SysEx/MIDI_DIN2USB_SysEx.ino new file mode 100644 index 0000000..4f439fa --- /dev/null +++ b/examples/MIDI_DIN2USB_SysEx/MIDI_DIN2USB_SysEx.ino @@ -0,0 +1,45 @@ +#include +USING_NAMESPACE_MIDI + +struct ModifiedSettings : public MIDI_NAMESPACE::DefaultSettings +{ + static const unsigned SysExMaxSize = 8196; +}; + +// Both Instances *must* use the same SysExMaxSize +USBMIDI_CREATE_CUSTOM_INSTANCE(0, MIDICoreUSB, ModifiedSettings); +MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial1, MIDICoreSerial, ModifiedSettings); + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +void setup() +{ + MIDICoreUSB.setHandleMessage(onUsbMessage); + MIDICoreSerial.setHandleMessage(onSerialMessage); + + MIDICoreUSB.begin(MIDI_CHANNEL_OMNI); + MIDICoreSerial.begin(MIDI_CHANNEL_OMNI); +} + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +void loop() +{ + MIDICoreUSB.read(); + MIDICoreSerial.read(); +} + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +void onUsbMessage(const MidiInterface::MidiMessage& message) +{ + MIDICoreSerial.send(message); +} + +void onSerialMessage(const MidiInterface, ModifiedSettings>::MidiMessage& message) +{ + MIDICoreUSB.send(message); +} diff --git a/src/USB-MIDI.h b/src/USB-MIDI.h index ce24344..a038f17 100644 --- a/src/USB-MIDI.h +++ b/src/USB-MIDI.h @@ -177,5 +177,9 @@ END_USBMIDI_NAMESPACE USBMIDI_NAMESPACE::usbMidiTransport usb##Name(CableNr);\ MIDI_NAMESPACE::MidiInterface Name((USBMIDI_NAMESPACE::usbMidiTransport&)usb##Name); +#define USBMIDI_CREATE_CUSTOM_INSTANCE(CableNr, Name, Settings) \ + USBMIDI_NAMESPACE::usbMidiTransport usb##Name(CableNr);\ + MIDI_NAMESPACE::MidiInterface Name((USBMIDI_NAMESPACE::usbMidiTransport&)usb##Name); + #define USBMIDI_CREATE_DEFAULT_INSTANCE() \ USBMIDI_CREATE_INSTANCE(0, MIDI)