Skip to content

Commit

Permalink
Fix append operator. (#4152)
Browse files Browse the repository at this point in the history
  • Loading branch information
toots authored Oct 1, 2024
1 parent fb38672 commit a25ebbe
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/libs/source.liq
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,19 @@ def append(~id=null("append"), ~insert_missing=true, ~merge=false, s, f) =
p = pending()
pending := null()
last_meta := null()

if
null.defined(p)
then
p = null.get(p)
sequence(merge=merge, [p, s])
else
s
null()
end
end

d = source.dynamic(track_sensitive=true, next)
s = fallback(id=id, track_sensitive=true, [d, s])
d = source.dynamic(track_sensitive=false, next)
s = fallback(id=id, track_sensitive=false, [d, s])
s.{
pending=
# Return the pending source
Expand Down
30 changes: 30 additions & 0 deletions tests/regression/append-merge.liq
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
music = chop(every=1., metadata=[("source", "s1")], sine(amplitude=0.1, 440.))

def next(_) =
s = sine(amplitude=0.1, duration=.5, 880.)
metadata.map(insert_missing=true, fun (_) -> [("source", "s2")], s)
end

s = append(merge=true, music, next)

count_s1 = ref(0)
count_s2 = ref(0)

s.on_metadata(
fun (m) ->
begin
s = m["source"]
if
s == "s1"
then
ref.incr(count_s1)
elsif s == "s2" then ref.incr(count_s2)
end

if count_s1() > 2 and count_s2() > 2 then test.pass() end
end
)

s.on_track(fun (m) -> if m["source"] == "s2" then test.fail() end)

output.dummy(s)
26 changes: 26 additions & 0 deletions tests/regression/append.liq
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
music = chop(every=1., metadata=[("source", "s1")], sine(amplitude=0.1, 440.))

def next(_) =
s = sine(amplitude=0.1, duration=.5, 880.)
metadata.map(insert_missing=true, fun (_) -> [("source", "s2")], s)
end

s = append(music, next)

count_s1 = ref(0)
count_s2 = ref(0)

s.on_metadata(fun (m) -> begin
s = m["source"]
if s == "s1" then
ref.incr(count_s1)
elsif s == "s2" then
ref.incr(count_s2)
end

if count_s1() > 2 and count_s2() > 2 then
test.pass()
end
end)

output.dummy(s)
32 changes: 32 additions & 0 deletions tests/regression/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,38 @@
(:run_test ../run_test.exe))
(action (run %{run_test} LS503.liq liquidsoap %{test_liq} LS503.liq)))

(rule
(alias citest)
(package liquidsoap)
(deps
append-merge.liq
../media/all_media_files
../../src/bin/liquidsoap.exe
../streams/file1.png
../streams/file1.mp3
./theora-test.mp4
(package liquidsoap)
(source_tree ../../src/libs)
(:test_liq ../test.liq)
(:run_test ../run_test.exe))
(action (run %{run_test} append-merge.liq liquidsoap %{test_liq} append-merge.liq)))

(rule
(alias citest)
(package liquidsoap)
(deps
append.liq
../media/all_media_files
../../src/bin/liquidsoap.exe
../streams/file1.png
../streams/file1.mp3
./theora-test.mp4
(package liquidsoap)
(source_tree ../../src/libs)
(:test_liq ../test.liq)
(:run_test ../run_test.exe))
(action (run %{run_test} append.liq liquidsoap %{test_liq} append.liq)))

(rule
(alias citest)
(package liquidsoap)
Expand Down

0 comments on commit a25ebbe

Please sign in to comment.