improve time displaying / allow markers for empty tags without color
This commit is contained in:
20
src/misc.cpp
20
src/misc.cpp
@@ -46,23 +46,3 @@ string IntoStr(double liczba, int precision)
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
string ShowTime(int length)
|
||||
{
|
||||
stringstream ss;
|
||||
|
||||
int minutes = length/60;
|
||||
length -= minutes*60;
|
||||
int seconds = length;
|
||||
|
||||
ss << minutes << ":";
|
||||
if (seconds == 0)
|
||||
{ ss << "00";
|
||||
return ss.str();
|
||||
}
|
||||
if (seconds < 10)
|
||||
ss << "0" << seconds;
|
||||
else
|
||||
ss << seconds;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,5 @@ int StrToInt(string);
|
||||
string IntoStr(int);
|
||||
string IntoStr(double, int);
|
||||
|
||||
string ShowTime(int);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -2060,7 +2060,7 @@ int main(int argc, char *argv[])
|
||||
songpos = 0;
|
||||
|
||||
wFooter->Bold(1);
|
||||
string tracklength = "[" + ShowTime(songpos) + "/" + s.GetLength() + "]";
|
||||
string tracklength = "[" + Song::ShowTime(songpos) + "/" + s.GetLength() + "]";
|
||||
wFooter->WriteXY(wFooter->GetWidth()-tracklength.length(), 1, tracklength);
|
||||
double progressbar_size = (double)songpos/(s.GetTotalLength());
|
||||
int howlong = wFooter->GetWidth()*progressbar_size;
|
||||
|
||||
71
src/song.cpp
71
src/song.cpp
@@ -30,16 +30,25 @@ string UNKNOWN_ALBUM;
|
||||
|
||||
void DefineEmptyTags()
|
||||
{
|
||||
const string et_col = IntoStr(Config.empty_tags_color);
|
||||
EMPTY_TAG = "[." + et_col + "]<empty>[/" + et_col + "]";
|
||||
UNKNOWN_ARTIST = "[." + et_col + "]<no artist>[/" + et_col + "]";
|
||||
UNKNOWN_TITLE = "[." + et_col + "]<no title>[/" + et_col + "]";
|
||||
UNKNOWN_ALBUM = "[." + et_col + "]<no album>[/" + et_col + "]";
|
||||
if (Config.empty_tags_color != clDefault)
|
||||
{
|
||||
const string et_col = IntoStr(Config.empty_tags_color);
|
||||
EMPTY_TAG = "[." + et_col + "]<empty>[/" + et_col + "]";
|
||||
UNKNOWN_ARTIST = "[." + et_col + "]<no artist>[/" + et_col + "]";
|
||||
UNKNOWN_TITLE = "[." + et_col + "]<no title>[/" + et_col + "]";
|
||||
UNKNOWN_ALBUM = "[." + et_col + "]<no album>[/" + et_col + "]";
|
||||
}
|
||||
else
|
||||
{
|
||||
EMPTY_TAG = "<empty>";
|
||||
UNKNOWN_ARTIST = "<no artist>";
|
||||
UNKNOWN_TITLE = "<no title>";
|
||||
UNKNOWN_ALBUM = "<no album";
|
||||
}
|
||||
}
|
||||
|
||||
Song::Song(mpd_Song *s) : itsHash(0),
|
||||
itsMinutesLength(s->time/60),
|
||||
itsSecondsLength((s->time-itsMinutesLength*60)),
|
||||
itsLength(s->time),
|
||||
itsPosition(s->pos),
|
||||
itsID(s->id),
|
||||
itsGetEmptyFields(0)
|
||||
@@ -85,22 +94,9 @@ Song::Song(mpd_Song *s) : itsHash(0),
|
||||
|
||||
string Song::GetLength() const
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
if (!GetTotalLength())
|
||||
if (!itsLength)
|
||||
return "-:--";
|
||||
|
||||
ss << itsMinutesLength << ":";
|
||||
if (!itsSecondsLength)
|
||||
{
|
||||
ss << "00";
|
||||
return ss.str();
|
||||
}
|
||||
if (itsSecondsLength < 10)
|
||||
ss << "0" << itsSecondsLength;
|
||||
else
|
||||
ss << itsSecondsLength;
|
||||
return ss.str();
|
||||
return ShowTime(itsLength);
|
||||
}
|
||||
|
||||
void Song::Clear()
|
||||
@@ -119,15 +115,14 @@ void Song::Clear()
|
||||
itsPerformer.clear();
|
||||
itsDisc.clear();
|
||||
itsComment.clear();
|
||||
itsMinutesLength = 0;
|
||||
itsSecondsLength = 0;
|
||||
itsLength = 0;
|
||||
itsPosition = 0;
|
||||
itsID = 0;
|
||||
}
|
||||
|
||||
bool Song::Empty() const
|
||||
{
|
||||
return itsFile.empty() && itsShortName.empty() && itsArtist.empty() && itsTitle.empty() && itsAlbum.empty() && itsTrack.empty() && itsYear.empty() && itsGenre.empty();
|
||||
return itsFile.empty() && itsShortName.empty() && itsArtist.empty() && itsTitle.empty() && itsAlbum.empty() && itsTrack.empty() && itsYear.empty() && itsGenre.empty() && itsComposer.empty() && itsPerformer.empty() && itsDisc.empty() && itsComment.empty();
|
||||
}
|
||||
|
||||
string Song::GetFile() const
|
||||
@@ -197,7 +192,7 @@ string Song::GetComment() const
|
||||
|
||||
bool Song::operator==(const Song &s) const
|
||||
{
|
||||
return itsFile == s.itsFile && itsArtist == s.itsArtist && itsTitle == s.itsTitle && itsAlbum == s.itsAlbum && itsTrack == s.itsTrack && itsYear == s.itsYear && itsGenre == s.itsGenre && itsComposer == s.itsComposer && itsPerformer == s.itsPerformer && itsDisc == s.itsDisc && itsComment == s.itsComment && itsHash == s.itsHash && itsMinutesLength && s.itsMinutesLength && itsSecondsLength == s.itsSecondsLength && itsPosition == s.itsPosition && itsID == s.itsID;
|
||||
return itsFile == s.itsFile && itsArtist == s.itsArtist && itsTitle == s.itsTitle && itsAlbum == s.itsAlbum && itsTrack == s.itsTrack && itsYear == s.itsYear && itsGenre == s.itsGenre && itsComposer == s.itsComposer && itsPerformer == s.itsPerformer && itsDisc == s.itsDisc && itsComment == s.itsComment && itsHash == s.itsHash && itsLength && s.itsLength && itsPosition == s.itsPosition && itsID == s.itsID;
|
||||
}
|
||||
|
||||
bool Song::operator!=(const Song &s) const
|
||||
@@ -210,3 +205,27 @@ bool Song::operator<(const Song &s) const
|
||||
return itsPosition < s.itsPosition;
|
||||
}
|
||||
|
||||
string Song::ShowTime(int length)
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
int hours = length/3600;
|
||||
length -= hours*3600;
|
||||
int minutes = length/60;
|
||||
length -= minutes*60;
|
||||
int seconds = length;
|
||||
|
||||
if (hours > 0)
|
||||
{
|
||||
ss << hours << ":"
|
||||
<< std::setw(2) << std::setfill('0') << minutes << ":"
|
||||
<< std::setw(2) << std::setfill('0') << seconds;
|
||||
}
|
||||
else
|
||||
{
|
||||
ss << minutes << ":"
|
||||
<< std::setw(2) << std::setfill('0') << seconds;
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
11
src/song.h
11
src/song.h
@@ -36,7 +36,7 @@ void DefineEmptyTags();
|
||||
class Song
|
||||
{
|
||||
public:
|
||||
Song() : itsHash(0), itsMinutesLength(0), itsSecondsLength(0), itsPosition(0), itsID(0), itsGetEmptyFields(0) { }
|
||||
Song() : itsHash(0), itsLength(0), itsPosition(0), itsID(0), itsGetEmptyFields(0) { }
|
||||
Song(mpd_Song *);
|
||||
~Song() {};
|
||||
|
||||
@@ -56,9 +56,7 @@ class Song
|
||||
string GetComment() const;
|
||||
string GetLength() const;
|
||||
long long GetHash() const { return itsHash; }
|
||||
int GetTotalLength() const { return itsSecondsLength < 0 ? 0 : itsMinutesLength*60+itsSecondsLength; }
|
||||
int GetMinutesLength() const { return itsMinutesLength; }
|
||||
int GetSecondsLength() const { return itsSecondsLength; }
|
||||
int GetTotalLength() const { return itsLength < 0 ? 0 : itsLength; }
|
||||
int GetPosition() const { return itsPosition; }
|
||||
int GetID() const { return itsID; }
|
||||
|
||||
@@ -85,6 +83,8 @@ class Song
|
||||
bool operator==(const Song &) const;
|
||||
bool operator!=(const Song &) const;
|
||||
bool operator<(const Song &rhs) const;
|
||||
|
||||
static string ShowTime(int);
|
||||
private:
|
||||
string itsFile;
|
||||
string itsShortName;
|
||||
@@ -102,8 +102,7 @@ class Song
|
||||
string itsDisc;
|
||||
string itsComment;
|
||||
long long itsHash;
|
||||
int itsMinutesLength;
|
||||
int itsSecondsLength;
|
||||
int itsLength;
|
||||
int itsPosition;
|
||||
int itsID;
|
||||
bool itsGetEmptyFields;
|
||||
|
||||
@@ -321,9 +321,9 @@ void NcmpcppStatusChanged(MPDConnection *Mpd, MPDStatusChanges changed, void *da
|
||||
{
|
||||
string tracklength;
|
||||
if (s.GetTotalLength())
|
||||
tracklength = " [" + ShowTime(elapsed) + "/" + s.GetLength() + "]";
|
||||
tracklength = " [" + Song::ShowTime(elapsed) + "/" + s.GetLength() + "]";
|
||||
else
|
||||
tracklength = " [" + ShowTime(elapsed) + "]";
|
||||
tracklength = " [" + Song::ShowTime(elapsed) + "]";
|
||||
my_string_t playing_song = TO_WSTRING(DisplaySong(s, &Config.song_status_format));
|
||||
|
||||
int max_length_without_scroll = wFooter->GetWidth()-player_state.length()-tracklength.length();
|
||||
|
||||
Reference in New Issue
Block a user