tsq1/lib.rs
1//! C-compatible dynamic library for TSQ1 conversion.
2
3pub use tsq1_core::ffi::{Tsq1Buffer, Tsq1Status};
4
5/// Convert SMF bytes into TSQ1 format, allocating a new buffer for the result.
6///
7/// The caller is responsible for freeing the resulting buffer with
8/// [`tsq1_buffer_free`].
9///
10/// # Safety
11///
12/// `midi_ptr` must point to `midi_len` readable bytes, and `out` must point to
13/// writable storage for one [`Tsq1Buffer`]. The returned allocation must be
14/// released exactly once with [`tsq1_buffer_free`].
15#[unsafe(no_mangle)]
16pub unsafe extern "C" fn tsq1_mid_to_tsq(
17 midi_ptr: *const u8,
18 midi_len: usize,
19 out: *mut Tsq1Buffer,
20) -> Tsq1Status {
21 unsafe { tsq1_core::ffi::tsq1_mid_to_tsq(midi_ptr, midi_len, out) }
22}
23
24/// Release a buffer produced by [`tsq1_mid_to_tsq`].
25///
26/// # Safety
27///
28/// `buf` must be either the untouched value returned by
29/// [`tsq1_mid_to_tsq`] or a buffer whose pointer is null. A non-null buffer
30/// must be passed exactly once.
31#[unsafe(no_mangle)]
32pub unsafe extern "C" fn tsq1_buffer_free(buf: Tsq1Buffer) {
33 unsafe {
34 tsq1_core::ffi::tsq1_buffer_free(buf);
35 }
36}