diff --git a/audioLocal.js b/audioLocal.js index 1f31a1a1e..4c1eb7737 100644 --- a/audioLocal.js +++ b/audioLocal.js @@ -39,29 +39,15 @@ AudioLocal.prototype._loadSoundFiles = function(filenames) { var samplers = []; for (var name of filenames) { - - // create an array of samplers for each sound (a hack to get polyphony for each sound) - var myVoices = []; - for (var i=0; i<6; i++) { - var p = new Tone.Sampler('sounds/' + name + '.mp3').toMaster(); - myVoices.push(p); - } - - var polySampler = { - voices : myVoices, - currentVoice : 0, - nextVoice : function() {return this.voices[this.currentVoice++ % this.voices.length];}, - stopAllVoices : function() {for (var i=0;i - - - - - - - - 1 - - - - - - - - 1 - - - - @@ -320,18 +300,10 @@ - - - - 1 - - - - - 1 + 60 @@ -339,34 +311,7 @@ - - - - - 1 - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/src/blocks/scratch3_sound.js b/src/blocks/scratch3_sound.js index 4706c7d68..e0777ab42 100644 --- a/src/blocks/scratch3_sound.js +++ b/src/blocks/scratch3_sound.js @@ -13,74 +13,34 @@ function Scratch3SoundBlocks(runtime) { Scratch3SoundBlocks.prototype.getPrimitives = function() { return { 'sound_playsound': this.playSound, - 'sound_playwithpitch': this.playSoundWithPitch, + // 'sound_playsoundandwait': this.playSoundAndWait, 'sound_stopallsounds': this.stopAllSounds, - 'sound_playnote': this.playNote, 'sound_playnoteforbeats': this.playNoteForBeats, - 'sound_scalenotetomidinote': this.scaleNoteToMidiNote, - 'sound_playdrum': this.playDrum, 'sound_playdrumforbeats': this.playDrumForBeats, - 'sound_setkey' : this.setKey, 'sound_seteffectto' : this.setEffect, 'sound_changeeffectby' : this.changeEffect, 'sound_cleareffects' : this.clearEffects, - 'sound_scales_menu' : this.scalesMenu, 'sound_sounds_menu' : this.soundsMenu, - 'sound_roots_menu' : this.rootsMenu, 'sound_beats_menu' : this.beatsMenu, 'sound_effects_menu' : this.effectsMenu, }; }; Scratch3SoundBlocks.prototype.playSound = function (args, util) { - // self.postMessage({method: 'playsound', soundnum:args.SOUND_NUM}); util.target.playSound(args.SOUND_NUM); }; -Scratch3SoundBlocks.prototype.playSoundWithPitch = function (args, util) { - self.postMessage({method: 'playsoundwithpitch', soundnum:args.SOUND_NUM, pitch:args.PITCH}); -}; - Scratch3SoundBlocks.prototype.stopAllSounds = function (args, util) { - self.postMessage({method: 'stopallsounds'}); + util.target.stopAllSounds(); }; Scratch3SoundBlocks.prototype.playNoteForBeats = function (args, util) { - self.postMessage({method: 'playnoteforbeats', note:args.NOTE, beats:args.BEATS}); - return new Promise(function(resolve) { - setTimeout(function() { - resolve(); - }, (1000 * args.BEATS) ); - }); -}; - -Scratch3SoundBlocks.prototype.playNote = function (args, util) { - self.postMessage({method: 'playnote', note:args.NOTE}); -}; - -Scratch3SoundBlocks.prototype.scaleNoteToMidiNote = function (args, util) { - - var root = parseInt(args.ROOT) + 60; - - var scales = { - 'MAJOR' : [0,2,4,5,7,9,11], - 'MINOR' : [0,2,3,5,7,8,10], - 'PENTATONIC': [0, 2, 4, 7, 9], - 'CHROMATIC' : [0,1,2,3,4,5,6,7,8,9,10,11], - }; - - var scale = scales[args.SCALE]; - - var scaleNote = args.NOTE; - - var scaleIndex = (Math.round(scaleNote) - 1) % scale.length; - if (scaleIndex < 0) { - scaleIndex += scale.length; - } - var octave = Math.floor((scaleNote - 1) / scale.length); - var midiNote = root + (octave * 12) + scale[scaleIndex]; - - return midiNote; + util.target.playNoteForBeats(args.NOTE, args.BEATS); + return new Promise(function(resolve) { + setTimeout(function() { + resolve(); + }, (1000 * args.BEATS) ); + }); }; Scratch3SoundBlocks.prototype.playDrumForBeats = function (args, util) { @@ -92,14 +52,6 @@ Scratch3SoundBlocks.prototype.playDrumForBeats = function (args, util) { }); }; -Scratch3SoundBlocks.prototype.playDrum = function (args, util) { - self.postMessage({method: 'playdrum', drum:args.DRUMTYPE}); -}; - -Scratch3SoundBlocks.prototype.setKey = function (args, util) { - self.postMessage({method: 'setkey', root:args.ROOT, scale:args.SCALE}); -}; - Scratch3SoundBlocks.prototype.setEffect = function (args, util) { self.postMessage({method: 'seteffect', effect:args.EFFECT, value:args.VALUE}); }; @@ -116,14 +68,6 @@ Scratch3SoundBlocks.prototype.soundsMenu = function (args, util) { return args.SOUND_MENU; }; -Scratch3SoundBlocks.prototype.scalesMenu = function (args, util) { - return args.SCALE; -}; - -Scratch3SoundBlocks.prototype.rootsMenu = function (args, util) { - return args.ROOT; -}; - Scratch3SoundBlocks.prototype.beatsMenu = function (args, util) { return args.BEATS; }; diff --git a/src/sprites/clone.js b/src/sprites/clone.js index 4f2c20a15..523a00fdd 100644 --- a/src/sprites/clone.js +++ b/src/sprites/clone.js @@ -244,4 +244,12 @@ Clone.prototype.playSound = function (soundNum) { this.audioWorker.playSound(soundNum); } +Clone.prototype.stopAllSounds = function () { + this.audioWorker.stopAllSounds(); +} + +Clone.prototype.playNoteForBeats = function (note,beats) { + this.audioWorker.playNoteForBeats(note, beats); +} + module.exports = Clone;