## Smart Playlists Smart Playlists — Data structure to represent an iPod smart playlist |

## Synopsis

    struct              Itdb_SPLPref;
    struct              Itdb_SPLRule;
    struct              Itdb_SPLRules;
    enum                ItdbLimitSort;
    enum                ItdbLimitType;
    enum                ItdbSPLAction;
    enum                ItdbSPLActionLast;
    enum                ItdbSPLActionType;
    enum                ItdbSPLField;
    enum                ItdbSPLFieldType;
    enum                ItdbSPLMatch;
    #define             ITDB_SPL_DATE_IDENTIFIER
    #define             ITDB_SPL_STRING_MAXLEN
    ItdbSPLFieldType    itdb_splr_get_field_type            (const Itdb_SPLRule *splr);
    ItdbSPLActionType   itdb_splr_get_action_type           (const Itdb_SPLRule *splr);
    void                itdb_splr_validate                  (Itdb_SPLRule *splr);
    void                itdb_splr_remove                    (Itdb_Playlist *pl,
                                                             Itdb_SPLRule *splr);
    Itdb_SPLRule *      itdb_splr_new                       (void);
    void                itdb_splr_add                       (Itdb_Playlist *pl,
                                                             Itdb_SPLRule *splr,
                                                             gint pos);
    Itdb_SPLRule *      itdb_splr_add_new                   (Itdb_Playlist *pl,
                                                             gint pos);
    void                itdb_spl_copy_rules                 (Itdb_Playlist *dest,
                                                             Itdb_Playlist *src);
    gboolean            itdb_splr_eval                      (Itdb_SPLRule *splr,
                                                             Itdb_Track *track);
    void                itdb_spl_update                     (Itdb_Playlist *spl);
    void                itdb_spl_update_all                 (Itdb_iTunesDB *itdb);
    void                itdb_spl_update_live                (Itdb_iTunesDB *itdb);

## Description

These functions and structures are for dealing with smart playlists.

## Details

### struct Itdb_SPLPref

    struct Itdb_SPLPref {
        guint8  liveupdate;
        guint8  checkrules;
        guint8  checklimits;
        guint32 limittype;
        guint32 limitsort;
        guint32 limitvalue;
        guint8  matchcheckedonly;
        gint32 reserved_int1;
        gint32 reserved_int2;
        gpointer reserved1;
        gpointer reserved2;
    };

Smart Playlist preferences are for various flags that are not strictly smart playlist "rules."

guint8 `liveupdate`; | Live Updating
guint8 `checkrules`; | Match this number of rules. If set to 0, ignore rules.
guint8 `checklimits`; | Limit to this number of `limittype`. If 0, no limits.
guint32 `limittype`; | an ItdbLimitType
guint32 `limitsort`; | an ItdbLimitSort
guint32 `limitvalue`; | The value typed next to "Limit type"
guint8 `matchcheckedonly`; | Match only checked songs
gint32 `reserved_int1`; | Reserved for future use
gint32 `reserved_int2`; | Reserved for future use
gpointer `reserved1`; | Reserved for future use
gpointer `reserved2`; | Reserved for future use

Since 0.5.0

### struct Itdb_SPLRule

    struct Itdb_SPLRule {
        guint32 field;
        guint32 action;
        gchar *string;
        guint64 fromvalue;
        gint64 fromdate;
        guint64 fromunits;
        guint64 tovalue;
        gint64 todate;
        guint64 tounits;
        guint32 unk052;
        guint32 unk056;
        guint32 unk060;
        guint32 unk064;
        guint32 unk068;
        /* reserved for future use */
        gint32 reserved_int1;
        gint32 reserved_int2;
        gpointer reserved1;
        gpointer reserved2;
    };

Smart Playlist Rule

The from and to fields require some explanation. If `field` is a date type, then `value` would be set to 0x2dae2dae2dae2dae, `date` would be a number, (e.g. 2 or -2), and `units` would be a time unit in seconds (e.g. one week would be 604800). If `field` is an integer comparison, like rating = 60 (i.e. 3 stars), then `value` would be the value we care about (e.g. 60), `date` would be 0, and `units` would be 1. Binary AND types are similar, `value` is the important part, with `date` = 0 and `units` = 1. Clear as mud, right?

For more details see ipodlinux.org.

