🚧 wip: FLTK GUI demo
parent
70e5182dfc
commit
f2484dda91
41
src/main.rs
41
src/main.rs
|
@ -8,9 +8,8 @@ use std::{
|
||||||
},
|
},
|
||||||
thread::{
|
thread::{
|
||||||
self,
|
self,
|
||||||
sleep,
|
|
||||||
},
|
},
|
||||||
time::{Duration, Instant},
|
time::{Instant},
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::{
|
use anyhow::{
|
||||||
|
@ -102,7 +101,14 @@ pub struct SharedState {
|
||||||
pub quit: bool,
|
pub quit: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cmd_gui (_args: &[String]) -> Result <()> {
|
fn cmd_gui (args: &[String]) -> Result <()> {
|
||||||
|
tracing_subscriber::fmt::init ();
|
||||||
|
|
||||||
|
let filenames: Vec <_> = args.iter ()
|
||||||
|
.skip (1)
|
||||||
|
.map (|s| s.to_string ())
|
||||||
|
.collect ();
|
||||||
|
|
||||||
let (fltk_tx, fltk_rx) = app::channel::<Message> ();
|
let (fltk_tx, fltk_rx) = app::channel::<Message> ();
|
||||||
|
|
||||||
let app = app::App::default ();
|
let app = app::App::default ();
|
||||||
|
@ -128,18 +134,35 @@ fn cmd_gui (_args: &[String]) -> Result <()> {
|
||||||
wind.end ();
|
wind.end ();
|
||||||
wind.show ();
|
wind.show ();
|
||||||
|
|
||||||
|
let shared_state = Arc::new ((Mutex::new (SharedState::default ()), Condvar::new ()));
|
||||||
|
let pcm_quit = Arc::new ((Mutex::new (false), Condvar::new ()));
|
||||||
|
|
||||||
|
let thread_decoder = DecoderThread::new (Arc::clone (&shared_state), filenames);
|
||||||
|
let mut audio_output = AudioOutput::new (Arc::clone (&pcm_quit), Arc::clone (&shared_state))?;
|
||||||
|
|
||||||
while app.wait () {
|
while app.wait () {
|
||||||
match fltk_rx.recv () {
|
match fltk_rx.recv () {
|
||||||
Some (Message::Play) => {
|
Some (Message::Play) => {
|
||||||
tracing::info! ("play");
|
tracing::info! ("play");
|
||||||
|
audio_output.play ()?;
|
||||||
},
|
},
|
||||||
Some (Message::Pause) => {
|
Some (Message::Pause) => {
|
||||||
tracing::info! ("pause");
|
tracing::info! ("pause");
|
||||||
|
audio_output.pause ()?;
|
||||||
},
|
},
|
||||||
None => (),
|
None => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tracing::debug! ("Joining decoder thread...");
|
||||||
|
thread_decoder.join ()?;
|
||||||
|
|
||||||
|
tracing::debug! ("Joining PCM thread...");
|
||||||
|
let (lock, cvar) = &*pcm_quit;
|
||||||
|
let _ = cvar.wait (lock.lock ().unwrap ()).unwrap ();
|
||||||
|
|
||||||
|
tracing::info! ("Exiting cleanly.");
|
||||||
|
|
||||||
Ok (())
|
Ok (())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,18 +181,14 @@ fn cmd_play (args: &[String]) -> Result <()> {
|
||||||
let audio_output = AudioOutput::new (Arc::clone (&pcm_quit), Arc::clone (&shared_state))?;
|
let audio_output = AudioOutput::new (Arc::clone (&pcm_quit), Arc::clone (&shared_state))?;
|
||||||
|
|
||||||
tracing::debug! ("Joining decoder thread...");
|
tracing::debug! ("Joining decoder thread...");
|
||||||
|
|
||||||
thread_decoder.join ()?;
|
thread_decoder.join ()?;
|
||||||
|
|
||||||
tracing::debug! ("Joining PCM thread...");
|
tracing::debug! ("Joining PCM thread...");
|
||||||
|
|
||||||
let (lock, cvar) = &*pcm_quit;
|
let (lock, cvar) = &*pcm_quit;
|
||||||
let _ = cvar.wait (lock.lock ().unwrap ()).unwrap ();
|
let _ = cvar.wait (lock.lock ().unwrap ()).unwrap ();
|
||||||
|
|
||||||
drop (audio_output);
|
drop (audio_output);
|
||||||
|
|
||||||
sleep (Duration::from_secs (1));
|
|
||||||
|
|
||||||
tracing::info! ("Exiting cleanly.");
|
tracing::info! ("Exiting cleanly.");
|
||||||
Ok (())
|
Ok (())
|
||||||
}
|
}
|
||||||
|
@ -226,8 +245,8 @@ impl DecoderThread {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AudioOutput {
|
struct AudioOutput {
|
||||||
host: cpal::Host,
|
_host: cpal::Host,
|
||||||
device: cpal::Device,
|
_device: cpal::Device,
|
||||||
stream: cpal::Stream,
|
stream: cpal::Stream,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,8 +307,8 @@ impl AudioOutput {
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok (Self {
|
Ok (Self {
|
||||||
host,
|
_host: host,
|
||||||
device,
|
_device: device,
|
||||||
stream,
|
stream,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue