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
79pub use module_def::ClockDef;
80
81/// Custom module factory — type registry for rack module construction
82pub mod module_factory;
83
84/// Servo constructor — creates servo actors from ModuleDef descriptors
85pub mod servo_constructor;
86
87/// Automaton wrapper in a green thread (tokio task)
88pub mod automaton_task;
89
90/// Serialization — documents, JSON, CBOR
91#[cfg(feature = "serde")]
92pub mod serialization;
93
94#[cfg(feature = "serde")]
95pub use serialization::PatchbayDef;
96
97/// MIDI hub — raw MIDI → ControlEvent bridge
98#[cfg(feature = "midi")]
99pub mod midi;
100/// MIDI clock tracker — 24ppqn → BPM derivation
101#[cfg(feature = "midi")]
102pub mod midi_clock;
103
104/// OSC sensor — OSC → ControlEvent bridge
105#[cfg(feature = "osc")]
106pub mod osc;
107
108/// Micro-control observer for RT safety monitoring
109pub mod observer;
110
111#[cfg(feature = "midi")]
112pub use midi::serialize_to_midi;
113#[cfg(feature = "midi")]
114pub use midi::spawn_midi_sensor;
115#[cfg(feature = "midi")]
116pub use midi::MidiHub;
117#[cfg(feature = "midi")]
118pub use midi_clock::MidiClockGenerator;
119#[cfg(feature = "midi")]
120pub use midi_clock::{
121 spawn_midi_clock_output, FreeRunning, MidiClockStrategy, MidiClockTracker, ResetOnStart,
122 SongPosition,
123};
124#[cfg(feature = "osc")]
125pub use osc::spawn_osc_sensor;
126#[cfg(feature = "osc")]
127pub use osc::OscSensor;
128pub use sensor::Sensor;
129
130// =============================================================================
131// Re-exports for convenience
132// =============================================================================
133
134// Selective re-exports
135pub use automaton::sequencer::{PlayMode, SequencerAutomaton, Step};
136pub use automaton::{
137 EnvelopeAutomaton, EnvelopeStage, EnvelopeType, FunctionAutomaton, LfoAutomaton, LfoWaveform,
138 Range, StatefulFunctionAutomaton, SyncMode,
139};
140pub use automaton_task::spawn_automaton_task;
141pub use engine::{
142 midi_cc, midi_note, osc_address, Automaton, BoxedModule, ControlEvent, EventPattern, Mapping,
143 MidiNoteKind, Module, NoAction, OscSurface, OscSurfaceEntry, ParameterMapping, Servo, Target,
144 Transform,
145};
146
147pub use strategy::{ConflictStrategy, ControlStrategy};
148
149// =============================================================================
150// Prelude for convenient imports
151// =============================================================================
152
153/// Prelude for convenient import of core types
154pub mod prelude {
155 // Core types
156 pub use crate::automaton::*;
157 pub use crate::automaton_task::*;
158 pub use crate::engine::*;
159 pub use crate::strategy::*;
160 pub use crate::utils::*;
161
162 // Re-exports from rill-core
163 pub use rill_core::prelude::*;
164 pub use rill_core::queues::RtQueue;
165 pub use rill_core::{NodeId, ParameterId, PortId};
166}
167
168// =============================================================================
169// Tests
170// =============================================================================
171
172#[cfg(test)]
173mod tests {
174 use super::*;
175
176 #[test]
177 fn test_basic_imports() {
178 // Just check that everything imports
179 let _ = automaton::LfoWaveform::Sine;
180 let _ = engine::Transform::Linear;
181 }
182}