PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

56 rindas
1.8KB

  1. #include <MIDI.h>
  2. // This example shows how to create two instances of the library to create a merger.
  3. // There are two MIDI couples of IO, A and B, each using thru and merging with the
  4. // input from the other node. The result is the following:
  5. // A out = A in + B in
  6. // B out = B in + A in
  7. #if defined(ARDUINO_SAM_DUE)
  8. MIDI_CREATE_INSTANCE(HardwareSerial, Serial, midiA);
  9. MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, midiB);
  10. #elif defined(ARDUINO_SAMD_ZERO)
  11. MIDI_CREATE_INSTANCE(Serial_, SerialUSB, midiA);
  12. MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, midiB);
  13. #elif defined(USBCON) || defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__)
  14. #include <SoftwareSerial.h>
  15. SoftwareSerial softSerial(2,3);
  16. MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, midiA);
  17. MIDI_CREATE_INSTANCE(SoftwareSerial, softSerial, midiB);
  18. #else
  19. #include <SoftwareSerial.h>
  20. SoftwareSerial softSerial(2,3);
  21. MIDI_CREATE_INSTANCE(HardwareSerial, Serial, midiA);
  22. MIDI_CREATE_INSTANCE(SoftwareSerial, softSerial, midiB);
  23. #endif
  24. void setup()
  25. {
  26. // Initiate MIDI communications, listen to all channels
  27. midiA.begin(MIDI_CHANNEL_OMNI);
  28. midiB.begin(MIDI_CHANNEL_OMNI);
  29. }
  30. void loop()
  31. {
  32. if (midiA.read())
  33. {
  34. // Thru on A has already pushed the input message to out A.
  35. // Forward the message to out B as well.
  36. midiB.send(midiA.getType(),
  37. midiA.getData1(),
  38. midiA.getData2(),
  39. midiA.getChannel());
  40. }
  41. if (midiB.read())
  42. {
  43. // Thru on B has already pushed the input message to out B.
  44. // Forward the message to out A as well.
  45. midiA.send(midiB.getType(),
  46. midiB.getData1(),
  47. midiB.getData2(),
  48. midiB.getChannel());
  49. }
  50. }