Download Aqualung User's Manual

Transcript
Aqualung User’s Manual
31
end
-- A string indicating the frequency in Hz, or the empty string if the frequency is 44100
function freq()
local hz = string.format("%i", i(’sample_rate’))
if hz == "44100" then
hz = ""
else
hz = formatif(hz, "[%sHz] ")
end
return hz
end
-- A string indicating the number of channels, unless the number of channels is 2 (stereo)
function chan()
local m = string.format("%i", i(’channels’))
if m == "2" then
m = ""
elseif m == "1" then
m = "[MONO] "
else
m = formatif(m, "[%s channels] ")
end
return m
end
-- Pad the string to the given length, adding spaces if it is too short and truncating
-- it if it is too long
function pad(s, n)
local l = string.len(s)
if l > n then
s = string.sub(s, 1, n)
else
s = s .. string.rep(’ ’, n-l)
end
return s
end
-- Combine the left and right sides, with the right side having priority
function finalize(l, r)
return pad(l, maxlen - string.len(r)) .. r
end
-- Build the title in two parts, a left part (channel and frequency expections, album,
-- track number, title) and a right part (artist, genre, comment, date, and gain).
-- The right part is columnar, the left side is not.
function playlist_title()
local l = chan() .. freq() .. formatif(album_or_dir(), "%s-")
.. formatif(m(’trackno’), "%s-") .. title_or_file()
local r = " " .. m(’artist’) .. " " .. formatif(m("genre"), "%s ")
.. pad(m(’comment’), 12) .. " " .. pad(m("date"), 4) .. " "
.. pad(m(’track_gain’), 5) .. " " .. pad(m(’album_gain’), 5)
return finalize(l, r)
end
Results: