maolan_plugin_host/
util.rs1use std::cell::UnsafeCell;
2
3pub struct SimpleMutex<T> {
4 data: UnsafeCell<T>,
5}
6
7unsafe impl<T: Send> Send for SimpleMutex<T> {}
8unsafe impl<T: Send> Sync for SimpleMutex<T> {}
9
10impl<T> SimpleMutex<T> {
11 pub fn new(data: T) -> Self {
12 SimpleMutex {
13 data: UnsafeCell::new(data),
14 }
15 }
16
17 #[allow(clippy::mut_from_ref)]
18 pub fn lock(&self) -> &mut T {
19 unsafe { &mut *self.data.get() }
20 }
21}
22
23pub struct AudioPort {
24 pub buffer: std::sync::Arc<SimpleMutex<Vec<f32>>>,
25 pub finished: std::sync::Arc<SimpleMutex<bool>>,
26}
27
28impl AudioPort {
29 pub fn new(size: usize) -> Self {
30 Self {
31 buffer: std::sync::Arc::new(SimpleMutex::new(vec![0.0; size])),
32 finished: std::sync::Arc::new(SimpleMutex::new(false)),
33 }
34 }
35
36 pub fn setup(&self) {}
37
38 pub fn process(&self) {}
39}
40
41#[derive(Debug, Clone, PartialEq)]
42pub struct MidiEvent {
43 pub frame: u32,
44 pub data: Vec<u8>,
45}
46
47impl MidiEvent {
48 pub fn new(frame: u32, data: Vec<u8>) -> Self {
49 Self { frame, data }
50 }
51}