pianod2
multisource multiuser scriptable networked music player
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Types | List of all members
MusicLibrary::Library Class Reference

#include <musiclibrary.h>

Inheritance diagram for MusicLibrary::Library:
Inheritance graph
[legend]
Collaboration diagram for MusicLibrary::Library:
Collaboration graph
[legend]

Public Types

using ArtistAllocator = ArtistContainer::Allocator
 
using AlbumAllocator = AlbumContainer::Allocator
 
using SongAllocator = SongContainer::Allocator
 
using PlaylistAllocator = PlaylistContainer::Allocator
 
- Public Types inherited from MusicLibrary::Foundation
enum  IMPORTANCE { IMPORTANT = 300 , NOMINAL = 1800 , TRIVIAL = 60 * 60 * 6 }
 

Public Member Functions

virtual bool removePlaylist (Playlist *play) override
 Remove a playlist from the library. More...
 
virtual ThingieList seedsForPlaylist (const Playlist *playlist) override
 Retrieve a list of seeds for a playlist. More...
 
virtual RetainedList< Song * > getAllSongs (void) override
 Get a list of all songs in the library. More...
 
virtual RetainedList< Song * > getMatchingSongs (const Filter &criteria) override
 Get a list of all songs matching a filter. More...
 
ThingieList getSuggestions (const Filter &criteria, SearchRange what)
 Retrieve suggestions from the library. More...
 
RetainedList< Song * > getMixSongs (void)
 Get a list of all songs belonging to enabled playlists. More...
 
virtual RetainedList< Song * > getPlaylistSongs (const Playlist *play, bool reassess=false) override
 Get a list of all songs assigned to a playlist. More...
 
PlaylistfindPlaylistForSong (Song *song, bool enabled=true)
 Find a playlist for a song, preferring enabled playlists. More...
 
virtual void populatePlaylist (Playlist *play, bool aggressive=false) override
 Review songs and assign them to a new candidate if they match. More...
 
void unpopulatePlaylist (Playlist *play)
 Reassign all a playlists' songs to some other playlist. More...
 
void mixRecalculate (void)
 Iterate over every song and replace its playlist assignment. More...
 
MusicThingiegetById (MusicThingie::Type type, const std::string &id)
 Retrieve anything stored in the library by its ID. More...
 
virtual RetainedList< Song * > getSongsForPlaylist (PianodPlaylist *playlist) override
 Retrieve all songs for a playlist, which may be a meta playlist. More...
 
PianodPlaylistcreatePlaylist (const std::string &name, MusicThingie::Type type, MusicThingie *from)
 Construct a playlist with an initial seed. More...
 
PianodPlaylistcreatePlaylist (const std::string &name, const Filter &filter)
 Construct a new smart playlist. More...
 
PianodPlaylistformTransientPlaylist (const Filter &criteria)
 Construct a temporary playlist. More...
 
virtual bool writeIndexToFile (const std::string &filename) const override
 Persist the library's index into a file. More...
 
virtual bool restoreIndexFromFile (const std::string &filename) override
 Restore the library's index, playlists, seeds and match criteria from a file. More...
 
- Public Member Functions inherited from MusicLibrary::Foundation
 Foundation (Media::Source *const owner, const bool persistence)
 Construct a new media library. More...
 
void markDirty (IMPORTANCE import=TRIVIAL) const
 
bool load ()
 Restore persisted library data from a file. More...
 
bool flush ()
 If memory is dirty, write library data to a file. More...
 
float periodic ()
 Do intermittent tasks, such as occasionally persisting the catalog to a file. More...
 
RetainedList< Song * > getRandomSongs (PianodPlaylist *playlist, const UserList &users, Media::SelectionMethod selectionMethod, const class LibraryParameters &settings)
 Retrieve some random selections from the library for queue/playback. More...
 

Protected Member Functions

 Library (Media::Source *const owner, const bool persistence, const SongAllocator &song_allocator=SongAllocator {song_allocate}, const AlbumAllocator &album_allocator=AlbumAllocator {album_allocate}, const ArtistAllocator &artist_allocator=ArtistAllocator {artist_allocate}, const PlaylistAllocator &playlist_allocator=PlaylistAllocator {playlist_allocate})
 Construct a library. More...
 
