1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
# We want:
# Track selection 1 -> s1 ready, s2 not ready -> switch to s1
# Track selection 2 -> s1 not ready, s2 ready -> switch to s2
# Track selection 3 -> s1 ready, s2 with weight 0 -> switch to s1
selected = ref([])
s1 = blank(duration=0.04)
def m1(_) =
[("id", "s1")]
end
s1 = metadata.map(insert_missing=true, id="s1-map", m1, s1)
s1_ready = ref(true)
s1 = switch(id="s1", track_sensitive=false, [(s1_ready, s1)])
s1_weight = ref(1)
s2 = blank(duration=0.04)
def m2(_) =
[("id", "s2")]
end
s2 = metadata.map(insert_missing=true, id="s2-map", m2, s2)
s2_ready = ref(false)
s2 = switch(id="s2", track_sensitive=false, [(s2_ready, s2)])
s2_weight = ref(1)
round = ref(1)
def f(m) =
if
round() == 1
then
s1_ready := false
s2_ready := true
elsif
round() == 2
then
s1_ready := true
s2_ready := true
s2_weight := 0
else
s1_ready := true
s1_weight := 2
s2_ready := true
s2_weight := 1
end
round := round() + 1
selected := list.cons(m["id"], selected())
end
s = random(weights=[s1_weight, s2_weight], [s1, s2])
s.on_track(synchronous=true, f)
output.dummy(fallible=true, s)
def on_done() =
s = list.rev(selected())
if
list.nth(default="", s, 0) == "s1"
and
list.nth(default="", s, 1) == "s2"
and
list.nth(default="", s, 2) == "s1"
then
test.pass()
else
test.fail()
end
end
thread.run(delay=1., on_done)
|