Discussion:
[RFC] More powerful format strings
Johannes Weißl
2011-01-24 08:51:25 UTC
Permalink
Hello!

with the recent request for codec/bitrate information, I remembered a
I don't like adding more format options, there are too many of them
already. But I've been planning to add conditionals support for format
" %02n. %(A%a / %t%:%t%)%= %y %d "
which would become
if (%A is set) {
" %02n. %a / %t%= %y %d "
} else {
" %02n. %t%= %y %d "
}
We could then even deprecate altformat_* options. I'm not sure about the
syntax, comments?
cmus does not support %A (albumartist) but it could be added. There are
also compilation, artistsort, albumartistsort keys so we should probably
allow long tag names, e.g. %{albumartist}, instead of adding more format
characters. Also %u or %{url} would be useful because I want to use
different format for streams.
I think conditionals and long tag names would be a great improvement to
cmus! For example I would like to display replaygain information, but I
can't think of a good way to map it to short characters. Also I have
to change many format options (format_playlist, format_playlist_va,
altformat_playlist) at once to get a consistent output.

So I thought maybe we can have a discussion if we want something like
this for cmus and how it should potentially look like (syntax)!

There is already a pretty popular format syntax used in the foobar2000
player and MusicBrainz Picard:
http://wiki.hydrogenaudio.org/index.php?title=Foobar2000:Title_Formatting_Reference
http://musicbrainz.org/doc/Picard_Qt/Scripting
The downside of a language like this is that we loose
backwards-compatibility and the c-like formating. Also the strings tend
to get really lengthy. The advantage is the great expressiveness and the
descriptive names (not too many special characters).


What are your comments / suggestions on this?


Greetings,
Johannes
gt
2011-01-24 10:09:13 UTC
Permalink
Post by Johannes Weißl
I think conditionals and long tag names would be a great improvement to
cmus! For example I would like to display replaygain information, but I
can't think of a good way to map it to short characters. Also I have
to change many format options (format_playlist, format_playlist_va,
altformat_playlist) at once to get a consistent output.
So I thought maybe we can have a discussion if we want something like
this for cmus and how it should potentially look like (syntax)!
There is already a pretty popular format syntax used in the foobar2000
http://wiki.hydrogenaudio.org/index.php?title=Foobar2000:Title_Formatting_Reference
http://musicbrainz.org/doc/Picard_Qt/Scripting
The downside of a language like this is that we loose
backwards-compatibility and the c-like formating. Also the strings tend
to get really lengthy. The advantage is the great expressiveness and the
descriptive names (not too many special characters).
What are your comments / suggestions on this?
Well i have been a fan of foobar while i used windows. I really liked
its syntax, and a similar one for cmus would be great and easier to
understand. But, as it is going to break backwards compatibility, and
c-like syntax, i think it's a very serious decision to take and this
should be discussed at length, and see how many people are comfortable
with this.
Gregory Petrosyan
2011-01-25 16:40:06 UTC
Permalink
Post by Johannes Weißl
Hello!
with the recent request for codec/bitrate information, I remembered a
I don't like adding more format options, there are too many of them
already.  But I've been planning to add conditionals support for format
    " %02n. %(A%a / %t%:%t%)%= %y %d "
which would become
    if (%A is set) {
            " %02n. %a / %t%= %y %d "
    } else {
            " %02n. %t%= %y %d "
    }
We could then even deprecate altformat_* options. I'm not sure about the
syntax, comments?
cmus does not support %A (albumartist) but it could be added.  There are
also compilation, artistsort, albumartistsort keys so we should probably
allow long tag names, e.g. %{albumartist}, instead of adding more format
characters.  Also %u or %{url} would be useful because I want to use
different format for streams.
I think conditionals and long tag names would be a great improvement to
cmus! For example I would like to display replaygain information, but I
can't think of a good way to map it to short characters. Also I have
to change many format options (format_playlist, format_playlist_va,
altformat_playlist) at once to get a consistent output.
So I thought maybe we can have a discussion if we want something like
this for cmus and how it should potentially look like (syntax)!
There is already a pretty popular format syntax used in the foobar2000
http://wiki.hydrogenaudio.org/index.php?title=Foobar2000:Title_Formatting_Reference
http://musicbrainz.org/doc/Picard_Qt/Scripting
The downside of a language like this is that we loose
backwards-compatibility and the c-like formating. Also the strings tend
to get really lengthy. The advantage is the great expressiveness and the
descriptive names (not too many special characters).
What are your comments / suggestions on this?
I am more of a person that wants really good defaults and doesn't
really care about configurability that much.