void purge (void)
 Remove albums & artists from the library that don't have any songs & albums respectively. More...
 
- Protected Member Functions inherited from MusicLibrary::Foundation
virtual void persist (Parsnip::Data &into) const
 
virtual bool restore (const Parsnip::Data &data)
 

Protected Attributes

ArtistContainer artists
 
AlbumContainer albums
 
SongContainer songs
 
PlaylistContainer playlists
 

Private Types

using ArtistContainer = ThingieContainer< Artist, Foundation >
 
using AlbumContainer = ThingieContainer< Album, Artist >
 
using SongContainer = ThingieContainer< Song, Album >
 
using PlaylistContainer = ThingieContainer< Playlist, Foundation >
 

Additional Inherited Members

- Public Attributes inherited from MusicLibrary::Foundation
Media::Source *const source
 

Member Typedef Documentation

◆ AlbumAllocator

◆ AlbumContainer

◆ ArtistAllocator

◆ ArtistContainer

◆ PlaylistAllocator

◆ PlaylistContainer

◆ SongAllocator

◆ SongContainer

Constructor & Destructor Documentation

◆ Library()

MusicLibrary::Library::Library ( Media::Source *const  owner,
const bool  persistence,
const SongAllocator song_allocator = SongAllocator {song_allocate},
const AlbumAllocator album_allocator = AlbumAllocator {album_allocate},
const ArtistAllocator artist_allocator = ArtistAllocator {artist_allocate},
const PlaylistAllocator playlist_allocator = PlaylistAllocator {playlist_allocate} 
)
protected

Construct a library.

Parameters
ownerThe source to which the media belongs.
persistenceIf true, library indexes are written to long-term storage.
song_allocatorA function constructing songs of the source's type.
album_allocatorA function constructing albums of the source's type.
artist_allocatorA function constructing artists of the source's type.
playlist_allocatorA function constructing playlists of the source's type.

Member Function Documentation

◆ createPlaylist() [1/2]

PianodPlaylist * MusicLibrary::Library::createPlaylist ( const std::string &  name,
const Filter filter 
)

Construct a new smart playlist.

Parameters
nameA name for the new playlist.
filterSearch criteria with which to construct the playlist.
Returns
The newly constructed playlist.
Here is the call graph for this function:

◆ createPlaylist() [2/2]

PianodPlaylist * MusicLibrary::Library::createPlaylist ( const std::string &  name,
MusicThingie::Type  type,
MusicThingie from 
)

Construct a playlist with an initial seed.

Parameters
nameThe name for the new playlist.
typeThe manner in which to interpret the initial seed.
fromAn initial seed.
Returns
The new playlist.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ findPlaylistForSong()

Playlist * MusicLibrary::Library::findPlaylistForSong ( Song song,
bool  enabled = true 
)

Find a playlist for a song, preferring enabled playlists.

First, aim for enabled playlists; if not found then recurse and aim for disabled playlists.

Here is the caller graph for this function:

◆ formTransientPlaylist()

PianodPlaylist * MusicLibrary::Library::formTransientPlaylist ( const Filter criteria)

Construct a temporary playlist.

Parameters
criteriaSearch criteria for the temporary playlist.
Returns
The temporary playlist.
Here is the caller graph for this function:

◆ getAllSongs()

RetainedList< Song * > MusicLibrary::Library::getAllSongs ( void  )
overridevirtual

Get a list of all songs in the library.

Implements MusicLibrary::Foundation.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getById()

MusicThingie * MusicLibrary::Library::getById ( MusicThingie::Type  type,
const std::string &  id 
)

Retrieve anything stored in the library by its ID.

Parameters
typeThe type of the thing.
idThe ID of the thing to retrieve.
Returns
The thing, or a nullptr if not found.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getMatchingSongs()

RetainedList< Song * > MusicLibrary::Library::getMatchingSongs ( const Filter criteria)
overridevirtual

Get a list of all songs matching a filter.

Implements MusicLibrary::Foundation.

Here is the call graph for this function:

◆ getMixSongs()

