2021-05-18 03:11:19 +00:00
|
|
|
// Copyright (c) 2021 Weird Constructor <weirdconstructor@gmail.com>
|
2021-08-04 01:58:43 +00:00
|
|
|
// This file is a part of HexoDSP. Released under GPL-3.0-or-later.
|
2021-05-18 03:11:19 +00:00
|
|
|
// See README.md and COPYING for details.
|
|
|
|
|
2022-08-05 04:45:06 +00:00
|
|
|
use synfx_dsp::{Trigger, TriggerPhaseClock};
|
2021-05-18 03:11:19 +00:00
|
|
|
use crate::dsp::tracker::TrackerBackend;
|
2022-07-17 09:58:28 +00:00
|
|
|
use crate::dsp::{DspNode, LedPhaseVals, NodeContext, NodeId, ProcBuf, SAtom};
|
|
|
|
use crate::nodes::{NodeAudioContext, NodeExecContext};
|
2021-05-18 03:11:19 +00:00
|
|
|
|
|
|
|
use crate::dsp::MAX_BLOCK_SIZE;
|
|
|
|
|
2021-06-04 16:14:41 +00:00
|
|
|
#[macro_export]
|
2022-07-17 09:58:28 +00:00
|
|
|
macro_rules! fa_tseq_cmode {
|
|
|
|
($formatter: expr, $v: expr, $denorm_v: expr) => {{
|
|
|
|
let s = match ($v.round() as usize) {
|
|
|
|
0 => "RowT",
|
|
|
|
1 => "PatT",
|
|
|
|
2 => "Phase",
|
|
|
|
_ => "?",
|
2021-06-04 16:14:41 +00:00
|
|
|
};
|
2022-07-17 09:58:28 +00:00
|
|
|
write!($formatter, "{}", s)
|
|
|
|
}};
|
|
|
|
}
|
2021-06-04 16:14:41 +00:00
|
|
|
|
2021-06-27 21:38:14 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct TSeqTime {
|
2022-07-17 09:58:28 +00:00
|
|
|
clock: TriggerPhaseClock,
|
|
|
|
trigger: Trigger,
|
2021-06-27 21:38:14 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 03:11:19 +00:00
|
|
|
/// A tracker based sequencer
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct TSeq {
|
2022-07-17 09:58:28 +00:00
|
|
|
backend: Option<Box<TrackerBackend>>,
|
|
|
|
srate: f64,
|
|
|
|
time: Box<TSeqTime>,
|
2021-05-18 03:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clone for TSeq {
|
2022-07-17 09:58:28 +00:00
|
|
|
fn clone(&self) -> Self {
|
|
|
|
Self::new(&NodeId::Nop)
|
|
|
|
}
|
2021-05-18 03:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl TSeq {
|
2021-06-03 03:10:29 +00:00
|
|
|
pub fn new(_nid: &NodeId) -> Self {
|
2021-05-18 03:11:19 +00:00
|
|
|
Self {
|
2022-07-17 09:58:28 +00:00
|
|
|
backend: None,
|
|
|
|
srate: 48000.0,
|
|
|
|
time: Box::new(TSeqTime { clock: TriggerPhaseClock::new(), trigger: Trigger::new() }),
|
2021-05-18 03:11:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_backend(&mut self, backend: TrackerBackend) {
|
|
|
|
self.backend = Some(Box::new(backend));
|
|
|
|
}
|
|
|
|
|
2022-07-17 09:58:28 +00:00
|
|
|
pub const clock: &'static str = "TSeq clock\nClock input\nRange: (0..1)\n";
|
|
|
|
pub const trig: &'static str =
|
2021-06-27 21:38:14 +00:00
|
|
|
"TSeq trig\nSynchronization trigger which restarts the sequence.\nRange: (-1..1)\n";
|
2022-07-17 09:58:28 +00:00
|
|
|
pub const cmode: &'static str = "TSeq cmode\n'clock' input signal mode:\n\
|
2021-05-18 03:11:19 +00:00
|
|
|
- RowT: Trigger = advance row\n\
|
|
|
|
- PatT: Trigger = pattern rate\n\
|
|
|
|
- Phase: Phase to pattern index\n\
|
|
|
|
\n";
|
2022-07-17 09:58:28 +00:00
|
|
|
pub const trk1: &'static str = "TSeq trk1\nTrack 1 signal output\nRange: (-1..1)\n";
|
|
|
|
pub const trk2: &'static str = "TSeq trk2\nTrack 2 signal output\nRange: (-1..1)\n";
|
|
|
|
pub const trk3: &'static str = "TSeq trk3\nTrack 3 signal output\nRange: (-1..1)\n";
|
|
|
|
pub const trk4: &'static str = "TSeq trk4\nTrack 4 signal output\nRange: (-1..1)\n";
|
|
|
|
pub const trk5: &'static str = "TSeq trk5\nTrack 5 signal output\nRange: (-1..1)\n";
|
|
|
|
pub const trk6: &'static str = "TSeq trk6\nTrack 6 signal output\nRange: (-1..1)\n";
|
|
|
|
|
|
|
|
pub const gat1: &'static str = "TSeq gat1\nTrack 1 gate output\nRange: (-1..1)\n";
|
|
|
|
pub const gat2: &'static str = "TSeq gat2\nTrack 2 gate output\nRange: (-1..1)\n";
|
|
|
|
pub const gat3: &'static str = "TSeq gat3\nTrack 3 gate output\nRange: (-1..1)\n";
|
|
|
|
pub const gat4: &'static str = "TSeq gat4\nTrack 4 gate output\nRange: (-1..1)\n";
|
|
|
|
pub const gat5: &'static str = "TSeq gat5\nTrack 5 gate output\nRange: (-1..1)\n";
|
|
|
|
pub const gat6: &'static str = "TSeq gat6\nTrack 6 gate output\nRange: (-1..1)\n";
|
|
|
|
|
|
|
|
pub const DESC: &'static str = "Tracker Sequencer\n\n\
|
2021-06-08 16:59:31 +00:00
|
|
|
This node implements a sequencer that can be programmed \
|
|
|
|
using the tracker interface in HexoSynth on the right.\n\
|
2021-08-31 03:00:27 +00:00
|
|
|
It provides 6 control signals and 6 gate outputs.";
|
2022-07-17 09:58:28 +00:00
|
|
|
pub const HELP: &'static str = r#"Tracker (based) Sequencer
|
2021-06-08 16:59:31 +00:00
|
|
|
|
2021-06-27 21:38:14 +00:00
|
|
|
This sequencer gets it's speed from the clock source. The 'clock'
|
|
|
|
signal can be interpreted in different modes. But if you want to
|
|
|
|
run multiple sequencers in parallel, you want to synchronize them.
|
|
|
|
For this you can use the 'trig' input, it resets the played row to
|
|
|
|
the beginning of the sequence every time a trigger is received.
|
|
|
|
|
|
|
|
Alternatively you can run the sequencer clock using the phase mode.
|
|
|
|
With that the phase (0..1) signal on the 'clock' input determines the
|
|
|
|
exact play head position in the pattern. With this you just need to
|
|
|
|
synchronize the phase generators for different sequencers.
|
|
|
|
|
|
|
|
For an idea how to chain multiple tracker sequencers, see the next page.
|
|
|
|
|
2021-06-08 16:59:31 +00:00
|
|
|
This tracker provides 6 columns that each can have one of the following
|
|
|
|
types:
|
|
|
|
|
|
|
|
- Note column: for specifying pitches.
|
2021-08-31 03:00:27 +00:00
|
|
|
- Step column: for specifying non interpolated control signals.
|
|
|
|
- Value column: for specifying linearly interpolated control signals.
|
2021-06-08 16:59:31 +00:00
|
|
|
- Gate column: for specifying gates, with probability and ratcheting.
|
|
|
|
|
|
|
|
Step, value and gate cells can be set to 4096 (0xFFF) different values
|
|
|
|
or contain nothing at all. For step and value columns these values
|
2021-08-31 03:00:27 +00:00
|
|
|
are mapped to the 0.0-1.0 control signal range, with 0xFFF being 1.0
|
2021-06-08 16:59:31 +00:00
|
|
|
and 0x000 being 0.0.
|
|
|
|
|
2021-07-27 01:37:29 +00:00
|
|
|
Value examples: 1.0 0.9 0.75 0.5 0.25 0.1
|
|
|
|
0xFFF 0xE70 0xC00 0x800 0x400 0x19A
|
|
|
|
Gate examples:
|
|
|
|
Probability Ratcheting Gate Length full on gate: 0xFFF
|
|
|
|
6% 0x000 16 0x000 1/16 0x000 2 short pulses: 0xFE0
|
|
|
|
18% 0x200 14 0x020 3/16 0x002 4 short pulses: 0xFC0
|
|
|
|
25% 0x300 13 0x030 4/16 0x003 2 50% pulses: 0xFE7
|
|
|
|
50% 0x700 9 0x070 8/16 0x007 half on gate: 0xFF7
|
|
|
|
62% 0x900 7 0x090 10/16 0x009 short pulse: 0xFF0
|
|
|
|
75% 0xC00 4 0x0C0 12/16 0x00C rare short pulse: 0xEF0
|
|
|
|
87% 0xE00 2 0x0E0 15/16 0x00E 50/50 short pulse: 0x7F0
|
|
|
|
100% 0xF00 1 0x0F0 16/16 0x00F 50/50 full gate: 0x7FF
|
|
|
|
|
2021-06-27 21:38:14 +00:00
|
|
|
On the next page you can read about the gate cells and the gate outputs.
|
|
|
|
---page---
|
|
|
|
Gate Input and Output
|
|
|
|
|
2021-06-08 16:59:31 +00:00
|
|
|
The gate cells are differently coded:
|
|
|
|
|
|
|
|
- 0x00F: The least significant nibble controls the gate length.
|
|
|
|
With 0x00F being the full row, and 0x000 being 1/16th of a row.
|
|
|
|
- 0x0F0: The second nibble controls ratcheting, with 0x0F0 being one
|
|
|
|
gate per row, and 0x000 being 16 gates per row.
|
2021-07-27 01:37:29 +00:00
|
|
|
Length of these gates is controlled by the last significant nibble.
|
2021-06-08 16:59:31 +00:00
|
|
|
- 0xF00: The most significant nibble controls probability of the
|
2021-06-27 21:38:14 +00:00
|
|
|
whole gate cell. With 0xF00 meaning the gate will always be
|
2021-06-08 16:59:31 +00:00
|
|
|
triggered, and 0x000 means that the gate is only triggered with
|
2021-07-27 01:37:29 +00:00
|
|
|
6% probability. 50% is 0x700.
|
2021-06-08 16:59:31 +00:00
|
|
|
|
|
|
|
The behaviour of the 6 gate outputs of TSeq depend on the corresponding
|
|
|
|
column type:
|
|
|
|
|
|
|
|
- Step gat1-gat6: Like note columns, this will output a 1.0 for the whole
|
|
|
|
row if a step value is set. With two step values directly
|
2021-06-27 21:38:14 +00:00
|
|
|
following each other no 0.0 will be emitted in between
|
2021-06-08 16:59:31 +00:00
|
|
|
the rows. This means if you want to drive an envelope
|
|
|
|
with release phase with this signal, you need to make
|
|
|
|
space for the release phase.
|
|
|
|
- Note gat1-gat6: Behaves just like step columns.
|
|
|
|
- Gate gat1-gat6: Behaves just like step columns.
|
|
|
|
- Value gat1-gat6: Outputs a 1.0 value for the duration of the last row.
|
|
|
|
You can use this to trigger other things once the
|
|
|
|
sequence has been played.
|
2021-06-27 21:38:14 +00:00
|
|
|
|
|
|
|
Tip:
|
|
|
|
If you want to use the end of a tracker sequence as trigger for
|
|
|
|
something else, eg. switching to a different 'tseq' and restart
|
|
|
|
it using it's 'trig' input, you will need to use the gate output
|
|
|
|
of a value column and invert it.
|
2021-06-08 16:59:31 +00:00
|
|
|
"#;
|
2021-05-18 03:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl DspNode for TSeq {
|
2022-07-17 09:58:28 +00:00
|
|
|
fn outputs() -> usize {
|
|
|
|
1
|
|
|
|
}
|
2021-05-18 03:11:19 +00:00
|
|
|
|
|
|
|
fn set_sample_rate(&mut self, srate: f32) {
|
|
|
|
self.srate = srate as f64;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn reset(&mut self) {
|
|
|
|
self.backend = None;
|
2021-06-27 21:38:14 +00:00
|
|
|
self.time.clock.reset();
|
|
|
|
self.time.trigger.reset();
|
2021-05-18 03:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn process<T: NodeAudioContext>(
|
2022-07-17 09:58:28 +00:00
|
|
|
&mut self,
|
|
|
|
ctx: &mut T,
|
|
|
|
_ectx: &mut NodeExecContext,
|
2021-07-10 19:27:18 +00:00
|
|
|
_nctx: &NodeContext,
|
2022-07-17 09:58:28 +00:00
|
|
|
atoms: &[SAtom],
|
|
|
|
inputs: &[ProcBuf],
|
|
|
|
outputs: &mut [ProcBuf],
|
|
|
|
ctx_vals: LedPhaseVals,
|
|
|
|
) {
|
|
|
|
use crate::dsp::{at, denorm, inp, out};
|
2021-05-18 03:11:19 +00:00
|
|
|
let clock = inp::TSeq::clock(inputs);
|
2022-07-17 09:58:28 +00:00
|
|
|
let trig = inp::TSeq::trig(inputs);
|
2021-05-18 03:11:19 +00:00
|
|
|
let cmode = at::TSeq::cmode(atoms);
|
|
|
|
|
2022-07-17 09:58:28 +00:00
|
|
|
let backend = if let Some(backend) = &mut self.backend {
|
|
|
|
backend
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
};
|
2021-05-18 03:11:19 +00:00
|
|
|
|
|
|
|
backend.check_updates();
|
|
|
|
|
2022-07-17 09:58:28 +00:00
|
|
|
let mut phase_out: [f32; MAX_BLOCK_SIZE] = [0.0; MAX_BLOCK_SIZE];
|
2021-05-18 03:11:19 +00:00
|
|
|
|
|
|
|
let cmode = cmode.i();
|
2022-07-17 09:58:28 +00:00
|
|
|
let plen = backend.pattern_len().max(1) as f64;
|
2021-06-27 21:38:14 +00:00
|
|
|
|
|
|
|
let time = &mut self.time;
|
2021-05-18 03:11:19 +00:00
|
|
|
|
|
|
|
for frame in 0..ctx.nframes() {
|
2022-07-17 09:58:28 +00:00
|
|
|
if time.trigger.check_trigger(denorm::TSeq::trig(trig, frame)) {
|
2021-06-27 21:38:14 +00:00
|
|
|
time.clock.sync();
|
2021-08-14 05:45:11 +00:00
|
|
|
println!("CLOCK SYNC");
|
2021-06-27 21:38:14 +00:00
|
|
|
}
|
|
|
|
|
2022-07-17 09:58:28 +00:00
|
|
|
let phase = match cmode {
|
|
|
|
0 => time.clock.next_phase(plen, clock.read(frame)) / plen,
|
|
|
|
1 => time.clock.next_phase(1.0, clock.read(frame)),
|
|
|
|
2 | _ => (clock.read(frame).abs() as f64).fract(),
|
|
|
|
};
|
2021-05-18 03:11:19 +00:00
|
|
|
|
|
|
|
phase_out[frame] = phase as f32;
|
|
|
|
}
|
|
|
|
|
2022-07-17 09:58:28 +00:00
|
|
|
let mut col_out: [f32; MAX_BLOCK_SIZE] = [0.0; MAX_BLOCK_SIZE];
|
|
|
|
let mut col_out_gate: [f32; MAX_BLOCK_SIZE] = [0.0; MAX_BLOCK_SIZE];
|
|
|
|
let col_out_slice = &mut col_out[0..ctx.nframes()];
|
|
|
|
let col_out_gate_slice = &mut col_out_gate[0..ctx.nframes()];
|
|
|
|
let phase_out_slice = &phase_out[0..ctx.nframes()];
|
2021-05-18 03:11:19 +00:00
|
|
|
|
2021-06-04 18:24:55 +00:00
|
|
|
let out_t1 = out::TSeq::trk1(outputs);
|
2022-07-17 09:58:28 +00:00
|
|
|
backend.get_col_at_phase(0, phase_out_slice, col_out_slice, col_out_gate_slice);
|
2021-05-18 03:11:19 +00:00
|
|
|
out_t1.write_from(col_out_slice);
|
|
|
|
|
2021-06-04 18:24:55 +00:00
|
|
|
let out_g1 = out::TSeq::gat1(outputs);
|
|
|
|
out_g1.write_from(col_out_gate_slice);
|
|
|
|
|
2021-05-18 03:11:19 +00:00
|
|
|
ctx_vals[0].set(col_out_slice[col_out_slice.len() - 1]);
|
|
|
|
|
2021-06-04 18:24:55 +00:00
|
|
|
let out_t2 = out::TSeq::trk2(outputs);
|
2022-07-17 09:58:28 +00:00
|
|
|
backend.get_col_at_phase(1, phase_out_slice, col_out_slice, col_out_gate_slice);
|
2021-05-18 03:11:19 +00:00
|
|
|
out_t2.write_from(col_out_slice);
|
|
|
|
|
2021-06-04 18:24:55 +00:00
|
|
|
let out_g2 = out::TSeq::gat2(outputs);
|
|
|
|
out_g2.write_from(col_out_gate_slice);
|
|
|
|
|
|
|
|
let out_t3 = out::TSeq::trk3(outputs);
|
2022-07-17 09:58:28 +00:00
|
|
|
backend.get_col_at_phase(2, phase_out_slice, col_out_slice, col_out_gate_slice);
|
2021-05-18 03:11:19 +00:00
|
|
|
out_t3.write_from(col_out_slice);
|
|
|
|
|
2021-06-04 18:24:55 +00:00
|
|
|
let out_g3 = out::TSeq::gat3(outputs);
|
|
|
|
out_g3.write_from(col_out_gate_slice);
|
|
|
|
|
|
|
|
let out_t4 = out::TSeq::trk4(outputs);
|
2022-07-17 09:58:28 +00:00
|
|
|
backend.get_col_at_phase(3, phase_out_slice, col_out_slice, col_out_gate_slice);
|
2021-05-18 03:11:19 +00:00
|
|
|
out_t4.write_from(col_out_slice);
|
|
|
|
|
2021-06-04 18:24:55 +00:00
|
|
|
let out_g4 = out::TSeq::gat4(outputs);
|
|
|
|
out_g4.write_from(col_out_gate_slice);
|
|
|
|
|
|
|
|
let out_t5 = out::TSeq::trk5(outputs);
|
2022-07-17 09:58:28 +00:00
|
|
|
backend.get_col_at_phase(4, phase_out_slice, col_out_slice, col_out_gate_slice);
|
2021-05-18 03:11:19 +00:00
|
|
|
out_t5.write_from(col_out_slice);
|
|
|
|
|
2021-06-04 18:24:55 +00:00
|
|
|
let out_g5 = out::TSeq::gat5(outputs);
|
|
|
|
out_g5.write_from(col_out_gate_slice);
|
|
|
|
|
|
|
|
let out_t6 = out::TSeq::trk6(outputs);
|
2022-07-17 09:58:28 +00:00
|
|
|
backend.get_col_at_phase(5, phase_out_slice, col_out_slice, col_out_gate_slice);
|
2021-05-18 03:11:19 +00:00
|
|
|
out_t6.write_from(col_out_slice);
|
|
|
|
|
2021-06-04 18:24:55 +00:00
|
|
|
let out_g6 = out::TSeq::gat6(outputs);
|
|
|
|
out_g6.write_from(col_out_gate_slice);
|
|
|
|
|
2021-05-18 03:11:19 +00:00
|
|
|
ctx_vals[1].set(phase_out_slice[phase_out_slice.len() - 1]);
|
|
|
|
}
|
|
|
|
}
|