pub struct TuringMachine { /* private fields */ }Expand description
A complete MIDI Turing Machine engine.
Combines a 16-bit shift register, write-probability knob, loop-length selector, two quantizers (main and scale output), and two clock dividers into a single step-driven sequencer.
Implementations§
Source§impl TuringMachine
impl TuringMachine
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new TuringMachine with default settings.
Defaults:
- Length: 16
- Write probability: 0.5
- Scale: chromatic
- Root: C (0)
- Note range: 36..=84 (C2–C6)
- RNG seeded from the operating system
Sourcepub fn with_seed(seed: u64) -> Self
pub fn with_seed(seed: u64) -> Self
Creates a new TuringMachine with a deterministic seed.
Two engines built with the same seed will produce identical output sequences, making this constructor ideal for testing and reproducibility.
Sourcepub fn tick(&mut self) -> StepOutputs
pub fn tick(&mut self) -> StepOutputs
Advances the engine by one clock pulse and returns all outputs.
Signal path:
- Read the feedback bit from the loop window.
- Resolve the write decision (keep or randomize).
- Clock the shift register with the resolved bit.
- Read the DAC byte and derive note, velocity, gate, and auxiliary outputs.
- Tick the clock dividers.
- Increment the step counter.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Resets the engine to its initial state.
Clears the shift register, resets both clock dividers, and zeroes the step counter. Scale, root, write probability, and length settings are preserved.
Sourcepub fn move_step(&mut self) -> StepOutputs
pub fn move_step(&mut self) -> StepOutputs
Advances the register by one step without ticking clock dividers or incrementing the step counter.
Useful for “preview” or manual-advance scenarios where the master clock should not progress.
Sourcepub fn set_write(&mut self, probability: f32)
pub fn set_write(&mut self, probability: f32)
Sets the write-knob probability (0.0 = fully random, 1.0 = locked).
Sourcepub fn modulate_write(&mut self, offset: f32)
pub fn modulate_write(&mut self, offset: f32)
Adds an offset to the current write probability (result is clamped).
Sourcepub fn set_length_position(&mut self, pos: usize)
pub fn set_length_position(&mut self, pos: usize)
Sets the length-selector rotary-switch position (0..=8).
Sourcepub fn set_length(&mut self, len: usize)
pub fn set_length(&mut self, len: usize)
Sets the loop length to the nearest valid value.
Sourcepub fn set_note_range(&mut self, range: RangeInclusive<u8>)
pub fn set_note_range(&mut self, range: RangeInclusive<u8>)
Sets the main quantizer’s MIDI note output range.
Sourcepub fn set_scale_output_scale(&mut self, scale: Scale)
pub fn set_scale_output_scale(&mut self, scale: Scale)
Replaces the scale-output quantizer’s scale.
Sourcepub fn set_scale_output_root(&mut self, root: u8)
pub fn set_scale_output_root(&mut self, root: u8)
Sets the scale-output quantizer’s root note (0 = C, …, 11 = B).
Sourcepub fn register_bits(&self) -> u16
pub fn register_bits(&self) -> u16
Returns the raw 16-bit shift-register contents.
Sourcepub fn current_length(&self) -> usize
pub fn current_length(&self) -> usize
Returns the currently active loop length.
Sourcepub fn write_probability(&self) -> f32
pub fn write_probability(&self) -> f32
Returns the current write-knob probability.
Sourcepub fn step_count(&self) -> u64
pub fn step_count(&self) -> u64
Returns the number of ticks processed since creation or the last reset.