Random + shuffle sur la playlist implémenté et testé et update proto
This commit is contained in:
parent
283d0b2065
commit
49eb71b326
78
Cargo.lock
generated
78
Cargo.lock
generated
@ -385,6 +385,17 @@ dependencies = [
|
|||||||
"version_check",
|
"version_check",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "getrandom"
|
||||||
|
version = "0.2.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"wasi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "glob"
|
name = "glob"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
@ -777,6 +788,15 @@ version = "0.3.30"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec"
|
checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ppv-lite86"
|
||||||
|
version = "0.2.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04"
|
||||||
|
dependencies = [
|
||||||
|
"zerocopy",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro-crate"
|
name = "proc-macro-crate"
|
||||||
version = "3.1.0"
|
version = "3.1.0"
|
||||||
@ -816,6 +836,36 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.8.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"rand_chacha",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_chacha"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||||
|
dependencies = [
|
||||||
|
"ppv-lite86",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.6.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "1.10.6"
|
version = "1.10.6"
|
||||||
@ -967,6 +1017,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"file-format",
|
"file-format",
|
||||||
"metadata",
|
"metadata",
|
||||||
|
"rand",
|
||||||
"regex",
|
"regex",
|
||||||
"rodio",
|
"rodio",
|
||||||
"serde",
|
"serde",
|
||||||
@ -1257,6 +1308,12 @@ dependencies = [
|
|||||||
"winapi-util",
|
"winapi-util",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasi"
|
||||||
|
version = "0.11.0+wasi-snapshot-preview1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen"
|
name = "wasm-bindgen"
|
||||||
version = "0.2.92"
|
version = "0.2.92"
|
||||||
@ -1540,3 +1597,24 @@ checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerocopy"
|
||||||
|
version = "0.7.35"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder",
|
||||||
|
"zerocopy-derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerocopy-derive"
|
||||||
|
version = "0.7.35"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
@ -6,6 +6,7 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
file-format = "0.25.0"
|
file-format = "0.25.0"
|
||||||
metadata = "0.1.9"
|
metadata = "0.1.9"
|
||||||
|
rand = "0.8.5"
|
||||||
regex = "1.10.6"
|
regex = "1.10.6"
|
||||||
rodio = { version = "0.19.0", features = ["symphonia-all"] }
|
rodio = { version = "0.19.0", features = ["symphonia-all"] }
|
||||||
serde = { version = "1.0.206", features = ["derive"] }
|
serde = { version = "1.0.206", features = ["derive"] }
|
||||||
|
16
src/main.rs
16
src/main.rs
@ -7,17 +7,21 @@ use crate::playlist::playlist::*;
|
|||||||
fn main() {
|
fn main() {
|
||||||
let mysong = SongMeta::frompath(&String::from("/home/justine/NAS/Musique/A_classer/Bleach/12 Big Cheese.mp3")).unwrap();
|
let mysong = SongMeta::frompath(&String::from("/home/justine/NAS/Musique/A_classer/Bleach/12 Big Cheese.mp3")).unwrap();
|
||||||
let mysong2 = SongMeta::frompath(&String::from("/home/justine/NAS/Musique/Folk/Galaverna - Dodsdans/Galaverna - Dodsdans - 01 Dods....flac")).unwrap();
|
let mysong2 = SongMeta::frompath(&String::from("/home/justine/NAS/Musique/Folk/Galaverna - Dodsdans/Galaverna - Dodsdans - 01 Dods....flac")).unwrap();
|
||||||
|
let mysong3 = SongMeta::frompath(&String::from("/home/justine/NAS/Musique/Jeux/Superliminal/Matt Christensen - Superliminal/12. Astral.mp3")).unwrap();
|
||||||
|
|
||||||
//let playlist = Playlist::from_file(&String::from("./cool.yml"));
|
//let playlist = Playlist::from_file(&String::from("./cool.yml"));
|
||||||
|
|
||||||
let playlist = Playlist {
|
let mut playlist = Playlist {
|
||||||
songs: vec![mysong, mysong2],
|
songs: vec![mysong, mysong2, mysong3],
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(false, playlist.check_index(2));
|
println!("RAND {:#?}", playlist);
|
||||||
let playlist = Playlist::new();
|
playlist.sort();
|
||||||
assert_eq!(false, playlist.check_index(0));
|
println!("SORT {:#?}", playlist);
|
||||||
assert_eq!(false, playlist.check_index(10));
|
playlist.shuffle();
|
||||||
|
println!("RAND {:#?}", playlist);
|
||||||
|
playlist.sort();
|
||||||
|
println!("SORT{:#?}", playlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@ pub mod playlist {
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use crate::songmeta::songmeta::*;
|
use crate::songmeta::songmeta::*;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use rand::thread_rng;
|
||||||
|
use rand::prelude::SliceRandom;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -116,5 +118,25 @@ pub mod playlist {
|
|||||||
self.songs.remove(index);
|
self.songs.remove(index);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///Shuffles the playlist
|
||||||
|
pub fn shuffle(&mut self) {
|
||||||
|
//Return if playlist is empty
|
||||||
|
if self.songs.len() == 0 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.songs.shuffle(&mut thread_rng());
|
||||||
|
}
|
||||||
|
|
||||||
|
///Sorts the playlist by artist, album, trackorder, title
|
||||||
|
pub fn sort(&mut self) {
|
||||||
|
self.songs.sort_by(|a, b| {
|
||||||
|
a.artist
|
||||||
|
.cmp(&b.artist)
|
||||||
|
.then_with(|| a.album.cmp(&b.album))
|
||||||
|
.then_with(|| a.track.cmp(&b.track))
|
||||||
|
.then_with(|| a.title.cmp(&b.title))
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -143,5 +143,12 @@ impl AudioPlayer {
|
|||||||
|
|
||||||
//Stoppe la lecture en cours et vide le sink renvoie rien
|
//Stoppe la lecture en cours et vide le sink renvoie rien
|
||||||
fn stop(&mut self);
|
fn stop(&mut self);
|
||||||
|
|
||||||
|
//Charge un fichier dans la playlist renvoie un result
|
||||||
|
fn load_file(&mut self);
|
||||||
|
|
||||||
|
//Charge un dossier entier dans la playlist renvoie un result (récursif ou pas je sais pas peut-être faire les deux)
|
||||||
|
fn load_folder(&mut self);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user