alemidev / scope-tui

a simple oscilloscope/vectorscope/spectroscope for your terminal
MIT License
184 stars 12 forks source link

scope-tui as library crate #7

Open alemidev opened 6 months ago

alemidev commented 6 months ago

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](https://github.com/sbechet/xmrsplayer). 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 commented 6 months ago
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 ```toml scope-tui = { git = "https://github.com/alemidev/scope-tui.git", rev = "b963aba7f93062acadf696efddab23ed93ecb7f2", default-features = false, features = ["tui"] } ``` and get access to `scope` lib: ```rs use scope::{input::Matrix, display::{GraphConfig, DisplayMode, oscilloscope::Oscilloscope}}; let data : Matrix = vec![]; // Matrix == Vec> let mut osc = Oscilloscope::default(); let cfg = GraphConfig::default(); let datasets = osc.process(&cfg, data); // these aren't ratatui's Dataset but implement Into ``` 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`. Note that `DataSet` is basically a ratatui's `Dataset` but with owned strings let me know if this works for you!