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 = "None")]
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 = "false")]
38    pub with_inputs: bool,
39    /// Optional chart title
40    ///
41    /// Default is `None`
42    #[builder(default = "None")]
43    pub chart_title: Option<String>,
44    /// Show grid lines on the chart
45    ///
46    /// Default is `false`
47    #[builder(default = "false")]
48    pub show_grid: bool,
49    /// Show axis labels
50    ///
51    /// Default is `true`
52    #[builder(default = "true")]
53    pub show_labels: bool,
54    /// Custom colors for output channels (hex strings)
55    ///
56    /// Default is `None` (uses default palette)
57    #[builder(default = "None")]
58    pub output_colors: Option<Vec<String>>,
59    /// Custom colors for input channels (hex strings)
60    ///
61    /// Default is `None` (uses default palette)
62    #[builder(default = "None")]
63    pub input_colors: Option<Vec<String>>,
64    /// Chart background color (hex string)
65    ///
66    /// Default is "#000000" (black)
67    #[builder(default = "\"#000000\".to_string()")]
68    pub background_color: String,
69    /// Waveform line thickness
70    ///
71    /// Default is 2.0
72    #[builder(default = "2.0")]
73    pub line_width: f32,
74}
75
76/// Processing mode for snapshotting an audio unit.
77#[derive(Debug, Clone, Copy, Default)]
78pub enum Processing {
79    #[default]
80    /// Process one sample at a time.
81    Tick,
82    /// Process a batch of samples at a time.
83    ///
84    /// max batch size is 64 [fundsp::MAX_BUFFER_SIZE]
85    Batch(u8),
86}
87
88impl Default for SnapshotConfig {
89    fn default() -> Self {
90        Self {
91            num_samples: 1024,
92            sample_rate: DEFAULT_SR,
93            svg_width: None,
94            svg_height_per_channel: DEFAULT_HEIGHT,
95            processing_mode: Processing::default(),
96            with_inputs: false,
97            chart_title: None,
98            show_grid: false,
99            show_labels: true,
100            output_colors: None,
101            input_colors: None,
102            background_color: "#000000".to_string(),
103            line_width: 2.0,
104        }
105    }
106}
107
108#[cfg(test)]
109mod tests {
110    use super::*;
111
112    #[test]
113    fn test_default_builder() {
114        SnapshotConfigBuilder::default()
115            .build()
116            .expect("defaul config builds");
117    }
118}