Track: Convert length_str into a function
I don't think this value needs to be stored anywhere in the Track class since it's fairly easy to calculate. Let's convert it into a function for now and reevaluate later! Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
2540a6aa7a
commit
cdd20da5c0
|
@ -8,7 +8,6 @@
|
||||||
#include <core/filter.h>
|
#include <core/filter.h>
|
||||||
#include <core/print.h>
|
#include <core/print.h>
|
||||||
|
|
||||||
#include <sstream>
|
|
||||||
#include <taglib/tag.h>
|
#include <taglib/tag.h>
|
||||||
#include <taglib/fileref.h>
|
#include <taglib/fileref.h>
|
||||||
|
|
||||||
|
@ -54,7 +53,6 @@ void Track :: read(File &f)
|
||||||
filter :: add(_artist->name(), index());
|
filter :: add(_artist->name(), index());
|
||||||
filter :: add(_album->name(), index());
|
filter :: add(_album->name(), index());
|
||||||
_library->inc_size();
|
_library->inc_size();
|
||||||
set_length_str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Track :: write(File &f)
|
void Track :: write(File &f)
|
||||||
|
@ -67,19 +65,6 @@ void Track :: write(File &f)
|
||||||
f << std::endl << filepath << std::endl;
|
f << std::endl << filepath << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Track :: set_length_str()
|
|
||||||
{
|
|
||||||
std::stringstream ss;
|
|
||||||
unsigned int minutes = _length / 60;
|
|
||||||
unsigned int seconds = _length % 60;
|
|
||||||
|
|
||||||
ss << minutes << ":";
|
|
||||||
if (seconds < 10)
|
|
||||||
ss << "0";
|
|
||||||
ss << seconds;
|
|
||||||
length_str = ss.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline const std::string format_tag(const TagLib::String &str)
|
static inline const std::string format_tag(const TagLib::String &str)
|
||||||
{
|
{
|
||||||
return str.stripWhiteSpace().to8Bit(true);
|
return str.stripWhiteSpace().to8Bit(true);
|
||||||
|
@ -117,7 +102,6 @@ bool Track :: tag()
|
||||||
//_title = format_tag(tag->title());
|
//_title = format_tag(tag->title());
|
||||||
|
|
||||||
//title_lower = filter :: add(title, index());
|
//title_lower = filter :: add(title, index());
|
||||||
set_length_str();
|
|
||||||
|
|
||||||
filter :: add(_artist->name(), index());
|
filter :: add(_artist->name(), index());
|
||||||
filter :: add(_album->name(), index());
|
filter :: add(_album->name(), index());
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
*/
|
*/
|
||||||
#include <core/tags/track.h>
|
#include <core/tags/track.h>
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
|
||||||
Track :: Track()
|
Track :: Track()
|
||||||
: GenericTag(),
|
: GenericTag(),
|
||||||
|
@ -34,3 +36,16 @@ Library *Track :: library() { return _library; }
|
||||||
unsigned int Track :: count() { return _count; }
|
unsigned int Track :: count() { return _count; }
|
||||||
unsigned int Track :: length() { return _length; }
|
unsigned int Track :: length() { return _length; }
|
||||||
unsigned int Track :: track() { return _track; }
|
unsigned int Track :: track() { return _track; }
|
||||||
|
|
||||||
|
const std::string Track :: length_str() const
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
unsigned int minutes = _length / 60;
|
||||||
|
unsigned int seconds = _length % 60;
|
||||||
|
|
||||||
|
ss << minutes << ":";
|
||||||
|
if (seconds < 10)
|
||||||
|
ss << 0;
|
||||||
|
ss << seconds;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ static void on_track_loaded(Track *track)
|
||||||
set_label_text(title, "xx-large", track->name());
|
set_label_text(title, "xx-large", track->name());
|
||||||
set_label_text(artist, "x-large", "By: " + track->artist()->name());
|
set_label_text(artist, "x-large", "By: " + track->artist()->name());
|
||||||
set_label_text(album, "x-large", "From: " + track->album()->name());
|
set_label_text(album, "x-large", "From: " + track->album()->name());
|
||||||
duration->set_text(track->length_str);
|
duration->set_text(track->length_str());
|
||||||
|
|
||||||
bool banned = playlist :: has(track, "Banned");
|
bool banned = playlist :: has(track, "Banned");
|
||||||
bool favorite = playlist :: has(track, "Favorites");
|
bool favorite = playlist :: has(track, "Favorites");
|
||||||
|
|
|
@ -48,8 +48,6 @@ private:
|
||||||
unsigned int _length; /**< Length of this track (in seconds). */
|
unsigned int _length; /**< Length of this track (in seconds). */
|
||||||
unsigned int _track; /**< Track number of this track. */
|
unsigned int _track; /**< Track number of this track. */
|
||||||
|
|
||||||
void set_length_str();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** The year this track was last played */
|
/** The year this track was last played */
|
||||||
unsigned int last_year;
|
unsigned int last_year;
|
||||||
|
@ -60,8 +58,6 @@ public:
|
||||||
|
|
||||||
/** The filepath of this track, relative to the library root */
|
/** The filepath of this track, relative to the library root */
|
||||||
std :: string filepath;
|
std :: string filepath;
|
||||||
/** The length of this track in a human readable string */
|
|
||||||
std :: string length_str;
|
|
||||||
|
|
||||||
/** Track constructor */
|
/** Track constructor */
|
||||||
Track();
|
Track();
|
||||||
|
@ -100,6 +96,10 @@ public:
|
||||||
unsigned int length(); /**< @return Track::_length. */
|
unsigned int length(); /**< @return Track::_length. */
|
||||||
unsigned int track(); /**< @return Track::_track. */
|
unsigned int track(); /**< @return Track::_track. */
|
||||||
|
|
||||||
|
/** @return Track::_length in mm:ss format. */
|
||||||
|
const std::string length_str() const;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called to access a track's primary key
|
* Called to access a track's primary key
|
||||||
* @return The full path of the track
|
* @return The full path of the track
|
||||||
|
|
|
@ -143,7 +143,7 @@ void QueueModel::get_value_str(Track *track, int column,
|
||||||
specific.set(track->name());
|
specific.set(track->name());
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
specific.set(track->length_str);
|
specific.set(track->length_str());
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
specific.set(track->artist()->name());
|
specific.set(track->artist()->name());
|
||||||
|
|
|
@ -18,7 +18,7 @@ static void test_track_tag_default()
|
||||||
test_equal(track.lowercase(), (std::string)"");
|
test_equal(track.lowercase(), (std::string)"");
|
||||||
test_equal(track.primary_key(), (std::string)"");
|
test_equal(track.primary_key(), (std::string)"");
|
||||||
test_equal(track.filepath, (std::string)"");
|
test_equal(track.filepath, (std::string)"");
|
||||||
test_equal(track.length_str, (std::string)"");
|
test_equal(track.length_str(), (std::string)"0:00");
|
||||||
|
|
||||||
test_equal(track.track(), (unsigned)0);
|
test_equal(track.track(), (unsigned)0);
|
||||||
test_equal(track.length(), (unsigned)0);
|
test_equal(track.length(), (unsigned)0);
|
||||||
|
@ -44,6 +44,7 @@ static void test_track_tag_constructor()
|
||||||
|
|
||||||
test_equal(track.name(), (std::string)"Legend of Zelda Medley");
|
test_equal(track.name(), (std::string)"Legend of Zelda Medley");
|
||||||
test_equal(track.lowercase(), (std::string)"legend of zelda medley");
|
test_equal(track.lowercase(), (std::string)"legend of zelda medley");
|
||||||
|
test_equal(track.length_str(), (std::string)"4:48");
|
||||||
|
|
||||||
test_equal(track.track(), (unsigned)13);
|
test_equal(track.track(), (unsigned)13);
|
||||||
test_equal(track.length(), (unsigned)288);
|
test_equal(track.length(), (unsigned)288);
|
||||||
|
@ -56,10 +57,27 @@ static void test_track_tag_destructor()
|
||||||
test_equal(library->size(), (unsigned)0);
|
test_equal(library->size(), (unsigned)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_track_tag_functional()
|
||||||
|
{
|
||||||
|
Album *album = tags :: get_album("Hyrule Symphony", 1998);
|
||||||
|
Artist *artist = tags :: get_artist("Koji Kondo");
|
||||||
|
Genre *genre = tags :: get_genre("Video Game Music");
|
||||||
|
Library *library = tags :: get_library("/home/Zelda/Music");
|
||||||
|
Track track;
|
||||||
|
|
||||||
|
track = Track(album, artist, genre, library, "Kakariko Village", 186, 6);
|
||||||
|
test_equal(track.length_str(), (std::string)"3:06");
|
||||||
|
|
||||||
|
/* Not an actual track on the album, I just needed something < 1 min. */
|
||||||
|
track = Track(album, artist, genre, library, "Intro", 56, 0);
|
||||||
|
test_equal(track.length_str(), (std::string)"0:56");
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
run_test("Track Tag Default Constructor Test", test_track_tag_default);
|
run_test("Track Tag Default Constructor Test", test_track_tag_default);
|
||||||
run_test("Track Tag Constructor Test", test_track_tag_constructor);
|
run_test("Track Tag Constructor Test", test_track_tag_constructor);
|
||||||
run_test("Track Tag Destructor Test", test_track_tag_destructor);
|
run_test("Track Tag Destructor Test", test_track_tag_destructor);
|
||||||
|
run_test("Track Tag Functional Test", test_track_tag_functional);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue