mirror of
https://github.com/ivabus/lonelyradio
synced 2024-11-10 02:25:17 +03:00
monolib + monoclient: Volume modification test
Signed-off-by: Ivan Bushchik <ivabus@ivabus.dev>
This commit is contained in:
parent
39cc35e16d
commit
c24d6d0175
|
@ -1,10 +1,11 @@
|
|||
use clap::Parser;
|
||||
use crossterm::cursor::MoveToColumn;
|
||||
use crossterm::event::{poll, read, Event};
|
||||
use crossterm::style::Print;
|
||||
use crossterm::terminal::{Clear, ClearType};
|
||||
use std::io::{stdout, IsTerminal};
|
||||
use std::path::PathBuf;
|
||||
use std::time::{Duration, Instant};
|
||||
use std::time::Instant;
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Args {
|
||||
|
@ -46,7 +47,25 @@ fn main() {
|
|||
.unwrap();
|
||||
let mut track_length = md.track_length_secs as f64 + md.track_length_frac as f64;
|
||||
let mut next_md = md.clone();
|
||||
crossterm::terminal::enable_raw_mode().unwrap();
|
||||
loop {
|
||||
if let Ok(true) = poll(std::time::Duration::from_micros(1)) {
|
||||
if let Event::Key(event) = read().unwrap() {
|
||||
match event.code {
|
||||
crossterm::event::KeyCode::Up => {
|
||||
monolib::set_volume(monolib::get_volume().saturating_add(16));
|
||||
}
|
||||
crossterm::event::KeyCode::Down => {
|
||||
monolib::set_volume(monolib::get_volume().saturating_sub(16));
|
||||
}
|
||||
crossterm::event::KeyCode::Char('q') => {
|
||||
crossterm::terminal::disable_raw_mode().unwrap();
|
||||
std::process::exit(0)
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
if monolib::get_metadata().unwrap() != md
|
||||
&& track_length <= (Instant::now() - track_start).as_secs_f64()
|
||||
{
|
||||
|
@ -84,6 +103,6 @@ fn main() {
|
|||
)
|
||||
.unwrap();
|
||||
}
|
||||
std::thread::sleep(Duration::from_secs_f32(0.25))
|
||||
//std::thread::sleep(Duration::from_secs_f32(0.25))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,12 +24,14 @@ use rodio::buffer::SamplesBuffer;
|
|||
use rodio::{OutputStream, Sink};
|
||||
use std::io::BufReader;
|
||||
use std::net::TcpStream;
|
||||
use std::sync::atomic::AtomicU8;
|
||||
use std::sync::RwLock;
|
||||
use std::time::Instant;
|
||||
|
||||
const CACHE_SIZE: usize = 32;
|
||||
const CACHE_SIZE: usize = 128;
|
||||
|
||||
static SINK: RwLock<Option<Sink>> = RwLock::new(None);
|
||||
static VOLUME: AtomicU8 = AtomicU8::new(255);
|
||||
static MD: RwLock<Option<TrackMetadata>> = RwLock::new(None);
|
||||
static STATE: RwLock<State> = RwLock::new(State::NotStarted);
|
||||
|
||||
|
@ -118,6 +120,18 @@ fn watching_sleep(dur: f32) -> bool {
|
|||
false
|
||||
}
|
||||
|
||||
pub fn get_volume() -> u8 {
|
||||
VOLUME.load(std::sync::atomic::Ordering::Acquire)
|
||||
}
|
||||
|
||||
pub fn set_volume(volume: u8) {
|
||||
let sink = SINK.read().unwrap();
|
||||
if let Some(sink) = sink.as_ref() {
|
||||
sink.set_volume(get_volume() as f32 / 255.0)
|
||||
}
|
||||
VOLUME.store(volume, std::sync::atomic::Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// Download track as samples
|
||||
pub fn get_track(server: &str, xor_key: Option<Vec<u8>>) -> Option<(TrackMetadata, Vec<i16>)> {
|
||||
let mut stream = BufReader::new(match xor_key {
|
||||
|
|
Loading…
Reference in a new issue