-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.ts
339 lines (303 loc) · 11.7 KB
/
test.ts
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
// *********** test codes **********
flexFX.awaitPlayStart()
basic.showNumber(flexFX.waitingToPlay());
basic.pause(500);
// perform a built-in FlexFX with all the defaults
basic.showIcon(IconNames.Target);
flexFX.playFlexFX("uhoh");
basic.showIcon(IconNames.Yes);
pause(2000);
// no such FlexFX? substitute beep
basic.showIcon(IconNames.Target);
flexFX.playFlexFX("this one is missing");
basic.showIcon(IconNames.Yes);
pause(2000);
// perform the simple built-in chime flexFX
basic.showIcon(IconNames.Target);
flexFX.playFlexFX("chime", true, Note.G5, 180, 400); // up a fifth
flexFX.playFlexFX("chime", true, Note.E5, 180, 400); // up a major 3rd
flexFX.playFlexFX("chime", true, Note.C5, 250, 1600);
basic.showIcon(IconNames.Yes);
pause(2000);
// perform like a cat
basic.showIcon(IconNames.Target);
flexFX.playFlexFX("miaow", true, 900, 255, 1000);
pause(800);
flexFX.playFlexFX("miaow", true, 1100, 255, 500);
pause(300);
flexFX.playFlexFX("miaow", true, 800, 255, 1500);
basic.showIcon(IconNames.Yes);
pause(2000);
// perform "New World" theme as individual performances
basic.showIcon(IconNames.Target);
flexFX.playFlexFX("horn", true, Note.E3, 255, 900);
flexFX.playFlexFX("horn", true, Note.G3, 255, 300);
flexFX.playFlexFX("horn", true, Note.G3, 255, 1200);
flexFX.playFlexFX("horn", true, Note.E3, 255, 900);
flexFX.playFlexFX("horn", true, Note.D3, 255, 300);
flexFX.playFlexFX("horn", true, Note.C3, 255, 1200);
flexFX.playFlexFX("horn", true, Note.D3, 255, 600);
flexFX.playFlexFX("horn", true, Note.E3, 255, 600);
flexFX.playFlexFX("horn", true, Note.G3, 255, 600);
flexFX.playFlexFX("horn", true, Note.E3, 255, 600);
flexFX.playFlexFX("horn", true, Note.D3, 255, 2400);
basic.showIcon(IconNames.Yes);
pause(2000);
// create a flexFX for a two-tone police-siren (middle part is silent)
basic.showIcon(IconNames.Target);
flexFX.defineFlexFX("police", 760, 160, flexFX.Wave.Sawtooth, flexFX.Attack.Even, flexFX.Effect.None, 800, 200, 450);
// (add a silent gap in the middle)
flexFX.extendFlexFX("police", flexFX.Wave.Silence, flexFX.Attack.Even, flexFX.Effect.None, 560, 200, 100);
flexFX.extendFlexFX("police", flexFX.Wave.Sawtooth, flexFX.Attack.Even, flexFX.Effect.None, 600, 160, 450);
// queue-up a sequence of Plays on the Play-list (complete with Doppler-shift)
flexFX.playFlexFX("police", false, 800, 16, 1000);
flexFX.playFlexFX("police", false, 800, 32, 1000);
flexFX.playFlexFX("police", false, 800, 64, 1000);
flexFX.playFlexFX("police", false, 800, 128, 1000);
flexFX.playFlexFX("police", false, 800, 255, 1000);
flexFX.playFlexFX("police", false, 775, 255, 1000);
flexFX.playFlexFX("police", false, 750, 128, 1000);
flexFX.playFlexFX("police", false, 750, 64, 1000);
flexFX.playFlexFX("police", false, 750, 32, 1000);
flexFX.playFlexFX("police", false, 750, 16, 1000);
flexFX.startPlaying(); // kick off the Play-list
// while the Play-list is playing, flash the blue light (sort of)
while (flexFX.isActive()) {
basic.showIcon(IconNames.SmallDiamond);
basic.showIcon(IconNames.Diamond);
}
basic.showIcon(IconNames.Yes);
pause(2000);
// queue-up a sequence of Plays on the Play-list (J.S.Bach)
basic.showIcon(IconNames.Target);
flexFX.stopPlaying(); // don't start Playing yet...
flexFX.playFlexFX("violin", false, Note.E5, 250, 300);
flexFX.playFlexFX("violin", false, Note.A5, 250, 900);
flexFX.playFlexFX("violin", false, Note.E5, 250, 300);
flexFX.playFlexFX("violin", false, Note.F5, 250, 900);
flexFX.playFlexFX("violin", false, Note.D5, 250, 300);
flexFX.playFlexFX("violin", false, Note.E5, 250, 150);
flexFX.playFlexFX("violin", false, Note.D5, 250, 150);
flexFX.playFlexFX("violin", false, Note.C5, 250, 150);
flexFX.playFlexFX("violin", false, Note.E5, 250, 150);
flexFX.playFlexFX("violin", false, Note.D5, 250, 150);
flexFX.playFlexFX("violin", false, Note.C5, 250, 150);
flexFX.playFlexFX("violin", false, Note.B4, 250, 150);
flexFX.playFlexFX("violin", false, Note.D5, 250, 150);
flexFX.playFlexFX("violin", false, Note.C5, 250, 300);
flexFX.playFlexFX("violin", false, Note.A4, 250, 900);
flexFX.startPlaying(); // kick off the Play-list
// while the Play-list is playing, jiggle a note around
while (flexFX.isActive()) {
images.iconImage(IconNames.QuarterNote).showImage(-2, 150);
images.iconImage(IconNames.QuarterNote).showImage(-1, 150);
images.iconImage(IconNames.QuarterNote).showImage(0, 150);
images.iconImage(IconNames.QuarterNote).showImage(-1, 150);
}
basic.showIcon(IconNames.Yes);
pause(2000);
// use events to choreograph faces to sounds
basic.showIcon(IconNames.Target);
// first queue up some Plays on the Play-list, with pauses queued in-between
flexFX.stopPlaying(); // don't start Playing yet...
flexFX.playFlexFX("shout", false, 200, 250, 1000);
flexFX.playSilence(2000);
flexFX.playFlexFX("shout", false, 300, 250, 1000);
flexFX.playSilence(1500);
flexFX.playFlexFX("shout", false, 400, 250, 1000);
flexFX.playSilence(1000);
flexFX.playFlexFX("shout", false, 600, 250, 1000);
flexFX.playSilence(800);
flexFX.playFlexFX("shout", false, 800, 250, 1000);
basic.showNumber(flexFX.waitingToPlay());
pause(500);
basic.showIcon(IconNames.Sad);
pause(1000)
flexFX.startPlaying(); // kick off the Play-list
while (flexFX.isActive()) {
flexFX.awaitPlayStart(); // starting the next (non-silent) Play...
basic.showIcon(IconNames.Surprised); // ... so open the mouth
flexFX.awaitPlayFinish();
basic.showIcon(IconNames.Sad); // close the mouth again
// (the active Player now "Plays" the queued silence)
}
basic.showIcon(IconNames.Yes);
pause(2000);
// synchronise a different way, by playing queued Plays one-at-a-time with explicit pauses...
basic.showIcon(IconNames.Target);
// first re-build the Play-list of 5 utterances
flexFX.stopPlaying(); // inhibit Playing
flexFX.playFlexFX("uhoh", false, 200, 250, 1000);
flexFX.playFlexFX("cry", false, 300, 250, 1000);
flexFX.playFlexFX("shout", false, 400, 250, 1000);
flexFX.playFlexFX("cry", false, 600, 250, 1000);
flexFX.playFlexFX("moan", false, 800, 250, 1000);
basic.showNumber(flexFX.waitingToPlay());
pause(1000)
basic.showIcon(IconNames.Sad);
let delay = 3000;
while (flexFX.waitingToPlay() > 0) {
flexFX.startPlaying(); // allow the next Play to happen
pause(20);
// as soon as the first Play begins, prevent any more being started
flexFX.stopPlaying();
basic.showIcon(IconNames.Surprised); // open the mouth...
flexFX.awaitPlayFinish(); // play next utterance
basic.showIcon(IconNames.Sad); // close the mouth again
pause(delay);
delay -= 600; // keep shortening the silence in-between
}
pause(500);
basic.showIcon(IconNames.Yes);
pause(2000);
// check we can delete an unwanted Play-list of 5 tweets
basic.showIcon(IconNames.Target);
flexFX.stopPlaying(); // inhibit Playing
flexFX.playFlexFX("tweet", false, 200, 250, 1000);
flexFX.playFlexFX("tweet", false, 300, 250, 1000);
flexFX.playFlexFX("tweet", false, 400, 250, 1000);
flexFX.playFlexFX("tweet", false, 600, 250, 1000);
flexFX.playFlexFX("tweet", false, 800, 250, 1000);
basic.showNumber(flexFX.waitingToPlay());
pause(1000);
basic.clearScreen();
basic.showString("del:");
flexFX.deletePlaylist();
basic.showNumber(flexFX.waitingToPlay());
pause(3000);
basic.showIcon(IconNames.Yes);
pause(2000);
// check playing of tunes
basic.showIcon(IconNames.Target);
flexFX.playTune("birthday", "tweet");
basic.showIcon(IconNames.Yes);
pause(2000);
// no such Tune? substitute triple-beep
basic.showIcon(IconNames.Target);
flexFX.playTune("this one is missing", "whale");
basic.showIcon(IconNames.Yes);
pause(2000);
// check that bad EKO note-inputs get beeped
// 1) Extent = non-EKO - missing - gross - good -
let tryExtent = " non-EKO C4 999C4 4C4 ";
flexFX.composeTune("noteTest", tryExtent);
flexFX.playTune("noteTest", "chime");
basic.showIcon(IconNames.Yes);
pause(2000);
// 2) Key = missing - not A-G; multi-letter - not #/b - good
let tryKey = "4#4 4H4 4ABC4 4A&4 4Eb4";
flexFX.composeTune("noteTest",tryKey);
flexFX.playTune("noteTest", "chime");
basic.showIcon(IconNames.Yes);
pause(2000);
// 3) Octave = missing - gross - good
let tryOctave = "4A 4A99 4F#4 ";
flexFX.composeTune("noteTest", tryOctave);
flexFX.playTune("noteTest", "chime");
basic.showIcon(IconNames.Yes);
pause(2000);
// check asynchrony of tunes
basic.showIcon(IconNames.Target);
flexFX.stopPlaying();
flexFX.playTune("birthday", "woof", false, -5, 200, 20000);
basic.showNumber(flexFX.waitingToPlay());
pause(1000);
flexFX.startPlaying();
while (flexFX.isActive()) {
images.iconImage(IconNames.StickFigure).showImage(-1, 150);
pause(200);
images.iconImage(IconNames.StickFigure).showImage(0, 150);
pause(200);
images.iconImage(IconNames.StickFigure).showImage(1, 150);
pause(200);
images.iconImage(IconNames.StickFigure).showImage(0, 150);
pause(200);
}
basic.showIcon(IconNames.Yes);
pause(2000);
// check pitch/volume/duration overrides
basic.showIcon(IconNames.Target);
flexFX.playTune("newWorld", "horn", true, 24, 100, 5000);
basic.showIcon(IconNames.Yes);
pause(2000);
// compose a brand new tune comprising 54 notes
basic.showIcon(IconNames.Target);
flexFX.composeTune("edelweiss", "4E4 2G4 6D5 4C5 2G4 6F4");
flexFX.extendTune("edelweiss", "4E4 2E4 2E4 2F4 2G4 6A4 6G4");
flexFX.extendTune("edelweiss", "4E4 2G4 6D5 4C5 2G4 6F4");
flexFX.extendTune("edelweiss", "4E4 2G4 2G4 2A4 2B4 6C5 6C5");
flexFX.extendTune("edelweiss", "3D5 1G4 2G4 3B4 1A4 2G4 4E4 2G4 6C5");
flexFX.extendTune("edelweiss", "4A4 2C5 4D5 2C5 6B4 6G4");
flexFX.extendTune("edelweiss", "4E4 2G4 6D5 4C5 2G#4 6F5");
flexFX.extendTune("edelweiss", "4E5 2G5 2G5 2A5 2B5 6C6 6C6");
// Play it, on the chime, asynchronously, softly,
// lasting exactly one minute, transposed down by a fifth.
flexFX.playTune("edelweiss", "chime", false, -7, 120, 60000);
basic.clearScreen();
basic.showNumber(flexFX.waitingToPlay());
pause(1000);
flexFX.startPlaying();
// while the Play-list is playing, keep rotating a snowflake!
while (flexFX.isActive()) {
basic.showLeds(`
. . # . .
# . # . #
. # # # .
# . # . #
. . # . .
`);
basic.pause(30);
basic.showLeds(`
# . . # .
. . # . .
# # # # #
. . # . .
. # . . #
`);
basic.pause(30);
basic.showLeds(`
. # . # .
. . # . .
# # # # #
. . # . .
. # . # .
`);
basic.pause(30);
basic.showLeds(`
. . # . #
# . # . .
. # # # .
. . # . #
# . # . .
`);
basic.pause(30);
}
basic.showIcon(IconNames.Yes);
pause(2000);
// Queue up a very big playlist (573 Plays)
basic.showIcon(IconNames.Target);
basic.pause(500);
basic.clearScreen();
flexFX.setNextTempo(240); // can't wait all day!
flexFX.playTune("birthday", "chime", false);
flexFX.playTune("jingleBells", "ting",false);
flexFX.playTune("teaPot", "hum",false);
flexFX.playTune("ifYoureHappy", "tweet",false);
flexFX.playTune("londonBridge", "flute",false);
flexFX.playTune("oldMacdonald", "chime",false);
flexFX.playTune("bearMountain", "horn",false);
flexFX.playTune("popWeasel", "violin",false);
flexFX.playTune("thisOldMan", "hum",false);
flexFX.playTune("roundMountain", "chime",false);
flexFX.playTune("edelweiss", "flute", false);
flexFX.playTune("newWorld", "horn", false);
flexFX.playTune("odeToJoy", "hum", false);
flexFX.playTune("bachViolin", "violin", false);
while (flexFX.isActive()) {
basic.showNumber(flexFX.waitingToPlay());
basic.pause(500);
basic.clearScreen();
basic.showArrow(ArrowNames.East);
basic.clearScreen();
basic.pause(500);
}