diff --git a/Cargo.toml b/Cargo.toml index 08c25dc..c12abb7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,3 +48,4 @@ tempfile = "3.10.1" listenbrainz = "0.7.0" discord-rpc-client = "0.4.0" nestify = "0.3.3" +kushi = "0.1.1" diff --git a/src/lib.rs b/src/lib.rs index 6f93ec1..d25f68f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,7 +11,7 @@ pub mod music_storage { pub mod music_controller { pub mod controller; pub mod connections; - pub mod queue; + // pub mod queue; } pub mod music_player { diff --git a/src/music_controller/controller.rs b/src/music_controller/controller.rs index 22109cc..8c64baa 100644 --- a/src/music_controller/controller.rs +++ b/src/music_controller/controller.rs @@ -4,6 +4,9 @@ use crossbeam_channel; use crossbeam_channel::{Receiver, Sender}; +use kushi::error::QueueError; +use kushi::traits::Location; +use kushi::{Queue, QueueItemType}; use std::path::PathBuf; use std::sync::{Arc, Mutex, RwLock}; use std::thread::{sleep, spawn}; @@ -16,14 +19,13 @@ use uuid::Uuid; use crate::config::ConfigError; use crate::music_player::player::{Player, PlayerCommand, PlayerError}; +use crate::music_storage::library::{Album, Song}; use crate::{ - config::Config, music_controller::queue::Queue, music_storage::library::MusicLibrary, + config::Config, music_storage::library::MusicLibrary, }; -use super::queue::QueueError; - -pub struct Controller { - pub queue: Arc>, +pub struct Controller<'a, P: Player + Send + Sync> { + pub queue: Arc, PlayerLocation>>>, pub config: Arc>, pub library: MusicLibrary, pub player: Arc>, @@ -39,6 +41,19 @@ pub enum ControllerError { ConfigError(#[from] ConfigError), } +// TODO: move this to a different location to be used elsewhere +#[derive(Debug, Clone, Copy, PartialEq)] +#[non_exhaustive] +pub enum PlayerLocation { + Test, + Library, + Playlist(Uuid), + File, + Custom, +} + +impl Location for PlayerLocation {} + #[derive(Debug)] pub(super) struct MailMan { pub tx: Sender, @@ -71,8 +86,8 @@ impl MailMan { } #[allow(unused_variables)] -impl Controller

{ - pub fn start(config_path: T) -> Result> +impl Controller<'static, P> { + pub fn start(config_path: T) -> Result > where std::path::PathBuf: std::convert::From, P: Player, @@ -85,8 +100,15 @@ impl Controller

{ let config_ = Arc::new(RwLock::from(config)); let library = MusicLibrary::init(config_.clone(), uuid)?; + let queue: Queue = Queue { + items: Vec::new(), + played: Vec::new(), + loop_: false, + shuffle: None + }; + let controller = Controller { - queue: Arc::new(RwLock::from(Queue::default())), + queue: Arc::new(RwLock::from(queue)), config: config_.clone(), library, player: Arc::new(Mutex::new(P::new()?)), @@ -112,10 +134,12 @@ impl Controller

{ player .lock() .unwrap() - .enqueue_next(uri.item - .primary_uri() - .unwrap() - .0) + .enqueue_next(&{ + match uri.item { + QueueItemType::Single(song) => song.primary_uri().unwrap().0.clone(), + _ => unimplemented!() + } + }) .unwrap(); }, PlayerCommand::EndOfStream => {dbg!()} @@ -129,7 +153,7 @@ impl Controller

{ Ok(controller) } - pub fn q_add(&mut self, item: &Uuid, source: super::queue::PlayerLocation, by_human: bool) { + pub fn q_add(&mut self, item: &Uuid, source: Option, by_human: bool) { let item = self.library.query_uuid(item).unwrap().0.to_owned(); self.queue.write().unwrap().add_item(item, source, by_human) } @@ -139,7 +163,7 @@ impl Controller

{ mod test_super { use std::{thread::sleep, time::Duration}; - use crate::{config::tests::read_config_lib, music_controller::queue::PlayerLocation, music_player::{gstreamer::GStreamer, player::Player}}; + use crate::{config::tests::read_config_lib, music_controller::controller::PlayerLocation, music_player::{gstreamer::GStreamer, player::Player}}; use super::Controller; @@ -154,21 +178,21 @@ mod test_super { { let mut queue = controller.queue.write().unwrap(); for x in config.1.library { - queue.add_item(x, PlayerLocation::Library, true); + queue.add_item(x, Some(PlayerLocation::Library), true); } } { controller.player.lock().unwrap().enqueue_next(next.primary_uri().unwrap().0).unwrap(); } { - controller.player.lock().unwrap().set_volume(0.2); + controller.player.lock().unwrap().set_volume(0.1); } { controller.player.lock().unwrap().play().unwrap(); } println!("I'm a tire"); } - sleep(Duration::from_secs(600)) + sleep(Duration::from_secs(10)) } } diff --git a/src/music_controller/queue.rs b/src/music_controller/queue.rs index 3acdd7a..d13ab35 100644 --- a/src/music_controller/queue.rs +++ b/src/music_controller/queue.rs @@ -23,16 +23,7 @@ pub enum QueueState { NoState, } -// TODO: move this to a different location to be used elsewhere -#[derive(Debug, Clone, Copy, PartialEq)] -#[non_exhaustive] -pub enum PlayerLocation { - Test, - Library, - Playlist(Uuid), - File, - Custom, -} + #[derive(Debug, Clone, PartialEq)] #[non_exhaustive] diff --git a/src/music_storage/library.rs b/src/music_storage/library.rs index ae189f4..022e1de 100644 --- a/src/music_storage/library.rs +++ b/src/music_storage/library.rs @@ -11,6 +11,7 @@ use std::ops::ControlFlow::{Break, Continue}; // Files use file_format::{FileFormat, Kind}; use glib::filename_to_uri; +use kushi::traits::TrackGroup; use lofty::{AudioFile, ItemKey, ItemValue, ParseOptions, Probe, TagType, TaggedFileExt}; use rcue::parser::parse_from_file; use std::fs; @@ -624,6 +625,9 @@ impl Album<'_> { } } +impl TrackGroup for Album<'_> {} + + #[derive(Debug, Serialize, Deserialize)] pub struct MusicLibrary { pub name: String,