-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvisuals.rs
More file actions
134 lines (115 loc) · 4.87 KB
/
Copy pathvisuals.rs
File metadata and controls
134 lines (115 loc) · 4.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (C) 2026 Maika Namuo
macro_rules! visual_modules {
($($module:ident { $processor:ident, $state:ident }),+ $(,)?) => {
$(pub mod $module {
pub mod processor;
pub mod render;
pub mod state;
pub(in crate::visuals) use processor::$processor;
pub(in crate::visuals) use state::{widget, $state};
})+
};
}
macro_rules! visualization_widget {
($widget:ident, $state:ty, |$this:ident, $renderer:ident, $theme:ident, $bounds:ident| $draw:block) => {
struct $widget<'a> {
state: &'a std::cell::RefCell<$state>,
}
impl<M> iced::advanced::widget::Widget<M, iced::Theme, iced::Renderer> for $widget<'_> {
$crate::macros::widget_method!(layout
iced::Size::new(iced::Length::Fill, iced::Length::Fill),
|limits| limits.resolve(iced::Length::Fill, iced::Length::Fill, iced::Size::ZERO)
);
$crate::macros::widget_method!(draw $this; _, $renderer, $theme, _, layout, _, _ => {
use iced_wgpu::primitive::Renderer as _;
let $bounds = layout.bounds();
$draw
});
}
pub(in crate::visuals) fn widget<'a, M: 'a>(
state: &'a std::cell::RefCell<$state>,
) -> iced::Element<'a, M> {
iced::Element::new($widget { state })
}
};
($widget:ident, $state:ty) => {
$crate::visuals::visualization_widget!($widget, $state, |this, renderer, theme, bounds| {
let state = this.state.borrow();
match state.visual_params(bounds) {
Some(params) => renderer.draw_primitive(bounds, params),
None => $crate::visuals::render::common::fill_rect(
renderer,
bounds,
theme.extended_palette().background.base.color,
),
}
});
};
}
pub(in crate::visuals) use visualization_widget;
macro_rules! palette_setter {
($size:expr $(=> $geometry:ident)?) => {
pub fn set_palette(&mut self, palette: &[iced::Color; $size]) {
self.palette = *palette;
$(self.$geometry.invalidate();)?
}
};
}
pub(in crate::visuals) use palette_setter;
visual_modules! {
loudness { LoudnessProcessor, LoudnessState },
oscilloscope { OscilloscopeProcessor, OscilloscopeState },
spectrogram { SpectrogramProcessor, SpectrogramState },
spectrum { SpectrumProcessor, SpectrumState },
stereometer { StereometerProcessor, StereometerState },
waveform { WaveformProcessor, WaveformState },
}
pub mod options {
crate::macros::choice_enum!(#[derive(Default)] pub enum StereometerMode {
Lissajous => "Lissajous",
DotCloud => "Dot Cloud",
#[default] DotCloudBands => "Dot Cloud (Bands)",
});
crate::macros::choice_enum!(#[derive(Default)] pub enum StereometerScale { Linear => "Linear", #[default] #[serde(alias = "exponential")] Scaled => "Scaled" });
crate::macros::choice_enum!(#[derive(Default)] pub enum CorrelationMeterMode { Off => "Off", SingleBand => "Single Band", #[default] MultiBand => "Multi Band" });
crate::macros::choice_enum!(#[derive(Default)] pub enum CorrelationMeterSide { Left => "Left", #[default] Right => "Right" });
crate::macros::choice_enum!(#[derive(Default)] pub enum PianoRollOverlay { #[default] Off => "Off", Right => "Right", Left => "Left" });
crate::macros::choice_enum!(pub enum MeterMode {
LufsShortTerm => "LUFS Short-term",
LufsMomentary => "LUFS Momentary",
RmsFast => "RMS Fast",
RmsSlow => "RMS Slow",
TruePeak => "True Peak",
});
crate::macros::choice_enum!(#[derive(Default)] pub enum SpectrumDisplayMode { #[default] Line => "Line", Bar => "Bar" });
crate::macros::choice_enum!(#[derive(Default)] pub enum SpectrumWeightingMode { #[default] AWeighted => "A-Weighted", Raw => "Raw" });
crate::macros::choice_enum!(#[derive(Default)] pub enum WaveformColorMode { #[default] Frequency => "Frequency Bands", Loudness => "Loudness", Static => "Static" });
crate::macros::choice_enum!(#[derive(Default)] pub enum WaveformHistoryMode { Off => "Off", #[default] RmsFast => "RMS Fast", RmsSlow => "RMS Slow" });
}
pub mod palettes;
pub mod registry;
pub mod render {
pub mod common;
}
use std::sync::atomic::{AtomicU64, Ordering};
static NEXT_VIS_KEY: AtomicU64 = AtomicU64::new(1);
#[derive(Debug, Clone, Copy)]
pub(crate) struct GeometryKey {
id: u64,
revision: u64,
}
impl GeometryKey {
fn new() -> Self {
Self {
id: next_key(),
revision: 0,
}
}
fn invalidate(&mut self) {
self.revision = self.revision.wrapping_add(1);
}
}
pub(in crate::visuals) fn next_key() -> u64 {
NEXT_VIS_KEY.fetch_add(1, Ordering::Relaxed)
}