Skip to content

Commit

Permalink
Bump bliss version
Browse files Browse the repository at this point in the history
  • Loading branch information
Polochon-street committed May 21, 2024
1 parent 8b63ebf commit e9cfea5
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 56 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## blissify 0.3.11
* Bump bliss version

## blissify 0.3.10
* Fix compilation for non-linux OSes

Expand Down
76 changes: 49 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "blissify"
version = "0.3.10"
version = "0.3.11"
authors = ["Polochon-street <polochonstreet@gmx.fr>"]
edition = "2021"
license = "GPL-3.0-only"
Expand All @@ -17,7 +17,7 @@ default = ["bliss-audio/library"]
rpi = ["bliss-audio/rpi"]

[dependencies]
bliss-audio = "0.6.11"
bliss-audio = "0.7.0"
mpd = "0.0.12"
dirs = "3.0.1"
tempdir = "0.3.7"
Expand Down
53 changes: 26 additions & 27 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
use anyhow::{bail, Context, Result};
use bliss_audio::library::{AppConfigTrait, BaseConfig, Library, LibrarySong};
use bliss_audio::playlist::{
closest_to_first_song_by_key, cosine_distance, euclidean_distance, song_to_song_by_key,
DistanceMetric,
closest_to_songs, cosine_distance, euclidean_distance, song_to_song, DistanceMetricBuilder,
};
use bliss_audio::{BlissError, BlissResult, Song};
use bliss_audio::{BlissError, BlissResult};
use clap::{App, Arg, ArgMatches, SubCommand};
#[cfg(not(test))]
use log::warn;
Expand All @@ -39,11 +38,13 @@ use std::{io::Read, os::unix::net::UnixStream};
use termion::input::TermRead;
use termion::raw::IntoRawMode;

use bliss_audio::decoder::ffmpeg::FFmpeg as Decoder;

/// The main struct that stores both the Library object, and some other
/// helper functions to make everything work properly.
struct MPDLibrary {
// A library object, containing database-related objects.
pub library: Library<Config>,
pub library: Library<Config, Decoder>,
/// A connection to the MPD server, used for retrieving song's paths,
/// currently played songs, and queue tracks.
#[cfg(not(test))]
Expand Down Expand Up @@ -334,16 +335,15 @@ impl MPDLibrary {
Ok(())
}

fn queue_from_current_song_custom<F, G>(
fn queue_from_current_song_custom<F>(
&self,
number_songs: usize,
distance: G,
sort_by: F,
distance: &dyn DistanceMetricBuilder,
mut sort_by: F,
dedup: bool,
) -> Result<()>
where
F: FnMut(&LibrarySong<()>, &mut Vec<LibrarySong<()>>, G, fn(&LibrarySong<()>) -> Song),
G: DistanceMetric + Copy,
F: FnMut(&[LibrarySong<()>], &mut [LibrarySong<()>], &dyn DistanceMetricBuilder),
{
let mut mpd_conn = self.mpd_conn.lock().unwrap();
mpd_conn.random(false)?;
Expand All @@ -354,10 +354,10 @@ impl MPDLibrary {
let path = self.mpd_to_bliss_path(&mpd_song)?;

let playlist = self.library.playlist_from_custom(
&path.to_string_lossy().clone(),
&[&path.to_string_lossy().clone()],
number_songs,
distance,
sort_by,
&mut sort_by,
dedup,
)?;
let current_pos = mpd_song.place.unwrap().pos;
Expand Down Expand Up @@ -500,8 +500,12 @@ impl MPDLibrary {
.join("\n")
);
}
songs
.sort_by_cached_key(|song| n32(current_song.bliss_song.distance(&song.bliss_song)));
songs.sort_by_cached_key(|song| {
n32(euclidean_distance(
&current_song.bliss_song.analysis.as_arr1(),
&song.bliss_song.analysis.as_arr1(),
))
});
// TODO put a proper dedup here
//dedup_playlist(&mut songs, None);
for (i, song) in songs[1..number_choices + 1].iter().enumerate() {
Expand Down Expand Up @@ -783,20 +787,20 @@ fn main() -> Result<()> {
};

let sort = match sub_m.is_present("seed") {
false => closest_to_first_song_by_key,
true => song_to_song_by_key,
false => closest_to_songs,
true => song_to_song,
};
if sub_m.is_present("dedup") {
library.queue_from_current_song_custom(
number_songs,
distance_metric,
&distance_metric,
sort,
true,
)?;
} else {
library.queue_from_current_song_custom(
number_songs,
distance_metric,
&distance_metric,
sort,
false,
)?;
Expand All @@ -818,7 +822,7 @@ fn main() -> Result<()> {
#[cfg(test)]
mod test {
use super::*;
use bliss_audio::Analysis;
use bliss_audio::{Analysis, Song};
use mpd::error::Result;
use mpd::song::{Id, QueuePlace, Song as MPDSong};
use pretty_assertions::assert_eq;
Expand Down Expand Up @@ -992,7 +996,7 @@ mod test {
.unwrap();
}
assert_eq!(
library.queue_from_current_song_custom(20, euclidean_distance, closest_to_first_song_by_key, true).unwrap_err().to_string(),
library.queue_from_current_song_custom(20, &euclidean_distance, closest_to_songs, true).unwrap_err().to_string(),
String::from("No song is currently playing. Add a song to start the playlist from, and try again."),
);
}
Expand Down Expand Up @@ -1031,8 +1035,8 @@ mod test {
library
.queue_from_current_song_custom(
20,
euclidean_distance,
closest_to_first_song_by_key,
&euclidean_distance,
closest_to_songs,
true
)
.unwrap_err()
Expand Down Expand Up @@ -1155,12 +1159,7 @@ mod test {
.unwrap();
}
library
.queue_from_current_song_custom(
20,
euclidean_distance,
closest_to_first_song_by_key,
false,
)
.queue_from_current_song_custom(20, &euclidean_distance, closest_to_songs, false)
.unwrap();

let playlist = library
Expand Down

0 comments on commit e9cfea5

Please sign in to comment.