summaryrefslogtreecommitdiff
path: root/tests/test_functions_chaserstep.py
blob: 134b8939bc89fd4391fdd60fd7c6c3ee6318fee4 (plain)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import datetime as dt

import pytest

from blc2.functions.chaserstep import ChaserStep
from blc2.topology import Fixture
from blc2.functions.scene import Scene
from blc2.functions.audio import Audio
from blc2.workspace import Workspace
from blc2.constants import INHERIT, MANUAL, EXTERNAL, INTERNAL, INFTY

class DummyChaser:
    def register_step(self, *args, **kwargs):
        return

    def __init__(self, w):
        self.w = w

@pytest.fixture
def cw():
    w = Workspace("", "", "", dt.datetime.now())
    f = Fixture(w=w, id_=0, channel_count=1)
    c0, = f.channels
    f2 = Fixture(w=w, id_=1, channel_count=4)
    Scene(w=w, id_=0, values={c0: 255})
    Scene(w=w, id_=1, values={c: 255-i for i, c in enumerate(f2.channels)})
    Audio(w=w, id_=2, filename="tests/silence.m4a")

    return w

def test_chaserstep(cw):
    c = DummyChaser(cw)
    s0 = cw.functions[0]
    s1 = cw.functions[1]
    a = cw.functions[2]
    c0, = cw.fixtures[0].channels

    ## Test how it handles inherit
    cs1 = ChaserStep(c, function=s0, duration_mode=INHERIT)
    assert cs1.duration == INFTY
    assert cs1.actual_duration == INFTY
    assert cs1.fade_out_mode == s0.fade_out_mode
    assert cs1.scope == s0.scope
    assert cs1.audio_scope == s0.audio_scope

    cs1.fade_in = 1000
    cs1.fade_out = 1000
    assert cs1.duration == INFTY
    assert cs1.actual_duration == INFTY

    data = cs1._get_data(0, 0)
    lc, ac, data = cs1.render(500, data)
    assert not ac
    assert lc == ((c0, 127),)

    lc, ac, data = cs1.render(1000, data)
    assert not ac
    assert lc == ((c0, 255),)

    data.end_time = 1500
    lc, ac, data = cs1.render(2000, data)
    assert not ac
    assert lc == ((c0, 127),)

    lc, ac, data = cs1.render(2501, data)
    assert not ac
    assert not lc

    ## Test how it handles manual mode
    cs1.duration_mode = MANUAL
    cs1.duration = 1500
    assert cs1.duration == 1500
    assert cs1.actual_duration == 2500

    data = cs1._get_data(0, 0)
    lc, ac, data = cs1.render(500, data)
    assert not ac
    assert lc == ((c0, 127),)

    lc, ac, data = cs1.render(1000, data)
    assert not ac
    assert lc == ((c0, 255),)

    lc, ac, data = cs1.render(2000, data)
    assert not ac 
    assert lc == ((c0, 127),)

    lc, ac, data = cs1.render(2501, data)
    assert not ac
    assert not lc

    ## Test how it handles inherit and a function change
    cs1.duration_mode = INHERIT
    assert cs1.duration == INFTY
    assert cs1.actual_duration == INFTY

    data = cs1._get_data(0, 0)
    
    cs1.fade_out = 0
    cs1.fade_in = 0
    cs1.function = a
    if a.actual_duration != 3024:
        raise ValueError("silence.m4a is wrong duration, fix the tests")
    assert cs1.audio_scope == a.audio_scope
    assert cs1.scope == a.scope
    assert cs1.duration == a.actual_duration
    assert cs1.actual_duration == a.actual_duration
    cs1.fade_out = 1000
    cs1.fade_in = 1000
    assert cs1.duration == a.actual_duration-1000

    lc, ac, data = cs1.render(500, data)
    assert not lc
    assert len(ac) == 1
    assert ac[0][1:] == ("tests/silence.m4a", 0, 1000, 2024, 1000)
    a.fade_out = 2000
    lc, ac, data = cs1.render(501, data)
    assert not lc
    assert len(ac) == 1
    assert ac[0][1:] == ("tests/silence.m4a", 0, 1000, 1024, 2000)

    lc, ac, data = cs1.render(3025, data)
    assert not lc
    assert not ac