conformal_component/lib.rs
1#![doc = include_str!("../docs_boilerplate.md")]
2#![doc = include_str!("../README.md")]
3
4pub mod audio;
5pub mod effect;
6pub mod events;
7pub mod parameters;
8pub mod synth;
9
10#[doc(hidden)]
11pub use itertools;
12
13/// The mode that the processor will run in.
14#[derive(Debug, Copy, Clone, PartialEq, Eq)]
15pub enum ProcessingMode {
16 /// The component is processing audio in realtime.
17 Realtime,
18
19 /// The component may not be running in realtime, but should use the same quality settings as `Realtime`.
20 Prefetch,
21
22 /// The component is processing audio in offline mode.
23 Offline,
24}
25
26/// Information about the processing environment that the processor will run in.
27#[derive(Debug, Clone, PartialEq)]
28pub struct ProcessingEnvironment {
29 /// The sample rate of the audio.
30 pub sampling_rate: f32,
31
32 /// The mazimum number of samples that will be passed to each call to `process`.
33 ///
34 /// Note that fewer samples may be passed to `process` than this.
35 pub max_samples_per_process_call: usize,
36
37 /// The channel layout of the audio
38 pub channel_layout: audio::ChannelLayout,
39
40 /// The processing mode that the processor will run in.
41 pub processing_mode: ProcessingMode,
42}
43
44/// The main plug-in abstraction in Conformal.
45///
46/// [`Component`]s can be wrapped in various plug-in formats
47/// for use in audio software.
48///
49/// [`Component`]s contain information about the parameters of a processor
50/// as well as the ability to create a processor.
51///
52/// Note that this is not intended to be used as an _internal_ interface for audio processors,
53/// but rather an _external_ one that can be easily wrapped in common plug-in formats. That is to
54/// say, a plug-in should only have one `Component` that represents the whole plug-in - to
55/// compose _parts_ of the plug-in you should use a different abstraction.
56pub trait Component {
57 /// The processor that this component creates.
58 type Processor;
59
60 /// Get information about the parameters of this component
61 ///
62 /// This must return the same value every time it is called.
63 fn parameter_infos(&self) -> Vec<parameters::Info> {
64 Default::default()
65 }
66
67 /// Create the processor that will actually process audio.
68 ///
69 /// Note any state needed to process audio should be allocated here.
70 fn create_processor(&self, environment: &ProcessingEnvironment) -> Self::Processor;
71}
72
73/// A base trait for audio processors.
74///
75/// Most audio processors should additionally implement [`effect::Effect`] or [`synth::Synth`].
76pub trait Processor {
77 /// Enable or disable processing. Must not allocate or block.
78 ///
79 /// processing starts off.
80 ///
81 /// Note that after toggling this on -> off -> on, we must generate the
82 /// _exact_ same output as the first time we were turned on - i.e.,
83 /// this acts as a reset.
84 ///
85 /// Note that `process` will only ever be called _after_ `set_processing(true)`
86 fn set_processing(&mut self, processing: bool);
87}