blob: 58616b3ffc8eef09ab2f9c43cd9a4a84ed2a5014 (
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
;;
;; starlet/fixture.scm
;;
;; Copyright © 2020-2021 Thomas White <taw@bitwiz.org.uk>
;;
;; This file is part of Starlet.
;;
;; Starlet is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;
(define-module (starlet fixture)
#:use-module (starlet colours)
#:use-module (starlet utils)
#:use-module (oop goops)
#:use-module (ice-9 exceptions)
#:use-module (srfi srfi-1)
#:export (<fixture>
get-fixture-name
get-fixture-addr
get-fixture-universe
get-fixture-attrs
find-attr
fixture?
scanout-fixture
attr-continuous
attr-list
attr-colour
define-fixture
get-attr-type
get-attr-range
get-attr-home-val
continuous-attribute?
colour-attribute?
intensity?))
(define-class <fixture-attribute> (<object>)
(name
#:init-form (error "Attribute name must be specified")
#:init-keyword #:name
#:getter get-attr-name)
(range
#:init-value '()
#:init-keyword #:range
#:getter get-attr-range)
(type
#:init-value 'continuous
#:init-keyword #:type
#:getter get-attr-type)
(home-value
#:init-value 0
#:init-keyword #:home-value
#:getter attr-home-value))
(define-class <fixture> (<object>)
(name
#:init-form (error "Fixture name must be specified")
#:init-keyword #:name
#:getter get-fixture-name)
(universe
#:init-value #f
#:init-keyword #:uni
#:getter get-fixture-universe
#:setter set-fixture-universe!)
(start-addr
#:init-value #f
#:init-keyword #:sa
#:getter get-fixture-addr
#:setter set-fixture-addr!)
(friendly-name
#:init-value "Fixture"
#:init-keyword #:friendly-name
#:getter get-fixture-friendly-name
#:setter set-fixture-friendly-name!)
(scanout-func
#:init-value (lambda (universe start-addr value set-dmx) #f)
#:init-keyword #:scanout-func
#:getter get-scanout-func))
(define-syntax attr-continuous
(syntax-rules ()
((_ attr-name attr-range attr-home-value)
(make <fixture-attribute>
#:name attr-name
#:range attr-range
#:type 'continuous
#:home-value attr-home-value))))
(define-syntax attr-list
(syntax-rules ()
((_ attr-name attr-allowed-values attr-home-value)
(make <fixture-attribute>
#:name attr-name
#:range attr-allowed-values
#:type 'list
#:home-value attr-home-value))))
(define-syntax attr-colour
(syntax-rules ()
((_ attr-name attr-home-value)
(make <fixture-attribute>
#:name attr-name
#:type 'colour
#:home-value attr-home-value))))
(define-generic scanout-fixture)
(define (get-fixture-attrs fix)
(slot-ref fix 'attributes))
(define (fixture? f)
(is-a? f <fixture>))
(define-method (find-attr (fix <fixture>) (attr-name <symbol>))
(find (lambda (a)
(eq? (get-attr-name a)
attr-name))
(get-fixture-attrs fix)))
(define-method (find-attr (fix <fixture>) (attr-name <colour-component-id>))
(find-attr fix 'colour))
(define-method (find-attr fix attr-name)
(raise-exception
(make-exception
(make-exception-with-message "Invalid parameters")
(make-exception-with-irritants fix))))
(define-method (get-attr-home-val (fix <fixture>) (attr <symbol>))
(let ((attr-obj (find-attr fix attr)))
(if attr-obj
(attr-home-value attr-obj)
'fixture-does-not-have-attribute)))
(define-method (get-attr-home-val (fix <fixture>) (attr <colour-component-id>))
(extract-colour-component
(get-attr-home-val fix 'colour)
attr))
(define (intensity? a)
(eq? 'intensity a))
(define (continuous-attribute? aobj)
(eq? 'continuous
(get-attr-type aobj)))
(define (colour-attribute? aobj)
(eq? 'colour
(get-attr-type aobj)))
(define-syntax define-fixture
(syntax-rules (fixture-attributes)
((_ classname
(fixture-attributes attr ...)
scanout-code ...)
(begin
(define-class classname (<fixture>)
(attributes #:init-form (list attr ...)))
(define-method (scanout-fixture (fixture classname))
scanout-code ...)))))
|