guint32 `field`; | an ItdbSPLFieldType
guint32 `action`; | an ItdbSPLActionType
gchar *`string`; | data in UTF8
guint64 `fromvalue`; | from value
gint64 `fromdate`; | from date
guint64 `fromunits`; | from units
guint64 `tovalue`; | to value
gint64 `todate`; | to date
guint64 `tounits`; | to units
guint32 `unk052`; | Unknown
guint32 `unk056`; | Unknown
guint32 `unk060`; | Unknown
guint32 `unk064`; | Unknown
guint32 `unk068`; | Unknown
gint32 `reserved_int1`; | Reserved for future use
gint32 `reserved_int2`; | Reserved for future use
gpointer `reserved1`; | Reserved for future use
gpointer `reserved2`; | Reserved for future use

Since 0.5.0

### struct Itdb_SPLRules

    struct Itdb_SPLRules {
        guint32 unk004;
        guint32 match_operator;
        GList *rules;
        /* reserved for future use */
        gint32 reserved_int1;
        gint32 reserved_int2;
        gpointer reserved1;
        gpointer reserved2;
    };

Smart Playlist Rules

guint32 `unk004`; | Unknown
guint32 `match_operator`; | Whether all rules must match (ITDB_SPLMATCH_AND) or any rules may match (ITDB_SPLMATCH_OR)
GList *`rules`; | list of Itdb_SPLRule's
gint32 `reserved_int1`; | Reserved for future use
gint32 `reserved_int2`; | Reserved for future use
gpointer `reserved1`; | Reserved for future use
gpointer `reserved2`; | Reserved for future use

Since 0.5.0

### enum ItdbLimitSort

    typedef enum {
        ITDB_LIMITSORT_RANDOM = 0x02,
        ITDB_LIMITSORT_SONG_NAME = 0x03,
        ITDB_LIMITSORT_ALBUM = 0x04,
        ITDB_LIMITSORT_ARTIST = 0x05,
        ITDB_LIMITSORT_GENRE = 0x07,
        ITDB_LIMITSORT_MOST_RECENTLY_ADDED = 0x10,
        ITDB_LIMITSORT_LEAST_RECENTLY_ADDED = 0x80000010, /* See note above */
        ITDB_LIMITSORT_MOST_OFTEN_PLAYED = 0x14,
        ITDB_LIMITSORT_LEAST_OFTEN_PLAYED = 0x80000014,   /* See note above */
        ITDB_LIMITSORT_MOST_RECENTLY_PLAYED = 0x15,
        ITDB_LIMITSORT_LEAST_RECENTLY_PLAYED = 0x80000015,/* See note above */
        ITDB_LIMITSORT_HIGHEST_RATING = 0x17,
        ITDB_LIMITSORT_LOWEST_RATING = 0x80000017         /* See note above */
    } ItdbLimitSort;

Which songs to pick when using a limit type

Note: the values for ITDB_LIMITSORT_LEAST_RECENTLY_ADDED, ITDB_LIMITSORT_LEAST_OFTEN_PLAYED, ITDB_LIMITSORT_LEAST_RECENTLY_PLAYED, and ITDB_LIMITSORT_LOWEST_RATING are really 0x10, 0x14, 0x15, 0x17, with the 'limitsort_opposite' flag set. This is the same value as the "positive" value (i.e. ITDB_LIMITSORT_LEAST_RECENTLY_ADDED), and is really very terribly awfully weird, so we map the values to iPodDB specific values with the high bit set.

On writing, we check the high bit and write the limitsort_opposite from that. That way, we don't have to deal with programs using the class needing to set the wrong limit and then make it into the "opposite", which would be frickin' annoying.

`ITDB_LIMITSORT_RANDOM` | Sort randomly
`ITDB_LIMITSORT_SONG_NAME` | Sort by track name
`ITDB_LIMITSORT_ALBUM` | Sort by album name
`ITDB_LIMITSORT_ARTIST` | Sort by artist name
`ITDB_LIMITSORT_GENRE` | Sort by genre
`ITDB_LIMITSORT_MOST_RECENTLY_ADDED` | Sort by most recently added
`ITDB_LIMITSORT_LEAST_RECENTLY_ADDED` | Sort by least recently added
`ITDB_LIMITSORT_MOST_OFTEN_PLAYED` | Sort by most often played
`ITDB_LIMITSORT_LEAST_OFTEN_PLAYED` | Sort by least often played
`ITDB_LIMITSORT_MOST_RECENTLY_PLAYED` | Sort by most recently played
`ITDB_LIMITSORT_LEAST_RECENTLY_PLAYED` | Sort by least recently played
`ITDB_LIMITSORT_HIGHEST_RATING` | Sort by highest rating
`ITDB_LIMITSORT_LOWEST_RATING` | Sort by lowest rating

