mirror of
https://github.com/Dangoware/dango-music-player.git
synced 2025-04-19 18:12:54 -05:00
Added more functions for testing
This commit is contained in:
parent
d2822bbb37
commit
74e2933de1
1 changed files with 77 additions and 24 deletions
|
@ -41,6 +41,7 @@ impl Queue {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_tracks(&mut self, tracks: Vec<Song>) {
|
fn set_tracks(&mut self, tracks: Vec<Song>) {
|
||||||
let mut tracks = tracks;
|
let mut tracks = tracks;
|
||||||
self.songs.clear();
|
self.songs.clear();
|
||||||
|
@ -73,6 +74,7 @@ enum ControllerResponse {
|
||||||
pub enum DatabaseCmd {
|
pub enum DatabaseCmd {
|
||||||
Default,
|
Default,
|
||||||
Test,
|
Test,
|
||||||
|
SaveLibrary,
|
||||||
GetSongs,
|
GetSongs,
|
||||||
QueryUuid(Uuid),
|
QueryUuid(Uuid),
|
||||||
QueryUuids(Vec<Uuid>),
|
QueryUuids(Vec<Uuid>),
|
||||||
|
@ -85,6 +87,7 @@ enum DatabaseResponse {
|
||||||
Empty,
|
Empty,
|
||||||
Song(Song),
|
Song(Song),
|
||||||
Songs(Vec<Song>),
|
Songs(Vec<Song>),
|
||||||
|
Library(MusicLibrary),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -96,12 +99,14 @@ enum QueueCmd {
|
||||||
SetSongs(Vec<Song>),
|
SetSongs(Vec<Song>),
|
||||||
// SetLocation(URI),
|
// SetLocation(URI),
|
||||||
Enqueue(URI),
|
Enqueue(URI),
|
||||||
|
SetVolume(f64),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum QueueResponse {
|
enum QueueResponse {
|
||||||
Default,
|
Default,
|
||||||
Test,
|
Test,
|
||||||
|
Index(i32),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -145,9 +150,10 @@ impl Controller {
|
||||||
let config = Config::read_file(config_path)?;
|
let config = Config::read_file(config_path)?;
|
||||||
let uuid = config.libraries.get_default()?.uuid;
|
let uuid = config.libraries.get_default()?.uuid;
|
||||||
|
|
||||||
let config = Arc::new(RwLock::from(config));
|
let config_ = Arc::new(RwLock::from(config));
|
||||||
let mut lib = MusicLibrary::init(config.clone(), uuid)?;
|
let mut lib = MusicLibrary::init(config_.clone(), uuid)?;
|
||||||
|
|
||||||
|
let config = config_.clone();
|
||||||
let (out_thread_controller, in_thread) = MailMan::double();
|
let (out_thread_controller, in_thread) = MailMan::double();
|
||||||
let monitor_thread = spawn(move || {
|
let monitor_thread = spawn(move || {
|
||||||
use ControllerCmd::*;
|
use ControllerCmd::*;
|
||||||
|
@ -163,7 +169,7 @@ impl Controller {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let config = config_.clone();
|
||||||
let (out_thread_db, in_thread) = MailMan::double();
|
let (out_thread_db, in_thread) = MailMan::double();
|
||||||
let db_monitor = spawn(move || {
|
let db_monitor = spawn(move || {
|
||||||
use DatabaseCmd::*;
|
use DatabaseCmd::*;
|
||||||
|
@ -179,6 +185,10 @@ impl Controller {
|
||||||
let songs = lib.query_tracks(&String::from(""), &(vec![Tag::Title]), &(vec![Tag::Title])).unwrap().iter().cloned().cloned().collect();
|
let songs = lib.query_tracks(&String::from(""), &(vec![Tag::Title]), &(vec![Tag::Title])).unwrap().iter().cloned().cloned().collect();
|
||||||
in_thread.send(DatabaseResponse::Songs(songs)).unwrap();
|
in_thread.send(DatabaseResponse::Songs(songs)).unwrap();
|
||||||
},
|
},
|
||||||
|
SaveLibrary => {
|
||||||
|
//TODO: make this send lib ref to the function to save instead
|
||||||
|
lib.save(config.read().unwrap().to_owned()).unwrap();
|
||||||
|
},
|
||||||
QueryUuid(uuid) => {
|
QueryUuid(uuid) => {
|
||||||
match lib.query_uuid(&uuid) {
|
match lib.query_uuid(&uuid) {
|
||||||
Some(song) => in_thread.send(DatabaseResponse::Song(song.0.clone())).unwrap(),
|
Some(song) => in_thread.send(DatabaseResponse::Song(song.0.clone())).unwrap(),
|
||||||
|
@ -209,7 +219,7 @@ impl Controller {
|
||||||
Ok(
|
Ok(
|
||||||
Controller {
|
Controller {
|
||||||
// queues: Vec::new(),
|
// queues: Vec::new(),
|
||||||
config,
|
config: config_.clone(),
|
||||||
controller_mail: out_thread_controller,
|
controller_mail: out_thread_controller,
|
||||||
db_mail: out_thread_db,
|
db_mail: out_thread_db,
|
||||||
queue_mail: Vec::new(),
|
queue_mail: Vec::new(),
|
||||||
|
@ -217,16 +227,27 @@ impl Controller {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_db_songs(&self) -> Vec<Song> {
|
fn lib_get_songs(&self) -> Vec<Song> {
|
||||||
self.db_mail.send(DatabaseCmd::GetSongs);
|
self.db_mail.send(DatabaseCmd::GetSongs);
|
||||||
match self.db_mail.recv().unwrap() {
|
match self.db_mail.recv().unwrap() {
|
||||||
DatabaseResponse::Songs(songs) => songs,
|
DatabaseResponse::Songs(songs) => songs,
|
||||||
_ => Vec::new()
|
_ => Vec::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_queue(&mut self) {
|
fn lib_scan_folder(&self, folder: String) -> Result<(), Box<dyn Error>> {
|
||||||
|
let mail = &self.db_mail;
|
||||||
|
mail.send(DatabaseCmd::ReadFolder(folder))?;
|
||||||
|
dbg!(mail.recv()?);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn lib_save(&self) -> Result<(), Box<dyn Error>> {
|
||||||
|
self.db_mail.send(DatabaseCmd::SaveLibrary);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn q_new(&mut self) -> Result<usize, Box<dyn Error>> {
|
||||||
let (out_thread_queue, in_thread) = MailMan::<QueueCmd, QueueResponse>::double();
|
let (out_thread_queue, in_thread) = MailMan::<QueueCmd, QueueResponse>::double();
|
||||||
let queues_monitor = spawn(move || {
|
let queues_monitor = spawn(move || {
|
||||||
use QueueCmd::*;
|
use QueueCmd::*;
|
||||||
|
@ -239,11 +260,16 @@ impl Controller {
|
||||||
Play => {
|
Play => {
|
||||||
match queue.player.play() {
|
match queue.player.play() {
|
||||||
Ok(_) => in_thread.send(QueueResponse::Default).unwrap(),
|
Ok(_) => in_thread.send(QueueResponse::Default).unwrap(),
|
||||||
Err(_) => unimplemented!()
|
Err(_) => todo!()
|
||||||
};
|
};
|
||||||
|
|
||||||
},
|
},
|
||||||
Pause => {},
|
Pause => {
|
||||||
|
match queue.player.pause() {
|
||||||
|
Ok(_) => in_thread.send(QueueResponse::Default).unwrap(),
|
||||||
|
Err(_) => todo!()
|
||||||
|
}
|
||||||
|
},
|
||||||
SetSongs(songs) => {
|
SetSongs(songs) => {
|
||||||
queue.set_tracks(songs);
|
queue.set_tracks(songs);
|
||||||
in_thread.send(QueueResponse::Default).unwrap();
|
in_thread.send(QueueResponse::Default).unwrap();
|
||||||
|
@ -252,57 +278,84 @@ impl Controller {
|
||||||
queue.player.enqueue_next(&uri).unwrap();
|
queue.player.enqueue_next(&uri).unwrap();
|
||||||
|
|
||||||
// in_thread.send(QueueResponse::Default).unwrap();
|
// in_thread.send(QueueResponse::Default).unwrap();
|
||||||
|
},
|
||||||
|
SetVolume(vol) => {
|
||||||
|
queue.player.set_volume(vol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
self.queue_mail.push(out_thread_queue);
|
self.queue_mail.push(out_thread_queue);
|
||||||
|
Ok((self.queue_mail.len() - 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn play(&self, index: usize) -> Result<(), Box<dyn Error>> {
|
fn q_play(&self, index: usize) -> Result<(), Box<dyn Error>> {
|
||||||
let mail = &self.queue_mail[index];
|
let mail = &self.queue_mail[index];
|
||||||
mail.send(QueueCmd::Play)?;
|
mail.send(QueueCmd::Play)?;
|
||||||
dbg!(mail.recv()?);
|
dbg!(mail.recv()?);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_songs(&self, index: usize, songs: Vec<Song>) -> Result<(), Box<dyn Error>> {
|
fn q_pause(&self, index: usize) -> Result<(), Box<dyn Error>> {
|
||||||
|
let mail = &self.queue_mail[index];
|
||||||
|
mail.send(QueueCmd::Pause)?;
|
||||||
|
dbg!(mail.recv()?);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn q_set_volume(&self, index: usize, volume: f64) -> Result<(), Box<dyn Error>> {
|
||||||
|
let mail = &self.queue_mail[index];
|
||||||
|
mail.send(QueueCmd::SetVolume(volume))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn q_set_songs(&self, index: usize, songs: Vec<Song>) -> Result<(), Box<dyn Error>> {
|
||||||
let mail = &self.queue_mail[index];
|
let mail = &self.queue_mail[index];
|
||||||
mail.send(QueueCmd::SetSongs(songs))?;
|
mail.send(QueueCmd::SetSongs(songs))?;
|
||||||
dbg!(mail.recv()?);
|
dbg!(mail.recv()?);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enqueue(&self, index: usize, uri: URI) -> Result<(), Box<dyn Error>> {
|
fn q_enqueue(&self, index: usize, uri: URI) -> Result<(), Box<dyn Error>> {
|
||||||
let mail = &self.queue_mail[index];
|
let mail = &self.queue_mail[index];
|
||||||
mail.send(QueueCmd::Enqueue(uri))?;
|
mail.send(QueueCmd::Enqueue(uri))?;
|
||||||
// dbg!(mail.recv()?);
|
// dbg!(mail.recv()?);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn scan_folder(&self, folder: String) -> Result<(), Box<dyn Error>> {
|
|
||||||
let mail = &self.db_mail;
|
|
||||||
mail.send(DatabaseCmd::ReadFolder(folder))?;
|
|
||||||
dbg!(mail.recv()?);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn name() {
|
fn play_test() {
|
||||||
let mut a = match Controller::start("test-config/config_test.json".to_string()) {
|
let mut a = match Controller::start("test-config/config_test.json".to_string()) {
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
Err(e) => panic!("{e}")
|
Err(e) => panic!("{e}")
|
||||||
};
|
};
|
||||||
sleep(Duration::from_millis(500));
|
sleep(Duration::from_millis(500));
|
||||||
a.scan_folder("test-config/music/".to_string());
|
|
||||||
a.new_queue();
|
let i = a.q_new().unwrap();
|
||||||
|
a.q_set_volume(i, 0.04);
|
||||||
// a.new_queue();
|
// a.new_queue();
|
||||||
let songs = a.get_db_songs();
|
let songs = a.lib_get_songs();
|
||||||
a.enqueue(0, songs[4].location.clone());
|
a.q_enqueue(i, songs[2].location.clone());
|
||||||
// a.enqueue(1, songs[2].location.clone());
|
// a.enqueue(1, songs[2].location.clone());
|
||||||
a.play(0).unwrap();
|
a.q_play(i).unwrap();
|
||||||
// a.play(1).unwrap();
|
// a.play(1).unwrap();
|
||||||
|
|
||||||
sleep(Duration::from_secs(10));
|
sleep(Duration::from_secs(10));
|
||||||
|
a.q_pause(i);
|
||||||
|
sleep(Duration::from_secs(10));
|
||||||
|
a.q_play(i);
|
||||||
|
sleep(Duration::from_secs(1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_() {
|
||||||
|
let a = match Controller::start("test-config/config_test.json".to_string()) {
|
||||||
|
Ok(c) => c,
|
||||||
|
Err(e) => panic!("{e}")
|
||||||
|
};
|
||||||
|
a.lib_scan_folder("F:/Music/Mp3".to_string());
|
||||||
|
a.lib_save();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue