unnieversal/crates/sample10-10/src/lib.rs

68 lines
1.6 KiB
Rust

#![allow(incomplete_features)]
#![feature(generic_associated_types)]
use baseplug::{Plugin, ProcessContext};
use serde::{Deserialize, Serialize};
baseplug::model! {
#[derive(Debug, Serialize, Deserialize)]
struct Sample1010Model {
#[model(min = 0.0, max = 200.0)]
#[parameter(name = "repeats")]
repeats: f32,
}
}
impl Default for Sample1010Model {
fn default() -> Self {
Self { repeats: 1.0 }
}
}
struct Sample1010 {
last: (f32, f32),
counter: usize,
}
impl Plugin for Sample1010 {
const NAME: &'static str = "sample - 10/10";
const PRODUCT: &'static str = "sample - 10/10";
const VENDOR: &'static str = "unnieversal";
const INPUT_CHANNELS: usize = 2;
const OUTPUT_CHANNELS: usize = 2;
type Model = Sample1010Model;
#[inline]
fn new(_sample_rate: f32, _model: &Sample1010Model) -> Self {
Self {
last: (0.0, 0.0),
counter: 0,
}
}
#[inline]
fn process(&mut self, model: &Sample1010ModelProcess, ctx: &mut ProcessContext<Self>) {
let input = &ctx.inputs[0].buffers;
let output = &mut ctx.outputs[0].buffers;
for i in 0..ctx.nframes {
if (self.counter as f32) < model.repeats[i] {
output[0][i] = self.last.0;
output[1][i] = self.last.1;
self.counter += 1;
} else {
output[0][i] = input[0][i];
output[1][i] = input[1][i];
self.counter = 0;
self.last = (input[0][i], input[1][i]);
}
}
}
}
baseplug::vst2!(Sample1010, b"1010");