Skip to main content

rill_patchbay/
strategy.rs

1//! # Automaton control strategies
2//!
3//! Defines how an automaton affects a node parameter and how
4//! conflicts between automatic and manual control are resolved.
5
6/// How the automaton affects the target parameter
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8#[derive(Debug, Clone, Copy, PartialEq)]
9pub enum ControlStrategy {
10    /// The automaton sets the parameter value directly.
11    ///
12    /// The automaton output is expected in the [0, 1] range and is mapped
13    /// to [min, max] of the target parameter.
14    Absolute,
15
16    /// The automaton modulates around the base value.
17    ///
18    /// The automaton output is expected in the [-1, 1] range.
19    /// Final value: `base + mod_val * depth * (max - min)`,
20    /// clamped to [min, max].
21    Modulation {
22        /// Modulation depth (0.0 — no modulation, 1.0 — full range)
23        depth: f64,
24    },
25}
26
27/// Conflict resolution strategy between UI and automaton
28#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
29#[derive(Debug, Clone, Copy, PartialEq)]
30pub enum ConflictStrategy {
31    /// UI touch freezes the automaton for this port.
32    ///
33    /// On `SetBase`, the automaton stops affecting the parameter.
34    /// On `Release`, the automaton resumes control.
35    TouchOverride,
36
37    /// UI sets the base value, the automaton modulates around it.
38    ///
39    /// The final value is computed using the control strategy formula
40    /// combining the UI base value and automaton modulation.
41    BasePlusModulation,
42
43    /// The last writer to the queue wins.
44    ///
45    /// UI and automaton write to the queue independently. The order of
46    /// application is determined by the message order in the MpscQueue.
47    LastWriteWins,
48}
49
50/// UI command (sent via actor mailbox, can be forwarded to an automaton)
51#[derive(Debug, Clone)]
52pub enum UiCommand {
53    /// Set the base value
54    SetValue(f64),
55
56    /// Release control (TouchOverride only)
57    Release,
58}