Since 0.5.0

### enum ItdbLimitType

    typedef enum {
        ITDB_LIMITTYPE_MINUTES = 0x01,
        ITDB_LIMITTYPE_MB      = 0x02,
        ITDB_LIMITTYPE_SONGS   = 0x03,
        ITDB_LIMITTYPE_HOURS   = 0x04,
        ITDB_LIMITTYPE_GB      = 0x05
    } ItdbLimitType;

The type of unit to use when limiting a playlist

`ITDB_LIMITTYPE_MINUTES` | Limit in minutes
`ITDB_LIMITTYPE_MB` | Limit in megabytes
`ITDB_LIMITTYPE_SONGS` | Limit in number of songs
`ITDB_LIMITTYPE_HOURS` | Limit in hours
`ITDB_LIMITTYPE_GB` | Limit in gigabytes

Since 0.5.0

### enum ItdbSPLAction

    typedef enum {
        ITDB_SPLACTION_IS_INT = 0x00000001,
        ITDB_SPLACTION_IS_GREATER_THAN = 0x00000010,
        ITDB_SPLACTION_IS_LESS_THAN = 0x00000040,
        ITDB_SPLACTION_IS_IN_THE_RANGE = 0x00000100,
        ITDB_SPLACTION_IS_IN_THE_LAST = 0x00000200,
        ITDB_SPLACTION_BINARY_AND = 0x00000400,
        /* This action has been seen in the smart playlists stored in mhsd5
         * on recent ipods. It operates on the "video kind" field.
         * It uses integer values, and the from/to values are different.
         * The "from" value might be the list of bits that are allowed to be set
         * in the value we are matching, and the "to" value might be a value
         * that must be set in the value we are matching. For example, there's
         * a TVShow playlist using that action, from is 0x208044, to is 0x40.
         * "video kind" is a bitfield so the 1st value let us filter out
         * entries with unwanted bits, and the second one ensures we have a
         * TVShow. A match could be tested with:
         * is_match = (((val & from) == val) && (val & to))
         * I'm not sure what this becomes when this action is negated...
         */
        ITDB_SPLACTION_BINARY_UNKNOWN1 = 0x00000800,

        ITDB_SPLACTION_IS_STRING = 0x01000001,
        ITDB_SPLACTION_CONTAINS = 0x01000002,
        ITDB_SPLACTION_STARTS_WITH = 0x01000004,
        ITDB_SPLACTION_ENDS_WITH = 0x01000008,

        ITDB_SPLACTION_IS_NOT_INT = 0x02000001,
        ITDB_SPLACTION_IS_NOT_GREATER_THAN = 0x02000010,
        ITDB_SPLACTION_IS_NOT_LESS_THAN = 0x02000040,
        ITDB_SPLACTION_IS_NOT_IN_THE_RANGE = 0x02000100,
        ITDB_SPLACTION_IS_NOT_IN_THE_LAST = 0x02000200,
        ITDB_SPLACTION_NOT_BINARY_AND = 0x02000400,
        ITDB_SPLACTION_BINARY_UNKNOWN2 = 0x02000800,

        ITDB_SPLACTION_IS_NOT = 0x03000001,
        ITDB_SPLACTION_DOES_NOT_CONTAIN = 0x03000002,
        ITDB_SPLACTION_DOES_NOT_START_WITH = 0x03000004,
        ITDB_SPLACTION_DOES_NOT_END_WITH = 0x03000008
    } ItdbSPLAction;

Smartlist Actions used in smart playlist rules.

Note by Otto (Samuel Wood):

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    really this is a bitmapped field...
    high byte
    bit 0 = "string" values if set, "int" values if not set
    bit 1 = "not", or to negate the check.
    lower 2 bytes
    bit 0 = simple "IS" query
    bit 1 = contains
    bit 2 = begins with
    bit 3 = ends with
    bit 4 = greater than
    bit 5 = unknown, but probably greater than or equal to
    bit 6 = less than
    bit 7 = unknown, but probably less than or equal to
    bit 8 = a range selection
    bit 9 = "in the last"
    bit 10 = binary AND
    bit 11 = unknown

