mirror of
https://github.com/Dangoware/dango-music-player.git
synced 2025-04-19 10:02:53 -05:00
minor changes to the Controller
This commit is contained in:
parent
39fc9e7960
commit
5aa675111e
1 changed files with 39 additions and 14 deletions
|
@ -81,18 +81,24 @@ pub enum PlayerResponse {
|
||||||
|
|
||||||
pub enum LibraryCommand {
|
pub enum LibraryCommand {
|
||||||
Song(Uuid),
|
Song(Uuid),
|
||||||
|
AllSongs,
|
||||||
|
GetLibrary,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum LibraryResponse {
|
pub enum LibraryResponse {
|
||||||
Songs(Song),
|
Song(Song),
|
||||||
|
AllSongs(Vec<Song>),
|
||||||
|
Library(MusicLibrary),
|
||||||
}
|
}
|
||||||
|
|
||||||
enum InnerLibraryCommand {
|
enum InnerLibraryCommand {
|
||||||
Song(Uuid),
|
Song(Uuid),
|
||||||
|
AllSongs,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum InnerLibraryResponse<'a> {
|
enum InnerLibraryResponse<'a> {
|
||||||
Song(&'a Song),
|
Song(&'a Song),
|
||||||
|
AllSongs(&'a Vec<Song>),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum QueueCommand {
|
pub enum QueueCommand {
|
||||||
|
@ -120,12 +126,12 @@ pub struct ControllerInput {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ControllerHandle {
|
pub struct ControllerHandle {
|
||||||
lib_mail: MailMan<LibraryCommand, LibraryResponse>,
|
pub lib_mail: MailMan<LibraryCommand, LibraryResponse>,
|
||||||
player_mail: MailMan<PlayerCommand, PlayerResponse>,
|
pub player_mail: MailMan<PlayerCommand, PlayerResponse>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ControllerHandle {
|
impl ControllerHandle {
|
||||||
fn new(library: MusicLibrary, config: Arc<RwLock<Config>>) -> (Self, ControllerInput) {
|
pub fn new(library: MusicLibrary, config: Arc<RwLock<Config>>) -> (Self, ControllerInput) {
|
||||||
let lib_mail = MailMan::double();
|
let lib_mail = MailMan::double();
|
||||||
let player_mail = MailMan::double();
|
let player_mail = MailMan::double();
|
||||||
|
|
||||||
|
@ -195,29 +201,24 @@ impl<'c, P: Player + Send + Sync> Controller<'c, P> {
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
})
|
});
|
||||||
.await;
|
|
||||||
scope
|
scope
|
||||||
.spawn(async move {
|
.spawn(async move {
|
||||||
Controller::<P>::player_event_loop(player, player_mail.0)
|
Controller::<P>::player_event_loop(player, player_mail.0)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
})
|
});
|
||||||
.await;
|
|
||||||
scope
|
scope
|
||||||
.spawn(async {
|
.spawn(async {
|
||||||
Controller::<P>::inner_library_loop(inner_lib_mail.1, &mut library)
|
Controller::<P>::inner_library_loop(inner_lib_mail.1, &mut library).await
|
||||||
.await
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
})
|
});
|
||||||
.await;
|
|
||||||
scope
|
scope
|
||||||
.spawn(async {
|
.spawn(async {
|
||||||
Controller::<P>::outer_library_loop(lib_mail, inner_lib_mail.0)
|
Controller::<P>::outer_library_loop(lib_mail, inner_lib_mail.0)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
})
|
});
|
||||||
.await
|
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
})
|
})
|
||||||
|
@ -315,15 +316,33 @@ impl<'c, P: Player + Send + Sync> Controller<'c, P> {
|
||||||
lib_mail: MailMan<LibraryResponse, LibraryCommand>,
|
lib_mail: MailMan<LibraryResponse, LibraryCommand>,
|
||||||
inner_lib_mail: MailMan<InnerLibraryCommand, InnerLibraryResponse<'c>>,
|
inner_lib_mail: MailMan<InnerLibraryCommand, InnerLibraryResponse<'c>>,
|
||||||
) -> Result<(), ()> {
|
) -> Result<(), ()> {
|
||||||
|
println!("outer lib loop");
|
||||||
while true {
|
while true {
|
||||||
match lib_mail.recv().await.unwrap() {
|
match lib_mail.recv().await.unwrap() {
|
||||||
LibraryCommand::Song(uuid) => {
|
LibraryCommand::Song(uuid) => {
|
||||||
|
println!("got song commandf");
|
||||||
inner_lib_mail
|
inner_lib_mail
|
||||||
.send(InnerLibraryCommand::Song(uuid))
|
.send(InnerLibraryCommand::Song(uuid))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let x = inner_lib_mail.recv().await.unwrap();
|
let x = inner_lib_mail.recv().await.unwrap();
|
||||||
}
|
}
|
||||||
|
LibraryCommand::AllSongs => {
|
||||||
|
println!("got command");
|
||||||
|
inner_lib_mail
|
||||||
|
.send(InnerLibraryCommand::AllSongs)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
println!("sent");
|
||||||
|
let x = inner_lib_mail.recv().await.unwrap();
|
||||||
|
println!("recieved");
|
||||||
|
if let InnerLibraryResponse::AllSongs(songs) = x {
|
||||||
|
lib_mail.send(LibraryResponse::AllSongs(songs.clone())).await.unwrap();
|
||||||
|
} else {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => { todo!() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -342,6 +361,12 @@ impl<'c, P: Player + Send + Sync> Controller<'c, P> {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
InnerLibraryCommand::AllSongs => {
|
||||||
|
let songs: &'c Vec<Song> = &library.library;
|
||||||
|
lib_mail.send(InnerLibraryResponse::AllSongs(songs))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue