Trait bliss_audio::library::Library[][src]

pub trait Library {
    fn get_songs_paths(&self) -> BlissResult<Vec<String>>;
fn store_song(&mut self, song: &Song) -> BlissResult<()>;
fn store_error_song(
        &mut self,
        song_path: String,
        error: BlissError
    ) -> BlissResult<()>;
fn get_stored_songs(&self) -> BlissResult<Vec<Song>>; fn playlist_from_song(
        &self,
        first_song: Song,
        playlist_length: usize
    ) -> BlissResult<Vec<Song>> { ... }
fn playlist_from_song_custom_distance(
        &self,
        first_song: Song,
        playlist_length: usize,
        distance: impl DistanceMetric
    ) -> BlissResult<Vec<Song>> { ... }
fn playlist_from_song_custom<F, G>(
        &self,
        first_song: Song,
        playlist_length: usize,
        distance: G,
        sort: F
    ) -> BlissResult<Vec<Song>>
    where
        F: FnMut(&Song, &mut Vec<Song>, G),
        G: DistanceMetric
, { ... }
fn analyze_paths(&mut self, paths: Vec<String>) -> BlissResult<()> { ... }
fn analyze_library(&mut self) -> BlissResult<()> { ... }
fn analyze_library_streaming(
        &mut self
    ) -> BlissResult<Receiver<(String, BlissResult<Song>)>> { ... } }
Expand description

Library trait to make creating plug-ins for existing audio players easier.

Required methods

Return the absolute path of all the songs in an audio player’s music library.

Store an analyzed Song object in some (cold) storage, e.g. a database, a file…

Log and / or store that an error happened while trying to decode and analyze a song.

Retrieve a list of all the stored Songs.

This should work only after having run analyze_library at least once.

Provided methods

Return a list of playlist_length songs that are similar to first_song, deduplicating identical songs.

Arguments

  • first_song - The song the playlist will be built from.
  • playlist_length - The playlist length. If there are not enough songs in the library, it will be truncated to the size of the library.

Returns

A vector of playlist_length songs, including first_song, that you most likely want to plug in your audio player by using something like ret.map(|song| song.path.to_owned()).collect::<Vec<String>>().

Return a list of songs that are similar to first_song, using a custom distance metric and deduplicating indentical songs.

Arguments

  • first_song - The song the playlist will be built from.
  • playlist_length - The playlist length. If there are not enough songs in the library, it will be truncated to the size of the library.
  • distance - a user-supplied valid distance metric, either taken from the distance module, or made from scratch.

Returns

A vector of playlist_length Songs, including first_song, that you most likely want to plug in your audio player by using something like ret.map(|song| song.path.to_owned()).collect::<Vec<String>>().

Custom distance example

use ndarray::Array1;

fn manhattan_distance(a: &Array1<f32>, b: &Array1<f32>) -> f32 {
    (a - b).mapv(|x| x.abs()).sum()
}

Return a playlist of songs, starting with first_song, sorted using the custom sort function, and the custom distance metric.

Arguments

  • first_song - The song the playlist will be built from.
  • playlist_length - The playlist length. If there are not enough songs in the library, it will be truncated to the size of the library.
  • distance - a user-supplied valid distance metric, either taken from the distance module, or made from scratch.
  • sort - a user-supplied sorting function that uses the distance metric, either taken from the distance, or made from scratch.

Returns

A vector of playlist_length Songs, including first_song, that you most likely want to plug in your audio player by using something like ret.map(|song| song.path.to_owned()).collect::<Vec<String>>().

Analyze and store songs in paths, using store_song and store_error_song implementations.

note: this is mostly useful for updating a song library. for the first run, you probably want to use analyze_library.

Analyzes a song library, using get_songs_paths, store_song and store_error_song implementations.

Analyze an entire library using get_songs_paths, but instead of storing songs using store_song and store_error_song.

Returns an iterable Receiver, whose items are a tuple made of the song path (to display to the user in case the analysis failed), and a Result.

Implementors