libsaria: Convert length into a string

I format it into mm:ss format for UIs to display.
This commit is contained in:
Bryan Schumaker 2011-09-18 11:39:18 -04:00
parent 3255b045f0
commit a685023bcb
2 changed files with 21 additions and 11 deletions

View File

@ -13,6 +13,7 @@ class TrackTag
string album;
string comment;
string genre;
string lenstr;
unsigned int year;
unsigned int track;
int length;
@ -20,10 +21,11 @@ class TrackTag
int sample;
int channels;
void make_lenstr();
public:
TrackTag(string);
~TrackTag();
void print_tag();
};
#endif /* LIBSARIA_TAGS_H */

View File

@ -6,17 +6,23 @@
#include <taglib/fileref.h>
using namespace TagLib;
void TrackTag::print_tag()
#include <sstream>
using namespace std;
void TrackTag::make_lenstr()
{
println("Title:\t" + title);
println("Artist:\t" + artist);
println("Album:\t" + album);
println("Comment:\t" + comment);
println("Genre:\t" + genre);
print("Year:\t");
println(year);
print("Track:\t");
println(track);
int minutes;
int seconds;
stringstream stream;
/* Convert length into mm:ss format */
minutes = length / 60;
seconds = length - (minutes * 60);
stream << minutes << ":";
if (seconds < 10)
stream << "0";
stream << seconds;
lenstr = stream.str();
}
TrackTag::TrackTag(string file)
@ -45,6 +51,8 @@ TrackTag::TrackTag(string file)
bitrate = prop->bitrate();
sample = prop->sampleRate();
channels = prop->channels();
make_lenstr();
}
TrackTag::~TrackTag()