rill_patchbay/sensor/mod.rs
1//! # Sensor — external input bridge
2//!
3//! A `Sensor` converts external data (MIDI, OSC, hardware knobs, signal analysis)
4//! into [`ControlEvent`](crate::sensor::ControlEvent)s that can be mapped through
5//! [`ParameterMapping`](crate::sensor::ParameterMapping) to graph parameters.
6//!
7//! ## Available sensor types
8//!
9//! - [`midi`] — MIDI controller and note sensors
10//! - [`osc`] — OSC address-based sensors
11//! - [`hearing`] — signal analysis algorithms (pitch, envelope, zero-crossing)
12//! for acoustic sensors that react to graph signal output.
13//!
14//! Multiple sensors can run independently — all events share a single
15//! mailbox drained by [`Patchbay::drain_events`].
16
17pub mod hearing;
18
19use rill_core_actor::ActorRef;
20
21use crate::engine::{ControlEvent, Module};
22
23/// External input that produces [`ControlEvent`]s and dispatches them
24/// via a shared [`ActorRef`].
25///
26/// `Sensor` extends [`Module`] so every sensor is also a rack module.
27pub trait Sensor: Module {
28 /// Attach the sensor to an event sink.
29 ///
30 /// Called before [`start`](Self::start). The sensor stores the
31 /// [`ActorRef`] and uses it to send events during its lifetime.
32 fn attach(&mut self, events: ActorRef<ControlEvent>);
33
34 /// Start the sensor (begin polling, open device, spawn thread, etc.).
35 fn start(&mut self);
36}