Skip to content

Commit 9ababe0

Browse files
committed
Viz app lib is roughly ready
1 parent 46bb639 commit 9ababe0

File tree

10 files changed

+134
-79
lines changed

10 files changed

+134
-79
lines changed

caw/examples/udp_viz_demo.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use std::{thread, time::Duration};
2-
31
use caw::prelude::*;
2+
use std::{thread, time::Duration};
43

54
fn main() -> anyhow::Result<()> {
5+
env_logger::init();
66
let sig = Stereo::new_fn_channel(|channel| {
77
let freq_hz = match channel {
88
Channel::Left => 60.,
@@ -19,13 +19,19 @@ fn main() -> anyhow::Result<()> {
1919
});
2020
let player_handle = play_stereo(
2121
sig,
22-
ConfigOwned {
22+
PlayerConfig {
2323
visualization_data_policy: Some(VisualizationDataPolicy::All),
2424
..Default::default()
2525
},
2626
)?;
2727
let viz_data = player_handle.visualization_data();
28-
let mut viz = VizUdpServer::new()?;
28+
let mut viz = VizUdpServer::new(VizAppConfig {
29+
scale: 1000.0,
30+
alpha_scale: 50,
31+
line_width: 2,
32+
max_num_samples: 10_000,
33+
..Default::default()
34+
})?;
2935
loop {
3036
viz_data.with_and_clear(|buf| viz.send_samples(buf))?;
3137
thread::sleep(Duration::from_millis(16));

interactive/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pub mod input;
22
pub mod window;
3-
pub use caw_player::ConfigSync;
3+
pub use caw_player::PlayerConfig;
44
pub use input::{Input, Key, KeySig, MouseButton};
55
pub use window::{Visualization, Window};

interactive/src/window.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::input::Input;
22
use anyhow::anyhow;
33
use caw_core::{SigSampleIntoBufT, Stereo};
4-
use caw_player::{ConfigSync, Player, ToF32};
4+
use caw_player::{Player, PlayerConfig, ToF32};
55
use line_2d::Coord;
66
pub use rgb_int::Rgb24;
77
use sdl2::{
@@ -318,7 +318,7 @@ impl Window {
318318
pub fn play_mono<T, S>(
319319
&self,
320320
sig: S,
321-
config: ConfigSync,
321+
config: PlayerConfig,
322322
) -> anyhow::Result<()>
323323
where
324324
T: ToF32 + Send + Sync + Copy + 'static,
@@ -350,7 +350,7 @@ impl Window {
350350
pub fn play_stereo<TL, TR, SL, SR>(
351351
&self,
352352
sig: Stereo<SL, SR>,
353-
config: ConfigSync,
353+
config: PlayerConfig,
354354
) -> anyhow::Result<()>
355355
where
356356
TL: ToF32 + Send + Sync + Copy + 'static,

live/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use caw_core::{Sig, SigBoxedVar, Stereo, StereoPair, svf32};
22
use caw_player::{
3-
ConfigOwned, PlayerVisualizationData, VisualizationDataPolicy, play_stereo,
4-
play_stereo_default,
3+
PlayerConfig, PlayerVisualizationData, VisualizationDataPolicy, play_stereo,
54
};
65
use lazy_static::lazy_static;
76
use std::sync::Mutex;
@@ -24,7 +23,7 @@ pub fn live_stereo_visualized(
2423
*initialized = true;
2524
let player = play_stereo(
2625
OUT.clone(),
27-
ConfigOwned {
26+
PlayerConfig {
2827
visualization_data_policy: Some(visualization_data_policy),
2928
..Default::default()
3029
},
@@ -42,7 +41,7 @@ pub fn live_stereo() -> StereoPair<Sig<SigBoxedVar<f32>>> {
4241
return OUT.clone();
4342
}
4443
*initialized = true;
45-
let player = play_stereo_default(OUT.clone()).unwrap();
44+
let player = play_stereo(OUT.clone(), Default::default()).unwrap();
4645
std::mem::forget(player);
4746
OUT.clone()
4847
}

player/examples/many_oscillators.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use caw_core::*;
22
use caw_modules::*;
3-
use caw_player::play_mono_default;
3+
use caw_player::play_mono;
44
use rand::Rng;
55

66
fn osc(freq: f32) -> Sig<impl SigT<Item = f32>> {
@@ -21,7 +21,7 @@ fn signal() -> Sig<impl SigT<Item = f32>> {
2121

2222
fn main() -> anyhow::Result<()> {
2323
env_logger::init();
24-
let _handle = play_mono_default(signal());
24+
let _handle = play_mono(signal(), Default::default());
2525
std::thread::park();
2626
Ok(())
2727
}

player/src/lib.rs

Lines changed: 17 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,20 @@ impl ToF32 for f64 {
2222
}
2323
}
2424

25-
#[derive(Debug, Clone, Copy)]
26-
pub struct ConfigSync {
27-
/// default: 0.01
28-
pub system_latency_s: f32,
29-
}
30-
31-
impl Default for ConfigSync {
32-
fn default() -> Self {
33-
Self {
34-
system_latency_s: 0.01,
35-
}
36-
}
37-
}
38-
3925
#[derive(Debug, Clone, Copy)]
4026
pub enum VisualizationDataPolicy {
4127
LatestOnly,
4228
All,
4329
}
4430

4531
#[derive(Debug, Clone, Copy)]
46-
pub struct ConfigOwned {
32+
pub struct PlayerConfig {
4733
/// default: 0.01
4834
pub system_latency_s: f32,
4935
pub visualization_data_policy: Option<VisualizationDataPolicy>,
5036
}
5137

52-
impl Default for ConfigOwned {
38+
impl Default for PlayerConfig {
5339
fn default() -> Self {
5440
Self {
5541
system_latency_s: 0.01,
@@ -121,7 +107,7 @@ impl Player {
121107
SyncCommandRequestNumSamples,
122108
>,
123109
recv_sync_command_done: mpsc::Receiver<SyncCommandDone>,
124-
config: ConfigSync,
110+
config: PlayerConfig,
125111
) -> anyhow::Result<(Stream, StreamConfig)>
126112
where
127113
T: ToF32 + Send + Sync + Copy + 'static,
@@ -163,7 +149,7 @@ impl Player {
163149
&self,
164150
mut sig: S,
165151
mut f: F,
166-
config: ConfigSync,
152+
config: PlayerConfig,
167153
) -> anyhow::Result<()>
168154
where
169155
T: ToF32 + Send + Sync + Copy + 'static,
@@ -217,7 +203,7 @@ impl Player {
217203
pub fn play_signal_sync_mono<T, S>(
218204
&self,
219205
signal: S,
220-
config: ConfigSync,
206+
config: PlayerConfig,
221207
) -> anyhow::Result<()>
222208
where
223209
T: ToF32 + Send + Sync + Copy + 'static,
@@ -231,7 +217,7 @@ impl Player {
231217
&self,
232218
signal: S,
233219
mut f: F,
234-
config: ConfigSync,
220+
config: PlayerConfig,
235221
) -> anyhow::Result<()>
236222
where
237223
T: ToF32 + Send + Sync + Copy + 'static,
@@ -255,7 +241,7 @@ impl Player {
255241
SyncCommandRequestNumSamples,
256242
>,
257243
recv_sync_command_done: mpsc::Receiver<SyncCommandDone>,
258-
config: ConfigSync,
244+
config: PlayerConfig,
259245
) -> anyhow::Result<(Stream, StreamConfig)>
260246
where
261247
TL: ToF32 + Send + Sync + Copy + 'static,
@@ -300,7 +286,7 @@ impl Player {
300286
&self,
301287
mut sig: Stereo<SL, SR>,
302288
mut f: F,
303-
config: ConfigSync,
289+
config: PlayerConfig,
304290
) -> anyhow::Result<()>
305291
where
306292
TL: ToF32 + Send + Sync + Copy + 'static,
@@ -362,7 +348,7 @@ impl Player {
362348
pub fn play_signal_sync_stereo<TL, TR, SL, SR>(
363349
&self,
364350
sig: Stereo<SL, SR>,
365-
config: ConfigSync,
351+
config: PlayerConfig,
366352
) -> anyhow::Result<()>
367353
where
368354
TL: ToF32 + Send + Sync + Copy + 'static,
@@ -378,7 +364,7 @@ impl Player {
378364
&self,
379365
sig: Stereo<SL, SR>,
380366
mut f: F,
381-
config: ConfigSync,
367+
config: PlayerConfig,
382368
) -> anyhow::Result<()>
383369
where
384370
TL: ToF32 + Send + Sync + Copy + 'static,
@@ -402,7 +388,7 @@ impl Player {
402388
pub fn play_stereo<SL, SR>(
403389
self,
404390
mut sig: Stereo<SL, SR>,
405-
config: ConfigOwned,
391+
config: PlayerConfig,
406392
) -> anyhow::Result<PlayerHandle>
407393
where
408394
SL: SigSampleIntoBufT<Item = f32> + Send + Sync + 'static,
@@ -469,7 +455,7 @@ impl Player {
469455
pub fn play_mono<S>(
470456
self,
471457
mut sig: S,
472-
config: ConfigOwned,
458+
config: PlayerConfig,
473459
) -> anyhow::Result<PlayerHandle>
474460
where
475461
S: SigSampleIntoBufT<Item = f32> + Send + Sync + 'static,
@@ -583,37 +569,23 @@ impl PlayerHandle {
583569
}
584570
}
585571

586-
pub fn play_mono<S>(sig: S, config: ConfigOwned) -> anyhow::Result<PlayerHandle>
572+
pub fn play_mono<S>(
573+
sig: S,
574+
config: PlayerConfig,
575+
) -> anyhow::Result<PlayerHandle>
587576
where
588577
S: SigSampleIntoBufT<Item = f32> + Send + Sync + 'static,
589578
{
590579
Player::new()?.play_mono(sig, config)
591580
}
592581

593-
pub fn play_mono_default<S>(sig: S) -> anyhow::Result<PlayerHandle>
594-
where
595-
S: SigSampleIntoBufT<Item = f32> + Send + Sync + 'static,
596-
{
597-
play_mono(sig, Default::default())
598-
}
599-
600582
pub fn play_stereo<SL, SR>(
601583
sig: Stereo<SL, SR>,
602-
config: ConfigOwned,
584+
config: PlayerConfig,
603585
) -> anyhow::Result<PlayerHandle>
604586
where
605587
SL: SigSampleIntoBufT<Item = f32> + Send + Sync + 'static,
606588
SR: SigSampleIntoBufT<Item = f32> + Send + Sync + 'static,
607589
{
608590
Player::new()?.play_stereo(sig, config)
609591
}
610-
611-
pub fn play_stereo_default<SL, SR>(
612-
sig: Stereo<SL, SR>,
613-
) -> anyhow::Result<PlayerHandle>
614-
where
615-
SL: SigSampleIntoBufT<Item = f32> + Send + Sync + 'static,
616-
SR: SigSampleIntoBufT<Item = f32> + Send + Sync + 'static,
617-
{
618-
play_stereo(sig, Default::default())
619-
}

viz-udp-app-lib/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
![CAW Logo](../assets/logo.png)
2+
3+
# caw_viz_udp_app_lib
4+
5+
[![Version](https://img.shields.io/crates/v/caw_viz_udp_app_lib.svg)](https://crates.io/crates/caw_viz_udp_app_lib)
6+
[![Documentation](https://docs.rs/caw_viz_udp_app_lib/badge.svg)](https://docs.rs/caw_viz_udp_app_lib)
7+
[![test](https://github.com/gridbugs/caw/actions/workflows/test.yml/badge.svg)](https://github.com/gridbugs/caw/actions/workflows/test.yml)
8+
[![dependency status](https://deps.rs/repo/github/gridbugs/caw/status.svg)](https://deps.rs/repo/github/gridbugs/caw)
9+
10+
Library for invoking `caw_viz_udp_app` and sending data to visualize to instances of the app.
11+
12+
Part of the [CAW Synthesizer Framework](..).

viz-udp-app-lib/examples/viz_udp_app_lib_handshake.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
use caw_viz_udp_app_lib::VizUdpServer;
1+
use caw_viz_udp_app_lib::{VizAppConfig, VizUdpServer};
22
use std::time::Duration;
33

44
fn main() -> anyhow::Result<()> {
5-
let mut server = VizUdpServer::new()?;
5+
let mut server = VizUdpServer::new(VizAppConfig {
6+
..Default::default()
7+
})?;
68
loop {
79
server.send_samples(&[1.0, 1.5, 2.0, 3.0])?;
810
std::thread::sleep(Duration::from_millis(100));

0 commit comments

Comments
 (0)