From f79bf8d477caf940927b512fe849d4acedbb0f02 Mon Sep 17 00:00:00 2001 From: MrDulfin Date: Mon, 20 May 2024 00:00:06 -0400 Subject: [PATCH] cleaned some warnings and updated player trait --- src/music_controller/controller.rs | 38 +++++++----------------------- src/music_player/player.rs | 7 +++--- src/music_storage/library.rs | 21 ++++------------- 3 files changed, 16 insertions(+), 50 deletions(-) diff --git a/src/music_controller/controller.rs b/src/music_controller/controller.rs index 2ab8811..f84545c 100644 --- a/src/music_controller/controller.rs +++ b/src/music_controller/controller.rs @@ -4,29 +4,24 @@ use crossbeam_channel; use crossbeam_channel::{Receiver, Sender}; -use listenbrainz::ListenBrainz; use std::path::PathBuf; use std::sync::{Arc, RwLock}; -use std::thread::spawn; use crossbeam_channel::unbounded; use std::error::Error; use uuid::Uuid; -use crate::music_controller::queue::QueueItem; -use crate::music_player::gstreamer::GStreamer; -use crate::music_storage::library::{Tag, URI}; +use crate::music_player::player::Player; +use crate::music_storage::library::URI; use crate::{ - config::config::Config, - music_controller::queue::Queue, - music_storage::library::{MusicLibrary, Song}, + config::config::Config, music_controller::queue::Queue, music_storage::library::MusicLibrary, }; -pub struct Controller { +pub struct Controller { pub queue: Queue, pub config: Arc>, pub library: MusicLibrary, - player_mail: MailMan, + pub player: P, } #[derive(Debug)] @@ -69,10 +64,10 @@ enum PlayerRes { } #[allow(unused_variables)] -impl Controller { - pub fn start

(config_path: P) -> Result> +impl

Controller

{ + pub fn start(config_path: T) -> Result> where - std::path::PathBuf: std::convert::From

, + std::path::PathBuf: std::convert::From, { let config_path = PathBuf::from(config_path); @@ -84,26 +79,11 @@ impl Controller { let (player_mail, in_thread) = MailMan::::double(); - spawn(move || { - let mut player = GStreamer::new().unwrap(); - - while true { - match in_thread.recv().unwrap() { - PlayerCmd::Test(uri) => { - &player.set_volume(0.04); - _ = &player.enqueue_next(&uri).unwrap(); - _ = &player.play(); - in_thread.send(PlayerRes::Test).unwrap(); - } - } - } - }); - Ok(Controller { queue: Queue::new(), config: config_.clone(), library, - player_mail, + player: P::new(), }) } diff --git a/src/music_player/player.rs b/src/music_player/player.rs index a30b2a6..ddf79c4 100644 --- a/src/music_player/player.rs +++ b/src/music_player/player.rs @@ -1,10 +1,9 @@ use chrono::Duration; -use thiserror::Error; use gstreamer as gst; +use thiserror::Error; use crate::music_storage::library::URI; - #[derive(Error, Debug)] pub enum PlayerError { #[error("player initialization failed")] @@ -24,6 +23,7 @@ pub enum PlayerError { } pub trait Player { + fn new() -> Self; fn source(&self) -> &Option; fn enqueue_next(&mut self, next_track: &URI) -> Result<(), PlayerError>; @@ -53,5 +53,4 @@ pub trait Player { fn seek_by(&mut self, seek_amount: Duration) -> Result<(), PlayerError>; fn seek_to(&mut self, target_pos: Duration) -> Result<(), PlayerError>; - -} \ No newline at end of file +} diff --git a/src/music_storage/library.rs b/src/music_storage/library.rs index 6fc3b36..344dd3a 100644 --- a/src/music_storage/library.rs +++ b/src/music_storage/library.rs @@ -6,7 +6,6 @@ use crate::config::config::Config; // Various std things use std::collections::BTreeMap; use std::error::Error; -use std::io::Write; use std::ops::ControlFlow::{Break, Continue}; // Files @@ -14,9 +13,8 @@ use file_format::{FileFormat, Kind}; use glib::filename_to_uri; use lofty::{AudioFile, ItemKey, ItemValue, ParseOptions, Probe, TagType, TaggedFileExt}; use rcue::parser::parse_from_file; -use std::fs::{self, File}; +use std::fs; use std::path::{Path, PathBuf}; -use tempfile::TempDir; use uuid::Uuid; use walkdir::WalkDir; @@ -144,22 +142,17 @@ pub enum DoNotTrack { Discord, } -#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, Default, Clone, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord)] #[non_exhaustive] pub enum SongType { // TODO: add MORE?! song types + #[default] Main, Instrumental, Remix, Custom(String), } -impl Default for SongType { - fn default() -> Self { - SongType::Main - } -} - /// Stores information about a single song #[derive(Debug, Clone, Deserialize, Serialize, PartialEq)] pub struct Song { @@ -1127,18 +1120,12 @@ impl MusicLibrary { #[cfg(test)] mod test { use std::{ - path::{Path, PathBuf}, + path::PathBuf, sync::{Arc, RwLock}, - thread::sleep, - time::{Duration, Instant}, }; - use tempfile::TempDir; - use crate::{config::config::Config, music_storage::library::MusicLibrary}; - use super::Song; - #[test] fn library_init() { let config = Config::read_file(PathBuf::from("test_config/config_test.json")).unwrap();