Nanomidi
Simple stream-based MIDI message encoder and decoder
decoder.h
Go to the documentation of this file.
1 /*
2  * This file is part of nanomidi.
3  *
4  * Copyright (C) 2018 Adam Heinrich <adam@adamh.cz>
5  *
6  * Nanomidi is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Nanomidi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with nanomidi. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef NANOMIDI_DECODER_H
21 #define NANOMIDI_DECODER_H
22 
23 #ifdef ARDUINO
24 #include <../include/nanomidi/common.h>
25 #include <../include/nanomidi/messages.h>
26 #else
27 #include <nanomidi/common.h>
28 #include <nanomidi/messages.h>
29 #endif
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
47  void *data;
49  size_t size;
50 };
51 
60 struct midi_istream {
71  size_t (*read_cb)(struct midi_istream *stream, void *data, size_t size);
77  size_t capacity;
82  struct midi_message msg;
88  struct midi_message rtmsg;
90  struct midi_sysex_buffer sysex_buffer;
95  void *param;
96 };
97 
98 void midi_istream_from_buffer(struct midi_istream *stream, const void *buffer,
99  size_t size);
100 struct midi_message *midi_decode(struct midi_istream *stream);
101 struct midi_message *midi_decode_usb(struct midi_istream *stream,
102  uint8_t *cable_number);
103 
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif /* NANOMIDI_DECODER_H */
Input stream for midi_decode()
Definition: decoder.h:60
int bytes_left
Number of bytes remaining to complete the current message (handled internally).
Definition: decoder.h:93
MIDI message data structure.
Definition: messages.h:83
void * data
Pointer to a optional buffer allocated by the user.
Definition: decoder.h:47
Buffer for SysEx messages decoding.
Definition: decoder.h:39
size_t capacity
Stream capacity.
Definition: decoder.h:77
void * param
Optional parameter to be passed to read_cb()
Definition: decoder.h:95
struct midi_message * midi_decode_usb(struct midi_istream *stream, uint8_t *cable_number)
Decodes a single MIDI message from USB packet.
Definition: nanomidi_decoder_usb.c:97
size_t size
Buffer size.
Definition: decoder.h:49
struct midi_message * midi_decode(struct midi_istream *stream)
Decodes a single MIDI message.
Definition: nanomidi_decoder.c:173
void midi_istream_from_buffer(struct midi_istream *stream, const void *buffer, size_t size)
Creates an input stream which reads from a buffer.
Definition: nanomidi_stream.c:67