myMPD
Internal API documentation
Loading...
Searching...
No Matches
random_select.c File Reference

Functions to select random songs or albums. More...

#include "compile_time.h"
#include "src/mympd_client/random_select.h"
#include "src/lib/convert.h"
#include "src/lib/log.h"
#include "src/lib/random.h"
#include "src/lib/sds_extras.h"
#include "src/lib/search.h"
#include "src/mympd_client/errorhandler.h"
#include "src/mympd_client/playlists.h"
#include "src/mympd_client/stickerdb.h"
#include "src/mympd_client/tags.h"
#include <string.h>
Include dependency graph for random_select.c:

Enumerations

enum  random_add_uniq_result { RANDOM_ADD_UNIQ_IN_QUEUE = -2 , RANDOM_ADD_UNIQ_IS_UNIQ = -1 }
 

Functions

static bool check_min_duration (const struct mpd_song *song, unsigned min_duration)
 
static bool check_max_duration (const struct mpd_song *song, unsigned max_duration)
 
static bool check_expression_song (const struct mpd_song *song, struct t_mympd_mpd_tags *tags, struct t_list *include_expr_list, struct t_list *exclude_expr_list)
 
static bool check_expression_album (const struct t_album *album, struct t_mympd_mpd_tags *tags, struct t_list *include_expr_list, struct t_list *exclude_expr_list)
 
static bool check_not_hated (rax *stickers_like, const char *uri, bool ignore_hated)
 
static bool check_last_played_album (rax *stickers_last_played, const char *uri, time_t since, enum album_modes album_mode)
 
static bool check_last_played (rax *stickers_last_played, const char *uri, time_t since)
 
static long check_uniq_tag (const char *uri, const char *value, struct t_list *queue_list, struct t_list *add_list)
 
static bool add_uri_constraint_or_expression (const char *include_expression, struct t_partition_state *partition_state)
 
unsigned random_select_albums (struct t_partition_state *partition_state, struct t_stickerdb_state *stickerdb, struct t_cache *album_cache, unsigned add_albums, struct t_list *queue_list, struct t_list *add_list, struct t_random_add_constraints *constraints)
 
unsigned random_select_songs (struct t_partition_state *partition_state, struct t_stickerdb_state *stickerdb, unsigned add_songs, const char *playlist, struct t_list *queue_list, struct t_list *add_list, struct t_random_add_constraints *constraints)
 

Detailed Description

Functions to select random songs or albums.

Enumeration Type Documentation

◆ random_add_uniq_result

Uniq constraints for random select

Function Documentation

◆ add_uri_constraint_or_expression()

static bool add_uri_constraint_or_expression ( const char *  expression,
struct t_partition_state partition_state 
)
static

Adds an expression if not empty, else adds an empty uri constraint to match all songs

Parameters
expressioninclude expression
partition_statepointer to partition state
Returns
true on success, else false

◆ check_expression_album()

static bool check_expression_album ( const struct t_album album,
struct t_mympd_mpd_tags tags,
struct t_list include_expr_list,
struct t_list exclude_expr_list 
)
static

Checks if the album matches the expression lists

Parameters
albumalbum to apply the expressions
tagstags to search
include_expr_listinclude expression list
exclude_expr_listexclude expression list
Returns
true if song should be included, else false

◆ check_expression_song()

static bool check_expression_song ( const struct mpd_song *  song,
struct t_mympd_mpd_tags tags,
struct t_list include_expr_list,
struct t_list exclude_expr_list 
)
static

Checks if the song matches the expression lists

Parameters
songsong to apply the expressions
tagstags to search
include_expr_listinclude expression list
exclude_expr_listexclude expression list
Returns
true if song should be included, else false

◆ check_last_played()

static bool check_last_played ( rax *  stickers_last_played,
const char *  uri,
time_t  since 
)
static

Checks if the songs last_played time is older then since

Parameters
stickers_last_playedlast_played stickers
uriuri to check against the stickers_last_played
sincetimestamp to check against
Returns
true if songs last_played time is older then since, else false

◆ check_last_played_album()

static bool check_last_played_album ( rax *  stickers_last_played,
const char *  uri,
time_t  since,
enum album_modes  album_mode 
)
static

Checks if the album last_played time is older then since

Parameters
stickers_last_playedlast_played stickers
uriuri to check against the stickers_last_played
sincetimestamp to check against
album_modemyMPD album mode
Returns
true if songs last_played time is older then since, else false

◆ check_max_duration()

static bool check_max_duration ( const struct mpd_song *  song,
unsigned  max_duration 
)
static

Checks for maximum duration constraint for songs

Parameters
songmpd song struct to check
max_durationthe maximum duration, 0 for no limit
Returns
if song is shorter then min_duration true, else false

◆ check_min_duration()

static bool check_min_duration ( const struct mpd_song *  song,
unsigned  min_duration 
)
static

Private functions Checks for minimum duration constraint for songs

Parameters
songmpd song struct to check
min_durationthe minimum duration, 0 for no limit
Returns
if song is longer then min_duration true, else false

◆ check_not_hated()

static bool check_not_hated ( rax *  stickers_like,
const char *  uri,
bool  ignore_hated 
)
static

Checks if the song is not hated and ignore_hated is set to true

Parameters
stickers_likelike stickers
uriuri to check against the stickers_like
ignore_hatedignore hated value
Returns
true if song is not hated, else false

◆ check_uniq_tag()

static long check_uniq_tag ( const char *  uri,
const char *  value,
struct t_list queue_list,
struct t_list add_list 
)
static

Checks for the uniq tag constraint for songs

Parameters
urisong uri or albumid
valuetag value to check
queue_listlist of current songs in mpd queue and last played
add_listlist to add the entries
Returns
value matches in the mpd queue: RANDOM_ADD_UNIQ_IN_QUEUE value matches in the add_list: position in the add_list value does not match, is uniq: RANDOM_ADD_UNIQ_IS_UNIQ

◆ random_select_albums()

unsigned random_select_albums ( struct t_partition_state partition_state,
struct t_stickerdb_state stickerdb,
struct t_cache album_cache,
unsigned  add_albums,
struct t_list queue_list,
struct t_list add_list,
struct t_random_add_constraints constraints 
)

Adds albums to the add_list

Parameters
partition_statepointer to myMPD partition state
stickerdbpointer to stickerdb state
album_cachepointer to album cache
add_albumsnumber of albums expected in add_list
queue_listlist of current songs in mpd queue and last played
add_listlist to add the albums
constraintsconstraints for album selection
Returns
new length of add_list

◆ random_select_songs()

unsigned random_select_songs ( struct t_partition_state partition_state,
struct t_stickerdb_state stickerdb,
unsigned  add_songs,
const char *  playlist,
struct t_list queue_list,
struct t_list add_list,
struct t_random_add_constraints constraints 
)

Adds songs to the add_list

Parameters
partition_statepointer to myMPD partition state
stickerdbpointer to stickerdb state
add_songsnumber of songs expected in add_list
playlistplaylist from which songs are added
queue_listlist of current songs in mpd queue and last played
add_listlist to add the songs
constraintsconstraints for song selection
Returns
new length of add_list