Compare commits

..

No commits in common. "39fc9e7960b0dbe56eb4566c88cbed7c43b99f09" and "15988ae8085b4e27a9fe3f8cbfa4e63873a3087e" have entirely different histories.

View file

@ -108,51 +108,16 @@ pub enum QueueResponse {
Item(QueueItem<QueueSong, QueueAlbum>),
}
pub struct ControllerInput {
player_mail: (
MailMan<PlayerCommand, PlayerResponse>,
MailMan<PlayerResponse, PlayerCommand>,
),
lib_mail: MailMan<LibraryResponse, LibraryCommand>,
library: MusicLibrary,
config: Arc<RwLock<Config>>,
}
pub struct ControllerHandle {
lib_mail: MailMan<LibraryCommand, LibraryResponse>,
player_mail: MailMan<PlayerCommand, PlayerResponse>,
}
impl ControllerHandle {
fn new(library: MusicLibrary, config: Arc<RwLock<Config>>) -> (Self, ControllerInput) {
let lib_mail = MailMan::double();
let player_mail = MailMan::double();
(
ControllerHandle {
lib_mail: lib_mail.0,
player_mail: player_mail.0.clone()
},
ControllerInput {
player_mail,
lib_mail: lib_mail.1,
library,
config
}
)
}
}
#[allow(unused_variables)]
impl<'c, P: Player + Send + Sync> Controller<'c, P> {
pub async fn start(
ControllerInput {
player_mail,
lib_mail,
mut library,
config
}: ControllerInput
player_mail: (
MailMan<PlayerCommand, PlayerResponse>,
MailMan<PlayerResponse, PlayerCommand>,
),
lib_mail: MailMan<LibraryResponse, LibraryCommand>,
mut library: MusicLibrary,
config: Arc<RwLock<Config>>,
) -> Result<(), Box<dyn Error>>
where
P: Player,
@ -406,7 +371,7 @@ mod test_super {
use crate::{
config::{tests::new_config_lib, Config},
music_controller::controller::{
LibraryCommand, LibraryResponse, MailMan, PlayerCommand, PlayerResponse, ControllerHandle
LibraryCommand, LibraryResponse, MailMan, PlayerCommand, PlayerResponse,
},
music_player::gstreamer::GStreamer,
music_storage::library::MusicLibrary,
@ -419,27 +384,21 @@ mod test_super {
// use if you don't have a config setup and add music to the music folder
new_config_lib();
let config = Config::read_file(PathBuf::from(std::env!("CONFIG-PATH"))).unwrap();
let mut library = {
MusicLibrary::init(
config.libraries.get_default().unwrap().path.clone(),
config.libraries.get_default().unwrap().uuid,
)
.unwrap()
};
let (handle, input) = ControllerHandle::new(library, Arc::new(RwLock::new(config)));
let lib_mail: (MailMan<LibraryCommand, LibraryResponse>, MailMan<_, _>) = MailMan::double();
let player_mail: (MailMan<PlayerCommand, PlayerResponse>, MailMan<_, _>) =
MailMan::double();
let _player_mail = player_mail.0.clone();
let b = spawn(move || {
futures::executor::block_on(async {
handle.player_mail
_player_mail
.send(PlayerCommand::SetVolume(0.01))
.await
.unwrap();
loop {
let buf: String = text_io::read!();
dbg!(&buf);
handle.player_mail
_player_mail
.send(match buf.to_lowercase().as_str() {
"next" => PlayerCommand::NextSong,
"prev" => PlayerCommand::PrevSong,
@ -453,16 +412,28 @@ mod test_super {
.await
.unwrap();
println!("sent it");
println!("{:?}", handle.player_mail.recv().await.unwrap())
println!("{:?}", _player_mail.recv().await.unwrap())
}
})
});
let a = spawn(move || {
futures::executor::block_on(async {
let config = Config::read_file(PathBuf::from(std::env!("CONFIG-PATH"))).unwrap();
let library = {
MusicLibrary::init(
config.libraries.get_default().unwrap().path.clone(),
config.libraries.get_default().unwrap().uuid,
)
.unwrap()
};
Controller::<GStreamer>::start(input)
Controller::<GStreamer>::start(
player_mail,
lib_mail.1,
library,
Arc::new(RwLock::new(config)),
)
.await
.unwrap();
});