Nanomidi
Simple stream-based MIDI message encoder and decoder
encoder.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_ENCODER_H
21 #define NANOMIDI_ENCODER_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 
45 struct midi_ostream {
56  size_t (*write_cb)(struct midi_ostream *stream, const void *data,
57  size_t size);
63  size_t capacity;
65  void *param;
66 };
67 
68 void midi_ostream_from_buffer(struct midi_ostream *stream, void *buffer,
69  size_t size);
70 size_t midi_encode(struct midi_ostream *stream, const struct midi_message *msg);
71 size_t midi_encode_usb(struct midi_ostream *stream,
72  const struct midi_message *msg, uint8_t cable_number);
73 
76 #ifdef __cplusplus
77 }
78 #endif
79 
80 #endif /* NANOMIDI_ENCODER_H */
MIDI message data structure.
Definition: messages.h:83
size_t midi_encode(struct midi_ostream *stream, const struct midi_message *msg)
Encodes a single MIDI message.
Definition: nanomidi_encoder.c:68
size_t(* write_cb)(struct midi_ostream *stream, const void *data, size_t size)
Pointer to a user-implemented write callback.
Definition: encoder.h:56
void midi_ostream_from_buffer(struct midi_ostream *stream, void *buffer, size_t size)
Creates an output stream which writes to a buffer.
Definition: nanomidi_stream.c:92
Output stream for midi_encode()
Definition: encoder.h:45
size_t capacity
Stream capacity.
Definition: encoder.h:63
void * param
Optional parameter to be passed to write_cb()
Definition: encoder.h:65
size_t midi_encode_usb(struct midi_ostream *stream, const struct midi_message *msg, uint8_t cable_number)
Encodes a single MIDI message into USB packet.
Definition: nanomidi_encoder_usb.c:125