Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix append operator. #4152

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading