Skip to content

Commit

Permalink
Reformat files. (#3508)
Browse files Browse the repository at this point in the history
  • Loading branch information
toots authored Nov 7, 2023
1 parent 61f7c9c commit 8a80fe6
Show file tree
Hide file tree
Showing 24 changed files with 413 additions and 207 deletions.
52 changes: 41 additions & 11 deletions src/libs/replaygain.liq
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ let file.replaygain = ()
# @flag hidden
def file.replaygain.compute(~ratio=50., file_name) =
_request = request.create(resolve_metadata=false, file_name)
if request.resolve(_request) then
if
request.resolve(_request)
then
_source = source.replaygain.compute(request.once(_request))
source.drop(ratio=ratio, _source)
_source.gain()
Expand All @@ -32,13 +34,17 @@ end
# @category Metadata
# @param _metadata Metadata from which the ReplayGain should be extracted.
def metadata.replaygain(_metadata) =
if list.assoc.mem("r128_track_gain", _metadata) then
if
list.assoc.mem("r128_track_gain", _metadata)
then
try
float_of_string(_metadata["r128_track_gain"]) / 256.
catch _ do
null()
end
elsif list.assoc.mem("replaygain_track_gain", _metadata) then
elsif
list.assoc.mem("replaygain_track_gain", _metadata)
then
replaygain_metadata = _metadata["replaygain_track_gain"]
match = r/([+-]?\d*\.?\d*)/.exec(replaygain_metadata)
try
Expand All @@ -65,16 +71,33 @@ def replaces file.replaygain(~id=null(), ~compute=true, ~ratio=50., file_name) =
_metadata = file.metadata(exclude=["replaygain_track_gain"], file_name)
gain = metadata.replaygain(_metadata)

if gain != null() then
log.info(label=id, "Detected track replaygain #{gain} dB for #{file_name_quoted}.")
if
gain != null()
then
log.info(
label=id,
"Detected track replaygain #{gain} dB for #{file_name_quoted}."
)
gain
elsif compute then
log.info(label=id, "Computing replay gain for #{file_name_quoted}.")
elsif
compute
then
log.info(
label=id,
"Computing replay gain for #{file_name_quoted}."
)
start_time = time()
gain = file.replaygain.compute(ratio=ratio, file_name)
elapsed_time = time() - start_time
if gain != null() then
log.info(label=id, "Computed replay gain #{gain} dB for #{file_name_quoted} (time: #{elapsed_time} s).")
if
gain != null()
then
log.info(
label=id,
"Computed replay gain #{gain} dB for #{file_name_quoted} (time: #{
elapsed_time
} s)."
)
end
gain
else
Expand All @@ -93,8 +116,15 @@ end
def enable_replaygain_metadata(~compute=true, ~ratio=50.) =
def replaygain_metadata(~metadata=_, file_name) =
gain = file.replaygain(compute=compute, ratio=ratio, file_name)
if gain != null() then
[("replaygain_track_gain", "#{null.get(gain)} dB")]
if
gain != null()
then
[
(
"replaygain_track_gain",
"#{null.get(gain)} dB"
)
]
else
[]
end
Expand Down
2 changes: 1 addition & 1 deletion tests/failures/ctype.liq
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Testing dynamic kind unification errors.

s = mean(sine())
def mkfilter(graph)
def mkfilter(graph) =
x = ffmpeg.filter.audio.input(channels=2, graph, s)
ffmpeg.filter.audio.output(graph, x)
end
Expand Down
4 changes: 3 additions & 1 deletion tests/failures/error.liq
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Test uncaught errors.

def f() =
error.raise("testing exceptions")
error.raise(
"testing exceptions"
)
end

f()
8 changes: 6 additions & 2 deletions tests/failures/ref.liq
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

# Ensure that value restriction prevents the usual problems.

def id(x) = x end
def id(x) =
x
end

def incr(n) = n+1 end
def incr(n) =
n + 1
end

r = ref(id)
r := incr
Expand Down
16 changes: 7 additions & 9 deletions tests/fixme/GH1170.liq
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,24 @@ s = noise()

s = chop(duration=20., s)

track_count = ref 0
track_count = ref
0

def f(_) =
track_count := !track_count + 1

# Let's do 3 tracks here for security.
if !track_count > 2 then
test.pass()
end
if !track_count > 2 then test.pass() end
end

s = on_track(f,s)
s = on_track(f, s)

s = crossfade(s)

clock.assign_new(sync="none",[s])
clock.assign_new(sync="none", [s])

def on_stop() =
if !track_count < 3 then
test.fail()
end
if !track_count < 3 then test.fail() end
end

output.dummy(on_stop=on_stop, fallible=true, s)
2 changes: 1 addition & 1 deletion tests/fixme/cross2.liq
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jingle = playlist("files/jingles")
# id). The inference thus thinks that a.source has methods. And the function f
# thus cannot be passed to cross because it is not general enough.

def f(a, b)
def f(a, b) =
sequence([a.source, once(jingle), b.source])
end

Expand Down
8 changes: 4 additions & 4 deletions tests/fixme/cross3.liq
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
# Our main source.
s = 3.

def once((s:float))
s.{id = "bla"}
def once((s:float)) =
s.{id="bla"}
end

# Here, because of once, we infer that f should take as argument a source with
# many methods (id, etc.). However, we use it with cross below, which takes a
# function operating on undecorated sources.
def f(a)
def f(a) =
ignore([once(2.), a])
end

def cross((f : (float) -> unit), s)
def cross((f:(float)->unit), s) =
ignore(f)
s
end
Expand Down
22 changes: 11 additions & 11 deletions tests/fixme/sequence-1.liq
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ s = once(sine(duration=1.))
# behavior at this point is to go back to seq2, which will notice that s has
# become unavailable and end its track and cleanup s. (By then s will be free,
# because seq1 will have also move away from it.)
test = fallback(track_sensitive=false,
[ delay(initial=true,0.5,
sequence(id="seq1",[s,fail()])),
sequence(id="seq2",[s,fail()]) ])
test =
fallback(
track_sensitive=false,
[
delay(initial=true, 0.5, sequence(id="seq1", [s, fail()])),
sequence(id="seq2", [s, fail()])
]
)

def check()
if source.is_up(s) then
test.fail()
else
test.pass()
end
def check() =
if source.is_up(s) then test.fail() else test.pass() end
end

output.dummy(fallback([test,on_track(fun(_)->check(),sine())]))
output.dummy(fallback([test, on_track(fun (_) -> check(), sine())]))
18 changes: 7 additions & 11 deletions tests/fixme/sequence-2.liq
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,16 @@
# Create a fallible source. We use the experimental operator source.dynamic()
# which is bit fragile for a test.

flag = ref true
thread.run(delay=1., { flag:=false })
flag = ref(true)
thread.run(delay=1., {flag := false})
on = sine()
off = fail()
s = source.dynamic({ if !flag then [on] else [off] end })
s = source.dynamic({if !flag then [on] else [off] end})

test = sequence([ s, fail() ])
test = sequence([s, fail()])

def check()
if source.is_up(s) then
test.fail()
else
test.pass()
end
def check() =
if source.is_up(s) then test.fail() else test.pass() end
end

output.dummy(fallback([test,on_track(fun(_)->check(),sine())]))
output.dummy(fallback([test, on_track(fun (_) -> check(), sine())]))
24 changes: 15 additions & 9 deletions tests/language/encoders.liq
Original file line number Diff line number Diff line change
@@ -1,47 +1,53 @@
def f() =
def five_point_one(s) =
if false then
output.file(%ffmpeg(%audio(channel_layout=5.1)), "", s)
end
if false then output.file(%ffmpeg(%audio(channel_layout = 5.1)), "", s) end
end
five_point_one((sine():source(audio=pcm(5.1))))
five_point_one((sine() : source(audio=pcm(5.1))))

try
enc = %wav(samplesize = 123456)
catch err do
if
err.kind != "encoder"
or
err.message !=

err.message !=
"invalid sample size"

then
test.fail()
end
end

try
let eval _ = "l = [%wav(channels=1), %wav(channels=2)]"
let eval _ =
"l = [%wav(channels=1), %wav(channels=2)]"
test.fail()
catch _ do
()
end

try
let eval _ = "l = [%mp3(stereo), %wav(channels=1)]"
let eval _ =
"l = [%mp3(stereo), %wav(channels=1)]"
test.fail()
catch _ do
()
end

try
let eval _ = "l = [(blank():source(audio=pcm(stereo))), (blank():source(audio=pcm(mono)))]"
let eval _ =
"l = [(blank():source(audio=pcm(stereo))), \
(blank():source(audio=pcm(mono)))]"
test.fail()
catch _ do
()
end

try
let eval _ = "l = [(blank():source(audio=pcm(mono))), (blank():source(audio=pcm(stereo)))]"
let eval _ =
"l = [(blank():source(audio=pcm(mono))), \
(blank():source(audio=pcm(stereo)))]"
test.fail()
catch _ do
()
Expand Down
Loading

0 comments on commit 8a80fe6

Please sign in to comment.