1 // Copyright 2021 Jean Pierre Cimalando
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
23 struct ysfx_midi_header_t
{
29 struct ysfx_midi_buffer_t
{
30 std::vector
<uint8_t> data
;
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
>;
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;
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
);