Track: Hide length from the public
I provide an accessor function to keep this value from ever getting changed outside of the Track class. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
eb23127f6d
commit
1fdee864a2
|
@ -42,7 +42,7 @@ void Queue :: read(File &f)
|
||||||
for (unsigned int i = 0; i < n; i++) {
|
for (unsigned int i = 0; i < n; i++) {
|
||||||
f >> id;
|
f >> id;
|
||||||
_tracks[i] = tagdb :: lookup(id);
|
_tracks[i] = tagdb :: lookup(id);
|
||||||
_length += _tracks[i]->length;
|
_length += _tracks[i]->length();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ unsigned int Queue :: find_sorted_id(Track *rhs)
|
||||||
unsigned int Queue :: _add_at(Track *track, unsigned int pos)
|
unsigned int Queue :: _add_at(Track *track, unsigned int pos)
|
||||||
{
|
{
|
||||||
_tracks.insert(_tracks.begin() + pos, track);
|
_tracks.insert(_tracks.begin() + pos, track);
|
||||||
_length += track->length;
|
_length += track->length();
|
||||||
get_callbacks()->on_queue_track_add(this, pos);
|
get_callbacks()->on_queue_track_add(this, pos);
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ unsigned int Queue :: _add_at(Track *track, unsigned int pos)
|
||||||
void Queue :: _del_at(Track *track, unsigned int pos)
|
void Queue :: _del_at(Track *track, unsigned int pos)
|
||||||
{
|
{
|
||||||
_tracks.erase(_tracks.begin() + pos);
|
_tracks.erase(_tracks.begin() + pos);
|
||||||
_length -= track->length;
|
_length -= track->length();
|
||||||
get_callbacks()->on_queue_track_del(this, pos);
|
get_callbacks()->on_queue_track_del(this, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ void Track :: read(File &f)
|
||||||
|
|
||||||
f >> library_id >> artist_id >> album_id >> genre_id;
|
f >> library_id >> artist_id >> album_id >> genre_id;
|
||||||
f >> _track >> last_year >> last_month >> last_day;
|
f >> _track >> last_year >> last_month >> last_day;
|
||||||
f >> _count >> length;
|
f >> _count >> _length;
|
||||||
|
|
||||||
title = f.getline();
|
title = f.getline();
|
||||||
filepath = f.getline();
|
filepath = f.getline();
|
||||||
|
@ -62,15 +62,15 @@ void Track :: write(File &f)
|
||||||
f << _library->index() << " " << _artist->index() << " ";
|
f << _library->index() << " " << _artist->index() << " ";
|
||||||
f << _album->index() << " " << _genre->index() << " " << _track << " ";
|
f << _album->index() << " " << _genre->index() << " " << _track << " ";
|
||||||
f << last_year << " " << last_month << " " << last_day << " ";
|
f << last_year << " " << last_month << " " << last_day << " ";
|
||||||
f << _count << " " << length << " " << title << std::endl;
|
f << _count << " " << _length << " " << title << std::endl;
|
||||||
f << filepath << std::endl;
|
f << filepath << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Track :: set_length_str()
|
void Track :: set_length_str()
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
unsigned int minutes = length / 60;
|
unsigned int minutes = _length / 60;
|
||||||
unsigned int seconds = length % 60;
|
unsigned int seconds = _length % 60;
|
||||||
|
|
||||||
ss << minutes << ":";
|
ss << minutes << ":";
|
||||||
if (seconds < 10)
|
if (seconds < 10)
|
||||||
|
@ -112,7 +112,7 @@ bool Track :: tag()
|
||||||
_album = tags :: get_album(format_tag(tag->album()), tag->year());
|
_album = tags :: get_album(format_tag(tag->album()), tag->year());
|
||||||
_genre = tags :: get_genre(format_tag(tag->genre()));
|
_genre = tags :: get_genre(format_tag(tag->genre()));
|
||||||
_track = tag->track();
|
_track = tag->track();
|
||||||
length = audio->length();
|
_length = audio->length();
|
||||||
title = format_tag(tag->title());
|
title = format_tag(tag->title());
|
||||||
|
|
||||||
title_lower = filter :: add(title, index());
|
title_lower = filter :: add(title, index());
|
||||||
|
@ -181,7 +181,7 @@ int Track :: less_than(Track *rhs, sort_t field)
|
||||||
case SORT_GENRE:
|
case SORT_GENRE:
|
||||||
return _genre->compare(rhs->genre());
|
return _genre->compare(rhs->genre());
|
||||||
case SORT_LENGTH:
|
case SORT_LENGTH:
|
||||||
return compare_uint(length, rhs->length);
|
return compare_uint(_length, rhs->_length);
|
||||||
case SORT_PLAYED:
|
case SORT_PLAYED:
|
||||||
ret = compare_uint(last_year, rhs->last_year);
|
ret = compare_uint(last_year, rhs->last_year);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
|
|
|
@ -8,13 +8,13 @@
|
||||||
Track :: Track()
|
Track :: Track()
|
||||||
: GenericTag(),
|
: GenericTag(),
|
||||||
_album(NULL), _artist(NULL), _genre(NULL), _library(NULL),
|
_album(NULL), _artist(NULL), _genre(NULL), _library(NULL),
|
||||||
_count(0), _track(0), length(0), last_year(0), last_month(0), last_day(0)
|
_count(0), _length(0), _track(0), last_year(0), last_month(0), last_day(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Track :: Track(Album *album, Artist *artist, Genre *genre, Library *library,
|
Track :: Track(Album *album, Artist *artist, Genre *genre, Library *library,
|
||||||
unsigned int track)
|
unsigned int length, unsigned int track)
|
||||||
: _album(album), _artist(artist), _genre(genre), _library(library),
|
: _album(album), _artist(artist), _genre(genre), _library(library),
|
||||||
_count(0), _track(track)
|
_count(0), _length(length), _track(track)
|
||||||
{
|
{
|
||||||
_library->inc_size();
|
_library->inc_size();
|
||||||
}
|
}
|
||||||
|
@ -30,5 +30,6 @@ Artist *Track :: artist() { return _artist; }
|
||||||
Genre *Track :: genre() { return _genre; }
|
Genre *Track :: genre() { return _genre; }
|
||||||
Library *Track :: library() { return _library; }
|
Library *Track :: library() { return _library; }
|
||||||
|
|
||||||
unsigned int Track :: count() { return _count; }
|
unsigned int Track :: count() { return _count; }
|
||||||
unsigned int Track :: track() { return _track; }
|
unsigned int Track :: length() { return _length; }
|
||||||
|
unsigned int Track :: track() { return _track; }
|
||||||
|
|
|
@ -44,14 +44,13 @@ private:
|
||||||
Genre *_genre; /**< Pointer to the Genre describing this track. */
|
Genre *_genre; /**< Pointer to the Genre describing this track. */
|
||||||
Library *_library; /**< Pointer to the Library containing this track. */
|
Library *_library; /**< Pointer to the Library containing this track. */
|
||||||
|
|
||||||
unsigned int _count; /**< Number of times this track has been played. */
|
unsigned int _count; /**< Number of times this track has been played.*/
|
||||||
unsigned int _track; /**< Track number of this track. */
|
unsigned int _length; /**< Length of this track (in seconds). */
|
||||||
|
unsigned int _track; /**< Track number of this track. */
|
||||||
|
|
||||||
void set_length_str();
|
void set_length_str();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** Length of this track (in seconds) */
|
|
||||||
unsigned int length;
|
|
||||||
/** The year this track was last played */
|
/** The year this track was last played */
|
||||||
unsigned int last_year;
|
unsigned int last_year;
|
||||||
/** The month this track was last played */
|
/** The month this track was last played */
|
||||||
|
@ -78,9 +77,10 @@ public:
|
||||||
* @param artist The artist performing this track.
|
* @param artist The artist performing this track.
|
||||||
* @param genre The genre describing this track.
|
* @param genre The genre describing this track.
|
||||||
* @param library The library containing this track.
|
* @param library The library containing this track.
|
||||||
|
* @param length The length of this track (in seconds).
|
||||||
* @param track The track number of this track.
|
* @param track The track number of this track.
|
||||||
*/
|
*/
|
||||||
Track(Album *, Artist *, Genre *, Library *, unsigned int);
|
Track(Album *, Artist *, Genre *, Library *, unsigned int, unsigned int);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Track constructor
|
* Track constructor
|
||||||
|
@ -98,8 +98,9 @@ public:
|
||||||
Genre *genre(); /**< @return Track::_genre. */
|
Genre *genre(); /**< @return Track::_genre. */
|
||||||
Library *library(); /**< @return Track::_library. */
|
Library *library(); /**< @return Track::_library. */
|
||||||
|
|
||||||
unsigned int count(); /**< @return Track::_count. */
|
unsigned int count(); /**< @return Track::_count. */
|
||||||
unsigned int track(); /**< @return Track::_track. */
|
unsigned int length(); /**< @return Track::_length. */
|
||||||
|
unsigned int track(); /**< @return Track::_track. */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called to access a track's primary key
|
* Called to access a track's primary key
|
||||||
|
|
|
@ -159,7 +159,7 @@ void test_add_remove()
|
||||||
|
|
||||||
test :: begin();
|
test :: begin();
|
||||||
for (unsigned int i = 23; i >= 12; i--) {
|
for (unsigned int i = 23; i >= 12; i--) {
|
||||||
expected -= q[i]->length;
|
expected -= q[i]->length();
|
||||||
q.del(i);
|
q.del(i);
|
||||||
}
|
}
|
||||||
test :: success();
|
test :: success();
|
||||||
|
|
|
@ -23,7 +23,7 @@ static void test_track_tag_default()
|
||||||
test_equal(track.length_str, (std::string)"");
|
test_equal(track.length_str, (std::string)"");
|
||||||
|
|
||||||
test_equal(track.track(), (unsigned)0);
|
test_equal(track.track(), (unsigned)0);
|
||||||
test_equal(track.length, (unsigned)0);
|
test_equal(track.length(), (unsigned)0);
|
||||||
test_equal(track.count(), (unsigned)0);
|
test_equal(track.count(), (unsigned)0);
|
||||||
test_equal(track.last_year, (unsigned)0);
|
test_equal(track.last_year, (unsigned)0);
|
||||||
test_equal(track.last_month, (unsigned)0);
|
test_equal(track.last_month, (unsigned)0);
|
||||||
|
@ -36,7 +36,7 @@ static void test_track_tag_constructor()
|
||||||
Artist *artist = tags :: get_artist("Koji Kondo");
|
Artist *artist = tags :: get_artist("Koji Kondo");
|
||||||
Genre *genre = tags :: get_genre("Video Game Music");
|
Genre *genre = tags :: get_genre("Video Game Music");
|
||||||
Library *library = tags :: get_library("/home/Zelda/Music");
|
Library *library = tags :: get_library("/home/Zelda/Music");
|
||||||
Track track(album, artist, genre, library, 13);
|
Track track(album, artist, genre, library, 288, 13);
|
||||||
|
|
||||||
test_equal(track.album(), album);
|
test_equal(track.album(), album);
|
||||||
test_equal(track.artist(), artist);
|
test_equal(track.artist(), artist);
|
||||||
|
@ -44,8 +44,9 @@ static void test_track_tag_constructor()
|
||||||
test_equal(track.library(), library);
|
test_equal(track.library(), library);
|
||||||
test_equal(library->size(), (unsigned)1);
|
test_equal(library->size(), (unsigned)1);
|
||||||
|
|
||||||
test_equal(track.track(), (unsigned)13);
|
test_equal(track.track(), (unsigned)13);
|
||||||
test_equal(track.count(), (unsigned)0);
|
test_equal(track.length(), (unsigned)288);
|
||||||
|
test_equal(track.count(), (unsigned)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_track_tag_destructor()
|
static void test_track_tag_destructor()
|
||||||
|
|
Loading…
Reference in New Issue