Skip to content

Commit 974de9b

Browse files
committed
Tests for sound blocks
1 parent 7284cd2 commit 974de9b

File tree

3 files changed

+86
-7
lines changed

3 files changed

+86
-7
lines changed

js/runtime.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,9 @@
11411141
}).set({buddies:oscenv}).start();
11421142
},
11431143
playAudio: function(audio){
1144-
audio.play();
1144+
if (audio){
1145+
audio.play();
1146+
}
11451147
},
11461148
playNotes: function(sound){
11471149
console.log(song);
@@ -1161,12 +1163,12 @@
11611163
tempoChange: function(tempo){
11621164
song += ("t" + tempo + " ");
11631165
},
1164-
pauseAudio: function(sound){
1165-
if (assets.sounds[sound.name]){
1166-
assets.sounds[sound.name].pause();
1166+
pauseAudio: function(audio){
1167+
if (audio){
1168+
audio.pause();
11671169
}
11681170
},
1169-
keys: function(synth, vol){
1171+
keys: function(synth){
11701172
var keydict = T("ndict.key");
11711173
var midicps = T("midicps");
11721174
T("keyboard").on("keydown", function(e) {
@@ -1181,7 +1183,6 @@
11811183
synth.noteOff(midi, 100);
11821184
}
11831185
}).start();
1184-
11851186
alert("Play notes on the keyboard");
11861187
},
11871188
soundEffect: function(effect){

playground.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ <h1>Waterbear Playground</h1>
241241
<wb-value type="list" allow="literal" options="1,2,3,4,5,6,7,8" value="4">octave</wb-value>
242242
<wb-value type="list" allow="literal" options="1/32,1/16,1/8,1/4,1/2,1" value="1/4">beats</wb-value>
243243
</wb-step>
244-
<wb-step type="sound" ns="sound" fn="playChord">
244+
<wb-step ns="sound" fn="playChord">
245245
<wb-value>play chord</wb-value>
246246
<wb-value type="sound">synth</wb-value>
247247
<wb-row>

test/runtime.js

+78
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,84 @@ QUnit.test('check for collision, no colliding circle and polygon', function(asse
315315
});
316316

317317
/* TODO: sound */
318+
QUnit.module('sound');
319+
QUnit.test('get', function(assert){
320+
var sound = runtime.sound;
321+
var synth = sound.get('tri', '10', '300');
322+
assert.ok(synth);
323+
});
324+
QUnit.test('addNote', function(assert){
325+
var sound = runtime.sound;
326+
var notes = ['C','C#/Db','D','D#/Eb','E','F','F#/Gb','G','G#/Ab','A','A#/Bb','B','Rest'];
327+
notes.forEach(function (note, index) {
328+
sound.addNote(note, '4', '1/4');
329+
});
330+
var octaves = ['1','2','3','4','5','6','7','8'];
331+
octaves.forEach(function (octave, index) {
332+
sound.addNote('C', octave, '1/16');
333+
})
334+
var beats = ['1/32','1/16','1/8','1/4','1/2','1'];
335+
beats.forEach(function (length, index) {
336+
sound.addNote('C', '3', length);
337+
})
338+
assert.ok(sound);
339+
});
340+
QUnit.test('playChord', function(assert){
341+
var sound = runtime.sound;
342+
var synth = sound.get('tri', '10', '300');
343+
sound.playChord(synth, 'A', '4', 'A#/Bb', '4', 'B', '4', 'C', '4', 'C#/Db', '4', 'D', '4', 'D#/Eb', '4', 'E', '4', 'F', '4', 'F#/Gb', '4', 'G', '4', 'G#/Ab', '4');
344+
assert.ok(sound);
345+
});
346+
QUnit.test('playNotes', function(assert){
347+
var sound = runtime.sound;
348+
var synth = sound.get('tri', '10', '300');
349+
sound.playNotes(synth);
350+
assert.ok(sound);
351+
});
352+
QUnit.test('playMML', function(assert){
353+
var sound = runtime.sound;
354+
var synth = sound.get('tri', '10', '300');
355+
var mml = "abcdefg";
356+
sound.playMML(synth, mml);
357+
assert.ok(sound);
358+
});
359+
QUnit.test('tempoChange', function(assert){
360+
var sound = runtime.sound;
361+
sound.tempoChange('200');
362+
assert.ok(sound);
363+
});
364+
QUnit.test('keys', function(assert){
365+
var sound = runtime.sound;
366+
var synth = sound.get('tri', '10', '300');
367+
sound.keys(synth);
368+
assert.ok(sound);
369+
});
370+
QUnit.test('soundEffect', function(assert){
371+
var sound = runtime.sound;
372+
sound.soundEffect('laser');
373+
sound.soundEffect('alarm');
374+
assert.ok(sound);
375+
});
376+
QUnit.test('getAudio', function(assert){
377+
var sound = runtime.sound;
378+
var audio = sound.getAudio('/sounds/pianoA.wav');
379+
assert.ok(audio);
380+
});
381+
QUnit.test('playAudio', function(assert){
382+
var sound = runtime.sound;
383+
var audio = sound.getAudio('/sounds/pianoA.wav');
384+
sound.playAudio(audio);
385+
sound.playAudio();
386+
assert.ok(sound);
387+
});
388+
QUnit.test('pauseAudio', function(assert){
389+
var sound = runtime.sound;
390+
var audio = sound.getAudio('/sounds/pianoA.wav');
391+
sound.playAudio(audio);
392+
sound.pauseAudio(audio);
393+
sound.pauseAudio();
394+
assert.ok(sound);
395+
});
318396
/* TODO: arrays */
319397
QUnit.module('arrays');
320398
QUnit.test('create', function(assert){

0 commit comments

Comments
 (0)