`ITDB_SPLACTION_IS_INT` | is integer ("Is Set" in iTunes)
`ITDB_SPLACTION_IS_GREATER_THAN` | is greater than ("Is after" in iTunes)
`ITDB_SPLACTION_IS_LESS_THAN` | is less than ("Is Before" in iTunes)
`ITDB_SPLACTION_IS_IN_THE_RANGE` | is in the range
`ITDB_SPLACTION_IS_IN_THE_LAST` | is in the last
`ITDB_SPLACTION_BINARY_AND` | binary AND
`ITDB_SPLACTION_BINARY_UNKNOWN1` |
`ITDB_SPLACTION_IS_STRING` | is a string
`ITDB_SPLACTION_CONTAINS` | contains
`ITDB_SPLACTION_STARTS_WITH` | starts with
`ITDB_SPLACTION_ENDS_WITH` | ends with
`ITDB_SPLACTION_IS_NOT_INT` | is not an integer ("Is Not Set" in iTunes)
`ITDB_SPLACTION_IS_NOT_GREATER_THAN` | is not greater than (not in iTunes)
`ITDB_SPLACTION_IS_NOT_LESS_THAN` | is not less than (not in iTunes)
`ITDB_SPLACTION_IS_NOT_IN_THE_RANGE` | is not in the range (not in iTunes)
`ITDB_SPLACTION_IS_NOT_IN_THE_LAST` | is not in the last
`ITDB_SPLACTION_NOT_BINARY_AND` |
`ITDB_SPLACTION_BINARY_UNKNOWN2` |
`ITDB_SPLACTION_IS_NOT` | is not
`ITDB_SPLACTION_DOES_NOT_CONTAIN` | does not contain
`ITDB_SPLACTION_DOES_NOT_START_WITH` | does not start with (not in iTunes)
`ITDB_SPLACTION_DOES_NOT_END_WITH` | does not end with (not in iTunes)

Since 0.5.0

### enum ItdbSPLActionLast

    typedef enum {
        ITDB_SPLACTION_LAST_DAYS_VALUE = 86400,    /* nr of secs in 24 hours */
        ITDB_SPLACTION_LAST_WEEKS_VALUE = 604800,  /* nr of secs in 7 days   */
        ITDB_SPLACTION_LAST_MONTHS_VALUE = 2628000 /* nr of secs in 30.4167
    						  days ~= 1 month */
    } ItdbSPLActionLast;

These are to pass to `AddRule()` when you need a unit for the two "in the last" action types. In theory, you can use any time range. iTunes might not like it, but the iPod shouldn't care.

`ITDB_SPLACTION_LAST_DAYS_VALUE` | Seconds in 24 hours
`ITDB_SPLACTION_LAST_WEEKS_VALUE` | Seconds in 7 days
`ITDB_SPLACTION_LAST_MONTHS_VALUE` | Seconds in 1 month (approximately)

Since 0.5.0

### enum ItdbSPLActionType

    typedef enum {
        ITDB_SPLAT_STRING = 1,
        ITDB_SPLAT_INT,
        ITDB_SPLAT_DATE,
        ITDB_SPLAT_RANGE_INT,
        ITDB_SPLAT_RANGE_DATE,
        ITDB_SPLAT_INTHELAST,
        ITDB_SPLAT_PLAYLIST,
        ITDB_SPLAT_NONE,
        ITDB_SPLAT_INVALID,
        ITDB_SPLAT_UNKNOWN,
        ITDB_SPLAT_BINARY_AND
    } ItdbSPLActionType;

Smart Playlist Action Types

`ITDB_SPLAT_STRING` | string
`ITDB_SPLAT_INT` | from integer
`ITDB_SPLAT_DATE` | from date ...
`ITDB_SPLAT_RANGE_INT` | an integer range ...
`ITDB_SPLAT_RANGE_DATE` | a date range ...
`ITDB_SPLAT_INTHELAST` | in the last ...
`ITDB_SPLAT_PLAYLIST` | in playlist
`ITDB_SPLAT_NONE` | none
`ITDB_SPLAT_INVALID` | invalid
`ITDB_SPLAT_UNKNOWN` | unknown
`ITDB_SPLAT_BINARY_AND` | is / is not (binary AND)

Since 0.5.0

### enum ItdbSPLField

    typedef enum {
        ITDB_SPLFIELD_SONG_NAME = 0x02,
        ITDB_SPLFIELD_ALBUM = 0x03,
        ITDB_SPLFIELD_ARTIST = 0x04,
        ITDB_SPLFIELD_BITRATE = 0x05,
        ITDB_SPLFIELD_SAMPLE_RATE = 0x06,
        ITDB_SPLFIELD_YEAR = 0x07,
        ITDB_SPLFIELD_GENRE = 0x08,
        ITDB_SPLFIELD_KIND = 0x09,
        ITDB_SPLFIELD_DATE_MODIFIED = 0x0a,
        ITDB_SPLFIELD_TRACKNUMBER = 0x0b,
        ITDB_SPLFIELD_SIZE = 0x0c,
        ITDB_SPLFIELD_TIME = 0x0d,
        ITDB_SPLFIELD_COMMENT = 0x0e,
        ITDB_SPLFIELD_DATE_ADDED = 0x10,
        ITDB_SPLFIELD_COMPOSER = 0x12,
        ITDB_SPLFIELD_PLAYCOUNT = 0x16,
        ITDB_SPLFIELD_LAST_PLAYED = 0x17,
        ITDB_SPLFIELD_DISC_NUMBER = 0x18,
        ITDB_SPLFIELD_RATING = 0x19,
        ITDB_SPLFIELD_COMPILATION = 0x1f,
        ITDB_SPLFIELD_BPM = 0x23,
        ITDB_SPLFIELD_GROUPING = 0x27,
        ITDB_SPLFIELD_PLAYLIST = 0x28,
        ITDB_SPLFIELD_PURCHASE = 0x29,
        ITDB_SPLFIELD_DESCRIPTION = 0x36,
        ITDB_SPLFIELD_CATEGORY = 0x37,
        ITDB_SPLFIELD_PODCAST = 0x39,
        ITDB_SPLFIELD_VIDEO_KIND = 0x3c,
        ITDB_SPLFIELD_TVSHOW = 0x3e,
        ITDB_SPLFIELD_SEASON_NR = 0x3f,
        ITDB_SPLFIELD_SKIPCOUNT = 0x44,
        ITDB_SPLFIELD_LAST_SKIPPED = 0x45,
        ITDB_SPLFIELD_ALBUMARTIST = 0x47,
        ITDB_SPLFIELD_SORT_SONG_NAME = 0x4e,
        ITDB_SPLFIELD_SORT_ALBUM = 0x4f,
        ITDB_SPLFIELD_SORT_ARTIST = 0x50,
        ITDB_SPLFIELD_SORT_ALBUMARTIST = 0x51,
        ITDB_SPLFIELD_SORT_COMPOSER = 0x52,
        ITDB_SPLFIELD_SORT_TVSHOW = 0x53,
        ITDB_SPLFIELD_ALBUM_RATING = 0x5a
    } ItdbSPLField;

Smart Playlist Fields, used for Smart Playlist Rules (Itdb_SPLRule).

`ITDB_SPLFIELD_SONG_NAME` | Song name (string)
`ITDB_SPLFIELD_ALBUM` | Album (string)
`ITDB_SPLFIELD_ARTIST` | Artist (string)
`ITDB_SPLFIELD_BITRATE` | Bitrate (integer, e.g. from/to = 128)
`ITDB_SPLFIELD_SAMPLE_RATE` | Sample rate (integer, e.g. from/to = 44100)
`ITDB_SPLFIELD_YEAR` | Year (integer, e.g. from/to = 2004)
`ITDB_SPLFIELD_GENRE` | Genre (string)
`ITDB_SPLFIELD_KIND` | File type (string, e.g. MP3-File)
`ITDB_SPLFIELD_DATE_MODIFIED` | Date modified (integer, e.g. from/to = bcf93280 == is before 6/19/2004)
`ITDB_SPLFIELD_TRACKNUMBER` | Track number (integer, e.g. from/to = 2)
`ITDB_SPLFIELD_SIZE` | Size (integer, e.g. from/to = 0x00600000 for 6MB)
`ITDB_SPLFIELD_TIME` | Time (integer, e.g. from/to = 83999 for 1:23/83 seconds)
`ITDB_SPLFIELD_COMMENT` | Comment (string)
`ITDB_SPLFIELD_DATE_ADDED` | Date added (integer, e.g. from/to = bcfa83ff == is after 6/19/2004)
`ITDB_SPLFIELD_COMPOSER` | Composer (string)
`ITDB_SPLFIELD_PLAYCOUNT` | Playcount (integer, e.g. from/to = 1)
`ITDB_SPLFIELD_LAST_PLAYED` | Date last played (integer, e.g. from = bcfa83ff (6/19/2004) to = 0xbcfbd57f (6/20/2004))
`ITDB_SPLFIELD_DISC_NUMBER` | Disc number (integer, e.g. from/to = 1)
`ITDB_SPLFIELD_RATING` | Rating (integer, e.g. from/to = 60 (3 stars))
`ITDB_SPLFIELD_COMPILATION` | Compilation (integer, e.g. is set -> ITDB_SPLACTION_IS_INT/from=1, not set -> ITDB_SPLACTION_IS_NOT_INT/from=1)
`ITDB_SPLFIELD_BPM` | Beats per minute (integer, e.g. from/to = 60)
`ITDB_SPLFIELD_GROUPING` | Grouping (string)
`ITDB_SPLFIELD_PLAYLIST` | FIXME Unknown...not parsed correctly... from/to = 0xb6fbad5f for "Purchased Music". Extra data after "to"...
`ITDB_SPLFIELD_PURCHASE` |
`ITDB_SPLFIELD_DESCRIPTION` |
`ITDB_SPLFIELD_CATEGORY` |
`ITDB_SPLFIELD_PODCAST` |
`ITDB_SPLFIELD_VIDEO_KIND` | Logical integer (works on mediatype)
`ITDB_SPLFIELD_TVSHOW` | TV Show (string)
`ITDB_SPLFIELD_SEASON_NR` | Season number (integer)
`ITDB_SPLFIELD_SKIPCOUNT` | Skipcount (integer)
`ITDB_SPLFIELD_LAST_SKIPPED` | Last skipped (integer)
`ITDB_SPLFIELD_ALBUMARTIST` | Album artist (string)
`ITDB_SPLFIELD_SORT_SONG_NAME` |
`ITDB_SPLFIELD_SORT_ALBUM` |
`ITDB_SPLFIELD_SORT_ARTIST` |
`ITDB_SPLFIELD_SORT_ALBUMARTIST` |
`ITDB_SPLFIELD_SORT_COMPOSER` |
`ITDB_SPLFIELD_SORT_TVSHOW` |
`ITDB_SPLFIELD_ALBUM_RATING` |

Since 0.5.0

### enum ItdbSPLFieldType

    typedef enum {
        ITDB_SPLFT_STRING = 1,
        ITDB_SPLFT_INT,
        ITDB_SPLFT_BOOLEAN,
        ITDB_SPLFT_DATE,
        ITDB_SPLFT_PLAYLIST,
        ITDB_SPLFT_UNKNOWN,
        ITDB_SPLFT_BINARY_AND
    } ItdbSPLFieldType;

Smart Playlist Field Types

`ITDB_SPLFT_STRING` | string
`ITDB_SPLFT_INT` | integer
`ITDB_SPLFT_BOOLEAN` | boolean
`ITDB_SPLFT_DATE` | date
`ITDB_SPLFT_PLAYLIST` | playlist
`ITDB_SPLFT_UNKNOWN` | unknown
`ITDB_SPLFT_BINARY_AND` | binary AND

Since 0.5.0

### enum ItdbSPLMatch

    typedef enum {
        ITDB_SPLMATCH_AND = 0,
        ITDB_SPLMATCH_OR = 1
    } ItdbSPLMatch;

Types for smart playlist rules match_operator

`ITDB_SPLMATCH_AND` | Logical AND - all of the rules must be true in order for the combined rule to be applied
`ITDB_SPLMATCH_OR` | Logical OR - any of the rules may be true

### ITDB_SPL_DATE_IDENTIFIER

    #define ITDB_SPL_DATE_IDENTIFIER (G_GINT64_CONSTANT (0x2dae2dae2dae2daeU))

