inLimbo
TUI Music Player that keeps you in Limbo.
 
Loading...
Searching...
No Matches
SongTree Class Reference

Represents a hierarchical tree structure to store songs by artist, album, disc number, and track number. More...

#include <songmap.hpp>

Public Member Functions

void addSong (const Song &song)
 Adds a song to the tree.
 
void display () const
 Displays all songs in the tree hierarchically.
 
void printAllArtists () const
 Prints all the artists in the song tree.
 
void printSongs (const std::vector< Song > &songs)
 Prints the songs by album.
 
auto getSongsByArtist (const std::string &artist)
 Retrieves all songs by a specific artist.
 
auto getSongsByAlbum (const std::string &artist, const std::string &album) const
 Retrieves all songs from a specific album by a given artist.
 
void getSongsByGenreAndPrint () const
 Groups and prints songs by genre.
 
auto returnSongMap () const
 Returns the internal song map.
 
template<class Archive>
void serialize (Archive &ar)
 Serializes the SongTree object.
 
void saveToFile (const std::string &filename) const
 Saves the SongTree to a file.
 
void loadFromFile (const std::string &filename)
 Loads a SongTree from a file.
 
void printSongInfo (const std::string &input)
 Prints metadata and additional properties of a song.
 

Detailed Description

Represents a hierarchical tree structure to store songs by artist, album, disc number, and track number.

The SongTree class organizes songs in a nested map structure, allowing for efficient storage and retrieval of songs based on artist, album, disc, and track numbers. It supports the addition, display, and serialization of songs, and provides methods for querying songs by specific criteria such as artist, album, and genre.

Songs are added to the tree via the addSong method, and the tree can be serialized and deserialized to a file using the Cereal library.

Member Function Documentation

◆ addSong()

void SongTree::addSong ( const Song & song)
inline

Adds a song to the tree.

This method inserts a song into the appropriate location in the tree based on its artist, album, disc number, and track number.

Parameters
songThe song to be added to the tree.

◆ display()

void SongTree::display ( ) const
inline

Displays all songs in the tree hierarchically.

This method prints the entire song tree to the console, organized by artist, album, disc number, and track number. It also provides a summary of the library, including the total number of artists, albums, discs, songs, and unique genres.

◆ getSongsByAlbum()

auto SongTree::getSongsByAlbum ( const std::string & artist,
const std::string & album ) const
inlinenodiscard

Retrieves all songs from a specific album by a given artist.

This method returns a vector of all songs from a particular album by an artist.

Parameters
artistThe name of the artist whose album's songs are to be retrieved.
albumThe title of the album whose songs are to be retrieved.
Returns
A vector of Song objects from the specified album by the specified artist.

◆ getSongsByArtist()

auto SongTree::getSongsByArtist ( const std::string & artist)
inline

Retrieves all songs by a specific artist.

This method returns a vector of all songs by a given artist, organized by album, disc number, and track number.

Parameters
artistThe name of the artist whose songs are to be retrieved.
Returns
A vector of Song objects by the specified artist.

◆ getSongsByGenreAndPrint()

void SongTree::getSongsByGenreAndPrint ( ) const
inline

Groups and prints songs by genre.

This method groups the songs by genre and prints them in a readable format.

◆ loadFromFile()

void SongTree::loadFromFile ( const std::string & filename)
inline

Loads a SongTree from a file.

This method loads the serialized SongTree object from a binary file.

Parameters
filenameThe name of the file to load the SongTree from.
Exceptions
std::runtime_errorIf the file cannot be opened for loading.

◆ printAllArtists()

void SongTree::printAllArtists ( ) const
inline

Prints all the artists in the song tree.

This method prints a list of all artists present in the song tree.

◆ printSongInfo()

void SongTree::printSongInfo ( const std::string & input)
inline

Prints metadata and additional properties of a song.

This function retrieves a song based on either a file path or a song name and prints all relevant metadata, including title, artist, album, genre, track number, disc number, and inode.

Parameters
inputThe file path or song name to search for.

◆ printSongs()

void SongTree::printSongs ( const std::vector< Song > & songs)
inline

Prints the songs by album.

This method groups the songs by album and prints them in a readable format.

Parameters
songsA vector of Song objects to be displayed.

◆ returnSongMap()

auto SongTree::returnSongMap ( ) const
inlinenodiscard

Returns the internal song map.

This method returns the entire nested map structure containing all the songs.

Returns
The nested map structure of songs.

◆ saveToFile()

void SongTree::saveToFile ( const std::string & filename) const
inline

Saves the SongTree to a file.

This method saves the serialized SongTree object to a binary file.

Parameters
filenameThe name of the file to save the SongTree to.
Exceptions
std::runtime_errorIf the file cannot be opened for saving.

◆ serialize()

template<class Archive>
void SongTree::serialize ( Archive & ar)
inline

Serializes the SongTree object.

This function serializes the SongTree object into a binary format for storage or transmission.

Parameters
arThe archive object used for serialization.

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