core/tags/track: Move comparison fields into track.h
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
9a16a18b9f
commit
08c7323dfc
|
@ -60,7 +60,7 @@ void TempQueue :: del(unsigned int id)
|
|||
deck :: write();
|
||||
}
|
||||
|
||||
void TempQueue :: sort(sort_t field, bool ascending)
|
||||
void TempQueue :: sort(compare_t field, bool ascending)
|
||||
{
|
||||
Queue :: sort(field, ascending);
|
||||
deck :: write();
|
||||
|
@ -79,9 +79,9 @@ static void upgrade_v0()
|
|||
|
||||
for (unsigned int i = 0; i < num; i++) {
|
||||
file_readf(&deck_file, "%u %d", &field, &ascending);
|
||||
library->sort((sort_t)field, (i == 0) ? true : false);
|
||||
library->sort((compare_t)field, (i == 0) ? true : false);
|
||||
if (!ascending)
|
||||
library->sort((sort_t)field, false);
|
||||
library->sort((compare_t)field, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,9 +19,9 @@ public:
|
|||
LibraryQueue() : Queue(Q_ENABLED | Q_REPEAT)
|
||||
{
|
||||
file_init(&f, "library.q", 0);
|
||||
Queue :: sort(SORT_ARTIST, true);
|
||||
Queue :: sort(SORT_YEAR, false);
|
||||
Queue :: sort(SORT_TRACK, false);
|
||||
Queue :: sort(COMPARE_ARTIST, true);
|
||||
Queue :: sort(COMPARE_YEAR, false);
|
||||
Queue :: sort(COMPARE_TRACK, false);
|
||||
}
|
||||
|
||||
void save()
|
||||
|
@ -48,9 +48,9 @@ public:
|
|||
file_readf(&f, "%u %u", &_flags, &n);
|
||||
for (unsigned int i = 0; i < n; i++) {
|
||||
file_readf(&f, "%u %d", &field, &ascending);
|
||||
Queue :: sort((sort_t)field, (i == 0) ? true : false);
|
||||
Queue :: sort((compare_t)field, (i == 0) ? true : false);
|
||||
if (ascending == false)
|
||||
Queue :: sort((sort_t)field, false);
|
||||
Queue :: sort((compare_t)field, false);
|
||||
}
|
||||
file_close(&f);
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public:
|
|||
void set_flag(queue_flags f) { Queue :: set_flag(f); save(); }
|
||||
void unset_flag(queue_flags f) { Queue :: unset_flag(f); save(); }
|
||||
|
||||
void sort(sort_t field, bool ascending)
|
||||
void sort(compare_t field, bool ascending)
|
||||
{
|
||||
Queue :: sort(field, ascending);
|
||||
save();
|
||||
|
|
|
@ -10,9 +10,9 @@ public:
|
|||
|
||||
PlaylistQueue() : Queue(Q_ENABLED | Q_REPEAT)
|
||||
{
|
||||
sort(SORT_ARTIST, true);
|
||||
sort(SORT_YEAR, false);
|
||||
sort(SORT_TRACK, false);
|
||||
sort(COMPARE_ARTIST, true);
|
||||
sort(COMPARE_YEAR, false);
|
||||
sort(COMPARE_TRACK, false);
|
||||
set_flag(Q_NO_SORT);
|
||||
}
|
||||
|
||||
|
|
|
@ -76,26 +76,27 @@ void Queue :: set_notifier(QNotifier *notify)
|
|||
* < 0: lhs < rhs, or rhs is empty
|
||||
* > 0: lhs > rhs, or lhs is empty
|
||||
*/
|
||||
static inline int track_compare(struct track *lhs, struct track *rhs, sort_t field)
|
||||
static inline int track_compare(struct track *lhs, struct track *rhs,
|
||||
compare_t field)
|
||||
{
|
||||
switch (field) {
|
||||
case SORT_ARTIST:
|
||||
case COMPARE_ARTIST:
|
||||
return artist_compare(lhs->tr_artist, rhs->tr_artist);
|
||||
case SORT_COUNT:
|
||||
case COMPARE_COUNT:
|
||||
return lhs->tr_count - rhs->tr_count;
|
||||
case SORT_GENRE:
|
||||
case COMPARE_GENRE:
|
||||
return genre_compare(lhs->tr_genre, rhs->tr_genre);
|
||||
case SORT_LENGTH:
|
||||
case COMPARE_LENGTH:
|
||||
return lhs->tr_length - rhs->tr_length;
|
||||
case SORT_PLAYED:
|
||||
case COMPARE_PLAYED:
|
||||
return date_compare(&lhs->tr_date, &rhs->tr_date);
|
||||
case SORT_TITLE:
|
||||
case COMPARE_TITLE:
|
||||
return track_compare(lhs, rhs);
|
||||
case SORT_TRACK:
|
||||
case COMPARE_TRACK:
|
||||
return lhs->tr_track - rhs->tr_track;
|
||||
case SORT_YEAR:
|
||||
case COMPARE_YEAR:
|
||||
return album_compare_year(lhs->tr_album, rhs->tr_album);
|
||||
case SORT_ALBUM:
|
||||
case COMPARE_ALBUM:
|
||||
return album_compare(lhs->tr_album, rhs->tr_album);
|
||||
}
|
||||
return 0;
|
||||
|
@ -226,7 +227,7 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
void Queue :: sort(sort_t field, bool reset)
|
||||
void Queue :: sort(compare_t field, bool reset)
|
||||
{
|
||||
bool found = false;
|
||||
struct sort_info info = { field, true };
|
||||
|
|
|
@ -14,10 +14,10 @@ extern "C" {
|
|||
|
||||
static std::map<Queue *, Tab *> queue_mapping;
|
||||
|
||||
static sort_t sort_fields[] = {
|
||||
SORT_TRACK, SORT_TITLE, SORT_LENGTH,
|
||||
SORT_ARTIST, SORT_ALBUM, SORT_YEAR,
|
||||
SORT_GENRE, SORT_COUNT, SORT_PLAYED
|
||||
static compare_t sort_fields[] = {
|
||||
COMPARE_TRACK, COMPARE_TITLE, COMPARE_LENGTH,
|
||||
COMPARE_ARTIST, COMPARE_ALBUM, COMPARE_YEAR,
|
||||
COMPARE_GENRE, COMPARE_COUNT, COMPARE_PLAYED
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
void del(struct track *);
|
||||
void del(unsigned int);
|
||||
|
||||
void sort(sort_t, bool);
|
||||
void sort(compare_t, bool);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -24,23 +24,6 @@ enum queue_flags {
|
|||
};
|
||||
|
||||
|
||||
/**
|
||||
* Track fields that can be compared.
|
||||
*/
|
||||
enum sort_t {
|
||||
SORT_ARTIST, /**< Sort tracks by Artist name. */
|
||||
SORT_ALBUM, /**< Sort tracks by Album name. */
|
||||
SORT_COUNT, /**< Sort tracks by Play count. */
|
||||
SORT_GENRE, /**< Sort tracks by Genre. */
|
||||
SORT_LENGTH, /**< Sort tracks by Track length. */
|
||||
SORT_PLAYED, /**< Sort tracks by last played date. */
|
||||
SORT_TITLE, /**< Sort tracks by Track title. */
|
||||
SORT_TRACK, /**< Sort tracks by Track number. */
|
||||
SORT_YEAR, /**< Sort tracks by Track year. */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Class to assist in notifying the GUI of queue changes.
|
||||
*/
|
||||
|
@ -75,8 +58,8 @@ public:
|
|||
* Struct for passing sort parameters.
|
||||
*/
|
||||
struct sort_info {
|
||||
sort_t field;
|
||||
bool ascending;
|
||||
compare_t field;
|
||||
bool ascending;
|
||||
};
|
||||
|
||||
|
||||
|
@ -224,7 +207,7 @@ public:
|
|||
* @param field Field to sort by.
|
||||
* @param reset Set to true if current sort data should be discarded.
|
||||
*/
|
||||
virtual void sort(sort_t, bool);
|
||||
virtual void sort(compare_t, bool);
|
||||
|
||||
/**
|
||||
* Access a track by index.
|
||||
|
|
|
@ -28,6 +28,19 @@
|
|||
#include <core/tags/library.h>
|
||||
|
||||
|
||||
enum compare_t {
|
||||
COMPARE_ARTIST, /* Compare tracks by artist name. */
|
||||
COMPARE_ALBUM, /* Compare tracks by album name. */
|
||||
COMPARE_COUNT, /* Compare tracks by play count. */
|
||||
COMPARE_GENRE, /* Compare tracks by genre. */
|
||||
COMPARE_LENGTH, /* Compare tracks by length. */
|
||||
COMPARE_PLAYED, /* Compare tracks by last played date. */
|
||||
COMPARE_TITLE, /* Compare tracks by title. */
|
||||
COMPARE_TRACK, /* Compare tracks by track number. */
|
||||
COMPARE_YEAR, /* Compare tracks by year. */
|
||||
};
|
||||
|
||||
|
||||
struct track {
|
||||
struct album *tr_album; /* This track's associated album. */
|
||||
struct artist *tr_artist; /* This track's associated artist. */
|
||||
|
|
|
@ -253,27 +253,27 @@ void test_sorting()
|
|||
{
|
||||
TestQueue q(0);
|
||||
|
||||
q.sort(SORT_TITLE, true);
|
||||
q.sort(COMPARE_TITLE, true);
|
||||
test_equal(q.get_sorder().size(), (size_t)1);
|
||||
test_fill_q(&q);
|
||||
for (unsigned int i = 0; i < 24; i++)
|
||||
test_loop_equal(q[i]->tr_dbe.dbe_index, exp_sort_title[i], i);
|
||||
test_loop_passed();
|
||||
|
||||
q.sort(SORT_TITLE, false);
|
||||
q.sort(COMPARE_TITLE, false);
|
||||
test_equal(q.get_sorder().size(), (size_t)1);
|
||||
for (unsigned int i = 0; i < 24; i++)
|
||||
test_loop_equal(q[i]->tr_dbe.dbe_index, exp_sort_title[23 - i], i);
|
||||
test_loop_passed();
|
||||
|
||||
q.sort(SORT_LENGTH, true);
|
||||
q.sort(COMPARE_LENGTH, true);
|
||||
for (unsigned int i = 0; i < 24; i++)
|
||||
test_loop_equal(q[i]->tr_dbe.dbe_index, i, i);
|
||||
test_loop_passed();
|
||||
|
||||
q.sort(SORT_YEAR, true);
|
||||
q.sort(SORT_TITLE, false);
|
||||
q.sort(SORT_TITLE, false);
|
||||
q.sort(COMPARE_YEAR, true);
|
||||
q.sort(COMPARE_TITLE, false);
|
||||
q.sort(COMPARE_TITLE, false);
|
||||
test_equal(q.get_sorder().size(), (size_t)2);
|
||||
for (unsigned int i = 0; i < 24; i++)
|
||||
test_loop_equal(q[i]->tr_dbe.dbe_index, exp_sort_ye_ti[i], i);
|
||||
|
|
Loading…
Reference in New Issue