82 lines
1.9 KiB
Rust
82 lines
1.9 KiB
Rust
|
|
|
|
pub mod build;
|
|
pub mod pipeline;
|
|
pub mod primitive;
|
|
pub mod state;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use iced_wgpu::core::{mouse, Rectangle};
|
|
use iced_widget::shader::Program;
|
|
|
|
use crate::analyzer::FrameData;
|
|
use crate::visualizer::primitive::VisPrimitive;
|
|
|
|
/// snapshot of every visualizer toggle and slider value.
|
|
#[derive(Debug, Clone, Copy)]
|
|
pub struct VizParams {
|
|
pub glass: bool,
|
|
pub entropy_on: bool,
|
|
pub entropy_strength: f32,
|
|
pub album_colors: bool,
|
|
pub mirrored: bool,
|
|
pub inverted: bool,
|
|
pub hue: f32,
|
|
pub contrast: f32,
|
|
pub brightness: f32,
|
|
}
|
|
|
|
impl Default for VizParams {
|
|
fn default() -> Self {
|
|
Self {
|
|
glass: true,
|
|
entropy_on: false,
|
|
entropy_strength: 0.0,
|
|
album_colors: false,
|
|
mirrored: false,
|
|
inverted: false,
|
|
hue: 0.9,
|
|
contrast: 1.0,
|
|
brightness: 1.0,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// iced shader-widget bundle holding the latest analyzer frames, render params, and album palette.
|
|
#[derive(Debug, Clone)]
|
|
pub struct VisualizerProgram {
|
|
pub frames: Arc<Vec<FrameData>>,
|
|
pub params: VizParams,
|
|
pub palette: Option<Arc<Vec<[f32; 3]>>>,
|
|
}
|
|
|
|
impl VisualizerProgram {
|
|
pub fn new(
|
|
frames: Arc<Vec<FrameData>>,
|
|
params: VizParams,
|
|
palette: Option<Arc<Vec<[f32; 3]>>>,
|
|
) -> Self {
|
|
Self { frames, params, palette }
|
|
}
|
|
}
|
|
|
|
impl<Message> Program<Message> for VisualizerProgram {
|
|
type State = ();
|
|
type Primitive = VisPrimitive;
|
|
|
|
/// hands the frames, params, and palette across to the wgpu primitive layer.
|
|
fn draw(
|
|
&self,
|
|
_state: &Self::State,
|
|
_cursor: mouse::Cursor,
|
|
_bounds: Rectangle,
|
|
) -> Self::Primitive {
|
|
VisPrimitive {
|
|
frames: self.frames.clone(),
|
|
params: self.params,
|
|
palette: self.palette.clone(),
|
|
}
|
|
}
|
|
}
|