That being said, conditionals are great, can be implemented
backwards-compatible, and will definitely improve cmus' defaults.

How exactly do we lose backwards compatibility with long option names?
If we will require e.g. "%|" at the beginning of new-style format
strings to distinguish them, we will be fine, right?

f2k's syntax is fine IMHO. I don't think we really need a full-blown
formatting language, though :-)

                Gregory
Johannes Weißl
2011-01-25 17:28:04 UTC
Permalink
Post by Gregory Petrosyan
How exactly do we lose backwards compatibility with long option names?
If we will require e.g. "%|" at the beginning of new-style format
strings to distinguish them, we will be fine, right?
f2k's syntax is fine IMHO. I don't think we really need a full-blown
formatting language, though :-)
If we literally include f2k's syntax, we will loose compatibility:
"%artist%f" -> artist + "f" || artist + "rtist" + filename

However I do not consider f2k's titleformat appropriate for cmus, just
some ideas and constructs from it. Mainly because it formats GUI
columns, not a single line of text, so things often used in cmus are
very lengthy: "%20a" -> "$padcut_right(%artist%)"

I think a subset of the new Python format strings [1] would be a very
good replacement for the old c-style syntax. It fit's because Python
also replaced it's c-style formatting operations with it. Here are
some examples:

"%20a" -> "{artist:>20}" or "{a:>20}"
"%3n" -> "{tracknumber:3}" or "{n:3}"

Of course the old syntax can be kept for compatibility reasons.

From foobar2000 I would like to borrow something similar to the
conditional section [2] and some functions. A unified format_playlist
string could look like this:

$if($and({artist},{title}),{$if($isVA(),albumartist,artist):20} {tracknumber:3}. {title}$if($isVA(), ({artist})),{filename}){=} {date} {duration}

or shorter:
$if($and({a},{t}),{$if($isVA(),A,a):20} {n:3}. {t}$if($isVA(), ({a})),{f}){=} {y} {d}


which would translate to (python pseudo code):

str = ""
if artist and title:
tmp = albumartist if is_various_artist() else artist
str += "%20s %3d. %s" % (tmp, tracknumber, title)
if is_various_artist():
str += " (%s)" % artist
else:
str += filename
str += "%s %s %s" % (align_right, date, duration)


Any comments on this?


[1] http://docs.python.org/library/string.html#formatstrings
[2] http://wiki.hydrogenaudio.org/index.php?title=Foobar2000:Title_Formatting_Reference#.5B....5D_.28conditional_section.29



Johannes
Johannes Weißl
2011-03-16 00:57:30 UTC
Permalink
Hello,

I tried to come up with a format, but none of my attempts were
satisfying, so I let it rest. The problem is, if we have descriptive
names for conditionals, the format strings get very long. If we have
a short syntax, the string is nearly unreadable, e.g.

format_playlist= (%-20(%A%:%a%) %3n. %t %(%A%?%:(%t)%)%:%f%)%= %y %d

So maybe multiple format options are not so bad after all, at least the
strings are readable. The main reason for implementing conditionals for
me was the ability to change all format_playlist options at at once.

I attached a small shell script which accomplishes this via cmus-remote,
maybe it is useful for someone!

Example:
$ cmus_format_playlist.sh append "%6{rg_track_gain} dB %8{rg_track_peak} "
$ cmus_format_playlist.sh rstrip "%6{rg_track_gain} dB %8{rg_track_peak} "


Johannes

Loading...