-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathevent.lisp
165 lines (154 loc) · 7.9 KB
/
event.lisp
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
;;;; t/event.lisp - tests for `event' and related functionality.
;;; TODO:
;; FIX: add more
(in-package #:cl-patterns/tests)
(in-suite cl-patterns-tests)
(test event
"Test event functionality"
(is (= 1
(event-value (event :dur 0 :sustain 1) :sustain))
"event returns the wrong sustain when sustain is provided and dur is 0")
(is (= 0.8
(event-value (event) :sustain))
"event returns the wrong default value for sustain")
(is (= 0.5
(event-value (event :dur 0 :legato 0.5) :legato))
"event returns the wrong legato when legato is provided and dur is 0")
(is (= 0.8
(event-value (event) :legato))
"event returns the wrong default value for legato")
(is (= 1
(event-value (event) :dur))
"event returns the wrong default value for dur")
(is (eql :default
(event-value (event) :instrument))
"event returns the wrong default value for instrument")
(is (= (amp-db 0.125)
(event-value (event :amp 0.125) :db))
"event incorrectly converts amp to db")
(is (= (db-amp -7)
(event-value (event :db -7) :amp))
"event incorrectly converts db to amp")
(is (eql :freq
(cadr (multiple-value-list (event-value (event :freq 420) :midinote))))
"event-value does not provide the key it derives its value from as the second return value")
(is (eql :freq
(cadr (multiple-value-list (event-value (event :freq 420) :rate))))
"event-value does not provide the key it derives its value from as the second return value when called for :rate")
(is-true (let ((*clock* (make-clock 9/7)))
(equal (list 9/7 :tempo)
(multiple-value-list (event-value (event) :tempo))))
"event-value doesn't provide :tempo when getting the tempo from *clock*")
(is-true (= 110
(event-value (event :octave 2) :freq))
"(event :octave 2) doesn't set the correct freq")
(is (listp (event-value (event :degree (list 0 1 2 3)) :freq))
"event doesn't multi-channel expand into a list")
(is (length= 4 (event-value (event :degree (list 0 1 2 3)) :freq))
"event doesn't multi-channel expand to a list of the correct length")
(is (atom (event-value (event :degree 3 :bar (list 0 1 2 3)) :freq))
"event multi-channel expands event values that are atoms"))
(test event-beat
"Test the beat key for events"
(is-true (= 5
(slot-value (event :beat 5) 'cl-patterns::%beat))
"event doesn't set the internal %beat slot correctly")
(is-true (= 2
(slot-value (combine-events
(event :beat 3)
(event :beat 2))
'cl-patterns::%beat))
"combine-events doesn't set the internal %beat slot correctly")
(is-true (= 94
(let ((ev (event)))
(setf (event-value ev :beat) 94)
(slot-value ev 'cl-patterns::%beat)))
"setting an event's :beat key incorrectly sets its %beat slot"))
(test event-equal
"Test event-equal"
(is-true (event-equal (event :dur 1) (event :dur 1))
"event-equal doesn't return true for equivalent events")
(is-false (event-equal (event :dur 1) (event :dur 1 :foo 2))
"event-equal doesn't return false for events with differing keys")
(is-true (event-equal (list (event :foo 1)) (event :foo 1))
"event-equal doesn't consider an event to be equal to a list of the same event"))
(test every-event-equal
"Test every-event-equal"
(is-true (every-event-equal (list (event :freq 440))
(list (event :freq 440)))
"every-event-equal doesn't return true for two lists of equivalent events")
(is-false (every-event-equal (list (event :dur 1))
(list))
"every-event-equal doesn't return false for two lists of different length"))
(test events-differing-keys
"Test `events-differing-keys'"
(is-true (equal (list :bar)
(events-differing-keys (event :foo 1 :bar 2) (event :foo 1 :bar 4) (event :foo 1 :bar 5)))
"events-differing-keys doesn't return keys whose values differ")
(is-true (equal (list :foo)
(events-differing-keys (event :foo 1 :bar 5) (event :foo 1 :bar 5) (event :bar 5)))
"events-differing-keys doesn't return keys that are missing from some events"))
(test combine-events
"Test combine-events"
(is-true (event-equal (event :foo 1 :bar 2 :baz 3)
(combine-events (event :foo 1) (event :bar 2 :baz 3)))
"combine-events doesn't work correctly on two events")
(is-true (event-equal (event :freq 450 :qux 69 :baz 3)
(combine-events (event :freq 450) (event :qux 69) (event :baz 3)))
"combine-events doesn't work correctly on three events")
(is-true (event-equal (event :freq 200)
(combine-events (event :freq 200) (event)))
"combine-events doesn't work correctly for empty second event")
(is-true (event-equal (event :qux 69)
(combine-events (event) (event :qux 69)))
"combine-events doesn't work correctly for empty first event")
(is-true (eop-p (combine-events eop (event :qux 69)))
"combine-events doesn't work correctly for nil first event")
(is-true (eop-p (combine-events (event :foo 1) eop))
"combine-events doesn't work correctly for nil second event")
(is (event-equal (event)
(copy-event (event)))
"copy-event doesn't copy an empty event")
(is (eql 2
(let ((ev1 (event))
(ev2 (event))
(ev3 (event)))
(setf (slot-value ev1 'cl-patterns::%beat) 1
(slot-value ev2 'cl-patterns::%beat) 2)
(slot-value (combine-events ev1 ev2 ev3) 'cl-patterns::%beat)))
"combine-events doesn't propagate the %beat slot")
(is (eql 2
(let ((ev1 (event))
(ev2 (event :beat 2))
(ev3 (event)))
(setf (slot-value ev1 'cl-patterns::%beat) 1
(slot-value ev3 'cl-patterns::%beat) 3)
(beat (combine-events ev1 ev2 ev3))))
"combine-events doesn't prioritize the :beat key over the %beat slot"))
(test split-event-by-lists
"Test split-event-by-lists"
(is-true (every-event-equal (list (event :foo 1 :bar 1 :baz 3)
(event :foo 1 :bar 2 :baz 4)
(event :foo 1 :bar 1 :baz 5))
(split-event-by-lists (event :foo 1 :bar (list 1 2) :baz (list 3 4 5))))
"split-event-by-lists returns incorrect results")
(is-true (every-event-equal (list (event :foo 1 :bar 1 :baz 3)
(event :foo 1 :bar 2 :baz 4)
(event :foo 1 :bar 1 :baz 5))
(split-event-by-lists (event :foo (list 1) :bar (list 1 2) :baz (list 3 4 5))))
"split-event-by-lists returns incorrect results if one of the event values is a list of length 1")
(is-true (equal (list 999)
(let ((event (event)))
(setf (beat event) 999)
(mapcar #'beat (split-event-by-lists event))))
"split-event-by-lists doesn't carry over the %beat slot for empty events")
(is-true (equal (list 999 999 999)
(let ((event (event :midinote (list 40 50 60))))
(setf (beat event) 999)
(mapcar #'beat (split-event-by-lists event))))
"split-event-by-lists doesn't carry over the %beat slot for events with lists"))
(test combine-events-via-lists
"Test combine-events-via-lists"
(is-true (event-equal (event :foo 1 :bar (list 2 3) :qux 4 :baz 5)
(combine-events-via-lists (event :foo 1 :bar 2 :qux 4) (event :foo 1 :bar 3 :baz 5)))
"combine-events-via-lists returns incorrect results"))