summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2020-08-09 09:23:38 +0200
committerLars-Dominik Braun <lars@6xq.net>2020-08-09 09:23:38 +0200
commit4c228cd60890c0ef09c345c13713453c4c2dd508 (patch)
tree12b39298dd172291ea82529354578cf6e0cf8d73
parentbc6bd8a2b8b84a79dd77b81d6a25b661c5d1d1ca (diff)
downloadpianobar-4c228cd60890c0ef09c345c13713453c4c2dd508.tar.gz
pianobar-4c228cd60890c0ef09c345c13713453c4c2dd508.tar.bz2
pianobar-4c228cd60890c0ef09c345c13713453c4c2dd508.zip
Allow choosing time format
Introduce new format string for playback time, supporting formats like -remaining/total, elapsed/total, … Fixes #699.
-rw-r--r--contrib/config-example1
-rw-r--r--contrib/pianobar.116
-rw-r--r--src/main.c23
-rw-r--r--src/settings.c5
-rw-r--r--src/settings.h2
-rw-r--r--src/ui.c2
-rw-r--r--src/ui.h2
7 files changed, 43 insertions, 8 deletions
diff --git a/contrib/config-example b/contrib/config-example
index d6186c4..5f5dc2d 100644
--- a/contrib/config-example
+++ b/contrib/config-example
@@ -60,6 +60,7 @@
#tired_icon = zZ
#format_nowplaying_station = Station %n
#format_list_song = %i) %a - %t%r (%d)%@%s
+#format_time = %e/%t
#rpc_host = internal-tuner.pandora.com
#partner_user = pandora one
diff --git a/contrib/pianobar.1 b/contrib/pianobar.1
index 0cdf6c8..c5b82aa 100644
--- a/contrib/pianobar.1
+++ b/contrib/pianobar.1
@@ -329,6 +329,22 @@ Station name
Station id
.TP
+.B format_time = %s%r/%t
+Time format.
+
+.B %e
+Elapsed time
+
+.B %r
+Remaining time
+
+.B %s
+Sign
+
+.B %t
+Total time
+
+.TP
.B gain_mul = 1.0
Pandora sends a ReplayGain value with every song. This sets a multiplier so that the gain adjustment can be
reduced. 0.0 means no gain adjustment, 1.0 means full gain adjustment, values inbetween reduce the magnitude
diff --git a/src/main.c b/src/main.c
index de09fb7..c726b28 100644
--- a/src/main.c
+++ b/src/main.c
@@ -312,7 +312,7 @@ static void BarMainPlayerCleanup (BarApp_t *app, pthread_t *playerThread) {
*/
static void BarMainPrintTime (BarApp_t *app) {
unsigned int songRemaining;
- char sign;
+ char sign[2] = {0, 0};
player_t * const player = &app->player;
pthread_mutex_lock (&player->lock);
@@ -322,15 +322,26 @@ static void BarMainPrintTime (BarApp_t *app) {
if (songPlayed <= songDuration) {
songRemaining = songDuration - songPlayed;
- sign = '-';
+ sign[0] = '-';
} else {
/* longer than expected */
songRemaining = songPlayed - songDuration;
- sign = '+';
+ sign[0] = '+';
}
- BarUiMsg (&app->settings, MSG_TIME, "%c%02u:%02u/%02u:%02u\r",
- sign, songRemaining / 60, songRemaining % 60,
- songDuration / 60, songDuration % 60);
+
+ char outstr[512], totalFormatted[16], remainingFormatted[16],
+ elapsedFormatted[16];
+ const char *vals[] = {totalFormatted, remainingFormatted,
+ elapsedFormatted, sign};
+ snprintf (totalFormatted, sizeof (totalFormatted), "%02u:%02u",
+ songDuration/60, songDuration%60);
+ snprintf (remainingFormatted, sizeof (remainingFormatted), "%02u:%02u",
+ songRemaining/60, songRemaining%60);
+ snprintf (elapsedFormatted, sizeof (elapsedFormatted), "%02u:%02u",
+ songPlayed/60, songPlayed%60);
+ BarUiCustomFormat (outstr, sizeof (outstr), app->settings.timeFormat,
+ "tres", vals);
+ BarUiMsg (&app->settings, MSG_TIME, "%s\r", outstr);
}
/* main loop
diff --git a/src/settings.c b/src/settings.c
index 7518177..5859b82 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -124,6 +124,7 @@ void BarSettingsDestroy (BarSettings_t *settings) {
free (settings->npSongFormat);
free (settings->npStationFormat);
free (settings->listSongFormat);
+ free (settings->timeFormat);
free (settings->fifo);
free (settings->audioPipe);
free (settings->rpcHost);
@@ -175,6 +176,7 @@ void BarSettingsRead (BarSettings_t *settings) {
settings->npSongFormat = strdup ("\"%t\" by \"%a\" on \"%l\"%r%@%s");
settings->npStationFormat = strdup ("Station \"%n\" (%i)");
settings->listSongFormat = strdup ("%i) %a - %t%r");
+ settings->timeFormat = strdup ("%s%r/%t");
settings->rpcHost = strdup (PIANO_RPC_HOST);
settings->rpcTlsPort = strdup ("443");
settings->partnerUser = strdup ("android");
@@ -389,6 +391,9 @@ void BarSettingsRead (BarSettings_t *settings) {
} else if (streq ("format_list_song", key)) {
free (settings->listSongFormat);
settings->listSongFormat = strdup (val);
+ } else if (streq ("format_time", key)) {
+ free (settings->timeFormat);
+ settings->timeFormat = strdup (val);
} else if (streq ("fifo", key)) {
free (settings->fifo);
settings->fifo = BarSettingsExpandTilde (val, userhome);
diff --git a/src/settings.h b/src/settings.h
index 1a9b256..2e5a378 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -100,7 +100,7 @@ typedef struct {
char *atIcon;
char *npSongFormat;
char *npStationFormat;
- char *listSongFormat;
+ char *listSongFormat, *timeFormat;
char *fifo;
char *rpcHost, *rpcTlsPort, *partnerUser, *partnerPassword, *device, *inkey, *outkey, *caBundle;
char *audioPipe;
diff --git a/src/ui.c b/src/ui.c
index 99b74c3..1ab54ae 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -652,7 +652,7 @@ char *BarUiSelectMusicId (BarApp_t *app, PianoStation_t *station,
* @param format characters
* @param replacement for each given format character
*/
-static void BarUiCustomFormat (char *dest, size_t destSize, const char *format,
+void BarUiCustomFormat (char *dest, size_t destSize, const char *format,
const char *formatChars, const char **formatVals) {
bool haveFormatChar = false;
diff --git a/src/ui.h b/src/ui.h
index da6bd8e..33d2a76 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -53,4 +53,6 @@ void BarUiStartEventCmd (const BarSettings_t *, const char *,
bool BarUiPianoCall (BarApp_t * const, const PianoRequestType_t,
void *, PianoReturn_t *, CURLcode *);
void BarUiHistoryPrepend (BarApp_t *app, PianoSong_t *song);
+void BarUiCustomFormat (char *dest, size_t destSize, const char *format,
+ const char *formatChars, const char **formatVals);