mirror of
https://github.com/Dangoware/dmp-core.git
synced 2025-04-20 01:32:54 -05:00
Compare commits
3 commits
15988ae808
...
39fc9e7960
Author | SHA1 | Date | |
---|---|---|---|
|
39fc9e7960 | ||
|
8daebb7212 | ||
|
ab5c65d64d |
1 changed files with 58 additions and 29 deletions
|
@ -108,16 +108,51 @@ pub enum QueueResponse {
|
||||||
Item(QueueItem<QueueSong, QueueAlbum>),
|
Item(QueueItem<QueueSong, QueueAlbum>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
|
||||||
impl<'c, P: Player + Send + Sync> Controller<'c, P> {
|
pub struct ControllerInput {
|
||||||
pub async fn start(
|
|
||||||
player_mail: (
|
player_mail: (
|
||||||
MailMan<PlayerCommand, PlayerResponse>,
|
MailMan<PlayerCommand, PlayerResponse>,
|
||||||
MailMan<PlayerResponse, PlayerCommand>,
|
MailMan<PlayerResponse, PlayerCommand>,
|
||||||
),
|
),
|
||||||
lib_mail: MailMan<LibraryResponse, LibraryCommand>,
|
lib_mail: MailMan<LibraryResponse, LibraryCommand>,
|
||||||
mut library: MusicLibrary,
|
library: MusicLibrary,
|
||||||
config: Arc<RwLock<Config>>,
|
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
|
||||||
) -> Result<(), Box<dyn Error>>
|
) -> Result<(), Box<dyn Error>>
|
||||||
where
|
where
|
||||||
P: Player,
|
P: Player,
|
||||||
|
@ -371,7 +406,7 @@ mod test_super {
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{tests::new_config_lib, Config},
|
config::{tests::new_config_lib, Config},
|
||||||
music_controller::controller::{
|
music_controller::controller::{
|
||||||
LibraryCommand, LibraryResponse, MailMan, PlayerCommand, PlayerResponse,
|
LibraryCommand, LibraryResponse, MailMan, PlayerCommand, PlayerResponse, ControllerHandle
|
||||||
},
|
},
|
||||||
music_player::gstreamer::GStreamer,
|
music_player::gstreamer::GStreamer,
|
||||||
music_storage::library::MusicLibrary,
|
music_storage::library::MusicLibrary,
|
||||||
|
@ -384,21 +419,27 @@ mod test_super {
|
||||||
// use if you don't have a config setup and add music to the music folder
|
// use if you don't have a config setup and add music to the music folder
|
||||||
new_config_lib();
|
new_config_lib();
|
||||||
|
|
||||||
let lib_mail: (MailMan<LibraryCommand, LibraryResponse>, MailMan<_, _>) = MailMan::double();
|
let config = Config::read_file(PathBuf::from(std::env!("CONFIG-PATH"))).unwrap();
|
||||||
let player_mail: (MailMan<PlayerCommand, PlayerResponse>, MailMan<_, _>) =
|
let mut library = {
|
||||||
MailMan::double();
|
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 _player_mail = player_mail.0.clone();
|
|
||||||
let b = spawn(move || {
|
let b = spawn(move || {
|
||||||
futures::executor::block_on(async {
|
futures::executor::block_on(async {
|
||||||
_player_mail
|
handle.player_mail
|
||||||
.send(PlayerCommand::SetVolume(0.01))
|
.send(PlayerCommand::SetVolume(0.01))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
loop {
|
loop {
|
||||||
let buf: String = text_io::read!();
|
let buf: String = text_io::read!();
|
||||||
dbg!(&buf);
|
dbg!(&buf);
|
||||||
_player_mail
|
handle.player_mail
|
||||||
.send(match buf.to_lowercase().as_str() {
|
.send(match buf.to_lowercase().as_str() {
|
||||||
"next" => PlayerCommand::NextSong,
|
"next" => PlayerCommand::NextSong,
|
||||||
"prev" => PlayerCommand::PrevSong,
|
"prev" => PlayerCommand::PrevSong,
|
||||||
|
@ -412,28 +453,16 @@ mod test_super {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
println!("sent it");
|
println!("sent it");
|
||||||
println!("{:?}", _player_mail.recv().await.unwrap())
|
println!("{:?}", handle.player_mail.recv().await.unwrap())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
let a = spawn(move || {
|
let a = spawn(move || {
|
||||||
futures::executor::block_on(async {
|
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(
|
|
||||||
player_mail,
|
Controller::<GStreamer>::start(input)
|
||||||
lib_mail.1,
|
|
||||||
library,
|
|
||||||
Arc::new(RwLock::new(config)),
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue