From 20f41b1dfdc2086d81ffa4d7b6de7c5f1b3836d1 Mon Sep 17 00:00:00 2001 From: Weird Constructor Date: Tue, 9 Aug 2022 19:39:26 +0200 Subject: [PATCH] Started working on MIDI processing --- src/nodes/note_buffer.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/nodes/note_buffer.rs diff --git a/src/nodes/note_buffer.rs b/src/nodes/note_buffer.rs new file mode 100644 index 0000000..9c3e98f --- /dev/null +++ b/src/nodes/note_buffer.rs @@ -0,0 +1,40 @@ +// Copyright (c) 2022 Weird Constructor +// This file is a part of HexoDSP. Released under GPL-3.0-or-later. +// See README.md and COPYING for details. + +use crate::dsp::MAX_BLOCK_SIZE; +use crate::util::Smoother; + +#[derive(Debug, Clone, Copy)] +pub struct ChannelState { + vel: f32, + pitch: u8, + gate: u8, +} + +pub struct NoteBuffer { + interleaved_chans: Vec, + buf_idx: usize, +} + +impl NoteBuffer { + pub fn new() -> Self { + Self { + interleaved_chans: vec![ChannelState::new(); 16 * MAX_BLOCK_SIZE], + buf_idx: 15, + } + } + + #[inline] + pub fn step(&mut self) { + let cur = self.buf_idx; + let next = (self.buf_idx + 1) % 16; + self.interleaved_chans.copy_within((cur * 16)..((cur + 1) * 16), next * 16); + } + +// pub fn play_velocity(&mut self, channel: u8, vel: f32) { +// let mut vel = &mut self.velocity[channel % 16]; +// vel.set(vel.current(), vel); +// } +} +