Browse and listen to thousands of radio stations across the globe right from your terminal ๐ŸŒŽ ๐Ÿ“ป ๐ŸŽตโœจ
radio rust tokio web-radio command-line-tool tui
at main 1.6 kB view raw
1use crate::music::Note; 2 3/// a simple oscilloscope/vectorscope for your terminal 4#[derive(Debug)] 5pub struct ScopeArgs { 6 pub opts: SourceOptions, 7 pub ui: UiOptions, 8} 9 10#[derive(Debug, Clone)] 11pub struct UiOptions { 12 /// floating point vertical scale, from 0 to 1 13 pub scale: f32, 14 15 /// use vintage looking scatter mode instead of line mode 16 pub scatter: bool, 17 18 /// don't draw reference line 19 pub no_reference: bool, 20 21 /// hide UI and only draw waveforms 22 pub no_ui: bool, 23 24 /// don't use braille dots for drawing lines 25 pub no_braille: bool, 26} 27 28#[derive(Debug, Clone)] 29pub struct SourceOptions { 30 /// number of channels to open 31 pub channels: usize, 32 33 /// size of audio buffer, and width of scope 34 pub buffer: u32, 35 36 /// sample rate to use 37 pub sample_rate: u32, 38 39 /// tune buffer size to be in tune with given note (overrides buffer option) 40 pub tune: Option<String>, 41} 42 43// TODO its convenient to keep this here but it's not really the best place... 44impl SourceOptions { 45 pub fn tune(&mut self) { 46 if let Some(txt) = &self.tune { 47 // TODO make it less jank 48 if let Ok(note) = txt.parse::<Note>() { 49 self.buffer = note.tune_buffer_size(self.sample_rate); 50 while self.buffer % (self.channels as u32 * 2) != 0 { 51 // TODO customizable bit depth 52 self.buffer += 1; // TODO jank but otherwise it doesn't align 53 } 54 } else { 55 eprintln!("[!] Unrecognized note '{}', ignoring option", txt); 56 } 57 } 58 } 59}