diff --git a/playground/sounds/this_is_a_test.mp3 b/playground/sounds/this_is_a_test.mp3 new file mode 100644 index 000000000..ed961d3dd Binary files /dev/null and b/playground/sounds/this_is_a_test.mp3 differ diff --git a/playground/sounds/who_put_the_bomp.mp3 b/playground/sounds/who_put_the_bomp.mp3 new file mode 100644 index 000000000..923a0fd78 Binary files /dev/null and b/playground/sounds/who_put_the_bomp.mp3 differ diff --git a/src/blocks/scratch3_sound.js b/src/blocks/scratch3_sound.js index 300b02fd2..5f5e4b5d6 100644 --- a/src/blocks/scratch3_sound.js +++ b/src/blocks/scratch3_sound.js @@ -48,7 +48,7 @@ Scratch3SoundBlocks.prototype.playNoteForBeats = function (args, util) { return new Promise(function(resolve) { setTimeout(function() { resolve(); - }, 1000 * args.BEATS); + }, (1000 * args.BEATS) ); }); }; @@ -61,7 +61,7 @@ Scratch3SoundBlocks.prototype.playDrumForBeats = function (args, util) { return new Promise(function(resolve) { setTimeout(function() { resolve(); - }, 1000 * args.BEATS); + }, (1000 * args.BEATS) ); }); }; diff --git a/src/worker.js b/src/worker.js index 5a7caac8e..8514a72fe 100644 --- a/src/worker.js +++ b/src/worker.js @@ -18,6 +18,11 @@ function VirtualMachine () { var tone = new Tone(); + Tone.Transport.start(); + + var quantizeUnit = '@8n'; + // var quantizeUnit = ''; + // effects var delay = new Tone.FeedbackDelay(0.25, 0.5); @@ -43,7 +48,7 @@ function VirtualMachine () { // sounds - var soundFileNames = ['meow', 'boing', 'cave', 'drip_drop', 'drum_machine', 'eggs', 'zoop']; + var soundFileNames = ['meow','boing','this_is_a_test','who_put_the_bomp','cave','drip_drop','drum_machine','eggs','zoop']; var soundSamplers = loadSoundFiles(soundFileNames); // polyphonic samplers @@ -112,17 +117,17 @@ function VirtualMachine () { function playNoteForBeats(note, beats) { var midiNote = scaleNoteToMidiNote(note, currentScale, rootNote); var freq = midiToFreq(midiNote); - synth.triggerAttackRelease(freq, beats); + synth.triggerAttackRelease(freq, beats, quantizeUnit); } // onmessage calls are converted into emitted events. instance.vmWorker.onmessage = function (e) { switch (e.data.method) { case 'playsound': - soundSamplers[e.data.soundnum].nextVoice().triggerAttack(); + soundSamplers[e.data.soundnum].nextVoice().triggerAttack(0, quantizeUnit); break; case 'playsoundwithpitch': - soundSamplers[e.data.soundnum].nextVoice().triggerAttack(e.data.pitch); + soundSamplers[e.data.soundnum].nextVoice().triggerAttack(e.data.pitch, quantizeUnit); break; case 'playnoteforbeats': playNoteForBeats(e.data.note, e.data.beats); @@ -137,7 +142,7 @@ function VirtualMachine () { case 'playdrumforbeats': case 'playdrum': var drumNum = e.data.drum - 1; // one-indexing - drumSamplers[drumNum].nextVoice().triggerAttack(); + drumSamplers[drumNum].nextVoice().triggerAttack(0, quantizeUnit); break; case 'seteffect' : switch (e.data.effect) {