Arduino MIDI Library  Version 4.3.1
MIDI.h File Reference

MIDI Library for the Arduino. More...

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

Go to the source code of this file.

Classes

class  MidiInterface< SerialPort, _Settings >
 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...
 

Functions

unsigned encodeSysEx (const byte *inData, byte *outSysEx, unsigned inLenght)
 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 inLenght)
 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
Date
24/02/11 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.

Function Documentation

§ decodeSysEx()

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

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 lenght of the input buffer.
Returns
The lenght of the output buffer.
See also
encodeSysEx
getSysExArrayLength Code inspired from Ruin & Wesen's SysEx encoder/decoder - http://ruinwesen.com

Definition at line 82 of file MIDI.cpp.

83 {
84  unsigned count = 0;
85  byte msbStorage = 0;
86  byte byteIndex = 0;
87 
88  for (unsigned i = 0; i < inLength; ++i)
89  {
90  if ((i % 8) == 0)
91  {
92  msbStorage = inSysEx[i];
93  byteIndex = 6;
94  }
95  else
96  {
97  const byte body = inSysEx[i];
98  const byte msb = ((msbStorage >> byteIndex--) & 1) << 7;
99  outData[count++] = msb | body;
100  }
101  }
102  return count;
103 }
uint8_t byte
Definition: midi_Defs.h:36

§ encodeSysEx()

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

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 lenght of the input buffer.
Returns
The lenght of the encoded output buffer.
See also
decodeSysEx Code inspired from Ruin & Wesen's SysEx encoder/decoder - http://ruinwesen.com

Definition at line 45 of file MIDI.cpp.

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