RetainedList< Song * > MusicLibrary::Library::getMixSongs ( void  )

Get a list of all songs belonging to enabled playlists.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPlaylistSongs()

RetainedList< Song * > MusicLibrary::Library::getPlaylistSongs ( const Playlist play,
bool  reassess = false 
)
overridevirtual

Get a list of all songs assigned to a playlist.

Parameters
playThe playlist for which to retrieve songs.
reassessIf false, only assigned songs are returned. If true, songs in other playlists are also considered.
Returns
A list of songs belonging to the playlist.

Implements MusicLibrary::Foundation.

Here is the call graph for this function:

◆ getSongsForPlaylist()

RetainedList< Song * > MusicLibrary::Library::getSongsForPlaylist ( PianodPlaylist playlist)
overridevirtual

Retrieve all songs for a playlist, which may be a meta playlist.

Implements MusicLibrary::Foundation.

Here is the call graph for this function:

◆ getSuggestions()

ThingieList MusicLibrary::Library::getSuggestions ( const Filter criteria,
SearchRange  what 
)

Retrieve suggestions from the library.

This returns a mix of artists, albums, and songs.

Parameters
criteriaSpecifies the criteria for which to select matching data.
whatDescribes a search manner.
  • For deep searches, all matching items will be returned.
  • For shallow searches, matches on an artist or album will skip their respective albums or songs.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mixRecalculate()

void MusicLibrary::Library::mixRecalculate ( void  )
inline

Iterate over every song and replace its playlist assignment.

Applicable on initialization.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ populatePlaylist()

void MusicLibrary::Library::populatePlaylist ( Playlist play,
bool  aggressive = false 
)
overridevirtual

Review songs and assign them to a new candidate if they match.

This is applicable when a playlist has been created or just been added to the mix.

Parameters
playThe playlist to populate with songs.
aggressiveIf true, songs with enabled playlists are considered for reassignment. If false, only songs without a playlist or with a disabled playlist are considered.

Implements MusicLibrary::Foundation.

Here is the caller graph for this function:

◆ purge()

void MusicLibrary::Library::purge ( void   )
protected

Remove albums & artists from the library that don't have any songs & albums respectively.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removePlaylist()

bool MusicLibrary::Library::removePlaylist ( Playlist play)
overridevirtual

Remove a playlist from the library.

Parameters
playThe playlist to remove.

Implements MusicLibrary::Foundation.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ restoreIndexFromFile()

bool MusicLibrary::Library::restoreIndexFromFile ( const std::string &  filename)
overridevirtual

Restore the library's index, playlists, seeds and match criteria from a file.

Parameters
filenameThe name of the file from which to restore.
Returns
True, or throws an exception.

Implements MusicLibrary::Foundation.

Here is the call graph for this function:

◆ seedsForPlaylist()

ThingieList MusicLibrary::Library::seedsForPlaylist ( const Playlist playlist)
overridevirtual

Retrieve a list of seeds for a playlist.

Parameters
playlistThe playlist for which to return data.
Returns
A list containing song, album, and artist seeds.

Implements MusicLibrary::Foundation.

Here is the call graph for this function:

◆ unpopulatePlaylist()

void MusicLibrary::Library::unpopulatePlaylist ( Playlist play)

Reassign all a playlists' songs to some other playlist.

Applicable when song has been removed from the mix, or playlist is about to be deleted.

Warning
May reassign current playlists, if no better ones are found and the current playlist is still in the playlist set.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeIndexToFile()

bool MusicLibrary::Library::writeIndexToFile ( const std::string &  filename) const
overridevirtual

Persist the library's index into a file.

This includes playlists and their seeds and match criteria.

Parameters
filenameThe name of the file.

Implements MusicLibrary::Foundation.

Here is the call graph for this function:

Member Data Documentation

◆ albums

AlbumContainer MusicLibrary::Library::albums
protected

◆ artists

ArtistContainer MusicLibrary::Library::artists
protected

◆ playlists

PlaylistContainer MusicLibrary::Library::playlists
protected

◆ songs

SongContainer MusicLibrary::Library::songs
protected

The documentation for this class was generated from the following files: