Skip to content

Commit

Permalink
Start work on "accumulators" system
Browse files Browse the repository at this point in the history
  • Loading branch information
exa04 committed Dec 15, 2024
1 parent 7049973 commit 2f296ed
Show file tree
Hide file tree
Showing 10 changed files with 408 additions and 231 deletions.
128 changes: 70 additions & 58 deletions examples/visualizers/src/editor.rs
Original file line number Diff line number Diff line change
@@ -1,88 +1,100 @@
use cyma::prelude::*;
use cyma::utils::{MonoChannel, PeakBuffer};
use cyma::utils::accumulators::{PeakAccumulator, RMSAccumulator};
use cyma::utils::MonoChannel;
use nih_plug::editor::Editor;
use nih_plug_vizia::widgets::ResizeHandle;
use nih_plug_vizia::{assets, create_vizia_editor, vizia::prelude::*, ViziaState, ViziaTheming};
use std::sync::{Arc, Mutex};

#[derive(Lens, Clone)]
pub(crate) struct Data {
peak_buffer: Arc<Mutex<PeakBuffer>>,
}
pub(crate) struct Data {}

impl Data {
pub(crate) fn new(channel: MonoChannel) -> Self {
Self {
peak_buffer: Arc::new(Mutex::new(PeakBuffer::new(channel.clone(), 10.0, 50.0))),
}
pub(crate) fn new() -> Self {
Self {}
}
}

impl Model for Data {}

pub(crate) fn default_state() -> Arc<ViziaState> {
ViziaState::new(|| (800, 800))
ViziaState::new(|| (800, 600))
}

pub(crate) fn create(editor_data: Data, editor_state: Arc<ViziaState>) -> Option<Box<dyn Editor>> {
pub(crate) fn create(
editor_data: Data,
editor_state: Arc<ViziaState>,
channel: MonoChannel,
) -> Option<Box<dyn Editor>> {
create_vizia_editor(editor_state, ViziaTheming::default(), move |cx, _| {
assets::register_noto_sans_light(cx);
editor_data.clone().build(cx);
VStack::new(cx, |cx| {
peak_graph(cx);
HStack::new(cx, |cx| {
ZStack::new(cx, |cx| {
Grid::new(
cx,
ValueScaling::Linear,
(-32., 8.0),
vec![6.0, 0.0, -6.0, -12.0, -18.0, -24.0, -30.0],
Orientation::Horizontal,
)
.border_width(Pixels(0.5))
.color(Color::rgb(30, 30, 30));

Graph::new(
cx,
PeakAccumulator::new(10.0, 50.0),
(-32.0, 8.0),
ValueScaling::Decibels,
channel.clone(),
)
.color(Color::rgba(255, 255, 255, 60))
.background_color(Color::rgba(255, 255, 255, 30));

Graph::new(
cx,
RMSAccumulator::new(10.0, 250.0),
(-32.0, 8.0),
ValueScaling::Decibels,
channel.clone(),
)
.color(Color::rgba(64, 128, 255, 128));

UnitRuler::new(
cx,
(-32.0, 8.0),
ValueScaling::Linear,
vec![
(6.0, "6 dB"),
(0.0, "0 dB"),
(-6.0, "-6 dB"),
(-12.0, "-12 dB"),
(-18.0, "-18 dB"),
(-24.0, "-24 dB"),
(-30.0, "-30 dB"),
],
Orientation::Vertical,
)
.font_size(12.)
.color(Color::rgb(220, 220, 220))
.right(Pixels(8.0))
.left(Stretch(1.0));
});
})
.background_color(Color::rgb(16, 16, 16))
.border_width(Pixels(1.0))
.border_color(Color::rgb(48, 48, 48));
Label::new(
cx,
format!("Cyma {} - Visualizers Example", env!("CARGO_PKG_VERSION")).as_str(),
)
.color(Color::rgb(180, 180, 180));
.color(Color::rgb(180, 180, 180));
})
.background_color(Color::rgb(8, 8, 8))
.child_space(Pixels(8.0))
.row_between(Pixels(4.0));
.background_color(Color::rgb(8, 8, 8))
.child_space(Pixels(8.0))
.row_between(Pixels(4.0));

ResizeHandle::new(cx);
})
}

fn peak_graph(cx: &mut Context) {
HStack::new(cx, |cx| {
ZStack::new(cx, |cx| {
Grid::new(
cx,
ValueScaling::Linear,
(-32., 8.),
vec![6.0, 0.0, -6.0, -12.0, -18.0, -24.0, -30.0],
Orientation::Horizontal,
)
.border_width(Pixels(0.5))
.color(Color::rgb(30, 30, 30));

Graph::new(cx, Data::peak_buffer, (-32.0, 8.0), ValueScaling::Decibels)
.color(Color::rgba(255, 255, 255, 60))
.background_color(Color::rgba(255, 255, 255, 30));

UnitRuler::new(
cx,
(-32.0, 8.0),
ValueScaling::Linear,
vec![
(6.0, "6 dB"),
(0.0, "0 dB"),
(-6.0, "-6 dB"),
(-12.0, "-12 dB"),
(-18.0, "-18 dB"),
(-24.0, "-24 dB"),
(-30.0, "-30 dB"),
],
Orientation::Vertical,
)
.font_size(12.)
.color(Color::rgb(220, 220, 220))
.right(Pixels(8.0))
.left(Stretch(1.0));
});
})
.background_color(Color::rgb(16, 16, 16))
.border_width(Pixels(1.0))
.border_color(Color::rgb(48, 48, 48));
}
4 changes: 2 additions & 2 deletions examples/visualizers/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use cyma::utils::PeakBuffer;
use cyma::{prelude::*, utils::MonoChannel};
use nih_plug::prelude::*;
use nih_plug_vizia::ViziaState;
Expand Down Expand Up @@ -65,8 +64,9 @@ impl Plugin for VisualizersPlugin {

fn editor(&mut self, _async_executor: AsyncExecutor<Self>) -> Option<Box<dyn Editor>> {
editor::create(
editor::Data::new(self.audio_inlet.clone()),
editor::Data::new(),
self.params.editor_state.clone(),
self.audio_inlet.clone(),
)
}

Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ pub mod visualizers;
pub mod prelude {
pub use crate::utils::MonoChannel;
pub use crate::utils::ValueScaling;
pub use crate::utils::VisualizerBuffer;
pub use crate::visualizers::*;
}
Loading

0 comments on commit 2f296ed

Please sign in to comment.