Add detuning and inputs for gate length

This commit is contained in:
Weird Constructor 2022-08-12 03:51:46 +02:00
parent 026b4b0028
commit 2e1c006d8d
2 changed files with 26 additions and 3 deletions

View file

@ -570,6 +570,7 @@ use crate::fa_cqnt_omin;
use crate::fa_delay_mode; use crate::fa_delay_mode;
use crate::fa_map_clip; use crate::fa_map_clip;
use crate::fa_midip_chan; use crate::fa_midip_chan;
use crate::fa_midip_gmode;
use crate::fa_mux9_in_cnt; use crate::fa_mux9_in_cnt;
use crate::fa_noise_mode; use crate::fa_noise_mode;
use crate::fa_out_mono; use crate::fa_out_mono;
@ -1429,7 +1430,9 @@ macro_rules! node_list {
[0 sig], [0 sig],
midip => MidiP UIType::Generic UICategory::IOUtil midip => MidiP UIType::Generic UICategory::IOUtil
(0 det n_det d_det r_det f_det stp_f -0.2, 0.2, 0.0) (0 det n_det d_det r_det f_det stp_f -0.2, 0.2, 0.0)
{1 0 chan setting(0) mode fa_midip_chan 0 16} (1 glen n_lfot d_lfot r_lfot f_lfoms stp_f 0.0, 1.0, 250.0)
{2 0 chan setting(0) mode fa_midip_chan 0 16}
{3 1 gmode setting(0) mode fa_midip_gmode 0 2}
[0 freq] [0 freq]
[1 gate] [1 gate]
[2 vel], [2 vel],

View file

@ -14,6 +14,19 @@ macro_rules! fa_midip_chan {
}}; }};
} }
#[macro_export]
macro_rules! fa_midip_gmode {
($formatter: expr, $v: expr, $denorm_v: expr) => {{
let s = match ($v.round() as usize) {
0 => "MIDI",
1 => "Trigger",
2 => "Gate Len",
_ => "?",
};
write!($formatter, "{}", s)
}};
}
/// The (stereo) output port of the plugin /// The (stereo) output port of the plugin
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct MidiP { pub struct MidiP {
@ -26,6 +39,8 @@ impl MidiP {
} }
pub const chan: &'static str = "MidiP chan\nMIDI Channel 0 to 15\n"; pub const chan: &'static str = "MidiP chan\nMIDI Channel 0 to 15\n";
pub const gmode: &'static str = "MidiP gmode\nMIDI gate mode.\n- 'MIDI' gate same as MIDI input\n- 'Trigger' output only triggers on 'gate' output\n- 'Gate Len' output gate with the length of the 'gatel' parameter\n";
pub const glen: &'static str = "MidiP glen\nMIDI gate length\nIf 'gmode' is set to 'Gate Len' this controls and overrides the gate length on a MIDI note event.";
pub const det: &'static str = "MidiP det\nDetune input pitch a bit\nRange: (-1..1)"; pub const det: &'static str = "MidiP det\nDetune input pitch a bit\nRange: (-1..1)";
pub const freq: &'static str = pub const freq: &'static str =
"MidiP freq\nMIDI note frequency, detuned by 'det'.\nRange: (-1..1)"; "MidiP freq\nMIDI note frequency, detuned by 'det'.\nRange: (-1..1)";
@ -78,10 +93,12 @@ impl DspNode for MidiP {
ectx: &mut NodeExecContext, ectx: &mut NodeExecContext,
_nctx: &NodeContext, _nctx: &NodeContext,
atoms: &[SAtom], atoms: &[SAtom],
_inputs: &[ProcBuf], inputs: &[ProcBuf],
outputs: &mut [ProcBuf], outputs: &mut [ProcBuf],
ctx_vals: LedPhaseVals, ctx_vals: LedPhaseVals,
) { ) {
let det = inp::MidiP::det(inputs);
let chan = at::MidiP::chan(atoms);
let out_i = out_idx::MidiP::gate(); let out_i = out_idx::MidiP::gate();
let (freq, r) = outputs.split_at_mut(out_i); let (freq, r) = outputs.split_at_mut(out_i);
let (gate, vel) = r.split_at_mut(1); let (gate, vel) = r.split_at_mut(1);
@ -89,10 +106,13 @@ impl DspNode for MidiP {
let gate = &mut gate[0]; let gate = &mut gate[0];
let vel = &mut vel[0]; let vel = &mut vel[0];
let channel = (chan.i() as usize % 16) as u8;
for frame in 0..ctx.nframes() { for frame in 0..ctx.nframes() {
let chan = ectx.note_buffer.get_chan_at(0, frame as u8); let chan = ectx.note_buffer.get_chan_at(channel, frame as u8);
let note = (chan.note as f32 - 69.0) / 120.0; let note = (chan.note as f32 - 69.0) / 120.0;
let note = note + denorm::MidiP::det(det, frame);
freq.write(frame, note); freq.write(frame, note);
if chan.gate > 0 { if chan.gate > 0 {