Cleanup
[carla.git] / source / modules / ysfx / sources / ysfx_midi.hpp
bloba36c21c46a2f6613a35247f4351d096fa070e269
1 // Copyright 2021 Jean Pierre Cimalando
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 // SPDX-License-Identifier: Apache-2.0
18 #pragma once
19 #include "ysfx.h"
20 #include <vector>
21 #include <memory>
23 struct ysfx_midi_header_t {
24 uint32_t bus;
25 uint32_t offset;
26 uint32_t size;
29 struct ysfx_midi_buffer_t {
30 std::vector<uint8_t> data;
31 size_t read_pos = 0;
32 size_t read_pos_for_bus[ysfx_max_midi_buses] = {};
33 bool extensible = false;
35 using ysfx_midi_buffer_u = std::unique_ptr<ysfx_midi_buffer_t>;
37 enum {
38 ysfx_midi_message_max_size = 1 << 24,
41 // NOTE: regarding buses,
42 // The buffer keeps 2 kinds of read positions: global, and per-bus.
44 // These are tracked separately, so use either global/per-bus reading API,
45 // but not both mixed in the same piece of code.
47 // The JSFX API `midi*` implementations should always use per-bus access:
48 // if `ext_midi_bus` is true, use the bus defined by `midi_bus`, otherwise 0.
50 void ysfx_midi_reserve(ysfx_midi_buffer_t *midi, uint32_t capacity, bool extensible);
51 void ysfx_midi_clear(ysfx_midi_buffer_t *midi);
52 bool ysfx_midi_push(ysfx_midi_buffer_t *midi, const ysfx_midi_event_t *event);
53 void ysfx_midi_rewind(ysfx_midi_buffer_t *midi);
54 bool ysfx_midi_get_next(ysfx_midi_buffer_t *midi, ysfx_midi_event_t *event);
55 bool ysfx_midi_get_next_from_bus(ysfx_midi_buffer_t *midi, uint32_t bus, ysfx_midi_event_t *event);
57 // incremental writer into a midi buffer
58 struct ysfx_midi_push_t {
59 ysfx_midi_buffer_t *midi = nullptr;
60 size_t start = 0;
61 uint32_t count = 0;
62 bool eob = false;
64 bool ysfx_midi_push_begin(ysfx_midi_buffer_t *midi, uint32_t bus, uint32_t offset, ysfx_midi_push_t *mp);
65 bool ysfx_midi_push_data(ysfx_midi_push_t *mp, const uint8_t *data, uint32_t size);
66 bool ysfx_midi_push_end(ysfx_midi_push_t *mp);
68 //------------------------------------------------------------------------------
70 // determine the length of a midi message according to its status byte
71 // if length is dynamic, returns 0
72 uint32_t ysfx_midi_sizeof(uint8_t id);