Nanomidi
Simple stream-based MIDI message encoder and decoder
MIDI Decoder

MIDI message decoder. More...

Data Structures

struct  midi_sysex_buffer
 Buffer for SysEx messages decoding. More...
 
struct  midi_istream
 Input stream for midi_decode() More...
 

Functions

struct midi_messagemidi_decode (struct midi_istream *stream)
 Decodes a single MIDI message. More...
 
struct midi_messagemidi_decode_usb (struct midi_istream *stream, uint8_t *cable_number)
 Decodes a single MIDI message from USB packet. More...
 
void midi_istream_from_buffer (struct midi_istream *stream, const void *buffer, size_t size)
 Creates an input stream which reads from a buffer. More...
 

Detailed Description

MIDI message decoder.

Function Documentation

◆ midi_decode()

struct midi_message * midi_decode ( struct midi_istream stream)

Decodes a single MIDI message.

If a message is decoded, it has to be processed (e.g. copied) immediately as it will become invalid with the next call to midi_decode().

Parameters
streamPointer to the midi_istream structure
Returns
Pointer to a decoded message (allocated in midi_istream) or NULL if the message has not been decoded yet.

◆ midi_decode_usb()

struct midi_message * midi_decode_usb ( struct midi_istream stream,
uint8_t *  cable_number 
)

Decodes a single MIDI message from USB packet.

The packet format is described in Universal Serial Bus Device Class Definition for MIDI Devices.

If a message is decoded, it has to be processed (e.g. copied) immediately as it will become invalid with the next call to midi_decode().

Parameters
streamPointer to the midi_istream structure
[out]cable_numberDecoded cable number (0 to 15)
Returns
Pointer to a decoded message (allocated in midi_istream) or NULL if the message has not been decoded yet.

◆ midi_istream_from_buffer()

void midi_istream_from_buffer ( struct midi_istream stream,
const void *  buffer,
size_t  size 
)

Creates an input stream which reads from a buffer.

The input stream can be used to read a finite number of bytes from a pre-allocated buffer. It can be also used to decode a single message if the function is called right before midi_decode().

Parameters
streamPointer to the midi_istream structure to be initialized
[in]bufferPointer to the buffer to be read from
sizeBuffer size (in bytes)