Skip to main content

rill_patchbay/
lib.rs

1//! # Rill Patchbay — Event routing and automation
2//!
3//! `rill-patchbay` is the evolution of `rill-automation` from version 0.2.0,
4//! merged with the mapping functionality from `rill-control`.
5//!
6//! ## Core components
7//!
8//! - **Automata** — generative signal sources (LFO, envelopes, sequencers)
9//! - **Servos** (in the `control` module) — connect automata to node parameters
10//! - **Mappings** — connect external events (MIDI/OSC) to parameters
11//! - **Sensors** — event sources from the external world
12//! - **Manager** — central coordinator for dual-thread architecture
13//!
14//! ## Architecture
15//!
16//! ```text
17//! ┌─────────────────────────────────────────────────────────────┐
18//! │                     CONTROL THREAD                         │
19//! │                                                              │
20//! │  ┌─────────────────────────────────────────────────────┐   │
21//! │  │               Manager                         │   │
22//! │  │  ┌────────────┐  ┌────────────┐  ┌────────────┐     │   │
23//! │  │  │  Automata  │  │  Servos    │  │  Mappings  │     │   │
24//! │  │  └────────────┘  └────────────┘  └────────────┘     │   │
25//! │  │                    │                │                │   │
26//! │  │                    ▼                ▼                │   │
27//! │  │              ┌──────────────────────────┐           │   │
28//! │  │              │   RtQueue<ParameterCommand>│         │   │
29//! │  │              └──────────────────────────┘           │   │
30//! │  └─────────────────────────────────────────────────────┘   │
31//! │                              │                               │
32//! │                              │ non-blocking queue              │
33//! │                              ▼                               │
34//! │  ┌─────────────────────────────────────────────────────┐   │
35//! │  │                  AUDIO THREAD                          │   │
36//! │  │              (rill-graph / rill-io)                  │   │
37//! │  └─────────────────────────────────────────────────────┘   │
38//! └─────────────────────────────────────────────────────────────┘
39//! ```
40
41#![warn(missing_docs)]
42#![deny(unsafe_code)]
43#![allow(clippy::too_many_arguments)]
44
45// =============================================================================
46// External dependencies
47// =============================================================================
48
49// Re-exports from rill-core
50pub use rill_core::prelude::*;
51pub use rill_core::queues::RtQueue;
52pub use rill_core::{NodeId, ParamValue, ParameterId, PortId};
53
54// =============================================================================
55// Public modules
56// =============================================================================
57
58/// Automata — generative control sources
59pub mod automaton;
60
61/// Control and event mapping
62pub mod engine;
63
64/// Patchbay manager — central coordinator
65pub mod manager;
66
67/// Sensors — event sources from the external world
68pub mod sensor;
69
70/// Utilities and helper functions
71pub mod utils;
72
73/// Named function registry for serialization
74pub mod function_registry;
75
76/// Automaton control strategies
77pub mod strategy;
78
79/// PortCombiner — combining automaton and UI per port
80pub mod port_combiner;
81
82/// Automaton wrapper in a green thread (tokio task)
83pub mod automaton_task;
84
85/// Parameter-lock step sequencer
86pub mod sequencer;
87
88/// Serialization — documents, DOT, formats
89#[cfg(feature = "serde")]
90pub mod serialization;
91
92#[cfg(feature = "serde")]
93pub use serialization::PatchbayDef;
94
95// =============================================================================
96// Re-exports for convenience
97// =============================================================================
98
99// Selective re-exports
100pub use automaton::{
101    EnvelopeAutomaton, EnvelopeStage, EnvelopeType, FunctionAutomaton, LfoAutomaton, LfoWaveform,
102    PlayMode, Range, SequencerAutomaton, StatefulFunctionAutomaton, Step, SyncMode,
103};
104pub use automaton_task::spawn_automaton_task;
105pub use engine::{
106    midi_cc, osc_address, AnyServo, Automaton, BoxedServo, ControlEvent, EventPattern, Mapping,
107    NoAction, OscSurface, OscSurfaceEntry, ParameterMapping, Patchbay, Servo, Target, Transform,
108};
109
110pub use manager::Manager;
111pub use port_combiner::{spawn_combiner, PortCombinerHandle};
112pub use strategy::{ConflictStrategy, ControlStrategy, UiCommand};
113
114// Sequencer re-exports
115pub use sequencer::{
116    ParameterTarget, Pattern, SequenceStep, SequencerHandle, Snapshot, SnapshotSequencer,
117    StepPlayMode,
118};
119#[cfg(feature = "serde")]
120pub use serialization::SequencerDef;
121
122// =============================================================================
123// Prelude for convenient imports
124// =============================================================================
125
126/// Prelude for convenient import of core types
127pub mod prelude {
128    // Core types
129    pub use crate::automaton::*;
130    pub use crate::automaton_task::*;
131    pub use crate::engine::*;
132    pub use crate::manager::*;
133    pub use crate::port_combiner::*;
134    pub use crate::sequencer::*;
135    pub use crate::strategy::*;
136    pub use crate::utils::*;
137
138    // Re-exports from rill-core
139    pub use rill_core::prelude::*;
140    pub use rill_core::queues::RtQueue;
141    pub use rill_core::{NodeId, ParameterId, PortId};
142}
143
144// =============================================================================
145// Tests
146// =============================================================================
147
148#[cfg(test)]
149mod tests {
150    use super::*;
151
152    #[test]
153    fn test_basic_imports() {
154        // Just check that everything imports
155        let _ = automaton::LfoWaveform::Sine;
156        let _ = engine::Transform::Linear;
157        let _ = manager::Config::default();
158    }
159}