Code

keyboard: add keyboard_unread()
[ncmpc.git] / src / screen_song.c
index 973812b4e53d393db8d531e575ad044cf7b63ef6..c6d7d801e47299c3413079bc60577898d704f25f 100644 (file)
@@ -1,5 +1,5 @@
 /* ncmpc (Ncurses MPD Client)
- * (c) 2004-2010 The Music Player Daemon Project
+ * (c) 2004-2017 The Music Player Daemon Project
  * Project homepage: http://musicpd.org
  *
  * This program is free software; you can redistribute it and/or modify
@@ -365,6 +365,41 @@ screen_song_add_stats(struct mpd_connection *connection)
        return true;
 }
 
+static void
+audio_format_to_string(char *buffer, size_t size,
+                      const struct mpd_audio_format *format)
+{
+#if LIBMPDCLIENT_CHECK_VERSION(2,10,0)
+       if (format->bits == MPD_SAMPLE_FORMAT_FLOAT) {
+               g_snprintf(buffer, size, _("%u:f:%u"),
+                          format->sample_rate,
+                          format->channels);
+               return;
+       }
+
+       if (format->bits == MPD_SAMPLE_FORMAT_DSD) {
+               if (format->sample_rate > 0 &&
+                   format->sample_rate % 44100 == 0) {
+                       /* use shortcuts such as "dsd64" which implies the
+                          sample rate */
+                       g_snprintf(buffer, size, _("dsd%u:%u"),
+                                  format->sample_rate * 8 / 44100,
+                                  format->channels);
+                       return;
+               }
+
+               g_snprintf(buffer, size, _("%u:dsd:%u"),
+                          format->sample_rate,
+                          format->channels);
+               return;
+       }
+#endif
+
+       g_snprintf(buffer, size, _("%u:%u:%u"),
+                  format->sample_rate, format->bits,
+                  format->channels);
+}
+
 static void
 screen_song_update(struct mpdclient *c)
 {
@@ -410,9 +445,7 @@ screen_song_update(struct mpdclient *c)
                        mpd_status_get_audio_format(c->status);
                if (format) {
                        char buf[32];
-                       g_snprintf(buf, sizeof(buf), _("%u:%u:%u"),
-                                  format->sample_rate, format->bits,
-                                  format->channels);
+                       audio_format_to_string(buf, sizeof(buf), format);
                        screen_song_append(_(tag_labels[LABEL_FORMAT]), buf,
                                           max_tag_label_width);
                }