2016-09-15 16:51:24 -04:00
|
|
|
var Cast = require('../util/cast');
|
|
|
|
var Promise = require('promise');
|
|
|
|
|
2016-08-09 15:40:50 -04:00
|
|
|
function Scratch3SoundBlocks(runtime) {
|
|
|
|
/**
|
|
|
|
* The runtime instantiating this block package.
|
|
|
|
* @type {Runtime}
|
|
|
|
*/
|
|
|
|
this.runtime = runtime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the block primitives implemented by this package.
|
|
|
|
* @return {Object.<string, Function>} Mapping of opcode to Function.
|
|
|
|
*/
|
|
|
|
Scratch3SoundBlocks.prototype.getPrimitives = function() {
|
|
|
|
return {
|
|
|
|
'sound_playsound': this.playSound,
|
2016-09-13 17:52:54 -04:00
|
|
|
// 'sound_playsoundandwait': this.playSoundAndWait,
|
2016-08-11 16:47:01 -04:00
|
|
|
'sound_stopallsounds': this.stopAllSounds,
|
|
|
|
'sound_playnoteforbeats': this.playNoteForBeats,
|
|
|
|
'sound_playdrumforbeats': this.playDrumForBeats,
|
|
|
|
'sound_seteffectto' : this.setEffect,
|
|
|
|
'sound_changeeffectby' : this.changeEffect,
|
|
|
|
'sound_cleareffects' : this.clearEffects,
|
|
|
|
'sound_sounds_menu' : this.soundsMenu,
|
2016-08-09 15:40:50 -04:00
|
|
|
'sound_beats_menu' : this.beatsMenu,
|
2016-08-11 16:47:01 -04:00
|
|
|
'sound_effects_menu' : this.effectsMenu,
|
2016-08-09 15:40:50 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
Scratch3SoundBlocks.prototype.playSound = function (args, util) {
|
2016-09-07 16:55:38 -04:00
|
|
|
util.target.playSound(args.SOUND_NUM);
|
2016-08-09 15:40:50 -04:00
|
|
|
};
|
|
|
|
|
2016-08-11 16:47:01 -04:00
|
|
|
Scratch3SoundBlocks.prototype.stopAllSounds = function (args, util) {
|
2016-09-13 17:52:54 -04:00
|
|
|
util.target.stopAllSounds();
|
2016-08-11 16:47:01 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
Scratch3SoundBlocks.prototype.playNoteForBeats = function (args, util) {
|
2016-09-13 17:52:54 -04:00
|
|
|
util.target.playNoteForBeats(args.NOTE, args.BEATS);
|
|
|
|
return new Promise(function(resolve) {
|
|
|
|
setTimeout(function() {
|
|
|
|
resolve();
|
|
|
|
}, (1000 * args.BEATS) );
|
|
|
|
});
|
2016-08-17 16:45:01 -04:00
|
|
|
};
|
|
|
|
|
2016-08-11 16:47:01 -04:00
|
|
|
Scratch3SoundBlocks.prototype.playDrumForBeats = function (args, util) {
|
2016-09-15 16:51:24 -04:00
|
|
|
util.target.playDrumForBeats(args.DRUMTYPE, args.BEATS);
|
2016-08-11 16:47:01 -04:00
|
|
|
return new Promise(function(resolve) {
|
|
|
|
setTimeout(function() {
|
|
|
|
resolve();
|
2016-08-16 16:32:35 -04:00
|
|
|
}, (1000 * args.BEATS) );
|
2016-08-11 16:47:01 -04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
Scratch3SoundBlocks.prototype.setEffect = function (args, util) {
|
|
|
|
};
|
|
|
|
|
|
|
|
Scratch3SoundBlocks.prototype.changeEffect = function (args, util) {
|
|
|
|
};
|
|
|
|
|
|
|
|
Scratch3SoundBlocks.prototype.clearEffects = function (args, util) {
|
|
|
|
};
|
|
|
|
|
|
|
|
Scratch3SoundBlocks.prototype.soundsMenu = function (args, util) {
|
|
|
|
return args.SOUND_MENU;
|
|
|
|
};
|
|
|
|
|
2016-08-09 15:40:50 -04:00
|
|
|
Scratch3SoundBlocks.prototype.beatsMenu = function (args, util) {
|
|
|
|
return args.BEATS;
|
|
|
|
};
|
|
|
|
|
2016-08-11 16:47:01 -04:00
|
|
|
Scratch3SoundBlocks.prototype.effectsMenu = function (args, util) {
|
|
|
|
return args.EFFECT;
|
|
|
|
};
|
|
|
|
|
2016-08-09 15:40:50 -04:00
|
|
|
module.exports = Scratch3SoundBlocks;
|