[velociter] create and implement crate

main
annieversary 2021-09-11 12:44:46 +02:00
parent e1b2004dcd
commit 6941c17f52
3 changed files with 109 additions and 0 deletions

View File

@ -65,6 +65,7 @@ the following is the current list of plugins
- `transmute_pitch`: pitch to midi converter
- `reverter`: play sound backwards
- `panera`: pan individual notes differently
- `velociter`: random velocity setter
there's a bit of an explanation of each of the plugins below, but it's not a thorough documentation or a manual, it's just a bunch of notes i've written and a short description of the parameters
@ -287,6 +288,16 @@ there's three panning modes:
the peak detector is still a bit fiddly, so you'll have to tweak the params a bit until it works for the kind of sound you're giving it. the defaults have worked great for me, so i recommend you start from there and change as you see fit
### velociter
velociter sets random velocities to midi notes
params:
- `min_vel`: minimum velocity
- `max_vel`: maximum velocity
it'll set the velocity of every incoming midi note to be in the range `[min_vel, max_vel)`
## contributing
issues and prs are welcome, but please open an issue before making any big pr, i don't wanna have to reject a pr where you have put a lot of effort on. if you are fine with that, ig go ahead i'm not your mum

View File

@ -0,0 +1,14 @@
[package]
name = "velociter"
version = "0.1.0"
edition = "2018"
[lib]
crate-type = ["cdylib"]
[dependencies]
baseplug = { git = "https://github.com/wrl/baseplug.git", rev = "9cec68f31cca9c0c7a1448379f75d92bbbc782a8" }
rand = "0.8.4"
serde = "1.0.126"
# utils = { path = "../utils" }

View File

@ -0,0 +1,84 @@
#![allow(incomplete_features)]
#![feature(generic_associated_types)]
use baseplug::{event::Data, Event, MidiReceiver, Plugin, ProcessContext};
use serde::{Deserialize, Serialize};
baseplug::model! {
#[derive(Debug, Serialize, Deserialize)]
struct VelociterModel {
#[model(min = 0.0, max = 127.9)]
#[parameter(name = "min_vel")]
min_vel: f32,
#[model(min = 0.0, max = 127.9)]
#[parameter(name = "max_vel")]
max_vel: f32,
}
}
impl Default for VelociterModel {
fn default() -> Self {
Self {
min_vel: 0.0,
max_vel: 127.9,
}
}
}
struct Velociter {
notes: Vec<[u8; 3]>,
}
impl Plugin for Velociter {
const NAME: &'static str = "velociter";
const PRODUCT: &'static str = "velociter";
const VENDOR: &'static str = "unnieversal";
const INPUT_CHANNELS: usize = 2;
const OUTPUT_CHANNELS: usize = 2;
type Model = VelociterModel;
#[inline]
fn new(_sample_rate: f32, _model: &VelociterModel) -> Self {
Self {
notes: Vec::with_capacity(300),
}
}
#[inline]
fn process(&mut self, model: &VelociterModelProcess, ctx: &mut ProcessContext<Self>) {
let input = &ctx.inputs[0].buffers;
let output = &mut ctx.outputs[0].buffers;
let enqueue_midi = &mut ctx.enqueue_event;
use rand::{thread_rng, Rng};
let mut rng = thread_rng();
for i in 0..ctx.nframes {
output[0][i] = input[0][i];
output[1][i] = input[1][i];
let min = model.min_vel[i];
let max = model.max_vel[i];
// make sure they're right
let (min, max) = (min.min(max), max.max(min));
for mut note in self.notes.drain(0..) {
note[2] = rng.gen_range(min..max).trunc() as u8;
let note = Event::<Velociter> {
frame: 0,
data: Data::Midi(note),
};
enqueue_midi(note);
}
}
}
}
impl MidiReceiver for Velociter {
fn midi_input(&mut self, _model: &VelociterModelProcess, data: [u8; 3]) {
self.notes.push(data);
}
}
baseplug::vst2!(Velociter, b"tAnE");