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, JSON, CBOR
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/// MIDI clock tracker — 24ppqn → BPM derivation
99#[cfg(feature = "midi")]
100pub mod midi_clock;
101
102/// OSC sensor — OSC → ControlEvent bridge
103#[cfg(feature = "osc")]
104pub mod osc;
105
106/// Micro-control observer for RT safety monitoring
107pub mod observer;
108
109#[cfg(feature = "midi")]
110pub use midi::spawn_midi_sensor;
111#[cfg(feature = "midi")]
112pub use midi::MidiHub;
113#[cfg(feature = "midi")]
114pub use midi_clock::{
115    FreeRunning, MidiClockStrategy, MidiClockTracker, ResetOnStart, SongPosition,
116};
117#[cfg(feature = "osc")]
118pub use osc::spawn_osc_sensor;
119#[cfg(feature = "osc")]
120pub use osc::OscSensor;
121pub use sensor::Sensor;
122
123// =============================================================================
124// Re-exports for convenience
125// =============================================================================
126
127// Selective re-exports
128pub use automaton::sequencer::{PlayMode, SequencerAutomaton, Step};
129pub use automaton::{
130    EnvelopeAutomaton, EnvelopeStage, EnvelopeType, FunctionAutomaton, LfoAutomaton, LfoWaveform,
131    Range, StatefulFunctionAutomaton, SyncMode,
132};
133pub use automaton_task::spawn_automaton_task;
134pub use engine::{
135    midi_cc, midi_note, osc_address, Automaton, BoxedModule, ControlEvent, EventPattern, Mapping,
136    MidiNoteKind, Module, NoAction, OscSurface, OscSurfaceEntry, ParameterMapping, Servo, Target,
137    Transform,
138};
139
140pub use strategy::{ConflictStrategy, ControlStrategy};
141
142// =============================================================================
143// Prelude for convenient imports
144// =============================================================================
145
146/// Prelude for convenient import of core types
147pub mod prelude {
148    // Core types
149    pub use crate::automaton::*;
150    pub use crate::automaton_task::*;
151    pub use crate::engine::*;
152    pub use crate::strategy::*;
153    pub use crate::utils::*;
154
155    // Re-exports from rill-core
156    pub use rill_core::prelude::*;
157    pub use rill_core::queues::RtQueue;
158    pub use rill_core::{NodeId, ParameterId, PortId};
159}
160
161// =============================================================================
162// Tests
163// =============================================================================
164
165#[cfg(test)]
166mod tests {
167    use super::*;
168
169    #[test]
170    fn test_basic_imports() {
171        // Just check that everything imports
172        let _ = automaton::LfoWaveform::Sine;
173        let _ = engine::Transform::Linear;
174    }
175}