Merge pull request #69 from Microsoft/sounds
Get rid of "play sound" blocks; add non-blocking "play sound effect"
This commit is contained in:
commit
2c22ea925f
@ -11,12 +11,10 @@
|
|||||||
"music.fromWAV": "Makes a sound bound to a buffer in WAV format.",
|
"music.fromWAV": "Makes a sound bound to a buffer in WAV format.",
|
||||||
"music.noteFrequency": "Get the frequency of a note.",
|
"music.noteFrequency": "Get the frequency of a note.",
|
||||||
"music.noteFrequency|param|name": "the note name, eg: Note.C",
|
"music.noteFrequency|param|name": "the note name, eg: Note.C",
|
||||||
"music.playSound": "Start playing a sound and don't wait for it to finish.\nNotes are expressed as a string of characters with this format: NOTE[octave][:duration]",
|
"music.playSoundEffect": "Start playing a sound and don't wait for it to finish.",
|
||||||
"music.playSoundEffect": "Plays a sound",
|
"music.playSoundEffectUntilDone": "Plays a sound",
|
||||||
|
"music.playSoundEffectUntilDone|param|sound": "the sound to play",
|
||||||
"music.playSoundEffect|param|sound": "the sound to play",
|
"music.playSoundEffect|param|sound": "the sound to play",
|
||||||
"music.playSoundUntilDone": "Play a sound and wait until the sound is done.\nNotes are expressed as a string of characters with this format: NOTE[octave][:duration]",
|
|
||||||
"music.playSoundUntilDone|param|sound": "the melody to play, eg: music.sounds(Sounds.PowerUp)",
|
|
||||||
"music.playSound|param|sound": "the melody to play, eg: music.sounds(Sounds.PowerUp)",
|
|
||||||
"music.playTone": "Play a tone through the speaker for some amount of time.",
|
"music.playTone": "Play a tone through the speaker for some amount of time.",
|
||||||
"music.playTone|param|frequency": "pitch of the tone to play in Hertz (Hz)",
|
"music.playTone|param|frequency": "pitch of the tone to play in Hertz (Hz)",
|
||||||
"music.playTone|param|ms": "tone duration in milliseconds (ms)",
|
"music.playTone|param|ms": "tone duration in milliseconds (ms)",
|
||||||
@ -28,8 +26,5 @@
|
|||||||
"music.setTempo|param|bpm": "The new tempo in beats per minute, eg: 120",
|
"music.setTempo|param|bpm": "The new tempo in beats per minute, eg: 120",
|
||||||
"music.setVolume": "Set the output volume of the sound synthesizer.",
|
"music.setVolume": "Set the output volume of the sound synthesizer.",
|
||||||
"music.setVolume|param|volume": "the volume 0...256, eg: 128",
|
"music.setVolume|param|volume": "the volume 0...256, eg: 128",
|
||||||
"music.sounds": "Get the melody string for a built-in melody.",
|
|
||||||
"music.sounds|param|name": "the note name, eg: Note.C",
|
|
||||||
"music.stopAllSounds": "Stop all sounds from playing.",
|
|
||||||
"music.tempo": "Return the tempo in beats per minute (bpm).\nTempo is the speed (bpm = beats per minute) at which notes play. The larger the tempo value, the faster the notes will play."
|
"music.tempo": "Return the tempo in beats per minute (bpm).\nTempo is the speed (bpm = beats per minute) at which notes play. The larger the tempo value, the faster the notes will play."
|
||||||
}
|
}
|
@ -20,28 +20,17 @@
|
|||||||
"Note.GSharp|block": "G#",
|
"Note.GSharp|block": "G#",
|
||||||
"SoundOutputDestination.Pin|block": "pin",
|
"SoundOutputDestination.Pin|block": "pin",
|
||||||
"SoundOutputDestination.Speaker|block": "speaker",
|
"SoundOutputDestination.Speaker|block": "speaker",
|
||||||
"Sounds.BaDing|block": "ba ding",
|
|
||||||
"Sounds.JumpDown|block": "jump down",
|
|
||||||
"Sounds.JumpUp|block": "jump up",
|
|
||||||
"Sounds.MagicWand|block": "magic wand",
|
|
||||||
"Sounds.PowerDown|block": "power down",
|
|
||||||
"Sounds.PowerUp|block": "power up",
|
|
||||||
"Sounds.Siren|block": "siren",
|
|
||||||
"Sounds.Wawawawaa|block": "wawawawaa",
|
|
||||||
"music._soundPicker|block": "%sound",
|
"music._soundPicker|block": "%sound",
|
||||||
"music.beat|block": "%fraction|beat",
|
"music.beat|block": "%fraction|beat",
|
||||||
"music.changeTempoBy|block": "change tempo by %value|(bpm)",
|
"music.changeTempoBy|block": "change tempo by %value|(bpm)",
|
||||||
"music.noteFrequency|block": "%note",
|
"music.noteFrequency|block": "%note",
|
||||||
"music.playSoundEffect|block": "play %sound",
|
"music.playSoundEffectUntilDone|block": "play sound effect %sound|until done",
|
||||||
"music.playSoundUntilDone|block": "play sound %sound=music_sounds|until done",
|
"music.playSoundEffect|block": "play sound effect %sound",
|
||||||
"music.playSound|block": "play sound %sound=music_sounds",
|
|
||||||
"music.playTone|block": "play tone|at %note=device_note|for %duration=device_beat",
|
"music.playTone|block": "play tone|at %note=device_note|for %duration=device_beat",
|
||||||
"music.rest|block": "rest|for %duration=device_beat",
|
"music.rest|block": "rest|for %duration=device_beat",
|
||||||
"music.ringTone|block": "ring tone|at %note=device_note",
|
"music.ringTone|block": "ring tone|at %note=device_note",
|
||||||
"music.setTempo|block": "set tempo to %value|(bpm)",
|
"music.setTempo|block": "set tempo to %value|(bpm)",
|
||||||
"music.setVolume|block": "set volume %volume",
|
"music.setVolume|block": "set volume %volume",
|
||||||
"music.sounds|block": "%name",
|
|
||||||
"music.stopAllSounds|block": "stop all sounds",
|
|
||||||
"music.tempo|block": "tempo (bpm)",
|
"music.tempo|block": "tempo (bpm)",
|
||||||
"music|block": "music",
|
"music|block": "music",
|
||||||
"sounds.animalsCatPurr|block": "Animals cat purr",
|
"sounds.animalsCatPurr|block": "Animals cat purr",
|
||||||
|
1
libs/music/melodies.ts
Normal file
1
libs/music/melodies.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
namespace music {}
|
@ -256,15 +256,17 @@ namespace sounds {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace music {
|
namespace music {
|
||||||
|
let numSoundsPlaying = 0;
|
||||||
|
let soundsLimit = 3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plays a sound
|
* Plays a sound
|
||||||
* @param sound the sound to play
|
* @param sound the sound to play
|
||||||
*/
|
*/
|
||||||
//% blockId=music_play_sound_effect block="play %sound"
|
//% blockId=music_play_sound_effect_until_done block="play sound effect %sound|until done"
|
||||||
//% weight=98
|
//% weight=98
|
||||||
export function playSoundEffect(sound: Sound) {
|
export function playSoundEffectUntilDone(sound: Sound) {
|
||||||
if (!sound) return;
|
if (!sound) return;
|
||||||
|
|
||||||
sound.play();
|
sound.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,4 +279,16 @@ namespace music {
|
|||||||
export function _soundPicker(sound: Sound): Sound {
|
export function _soundPicker(sound: Sound): Sound {
|
||||||
return sound;
|
return sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start playing a sound and don't wait for it to finish.
|
||||||
|
* @param sound the sound to play
|
||||||
|
*/
|
||||||
|
//% blockId=music_play_sound_effect block="play sound effect %sound"
|
||||||
|
//% weight=99
|
||||||
|
export function playSoundEffect(sound: Sound) {
|
||||||
|
if (!sound || numSoundsPlaying >= soundsLimit) return;
|
||||||
|
numSoundsPlaying++;
|
||||||
|
control.runInBackground(() => {sound.play(); numSoundsPlaying--;});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user