insta_fun/
config.rs

1use derive_builder::Builder;
2use fundsp::DEFAULT_SR;
3
4const DEFAULT_HEIGHT: usize = 500;
5
6#[derive(Debug, Clone, Builder)]
7/// Configuration for snapshotting an audio unit.
8pub struct SnapshotConfig {
9    /// Number of samples to generate.
10    ///
11    /// Default is 1024
12    #[builder(default = "1024")]
13    pub num_samples: usize,
14    /// Sample rate of the audio unit.
15    ///
16    /// Default is 44100.0 [fundsp::DEFAULT_SR]
17    #[builder(default = "fundsp::DEFAULT_SR")]
18    pub sample_rate: f64,
19    /// Optional width of the SVG `viewBox`
20    ///
21    /// `None` means proportional to num_samples
22    #[builder(default, setter(strip_option))]
23    pub svg_width: Option<usize>,
24    /// Height of **one** channel in the SVG `viewBox`
25    ///
26    /// `None` fallbacks to default - 100
27    #[builder(default = "DEFAULT_HEIGHT")]
28    pub svg_height_per_channel: usize,
29    /// Processing mode for snapshotting an audio unit.
30    ///
31    /// Default is `Tick`
32    #[builder(default = "Processing::default()")]
33    pub processing_mode: Processing,
34    /// Whether to include inputs in snapshot
35    ///
36    /// Default is `false`
37    #[builder(default)]
38    pub with_inputs: bool,
39    /// Optional chart title
40    ///
41    /// Default is `None`
42    #[builder(default, setter(into, strip_option))]
43    pub chart_title: Option<String>,
44    /// Optional titles for output channels
45    ///
46    /// Default is empty `Vec`
47    #[builder(default, setter(into, each(into, name = "output_title")))]
48    pub output_titles: Vec<String>,
49    /// Optional titles for input channels
50    ///
51    /// Default is empty `Vec`
52    #[builder(default, setter(into, each(into, name = "input_title")))]
53    pub input_titles: Vec<String>,
54    /// Show grid lines on the chart
55    ///
56    /// Default is `false`
57    #[builder(default)]
58    pub show_grid: bool,
59    /// Show axis labels
60    ///
61    /// Default is `true`
62    #[builder(default = "true")]
63    pub show_labels: bool,
64    /// Custom colors for output channels (hex strings)
65    ///
66    /// Default is `None` (uses default palette)
67    #[builder(default, setter(into, strip_option, each(into, name = "output_color")))]
68    pub output_colors: Option<Vec<String>>,
69    /// Custom colors for input channels (hex strings)
70    ///
71    /// Default is `None` (uses default palette)
72    #[builder(default, setter(into, strip_option, each(into, name = "input_color")))]
73    pub input_colors: Option<Vec<String>>,
74    /// Chart background color (hex string)
75    ///
76    /// Default is "#000000" (black)
77    #[builder(default = "\"#000000\".to_string()", setter(into))]
78    pub background_color: String,
79    /// Waveform line thickness
80    ///
81    /// Default is 2.0
82    #[builder(default = "2.0")]
83    pub line_width: f32,
84}
85
86/// Processing mode for snapshotting an audio unit.
87#[derive(Debug, Clone, Copy, Default)]
88pub enum Processing {
89    #[default]
90    /// Process one sample at a time.
91    Tick,
92    /// Process a batch of samples at a time.
93    ///
94    /// max batch size is 64 [fundsp::MAX_BUFFER_SIZE]
95    Batch(u8),
96}
97
98impl Default for SnapshotConfig {
99    fn default() -> Self {
100        Self {
101            num_samples: 1024,
102            sample_rate: DEFAULT_SR,
103            svg_width: None,
104            svg_height_per_channel: DEFAULT_HEIGHT,
105            processing_mode: Processing::default(),
106            with_inputs: false,
107            chart_title: None,
108            output_titles: Vec::new(),
109            input_titles: Vec::new(),
110            show_grid: false,
111            show_labels: true,
112            output_colors: None,
113            input_colors: None,
114            background_color: "#000000".to_string(),
115            line_width: 2.0,
116        }
117    }
118}
119
120#[cfg(test)]
121mod tests {
122    use super::*;
123
124    #[test]
125    fn test_default_builder() {
126        SnapshotConfigBuilder::default()
127            .build()
128            .expect("defaul config builds");
129    }
130}