Skip to main content

PatchTree

Struct PatchTree 

Source
pub struct PatchTree {
    pub amp: AmpEnv,
    pub root: AudioNode,
}
Expand description

A complete patch genome: an audio term wrapped in the mandatory voice stage (amp ADSR → VCA → limiter → stereo out, added by the compiler).

Fields§

§amp: AmpEnv

Amplitude envelope parameters.

§root: AudioNode

The evolved audio-term tree.

Implementations§

Source§

impl PatchTree

Source

pub fn domain_violations(&self) -> Vec<(String, f64)>

Every continuous site of this term that sits outside PARAM_DOMAIN, as (trace address, value), in address order.

Reads the trace, not the term, and that is the whole point: the trace enumerates exactly the continuous sites, by construction, from the same walk the prior samples. A hand-written match over 26 productions would be a second table of “which fields are knobs” — and the first module somebody forgot to add to it would be the one the next sentinel escaped through.

Source

pub fn clamp_domains(&mut self) -> usize

Pull every out-of-domain continuous site back into PARAM_DOMAIN. Returns how many sites were repaired (0 = the term was already clean, and nothing was rebuilt).

Repair, not refusal, and the asymmetry is deliberate. A term over the size/depth ceilings cannot be fixed without deciding which modules to delete, so those are refused. A knob outside its range can be fixed, exactly and locally, and the alternative — refusing — would mean a saved session that already contains one becomes an app the player cannot edit, load or evolve their way out of. Corruption must not be load-bearing.

NaN clamps to the middle of the range rather than to an end: it carries no information about which way it went, and pinning it to a boundary would state one.

Identities survive. The rebuild goes through the trace, which does not carry uids, so the repaired term inherits them back from the term it replaced — same rule, and the same reason, as crate::set_param.

Source§

impl PatchTree

Source

pub fn site_count(&self) -> usize

Total probabilistic-choice sites (amp envelope + tree).

Source

pub fn signature(&self) -> String

Short human-readable signature along the main signal spine (saw·ladr·dly) — the default display name for unnamed patches.

Source

pub fn to_sexpr(&self) -> String

Compact s-expression rendering for logs and tests.

Source

pub fn ensure_uids(&mut self)

Give every node that still lacks an identity a fresh one, and break any duplicates.

This is the settle step: the point at which an anonymous tree becomes a thing a person can point at. Call it wherever a tree is adopted — admitted to the pool, put on the bench, restored from a save, arrived from the panel — and nowhere in the middle of search.

De-duplication is not paranoia. A whole-tree replace from the panel is arbitrary client JSON, and the one gesture that most obviously produces a repeat is “duplicate this module”: copying a subtree copies its uids, and two nodes claiming one identity is worse than no identity at all — a lock on either would light both. First occurrence in walk order keeps the id; the copies are minted fresh.

Source

pub fn clear_uids(&mut self)

Strip every identity back to Uid::NEW.

Used where a tree must hash or serialize as pure content — the render memo’s key, above all, which would otherwise miss on every refinement step and invalidate every persisted row the moment uids started moving.

Source

pub fn inherit_uids(&mut self, parent: &PatchTree)

Carry parent’s identities onto this tree wherever the structure is unchanged.

This is what makes locks and hand positions survive ⚡ evolve. Refinement does not mutate a tree in place — EvolutionChain proposes over the trace, and every accepted step reconstructs the whole genome through crate::genome’s decoder, which knows nothing about uids and cannot: a trace is a map from address to value. So a refined child comes back structurally near-identical to its seed and completely anonymous, and without this pass every generation would look to the UI like a brand new patch — the exact failure (R6) that would make pinned routings and freeform layout read as broken.

The match is positional and shallow-by-variant: walking both trees in lockstep, a node inherits its counterpart’s identity only if it is the same variant, but the walk descends either way. That last part matters — a step that swaps one filter for a reverb should not orphan the entire chain beneath it, which was not touched.

Anything left unmatched (a genuinely new module, a branch that grew) stays Uid::NEW and is minted by the following Self::ensure_uids.

Trait Implementations§

Source§

impl Clone for PatchTree

Source§

fn clone(&self) -> PatchTree

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PatchTree

Source§

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

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

impl<'de> Deserialize<'de> for PatchTree

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl EvolutionaryGenome for PatchTree

Source§

fn generate<R: Rng>(rng: &mut R, _bounds: &MultiBounds) -> Self

Draws from the default grammar configuration; bounds is ignored (this genome has no numeric-box structure). Prefer PatchGrammarPrior::sample_with_rng to control the grammar.

Source§

fn distance(&self, other: &Self) -> f64

Structural distance: parameter L1 where the trees agree, and a subtree-size penalty where they diverge. Defined for any pair (never panics); a heuristic for diversity mechanisms, not a metric with audio-perceptual meaning.

Source§

type Allele = f64

The allele type for individual genes
Source§

type Phenotype = PatchTree

The phenotype or decoded solution type
Source§

fn decode(&self) -> Self::Phenotype

Decode genome into phenotype for fitness evaluation
Source§

fn dimension(&self) -> usize

Compute dimensionality for adaptive operators
Source§

fn try_distance(&self, other: &Self) -> Result<f64, GenomeError>

Fallible distance metric. Read more
§

fn as_slice(&self) -> Option<&[Self::Allele]>

Get the genome’s genes as a slice (for numeric genomes)
§

fn as_mut_slice(&mut self) -> Option<&mut [Self::Allele]>

Get the genome’s genes as a mutable slice (for numeric genomes)
Source§

impl PartialEq for PatchTree

Source§

fn eq(&self, other: &PatchTree) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for PatchTree

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TraceGenome for PatchTree

Source§

fn to_trace(&self) -> Trace

Convert genome to a fugue trace. Read more
Source§

fn from_trace(trace: &Trace) -> Result<Self, GenomeError>

Reconstruct genome from a fugue trace. Read more
Source§

fn trace_prefix() -> &'static str

Get the address prefix used for trace storage (default: "gene").
Source§

impl StructuralPartialEq for PatchTree

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,