Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,995 changes: 1,158 additions & 1,837 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ members = [
doctest = false

[dependencies]
nih_plug_vizia = { git = "https://github.com/robbert-vdh/nih-plug.git" }
vizia_plug = { git = "https://github.com/vizia/vizia-plug.git" }
nih_plug = { git = "https://github.com/robbert-vdh/nih-plug.git" }
lazy_static = "1.4.0"
realfft = "3.3.0"
Expand Down
2 changes: 1 addition & 1 deletion book/src/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ it to your `Cargo.toml`.
```diff
[dependencies]
nih_plug = { ... }
nih_plug_vizia = { ... }
vizia_plug = { ... }
+ cyma = { git = "https://github.com/exa04/cyma" }
```

Expand Down
2 changes: 1 addition & 1 deletion examples/benchmark_lots_of_visualizers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ crate-type = ["cdylib", "lib"]
[dependencies]
nih_plug = { git = "https://github.com/robbert-vdh/nih-plug.git", features = ["assert_process_allocs", "standalone"] }
cyma = { path = "../../" }
nih_plug_vizia = { git = "https://github.com/robbert-vdh/nih-plug.git" }
vizia_plug = { git = "https://github.com/vizia/vizia-plug.git" }

[profile.release]
lto = "thin"
Expand Down
2 changes: 1 addition & 1 deletion examples/peak_graph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ crate-type = ["cdylib", "lib"]
[dependencies]
nih_plug = { git = "https://github.com/robbert-vdh/nih-plug.git", features = ["assert_process_allocs", "standalone"] }
cyma = { path = "../../" }
nih_plug_vizia = { git = "https://github.com/robbert-vdh/nih-plug.git" }
vizia_plug = { git = "https://github.com/vizia/vizia-plug.git" }

[profile.release]
lto = "thin"
Expand Down
6 changes: 2 additions & 4 deletions examples/peak_graph/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use cyma::prelude::*;
use cyma::visualizers::{Graph, Grid, UnitRuler};
use nih_plug::editor::Editor;
use nih_plug::nih_dbg;
use nih_plug_vizia::{assets, create_vizia_editor, vizia::prelude::*, ViziaState, ViziaTheming};
use std::sync::Arc;
use vizia_plug::{create_vizia_editor, vizia::prelude::*, ViziaState, ViziaTheming};

pub(crate) fn default_state() -> Arc<ViziaState> {
ViziaState::new(|| (800, 500))
Expand All @@ -18,8 +18,6 @@ impl Model for TimerState {}

pub(crate) fn create(editor_state: Arc<ViziaState>, bus: Arc<MonoBus>) -> Option<Box<dyn Editor>> {
create_vizia_editor(editor_state, ViziaTheming::default(), move |cx, _| {
assets::register_noto_sans_light(cx);

bus.subscribe(cx);

HStack::new(cx, |cx| {
Expand Down Expand Up @@ -65,7 +63,7 @@ pub(crate) fn create(editor_state: Arc<ViziaState>, bus: Arc<MonoBus>) -> Option
.color(Color::rgb(160, 160, 160))
.width(Pixels(48.));
})
.col_between(Pixels(8.))
.gap(Pixels(8.))
.background_color(Color::rgb(0, 0, 0));
})
}
4 changes: 2 additions & 2 deletions examples/peak_graph/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cyma::prelude::*;
use nih_plug::prelude::*;
use nih_plug_vizia::ViziaState;
use std::sync::{Arc, Mutex};
use std::sync::Arc;
use vizia_plug::ViziaState;

mod editor;

Expand Down
2 changes: 1 addition & 1 deletion examples/visualizers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ crate-type = ["cdylib", "lib"]
[dependencies]
nih_plug = { git = "https://github.com/robbert-vdh/nih-plug.git", features = ["assert_process_allocs", "standalone"] }
cyma = { path = "../../" }
nih_plug_vizia = { git = "https://github.com/robbert-vdh/nih-plug.git" }
vizia_plug = { git = "https://github.com/vizia/vizia-plug.git" }

[profile.release]
lto = "thin"
Expand Down
8 changes: 3 additions & 5 deletions examples/visualizers/src/editor.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use cyma::prelude::*;
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};
use vizia_plug::{create_vizia_editor, vizia::prelude::*, ViziaState, ViziaTheming};

use cyma::prelude::*;

#[derive(Lens, Clone)]
pub(crate) struct Data {
Expand All @@ -27,8 +27,6 @@ pub(crate) fn create(

editor_data.clone().build(cx);

assets::register_noto_sans_light(cx);

VStack::new(cx, |cx| {
HStack::new(cx, |cx| {
ZStack::new(cx, |cx| {
Expand Down
2 changes: 1 addition & 1 deletion examples/visualizers/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cyma::prelude::*;
use nih_plug::prelude::*;
use nih_plug_vizia::ViziaState;
use std::sync::{Arc, Mutex};
use vizia_plug::ViziaState;

mod editor;

Expand Down
4 changes: 2 additions & 2 deletions src/bus/into_bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ where
})
}

fn update(&self) {
self.bus.update()
fn update(&self, cx: &mut ContextProxy) {
self.bus.update(cx)
}

#[inline]
Expand Down
6 changes: 3 additions & 3 deletions src/bus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod multichannel;
pub use into_bus::*;
pub use mono::*;
pub use multichannel::*;
use nih_plug_vizia::vizia::prelude::*;
use vizia_plug::vizia::prelude::*;

/// A bus for stereo data.
pub type StereoBus = MultiChannelBus<2>;
Expand Down Expand Up @@ -37,7 +37,7 @@ where

/// Calls all registered dispatchers and provides them with the latest
/// audio data, if any is available.
fn update(&self);
fn update(&self, cx: &mut ContextProxy);

/// Registers a new dispatcher and returns a handle to it.
///
Expand All @@ -53,7 +53,7 @@ where
fn subscribe(self: &Arc<Self>, cx: &mut Context) {
let bus = self.clone();
cx.spawn(move |cx| loop {
bus.update();
bus.update(cx);
thread::sleep(Duration::from_millis(15));
});
}
Expand Down
4 changes: 3 additions & 1 deletion src/bus/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Bus<f32> for MonoBus {
self.sample_rate.load(Ordering::Relaxed)
}

fn update(&self) {
fn update(&self, cx: &mut ContextProxy) {
if self.channel.1.is_empty() {
return;
}
Expand All @@ -88,6 +88,8 @@ impl Bus<f32> for MonoBus {
.iter()
.filter_map(|d| d.upgrade())
.for_each(|d| d(samples.iter()));

cx.redraw();
}

fn register_dispatcher<F: for<'a> Fn(Self::I<'a>) + Sync + Send + 'static>(
Expand Down
4 changes: 3 additions & 1 deletion src/bus/multichannel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl<const C: usize> Bus<[f32; C]> for MultiChannelBus<C> {
dispatcher
}

fn update(&self) {
fn update(&self, cx: &mut ContextProxy) {
let samples = self.channel.1.try_iter().collect::<Vec<_>>();

if samples.is_empty() {
Expand All @@ -141,6 +141,8 @@ impl<const C: usize> Bus<[f32; C]> for MultiChannelBus<C> {
.iter()
.filter_map(|d| d.upgrade())
.for_each(|d| d(samples.iter()));

cx.redraw();
}

fn set_sample_rate(&self, sample_rate: f32) {
Expand Down
21 changes: 2 additions & 19 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ mod ring_buffer;
pub(crate) use ring_buffer::*;

use nih_plug::util::db_to_gain;
use nih_plug_vizia::vizia::binding::Res;
use nih_plug_vizia::vizia::context::{Context, EventContext};
use nih_plug_vizia::vizia::entity::Entity;
use vizia_plug::vizia::prelude::*;

/// Analogous to VIZIA's own ValueScaling.
#[derive(Debug, Clone, Copy, PartialEq)]
Expand Down Expand Up @@ -85,19 +83,4 @@ impl ValueScaling {
}
}

// We can't use impl_res_simple!() since we're using nih_plug's version of VIZIA
impl Res<ValueScaling> for ValueScaling {
fn get_val(&self, _: &Context) -> ValueScaling {
*self
}

fn set_or_bind<F>(&self, cx: &mut Context, entity: Entity, closure: F)
where
F: 'static + Fn(&mut EventContext, Self),
{
cx.with_current(entity, |cx| {
let cx = &mut EventContext::new_with_current(cx, entity);
(closure)(cx, *self);
});
}
}
impl_res_simple!(ValueScaling);
34 changes: 21 additions & 13 deletions src/visualizers/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use super::{FillFrom, FillModifiers, RangeModifiers};
use crate::accumulators::*;
use crate::bus::Bus;
use crate::utils::{RingBuffer, ValueScaling};
use nih_plug_vizia::vizia::{prelude::*, vg};
use std::sync::{Arc, Mutex};
use vizia_plug::vizia::{prelude::*, vg};

/// A graph visualizer plotting a value over time.
///
Expand Down Expand Up @@ -58,8 +58,8 @@ impl<B: Bus<f32> + 'static, A: Accumulator + 'static> Graph<B, A> {

Self {
buffer,
range: range.get_val(cx),
scaling: scaling.get_val(cx),
range: range.get(cx),
scaling: scaling.get(cx),
fill_from: FillFrom::Bottom,
accumulator,
dispatcher_handle,
Expand All @@ -79,7 +79,7 @@ impl<B: Bus<f32>, A: Accumulator + 'static> View for Graph<B, A> {
GraphEvents::UpdateScaling(s) => self.scaling = *s,
});
}
fn draw(&self, cx: &mut DrawContext, canvas: &mut Canvas) {
fn draw(&self, cx: &mut DrawContext, canvas: &vizia_plug::vizia::vg::Canvas) {
let bounds = cx.bounds();

let x = bounds.x;
Expand Down Expand Up @@ -115,7 +115,7 @@ impl<B: Bus<f32>, A: Accumulator + 'static> View for Graph<B, A> {

let mut stroke = vg::Path::new();

stroke.move_to(x, y + h * (1. - peak));
stroke.move_to((x, y + h * (1. - peak)));

for i in 1..ring_buf.len() {
// Normalize peak value
Expand All @@ -124,7 +124,7 @@ impl<B: Bus<f32>, A: Accumulator + 'static> View for Graph<B, A> {
.value_to_normalized(ring_buf[i], self.range.0, self.range.1);

// Draw peak as a new point
stroke.line_to(x + i as f32, y + h * (1. - peak));
stroke.line_to((x + i as f32, y + h * (1. - peak)));
}

let mut fill = stroke.clone();
Expand All @@ -136,15 +136,23 @@ impl<B: Bus<f32>, A: Accumulator + 'static> View for Graph<B, A> {
}
};

fill.line_to(x + w, y + h * fill_from_n);
fill.line_to(x, y + h * fill_from_n);
fill.line_to((x + w, y + h * fill_from_n));
fill.line_to((x, y + h * fill_from_n));
fill.close();

canvas.fill_path(&fill, &vg::Paint::color(cx.background_color().into()));
canvas.draw_path(
&fill,
&vg::Paint::new(Into::<vg::Color4f>::into(cx.background_color()), None)
.set_style(vg::PaintStyle::Fill)
.set_anti_alias(true),
);

canvas.stroke_path(
canvas.draw_path(
&stroke,
&vg::Paint::color(cx.font_color().into()).with_line_width(line_width),
&vg::Paint::new(Into::<vg::Color4f>::into(cx.font_color()), None)
.set_style(vg::PaintStyle::Stroke)
.set_stroke_width(line_width)
.set_anti_alias(true),
);
}
}
Expand All @@ -171,7 +179,7 @@ impl<'a, B: Bus<f32> + 'static, A: Accumulator + 'static> RangeModifiers
let e = self.entity();

range.set_or_bind(self.context(), e, move |cx, r| {
(*cx).emit_to(e, GraphEvents::UpdateRange(r.clone()));
(*cx).emit_to(e, GraphEvents::UpdateRange(r.get(cx)));
});

self
Expand All @@ -180,7 +188,7 @@ impl<'a, B: Bus<f32> + 'static, A: Accumulator + 'static> RangeModifiers
let e = self.entity();

scaling.set_or_bind(self.context(), e, move |cx, s| {
(*cx).emit_to(e, GraphEvents::UpdateScaling(s.clone()))
(*cx).emit_to(e, GraphEvents::UpdateScaling(s.get(cx)))
});

self
Expand Down
26 changes: 14 additions & 12 deletions src/visualizers/grid.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use nih_plug_vizia::vizia::{prelude::*, vg};
use vizia_plug::vizia::{prelude::*, vg};

use crate::utils::ValueScaling;

Expand Down Expand Up @@ -64,8 +64,8 @@ impl Grid {
) -> Handle<Self> {
Self {
scaling,
range: range.get_val(cx),
lines: lines.get_val(cx),
range: range.get(cx),
lines: lines.get(cx),
orientation,
}
.build(cx, |_| {})
Expand All @@ -78,7 +78,7 @@ impl View for Grid {
fn element(&self) -> Option<&'static str> {
Some("grid")
}
fn draw(&self, cx: &mut DrawContext, canvas: &mut Canvas) {
fn draw(&self, cx: &mut DrawContext, canvas: &vizia_plug::vizia::vg::Canvas) {
let bounds = cx.bounds();

let x = bounds.x;
Expand All @@ -92,7 +92,7 @@ impl View for Grid {
cx.scale_factor()
};

canvas.stroke_path(
canvas.draw_path(
&{
let mut path = vg::Path::new();

Expand All @@ -105,8 +105,8 @@ impl View for Grid {
self.range.1,
);

path.move_to(x, y + h * (1. - y_line));
path.line_to(x + w, y + h * (1. - y_line));
path.move_to((x, y + h * (1. - y_line)));
path.line_to((x + w, y + h * (1. - y_line)));

path.close();
}
Expand All @@ -119,8 +119,8 @@ impl View for Grid {
self.range.1,
);

path.move_to(x + w * x_line, y);
path.line_to(x + w * x_line, y + h);
path.move_to((x + w * x_line, y));
path.line_to((x + w * x_line, y + h));

path.close();
}
Expand All @@ -129,7 +129,9 @@ impl View for Grid {

path
},
&vg::Paint::color(cx.font_color().into()).with_line_width(line_width),
&vg::Paint::new(Into::<vg::Color4f>::into(cx.font_color()), None)
.set_style(vg::PaintStyle::Stroke)
.set_stroke_width(line_width),
);
}
fn event(&mut self, _cx: &mut EventContext, event: &mut Event) {
Expand All @@ -145,7 +147,7 @@ impl<'a> RangeModifiers for Handle<'a, Grid> {
let e = self.entity();

range.set_or_bind(self.context(), e, move |cx, r| {
(*cx).emit_to(e, GridEvents::UpdateRange(r.clone()));
(*cx).emit_to(e, GridEvents::UpdateRange(r.get(cx)));
});

self
Expand All @@ -154,7 +156,7 @@ impl<'a> RangeModifiers for Handle<'a, Grid> {
let e = self.entity();

scaling.set_or_bind(self.context(), e, move |cx, s| {
(*cx).emit_to(e, GridEvents::UpdateScaling(s));
(*cx).emit_to(e, GridEvents::UpdateScaling(s.get(cx)));
});

self
Expand Down
Loading
Loading