libsaria: Use [] to access track properties (not string)
Rathen than using a bunch of get_PROPERTY_NAME() functions, I think it's cleaner to use dictionary-like indexing to access properties. This patch converts most track access functions, but I haven't gotten around to strings yet. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
21313e9b52
commit
a606830f7b
|
@ -7,6 +7,28 @@
|
|||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
enum track_uiprop_t {
|
||||
TRACK_ID,
|
||||
TRACK_LIBID,
|
||||
TRACK_YEAR,
|
||||
TRACK_TRACK,
|
||||
TRACK_COUNT,
|
||||
TRACK_LAST_DAY,
|
||||
TRACK_LAST_MONTH,
|
||||
TRACK_LAST_YEAR,
|
||||
};
|
||||
|
||||
enum track_iprop_t {
|
||||
TRACK_LENGTH,
|
||||
TRACK_BITRATE,
|
||||
TRACK_SAMPLE,
|
||||
TRACK_CHANNELS,
|
||||
};
|
||||
|
||||
enum track_bprop_t {
|
||||
TRACK_BANNED,
|
||||
};
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
namespace library
|
||||
|
@ -66,17 +88,13 @@ namespace libsaria
|
|||
string &get_genre();
|
||||
string &get_lenstr();
|
||||
string get_last_played();
|
||||
int &get_length();
|
||||
unsigned int &get_year();
|
||||
unsigned int &get_track();
|
||||
unsigned int &get_libid();
|
||||
unsigned int &get_id();
|
||||
unsigned int &get_count();
|
||||
bool &get_banned();
|
||||
|
||||
void set_banned(bool);
|
||||
|
||||
bool operator<(Track &);
|
||||
const unsigned int &operator[](track_uiprop_t);
|
||||
const int &operator[](track_iprop_t);
|
||||
const bool &operator[](track_bprop_t);
|
||||
};
|
||||
|
||||
Track *current_track();
|
||||
|
|
|
@ -82,7 +82,7 @@ void read_path(ifstream &stream)
|
|||
for (unsigned int i = 0; i < size; i++) {
|
||||
item = path_ptr->tracks.push_back(libsaria::Track(stream, path_ptr, version));
|
||||
track = &item->get_value();
|
||||
if (track->get_banned())
|
||||
if ((*track)[TRACK_BANNED])
|
||||
banned.push_back(track);
|
||||
else
|
||||
tracks.push_back(track);
|
||||
|
|
|
@ -42,7 +42,7 @@ struct sort_data {
|
|||
static void sort_tracks(libsaria::Track &track, void *data)
|
||||
{
|
||||
struct sort_data *sort = (struct sort_data *)data;
|
||||
if (track.get_banned())
|
||||
if (track[TRACK_BANNED])
|
||||
sort->banned.push_back(&track);
|
||||
else
|
||||
sort->tracks.push_back(&track);
|
||||
|
@ -50,7 +50,7 @@ static void sort_tracks(libsaria::Track &track, void *data)
|
|||
|
||||
static void hide_track(libsaria::Track &track, void *data)
|
||||
{
|
||||
if (track.get_banned())
|
||||
if (track[TRACK_BANNED])
|
||||
libsaria::ban::get_banned_plist()->remove_track(&track);
|
||||
else
|
||||
lib_playlist.remove_track(&track);
|
||||
|
@ -64,7 +64,7 @@ static void delete_track(libsaria::Track &track, void *data)
|
|||
|
||||
static bool check_trackid(libsaria::Track &track, void *data)
|
||||
{
|
||||
return track.get_id() == *(unsigned int *)data;
|
||||
return track[TRACK_ID] == *(unsigned int *)data;
|
||||
}
|
||||
|
||||
void pop_path(libsaria::library::Path *path)
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace libsaria
|
|||
|
||||
void Playlist::add_track(Track *track, unsigned int ins_index)
|
||||
{
|
||||
length += track->get_length();
|
||||
length += (*track)[TRACK_LENGTH];
|
||||
index.add_track(track);
|
||||
track->add_playlist(this);
|
||||
notify_ui(PLAYLIST_ADD, track, ins_index);
|
||||
|
@ -28,8 +28,9 @@ namespace libsaria
|
|||
unsigned int Playlist::remove_track_it(list<Track *>::iterator &it,
|
||||
unsigned int rm_index)
|
||||
{
|
||||
Track *track = *it;
|
||||
bool removing_cur = (it == cur);
|
||||
length -= (*it)->get_length();
|
||||
length -= (*track)[TRACK_LENGTH];
|
||||
index.remove_track(*it);
|
||||
(*it)->rm_playlist(this);
|
||||
it = plist.erase(it);
|
||||
|
|
|
@ -86,8 +86,8 @@ namespace libsaria
|
|||
stream << get_sorted() << "\n";
|
||||
|
||||
for (it = plist.begin(); it != plist.end(); it++) {
|
||||
stream << (*it)->get_libid() << " ";
|
||||
stream << (*it)->get_id() << "\n";
|
||||
stream << (**it)[TRACK_LIBID] << " ";
|
||||
stream << (**it)[TRACK_ID] << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,39 +45,4 @@ namespace libsaria
|
|||
return s.str();
|
||||
}
|
||||
|
||||
int &Track::get_length()
|
||||
{
|
||||
return length;
|
||||
}
|
||||
|
||||
unsigned int &Track::get_year()
|
||||
{
|
||||
return year;
|
||||
}
|
||||
|
||||
unsigned int &Track::get_track()
|
||||
{
|
||||
return track;
|
||||
}
|
||||
|
||||
unsigned int &Track::get_id()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
unsigned int &Track::get_libid()
|
||||
{
|
||||
return path->id;
|
||||
}
|
||||
|
||||
unsigned int &Track::get_count()
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
bool &Track::get_banned()
|
||||
{
|
||||
return banned;
|
||||
}
|
||||
|
||||
} /* Namespace: libsaria */
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// Copyright (c) 2011 Bryan Schumaker.
|
||||
#include <library.h>
|
||||
#include <track.h>
|
||||
#include <print.h>
|
||||
|
||||
|
@ -43,4 +44,48 @@ namespace libsaria
|
|||
return track < cmp_track.track;
|
||||
}
|
||||
|
||||
const unsigned int &Track::operator[](track_uiprop_t property)
|
||||
{
|
||||
switch (property) {
|
||||
case TRACK_ID:
|
||||
return id;
|
||||
case TRACK_LIBID:
|
||||
return path->id;
|
||||
case TRACK_YEAR:
|
||||
return year;
|
||||
case TRACK_TRACK:
|
||||
return track;
|
||||
case TRACK_COUNT:
|
||||
return count;
|
||||
case TRACK_LAST_DAY:
|
||||
return last_day;
|
||||
case TRACK_LAST_MONTH:
|
||||
return last_month;
|
||||
default: /* TRACK_LAST_YEAR */
|
||||
return last_year;
|
||||
}
|
||||
}
|
||||
|
||||
const int &Track::operator[](track_iprop_t property)
|
||||
{
|
||||
switch (property) {
|
||||
case TRACK_LENGTH:
|
||||
return length;
|
||||
case TRACK_BITRATE:
|
||||
return bitrate;
|
||||
case TRACK_SAMPLE:
|
||||
return sample;
|
||||
default: /* TRACK_CHANNELS */
|
||||
return channels;
|
||||
}
|
||||
}
|
||||
|
||||
const bool &Track::operator[](track_bprop_t property)
|
||||
{
|
||||
switch (property) {
|
||||
default: /* TRACK_BANNED */
|
||||
return banned;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,13 +30,13 @@ static void update_track(libsaria::Track *track, GtkListStore *liststore,
|
|||
{
|
||||
gtk_list_store_set(liststore, iter,
|
||||
0, track,
|
||||
1, track->get_track(),
|
||||
1, (*track)[TRACK_TRACK],
|
||||
2, track->get_title().c_str(),
|
||||
3, track->get_lenstr().c_str(),
|
||||
4, track->get_artist().c_str(),
|
||||
5, track->get_album().c_str(),
|
||||
6, track->get_year(),
|
||||
7, track->get_count(),
|
||||
6, (*track)[TRACK_YEAR],
|
||||
7, (*track)[TRACK_COUNT],
|
||||
8, track->get_last_played().c_str(),
|
||||
9, formatted(track->get_filepath()).c_str(),
|
||||
-1);
|
||||
|
|
|
@ -34,7 +34,7 @@ void update_labels(libsaria::Track *track)
|
|||
set_label("AlbumLabel", track->get_album(), "x-large");
|
||||
set_label("DurLabel", track->get_lenstr(), "");
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(get_widget("BanButton")),
|
||||
track->get_banned());
|
||||
(*track)[TRACK_BANNED]);
|
||||
}
|
||||
|
||||
void update_buttons(notify_t event)
|
||||
|
@ -122,7 +122,7 @@ static void toggle_ban(GtkWidget *b, gpointer d)
|
|||
else
|
||||
gtk_button_set_image(GTK_BUTTON(ban), get_widget("YesImage"));
|
||||
|
||||
if (cur->get_banned() == banned)
|
||||
if ((*cur)[TRACK_BANNED] == banned)
|
||||
return;
|
||||
|
||||
cur->set_banned(banned);
|
||||
|
|
Loading…
Reference in New Issue