Arduino MIDI Library  Version 5.0.1
MIDI.h File Reference

MIDI Library for the Arduino. More...

#include "midi_Defs.h"
#include "midi_Platform.h"
#include "midi_Settings.h"
#include "midi_Message.h"
#include "serialMIDI.h"
#include "MIDI.hpp"

Go to the source code of this file.

Classes

class  MidiInterface< Transport, _Settings, _Platform >
 The main class for MIDI handling. It is templated over the type of serial port to provide abstraction from the hardware interface, meaning you can use HardwareSerial, SoftwareSerial or ak47's Uart classes. The only requirement is that the class implements the begin, read, write and available methods. More...
 

Macros

#define MIDI_LIBRARY_VERSION   0x050000
 
#define MIDI_LIBRARY_VERSION_MAJOR   5
 
#define MIDI_LIBRARY_VERSION_MINOR   0
 
#define MIDI_LIBRARY_VERSION_PATCH   0
 

Functions

unsigned encodeSysEx (const byte *inData, byte *outSysEx, unsigned inLength, bool inFlipHeaderBits=false)
 Encode System Exclusive messages. SysEx messages are encoded to guarantee transmission of data bytes higher than 127 without breaking the MIDI protocol. Use this static method to convert the data you want to send. More...
 
unsigned decodeSysEx (const byte *inSysEx, byte *outData, unsigned inLength, bool inFlipHeaderBits=false)
 Decode System Exclusive messages. SysEx messages are encoded to guarantee transmission of data bytes higher than 127 without breaking the MIDI protocol. Use this static method to reassemble your received message. More...
 

Detailed Description

MIDI Library for the Arduino.

Project Arduino MIDI Library

Author
Francois Best, lathoub
Date
24/02/11 @license MIT - Copyright (c) 2015 Francois Best

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Definition in file MIDI.h.

Macro Definition Documentation

◆ MIDI_LIBRARY_VERSION

#define MIDI_LIBRARY_VERSION   0x050000

Definition at line 42 of file MIDI.h.

◆ MIDI_LIBRARY_VERSION_MAJOR

#define MIDI_LIBRARY_VERSION_MAJOR   5

Definition at line 43 of file MIDI.h.

◆ MIDI_LIBRARY_VERSION_MINOR

#define MIDI_LIBRARY_VERSION_MINOR   0

Definition at line 44 of file MIDI.h.

◆ MIDI_LIBRARY_VERSION_PATCH

#define MIDI_LIBRARY_VERSION_PATCH   0

Definition at line 45 of file MIDI.h.

Function Documentation

◆ decodeSysEx()

unsigned decodeSysEx ( const byte inSysEx,
byte outData,
unsigned  inLength,
bool  inFlipHeaderBits 
)

Decode System Exclusive messages. SysEx messages are encoded to guarantee transmission of data bytes higher than 127 without breaking the MIDI protocol. Use this static method to reassemble your received message.

Parameters
inSysExThe SysEx data received from MIDI in.
outDataThe output buffer where to store the decrypted message.
inLengthThe length of the input buffer.
inFlipHeaderBitsTrue for Korg and other who store MSB in reverse order
Returns
The length of the output buffer.
See also
encodeSysEx
getSysExArrayLength Code inspired from Ruin & Wesen's SysEx encoder/decoder - http://ruinwesen.com

Definition at line 87 of file MIDI.cpp.

91 {
92  unsigned count = 0;
93  byte msbStorage = 0;
94  byte byteIndex = 0;
95 
96  for (unsigned i = 0; i < inLength; ++i)
97  {
98  if ((i % 8) == 0)
99  {
100  msbStorage = inSysEx[i];
101  byteIndex = 6;
102  }
103  else
104  {
105  const byte body = inSysEx[i];
106  const byte shift = inFlipHeaderBits ? 6 - byteIndex : byteIndex;
107  const byte msb = byte(((msbStorage >> shift) & 1) << 7);
108  byteIndex--;
109  outData[count++] = msb | body;
110  }
111  }
112  return count;
113 }

◆ encodeSysEx()

unsigned encodeSysEx ( const byte inData,
byte outSysEx,
unsigned  inLength,
bool  inFlipHeaderBits 
)

Encode System Exclusive messages. SysEx messages are encoded to guarantee transmission of data bytes higher than 127 without breaking the MIDI protocol. Use this static method to convert the data you want to send.

Parameters
inDataThe data to encode.
outSysExThe output buffer where to store the encoded message.
inLengthThe length of the input buffer.
inFlipHeaderBitsTrue for Korg and other who store MSB in reverse order
Returns
The length of the encoded output buffer.
See also
decodeSysEx Code inspired from Ruin & Wesen's SysEx encoder/decoder - http://ruinwesen.com

Definition at line 46 of file MIDI.cpp.

50 {
51  unsigned outLength = 0; // Num bytes in output array.
52  byte count = 0; // Num 7bytes in a block.
53  outSysEx[0] = 0;
54 
55  for (unsigned i = 0; i < inLength; ++i)
56  {
57  const byte data = inData[i];
58  const byte msb = data >> 7;
59  const byte body = data & 0x7f;
60 
61  outSysEx[0] |= (msb << (inFlipHeaderBits ? count : (6 - count)));
62  outSysEx[1 + count] = body;
63 
64  if (count++ == 6)
65  {
66  outSysEx += 8;
67  outLength += 8;
68  outSysEx[0] = 0;
69  count = 0;
70  }
71  }
72  return outLength + count + (count != 0 ? 1 : 0);
73 }
byte
uint8_t byte
Definition: midi_Defs.h:36