bbx_draw/
config.rs

1//! Visualization configuration types.
2
3use nannou::color::Rgb;
4
5use crate::color::{Palette, to_rgb};
6
7/// Configuration for the graph topology visualizer.
8#[derive(Clone)]
9pub struct GraphTopologyConfig {
10    /// Width of each block rectangle.
11    pub block_width: f32,
12    /// Height of each block rectangle.
13    pub block_height: f32,
14    /// Horizontal spacing between depth columns.
15    pub horizontal_spacing: f32,
16    /// Vertical spacing between blocks in same column.
17    pub vertical_spacing: f32,
18    /// Color for generator blocks.
19    pub generator_color: Rgb,
20    /// Color for effector blocks.
21    pub effector_color: Rgb,
22    /// Color for modulator blocks.
23    pub modulator_color: Rgb,
24    /// Color for I/O blocks.
25    pub io_color: Rgb,
26    /// Color for audio connection lines.
27    pub audio_connection_color: Rgb,
28    /// Color for modulation connection lines.
29    pub modulation_connection_color: Rgb,
30    /// Color for block label text.
31    pub text_color: Rgb,
32    /// Audio connection line weight.
33    pub audio_connection_weight: f32,
34    /// Modulation connection line weight.
35    pub modulation_connection_weight: f32,
36    /// Whether to show directional arrows on connections.
37    pub show_arrows: bool,
38    /// Size of the arrow head.
39    pub arrow_size: f32,
40    /// Dash length for modulation connections.
41    pub dash_length: f32,
42    /// Gap length between dashes for modulation connections.
43    pub dash_gap: f32,
44}
45
46impl Default for GraphTopologyConfig {
47    fn default() -> Self {
48        Self {
49            block_width: 120.0,
50            block_height: 50.0,
51            horizontal_spacing: 80.0,
52            vertical_spacing: 30.0,
53            generator_color: to_rgb(Palette::generator()),
54            effector_color: to_rgb(Palette::effector()),
55            modulator_color: to_rgb(Palette::modulator()),
56            io_color: to_rgb(Palette::io()),
57            audio_connection_color: to_rgb(Palette::audio_connection()),
58            modulation_connection_color: to_rgb(Palette::modulation_connection()),
59            text_color: to_rgb(Palette::text()),
60            audio_connection_weight: 2.0,
61            modulation_connection_weight: 1.5,
62            show_arrows: true,
63            arrow_size: 8.0,
64            dash_length: 8.0,
65            dash_gap: 4.0,
66        }
67    }
68}
69
70/// Configuration for the waveform visualizer.
71#[derive(Clone)]
72pub struct WaveformConfig {
73    /// Color for the waveform line.
74    pub line_color: Rgb,
75    /// Line weight/thickness.
76    pub line_weight: f32,
77    /// Optional background color (None for transparent).
78    pub background_color: Option<Rgb>,
79    /// Trigger level for zero-crossing detection (-1.0 to 1.0).
80    pub trigger_level: f32,
81    /// Number of samples to display in the window.
82    pub time_window_samples: usize,
83}
84
85impl Default for WaveformConfig {
86    fn default() -> Self {
87        Self {
88            line_color: to_rgb(Palette::waveform()),
89            line_weight: 2.0,
90            background_color: None,
91            trigger_level: 0.0,
92            time_window_samples: 1024,
93        }
94    }
95}
96
97/// Display mode for the spectrum analyzer.
98#[derive(Clone, Copy, PartialEq, Eq, Default)]
99pub enum SpectrumDisplayMode {
100    /// Vertical bars for each frequency bin.
101    #[default]
102    Bars,
103    /// Connected line through bin peaks.
104    Line,
105    /// Filled area under the spectrum curve.
106    Filled,
107}
108
109/// Configuration for the spectrum analyzer.
110#[derive(Clone)]
111pub struct SpectrumConfig {
112    /// FFT size (must be power of 2: 512, 1024, 2048, 4096).
113    pub fft_size: usize,
114    /// Color for spectrum bars/line.
115    pub bar_color: Rgb,
116    /// Color for peak hold indicators.
117    pub peak_color: Rgb,
118    /// Minimum dB level to display.
119    pub min_db: f32,
120    /// Maximum dB level to display.
121    pub max_db: f32,
122    /// Temporal smoothing factor (0.0 = no smoothing, 1.0 = frozen).
123    pub smoothing: f32,
124    /// Display mode (bars, line, or filled).
125    pub display_mode: SpectrumDisplayMode,
126    /// Enable peak hold.
127    pub show_peaks: bool,
128    /// Peak decay rate (dB per frame).
129    pub peak_decay: f32,
130}
131
132impl Default for SpectrumConfig {
133    fn default() -> Self {
134        Self {
135            fft_size: 2048,
136            bar_color: to_rgb(Palette::spectrum()),
137            peak_color: to_rgb(Palette::spectrum_peak()),
138            min_db: -80.0,
139            max_db: 0.0,
140            smoothing: 0.8,
141            display_mode: SpectrumDisplayMode::Bars,
142            show_peaks: true,
143            peak_decay: 0.5,
144        }
145    }
146}
147
148/// Configuration for the MIDI activity visualizer.
149#[derive(Clone)]
150pub struct MidiActivityConfig {
151    /// Color for active (note on) notes.
152    pub note_on_color: Rgb,
153    /// Color for inactive notes.
154    pub note_off_color: Rgb,
155    /// Scale brightness by velocity.
156    pub velocity_brightness: bool,
157    /// MIDI note range to display (min, max). Default is piano range (21-108).
158    pub display_range: (u8, u8),
159    /// Time for note activity to decay after note off (milliseconds).
160    pub decay_time_ms: f32,
161}
162
163impl Default for MidiActivityConfig {
164    fn default() -> Self {
165        Self {
166            note_on_color: to_rgb(Palette::midi_note_on()),
167            note_off_color: to_rgb(Palette::midi_note_off()),
168            velocity_brightness: true,
169            display_range: (21, 108),
170            decay_time_ms: 200.0,
171        }
172    }
173}