Arduino MIDI Library  Version 5.0.1
serialMIDI.h
Go to the documentation of this file.
1 
27  #pragma once
28 
29 #include "midi_Namespace.h"
30 
32 
34 {
39  static const long BaudRate = 31250;
40 };
41 
42 template <class SerialPort, class _Settings = DefaultSerialSettings>
44 {
45  typedef _Settings Settings;
46 
47 public:
48  SerialMIDI(SerialPort& inSerial)
49  : mSerial(inSerial)
50  {
51  };
52 
53 public:
54  static const bool thruActivated = true;
55 
56  void begin()
57  {
58  // Initialise the Serial port
59  #if defined(AVR_CAKE)
60  mSerial. template open<Settings::BaudRate>();
61  #else
62  mSerial.begin(Settings::BaudRate);
63  #endif
64  }
65 
67  {
68  return true;
69  };
70 
71  void write(byte value)
72  {
73  mSerial.write(value);
74  };
75 
77  {
78  };
79 
80  byte read()
81  {
82  return mSerial.read();
83  };
84 
85  unsigned available()
86  {
87  return mSerial.available();
88  };
89 
90 private:
91  SerialPort& mSerial;
92 };
93 
99 #define MIDI_CREATE_INSTANCE(Type, SerialPort, Name) \
100  MIDI_NAMESPACE::SerialMIDI<Type> serial##Name(SerialPort);\
101  MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<Type>> Name((MIDI_NAMESPACE::SerialMIDI<Type>&)serial##Name);
102 
103 #if defined(ARDUINO_SAM_DUE) || defined(USBCON) || defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__)
104  // Leonardo, Due and other USB boards use Serial1 by default.
105  #define MIDI_CREATE_DEFAULT_INSTANCE() \
106  MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
107 #else
108 
112  #define MIDI_CREATE_DEFAULT_INSTANCE() \
113  MIDI_CREATE_INSTANCE(HardwareSerial, Serial, MIDI);
114 #endif
115 
116 
SerialMIDI::beginTransmission
bool beginTransmission(MidiType)
Definition: serialMIDI.h:66
SerialMIDI::endTransmission
void endTransmission()
Definition: serialMIDI.h:76
END_MIDI_NAMESPACE
#define END_MIDI_NAMESPACE
Definition: midi_Namespace.h:32
SerialMIDI::thruActivated
static const bool thruActivated
Definition: serialMIDI.h:54
SerialMIDI
Definition: serialMIDI.h:44
DefaultSerialSettings::BaudRate
static const long BaudRate
Definition: serialMIDI.h:39
midi_Namespace.h
MIDI Library for the Arduino - Namespace declaration.
SerialMIDI::begin
void begin()
Definition: serialMIDI.h:56
SerialMIDI::write
void write(byte value)
Definition: serialMIDI.h:71
SerialMIDI::SerialMIDI
SerialMIDI(SerialPort &inSerial)
Definition: serialMIDI.h:48
MidiType
MidiType
Definition: midi_Defs.h:95
BEGIN_MIDI_NAMESPACE
#define BEGIN_MIDI_NAMESPACE
Definition: midi_Namespace.h:31
DefaultSerialSettings
Definition: serialMIDI.h:34
SerialMIDI::available
unsigned available()
Definition: serialMIDI.h:85
SerialMIDI::read
byte read()
Definition: serialMIDI.h:80