Identifier for smart playlist date fields

Since 0.5.0

### ITDB_SPL_STRING_MAXLEN

    #define ITDB_SPL_STRING_MAXLEN 255

Maximum string length for smart playlists

Since 0.5.0

### itdb_splr_get_field_type ()

    ItdbSPLFieldType    itdb_splr_get_field_type            (const Itdb_SPLRule *splr);

Gets the type of the field of the `splr` rule

`splr` : | an Itdb_SPLRule
Returns : | an Itdb_SPLFieldType corresponding to `splr` field type (string, int, date, ...)

### itdb_splr_get_action_type ()

    ItdbSPLActionType   itdb_splr_get_action_type           (const Itdb_SPLRule *splr);

Gets the type of the action associated with `splr`.

`splr` : | an Itdb_SPLRule
Returns : | type (range, date, string...) of the action field

### itdb_splr_validate ()

    void                itdb_splr_validate                  (Itdb_SPLRule *splr);

Validates a smart playlist rule

`splr` : | an Itdb_SPLRule

### itdb_splr_remove ()

    void                itdb_splr_remove                    (Itdb_Playlist *pl,
                                                             Itdb_SPLRule *splr);

Removes the smart playlist rule `splr` from playlist `pl`. The memory used by `splr` is freed.

`pl` : | an Itdb_Playlist
`splr` : | an Itdb_SPLRule

### itdb_splr_new ()

    Itdb_SPLRule *      itdb_splr_new                       (void);

Creates a new default smart rule

Returns : | a new Itdb_SPLRule that must be freed with `itdb_splr_free()` when no longer needed

### itdb_splr_add ()

    void                itdb_splr_add                       (Itdb_Playlist *pl,
                                                             Itdb_SPLRule *splr,
                                                             gint pos);

Adds the smart rule `splr` to `pl` at position `pos`. If `pos` is -1, `splr` gets appended to the end. After this call, `splr` memory is managed by `pl`, so you no longer need to call `itdb_splr_free()`

`pl` : | an Itdb_Playlist
`splr` : | an Itdb_SPLRule
`pos` : | position of the rule

### itdb_splr_add_new ()

    Itdb_SPLRule *      itdb_splr_add_new                   (Itdb_Playlist *pl,
                                                             gint pos);

Creates a new smart rule and inserts it at position `pos` in `pl`. If `pos` is -1, the new rule gets appended to the end.

`pl` : | an Itdb_Playlist
`pos` : | position to insert the rule at
Returns : | pointer to the newly created Itdb_SPLRule. Its memory is handled by `pl` though, so you don't need to explicitly call `itdb_splr_free()` on it

### itdb_spl_copy_rules ()

    void                itdb_spl_copy_rules                 (Itdb_Playlist *dest,
                                                             Itdb_Playlist *src);

Copy all relevant information for smart playlist from playlist `src` to playlist `dest`. If `dest` is already a smart playlist, the existing data is overwritten/deleted.

`dest` : | destination Itdb_Playlist
`src` : | source Itdb_Playlist

### itdb_splr_eval ()

    gboolean            itdb_splr_eval                      (Itdb_SPLRule *splr,
                                                             Itdb_Track *track);

Evaluates `splr`'s truth against `track`. `track->itdb` must be set.

`splr` : | an Itdb_SPLRule
`track` : | an Itdb_Track
Returns : | TRUE if `track` matches `splr`, FALSE otherwise.

### itdb_spl_update ()

    void                itdb_spl_update                     (Itdb_Playlist *spl);

Updates the content of the smart playlist `spl` (meant to be called if the tracks stored in the Itdb_iTunesDB associated with `spl` have changed somehow and you want `spl->members` to be accurate with regards to those changes. Does nothing if `spl` isn't a smart playlist.

`spl` : | an Itdb_Playlist

### itdb_spl_update_all ()

    void                itdb_spl_update_all                 (Itdb_iTunesDB *itdb);

Updates all smart playlists contained in `itdb`

`itdb` : | an Itdb_iTunesDB

### itdb_spl_update_live ()

    void                itdb_spl_update_live                (Itdb_iTunesDB *itdb);

Updates all smart playlists contained in `itdb` which have the `liveupdate` flag set.

`itdb` : | an Itdb_iTunesDB

Since 0.2.0

## See Also

Playlists