Skip to main content

TuringMachine

Struct TuringMachine 

Source
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

Source

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
Source

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.

Source

pub fn tick(&mut self) -> StepOutputs

Advances the engine by one clock pulse and returns all outputs.

Signal path:

  1. Read the feedback bit from the loop window.
  2. Resolve the write decision (keep or randomize).
  3. Clock the shift register with the resolved bit.
  4. Read the DAC byte and derive note, velocity, gate, and auxiliary outputs.
  5. Tick the clock dividers.
  6. Increment the step counter.
Source

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.

Source

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.

Source

pub fn set_write(&mut self, probability: f32)

Sets the write-knob probability (0.0 = fully random, 1.0 = locked).

Source

pub fn modulate_write(&mut self, offset: f32)

Adds an offset to the current write probability (result is clamped).

Source

pub fn set_length_position(&mut self, pos: usize)

Sets the length-selector rotary-switch position (0..=8).

Source

pub fn set_length(&mut self, len: usize)

Sets the loop length to the nearest valid value.

Source

pub fn set_scale(&mut self, scale: Scale)

Replaces the main quantizer’s scale.

Source

pub fn set_root(&mut self, root: u8)

Sets the main quantizer’s root note (0 = C, …, 11 = B).

Source

pub fn set_note_range(&mut self, range: RangeInclusive<u8>)

Sets the main quantizer’s MIDI note output range.

Source

pub fn set_scale_output_scale(&mut self, scale: Scale)

Replaces the scale-output quantizer’s scale.

Source

pub fn set_scale_output_root(&mut self, root: u8)

Sets the scale-output quantizer’s root note (0 = C, …, 11 = B).

Source

pub fn register_bits(&self) -> u16

Returns the raw 16-bit shift-register contents.

Source

pub fn current_length(&self) -> usize

Returns the currently active loop length.

Source

pub fn write_probability(&self) -> f32

Returns the current write-knob probability.

Source

pub fn step_count(&self) -> u64

Returns the number of ticks processed since creation or the last reset.

Trait Implementations§

Source§

impl Debug for TuringMachine

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TuringMachine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for TuringMachine

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.