mirror of
https://github.com/Dangoware/dango-music-player.git
synced 2025-04-19 10:02:53 -05:00
implemented Queue changes with kushi crate
This commit is contained in:
parent
683b695bc6
commit
81ccab01f1
5 changed files with 48 additions and 28 deletions
|
@ -48,3 +48,4 @@ tempfile = "3.10.1"
|
||||||
listenbrainz = "0.7.0"
|
listenbrainz = "0.7.0"
|
||||||
discord-rpc-client = "0.4.0"
|
discord-rpc-client = "0.4.0"
|
||||||
nestify = "0.3.3"
|
nestify = "0.3.3"
|
||||||
|
kushi = "0.1.1"
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub mod music_storage {
|
||||||
pub mod music_controller {
|
pub mod music_controller {
|
||||||
pub mod controller;
|
pub mod controller;
|
||||||
pub mod connections;
|
pub mod connections;
|
||||||
pub mod queue;
|
// pub mod queue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod music_player {
|
pub mod music_player {
|
||||||
|
|
|
@ -4,6 +4,9 @@
|
||||||
|
|
||||||
use crossbeam_channel;
|
use crossbeam_channel;
|
||||||
use crossbeam_channel::{Receiver, Sender};
|
use crossbeam_channel::{Receiver, Sender};
|
||||||
|
use kushi::error::QueueError;
|
||||||
|
use kushi::traits::Location;
|
||||||
|
use kushi::{Queue, QueueItemType};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::{Arc, Mutex, RwLock};
|
use std::sync::{Arc, Mutex, RwLock};
|
||||||
use std::thread::{sleep, spawn};
|
use std::thread::{sleep, spawn};
|
||||||
|
@ -16,14 +19,13 @@ use uuid::Uuid;
|
||||||
|
|
||||||
use crate::config::ConfigError;
|
use crate::config::ConfigError;
|
||||||
use crate::music_player::player::{Player, PlayerCommand, PlayerError};
|
use crate::music_player::player::{Player, PlayerCommand, PlayerError};
|
||||||
|
use crate::music_storage::library::{Album, Song};
|
||||||
use crate::{
|
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<'a, P: Player + Send + Sync> {
|
||||||
|
pub queue: Arc<RwLock<Queue<Song, Album<'a>, PlayerLocation>>>,
|
||||||
pub struct Controller<P: Player + Send + Sync> {
|
|
||||||
pub queue: Arc<RwLock<Queue>>,
|
|
||||||
pub config: Arc<RwLock<Config>>,
|
pub config: Arc<RwLock<Config>>,
|
||||||
pub library: MusicLibrary,
|
pub library: MusicLibrary,
|
||||||
pub player: Arc<Mutex<P>>,
|
pub player: Arc<Mutex<P>>,
|
||||||
|
@ -39,6 +41,19 @@ pub enum ControllerError {
|
||||||
ConfigError(#[from] ConfigError),
|
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)]
|
#[derive(Debug)]
|
||||||
pub(super) struct MailMan<T: Send, U: Send> {
|
pub(super) struct MailMan<T: Send, U: Send> {
|
||||||
pub tx: Sender<T>,
|
pub tx: Sender<T>,
|
||||||
|
@ -71,8 +86,8 @@ impl<T: Send, U: Send> MailMan<T, U> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
impl<P: Player + Send + Sync + Sized + 'static> Controller<P> {
|
impl<P: Player + Send + Sync + Sized + 'static> Controller<'static, P> {
|
||||||
pub fn start<T>(config_path: T) -> Result<Self, Box<dyn Error>>
|
pub fn start<T>(config_path: T) -> Result <Self, Box<dyn Error>>
|
||||||
where
|
where
|
||||||
std::path::PathBuf: std::convert::From<T>,
|
std::path::PathBuf: std::convert::From<T>,
|
||||||
P: Player,
|
P: Player,
|
||||||
|
@ -85,8 +100,15 @@ impl<P: Player + Send + Sync + Sized + 'static> Controller<P> {
|
||||||
let config_ = Arc::new(RwLock::from(config));
|
let config_ = Arc::new(RwLock::from(config));
|
||||||
let library = MusicLibrary::init(config_.clone(), uuid)?;
|
let library = MusicLibrary::init(config_.clone(), uuid)?;
|
||||||
|
|
||||||
|
let queue: Queue<Song, Album, PlayerLocation> = Queue {
|
||||||
|
items: Vec::new(),
|
||||||
|
played: Vec::new(),
|
||||||
|
loop_: false,
|
||||||
|
shuffle: None
|
||||||
|
};
|
||||||
|
|
||||||
let controller = Controller {
|
let controller = Controller {
|
||||||
queue: Arc::new(RwLock::from(Queue::default())),
|
queue: Arc::new(RwLock::from(queue)),
|
||||||
config: config_.clone(),
|
config: config_.clone(),
|
||||||
library,
|
library,
|
||||||
player: Arc::new(Mutex::new(P::new()?)),
|
player: Arc::new(Mutex::new(P::new()?)),
|
||||||
|
@ -112,10 +134,12 @@ impl<P: Player + Send + Sync + Sized + 'static> Controller<P> {
|
||||||
player
|
player
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.enqueue_next(uri.item
|
.enqueue_next(&{
|
||||||
.primary_uri()
|
match uri.item {
|
||||||
.unwrap()
|
QueueItemType::Single(song) => song.primary_uri().unwrap().0.clone(),
|
||||||
.0)
|
_ => unimplemented!()
|
||||||
|
}
|
||||||
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
},
|
},
|
||||||
PlayerCommand::EndOfStream => {dbg!()}
|
PlayerCommand::EndOfStream => {dbg!()}
|
||||||
|
@ -129,7 +153,7 @@ impl<P: Player + Send + Sync + Sized + 'static> Controller<P> {
|
||||||
Ok(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<PlayerLocation>, by_human: bool) {
|
||||||
let item = self.library.query_uuid(item).unwrap().0.to_owned();
|
let item = self.library.query_uuid(item).unwrap().0.to_owned();
|
||||||
self.queue.write().unwrap().add_item(item, source, by_human)
|
self.queue.write().unwrap().add_item(item, source, by_human)
|
||||||
}
|
}
|
||||||
|
@ -139,7 +163,7 @@ impl<P: Player + Send + Sync + Sized + 'static> Controller<P> {
|
||||||
mod test_super {
|
mod test_super {
|
||||||
use std::{thread::sleep, time::Duration};
|
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;
|
use super::Controller;
|
||||||
|
|
||||||
|
@ -154,21 +178,21 @@ mod test_super {
|
||||||
{
|
{
|
||||||
let mut queue = controller.queue.write().unwrap();
|
let mut queue = controller.queue.write().unwrap();
|
||||||
for x in config.1.library {
|
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().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();
|
controller.player.lock().unwrap().play().unwrap();
|
||||||
}
|
}
|
||||||
println!("I'm a tire");
|
println!("I'm a tire");
|
||||||
}
|
}
|
||||||
sleep(Duration::from_secs(600))
|
sleep(Duration::from_secs(10))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,16 +23,7 @@ pub enum QueueState {
|
||||||
NoState,
|
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)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
|
|
|
@ -11,6 +11,7 @@ use std::ops::ControlFlow::{Break, Continue};
|
||||||
// Files
|
// Files
|
||||||
use file_format::{FileFormat, Kind};
|
use file_format::{FileFormat, Kind};
|
||||||
use glib::filename_to_uri;
|
use glib::filename_to_uri;
|
||||||
|
use kushi::traits::TrackGroup;
|
||||||
use lofty::{AudioFile, ItemKey, ItemValue, ParseOptions, Probe, TagType, TaggedFileExt};
|
use lofty::{AudioFile, ItemKey, ItemValue, ParseOptions, Probe, TagType, TaggedFileExt};
|
||||||
use rcue::parser::parse_from_file;
|
use rcue::parser::parse_from_file;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
@ -624,6 +625,9 @@ impl Album<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TrackGroup for Album<'_> {}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct MusicLibrary {
|
pub struct MusicLibrary {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
|
Loading…
Reference in a new issue