scope-tui icon indicating copy to clipboard operation
scope-tui copied to clipboard

scope-tui as library crate

Open alemidev opened this issue 1 year ago • 2 comments

Discussed in https://github.com/alemidev/scope-tui/discussions/6

Originally posted by sbechet March 24, 2024

Hello, I am currently writing a small sound tracking player here. The usage example uses rodio. It might be fun to add scope-tui as a feature. is this a possibility? What do you think about that?


it may be cool to provide scope-tui as a dependency and not only a binary, so that other projects handling music and making TUIs can integrate these visualizers and not reinvent the wheel. idk if we can have a generic event type instead of crossterm's, and also if lib should include parsing/file sources

alemidev avatar Apr 04 '24 22:04 alemidev

Originally posted by alemi April 4, 2024

hey, thanks for your interest! i believe it should be possible but it's probably still quite rough around the edges

i just pushed few commits separating the lib itself from the app code. you should be able to do

scope-tui = { git = "https://github.com/alemidev/scope-tui.git", rev = "b963aba7f93062acadf696efddab23ed93ecb7f2", default-features = false, features = ["tui"] }

and get access to scope lib:

use scope::{input::Matrix, display::{GraphConfig, DisplayMode, oscilloscope::Oscilloscope}};

let data : Matrix<f64> = vec![]; // Matrix<T> == Vec<Vec<T>>
let mut osc = Oscilloscope::default();
let cfg = GraphConfig::default();
let datasets = osc.process(&cfg, data); // these aren't ratatui's Dataset but implement Into<Dataset>

you should probably receive batches of samples from rodio and pass them to Oscilloscope/Vectorscope/Spectroscope. These will process your data and spit out a Vec<DataSet>. Note that DataSet is basically a ratatui's Dataset but with owned strings

let me know if this works for you!

alemidev avatar Apr 04 '24 22:04 alemidev