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//! │  │                  SIGNAL 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/// Sensors — event sources from the external world
65pub mod sensor;
66
67/// Utilities and helper functions
68pub mod utils;
69
70/// Named function registry for serialization
71pub mod function_registry;
72
73/// Automaton control strategies
74pub mod strategy;
75
76/// Rack module type definitions (always compiled)
77pub mod module_def;
78
79/// Custom module factory — type registry for rack module construction
80pub mod module_factory;
81
82/// Servo constructor — creates servo actors from ModuleDef descriptors
83pub mod servo_constructor;
84
85/// Automaton wrapper in a green thread (tokio task)
86pub mod automaton_task;
87
88/// Serialization — documents, DOT, formats
89#[cfg(feature = "serde")]
90pub mod serialization;
91
92#[cfg(feature = "serde")]
93pub use serialization::PatchbayDef;
94
95/// MIDI hub — raw MIDI → ControlEvent bridge
96#[cfg(feature = "midi")]
97pub mod midi;
98
99/// Micro-control observer for RT safety monitoring
100pub mod observer;
101
102#[cfg(feature = "midi")]
103pub use midi::spawn_midi_sensor;
104#[cfg(feature = "midi")]
105pub use midi::MidiHub;
106pub use sensor::Sensor;
107
108// =============================================================================
109// Re-exports for convenience
110// =============================================================================
111
112// Selective re-exports
113pub use automaton::sequencer::{PlayMode, SequencerAutomaton, Step};
114pub use automaton::{
115    EnvelopeAutomaton, EnvelopeStage, EnvelopeType, FunctionAutomaton, LfoAutomaton, LfoWaveform,
116    Range, StatefulFunctionAutomaton, SyncMode,
117};
118pub use automaton_task::spawn_automaton_task;
119pub use engine::{
120    midi_cc, midi_note, osc_address, Automaton, BoxedModule, ControlEvent, EventPattern, Mapping,
121    MidiNoteKind, Module, NoAction, OscSurface, OscSurfaceEntry, ParameterMapping, Servo, Target,
122    Transform,
123};
124
125pub use strategy::{ConflictStrategy, ControlStrategy};
126
127// =============================================================================
128// Prelude for convenient imports
129// =============================================================================
130
131/// Prelude for convenient import of core types
132pub mod prelude {
133    // Core types
134    pub use crate::automaton::*;
135    pub use crate::automaton_task::*;
136    pub use crate::engine::*;
137    pub use crate::strategy::*;
138    pub use crate::utils::*;
139
140    // Re-exports from rill-core
141    pub use rill_core::prelude::*;
142    pub use rill_core::queues::RtQueue;
143    pub use rill_core::{NodeId, ParameterId, PortId};
144}
145
146// =============================================================================
147// Tests
148// =============================================================================
149
150#[cfg(test)]
151mod tests {
152    use super::*;
153
154    #[test]
155    fn test_basic_imports() {
156        // Just check that everything imports
157        let _ = automaton::LfoWaveform::Sine;
158        let _ = engine::Transform::Linear;
159    }
160}