Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Music Changes #1024

Merged
merged 3 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions libs/ev3/ns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace sensors {
//% groups='["Move", "Counters", "Properties"]'
//% labelLineWidth=50
namespace motors {

}

//% labelLineWidth=0
Expand All @@ -25,9 +26,11 @@ namespace chassis {

//% labelLineWidth=0
namespace behaviors {

}

//% color="#D67923" weight=80 icon="\uf10e"
//% groups='["Sounds", "Tone", "Volume", "Tempo"]'
namespace music {

}
Expand All @@ -37,11 +40,6 @@ namespace control {

}

//% color="#EF2D56"
namespace pins {

}

//% color="#011C32"
namespace serial {

Expand Down
4 changes: 4 additions & 0 deletions libs/music/music.cpp
THEb0nny marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ int writeDev(void *data, int size) {
//% volume.min=0 volume.max=100
//% help=music/set-volume
//% weight=1
//% group="Volume"
void setVolume(int volume) {
currVolume = max(0, min(100, volume));
}
Expand All @@ -60,6 +61,7 @@ void setVolume(int volume) {
//% parts="speaker" blockGap=8
//% help=music/volume
//% weight=1
//% group="Volume"
int volume() {
return currVolume;
}
Expand Down Expand Up @@ -188,6 +190,7 @@ void playSample(Buffer buf) {
//% parts="headphone" async
//% blockNamespace=music
//% weight=76 blockGap=8
//% group="Tone"
void playTone(int frequency, int ms) {
if (frequency <= 0) {
_stopSound();
Expand Down Expand Up @@ -215,6 +218,7 @@ void playTone(int frequency, int ms) {
//% parts="headphone"
//% blockNamespace=music
//% weight=97
//% group="Volume"
void stopAllSounds() {
if (currentSample) {
samplePtr = currentSample->length;
Expand Down
1 change: 1 addition & 0 deletions libs/music/piano.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace music {
//% note.fieldOptions.minNote=40 note.fieldOptions.maxNote=75
//% useEnumVal=1
//% weight=10 blockGap=8
//% group="Tone"
export function noteFrequency(note: Note): number {
//TODO fill in actual min/max note values
return note;
Expand Down
1 change: 0 additions & 1 deletion libs/music/pins.cpp

This file was deleted.

12 changes: 8 additions & 4 deletions libs/music/shims.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ declare namespace music {
//% parts="speaker" blockGap=8
//% volume.min=0 volume.max=100
//% help=music/set-volume
//% weight=1 shim=music::setVolume
//% weight=1
//% group="Volume" shim=music::setVolume
function setVolume(volume: int32): void;

/**
Expand All @@ -20,7 +21,8 @@ declare namespace music {
//% blockId=synth_get_volume block="volume"
//% parts="speaker" blockGap=8
//% help=music/volume
//% weight=1 shim=music::volume
//% weight=1
//% group="Volume" shim=music::volume
function volume(): int32;

/**
Expand All @@ -32,7 +34,8 @@ declare namespace music {
//% blockId=music_play_note block="play tone|at %note=device_note|for %duration=device_beat"
//% parts="headphone" async
//% blockNamespace=music
//% weight=76 blockGap=8 shim=music::playTone
//% weight=76 blockGap=8
//% group="Tone" shim=music::playTone
function playTone(frequency: int32, ms: int32): void;

/**
Expand All @@ -42,7 +45,8 @@ declare namespace music {
//% blockId=music_stop_all_sounds block="stop all sounds"
//% parts="headphone"
//% blockNamespace=music
//% weight=97 shim=music::stopAllSounds
//% weight=97
//% group="Volume" shim=music::stopAllSounds
function stopAllSounds(): void;

/** Makes a sound bound to a buffer in WAV format. */
Expand Down
30 changes: 17 additions & 13 deletions libs/music/sounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,41 +256,45 @@ namespace sounds {
}

namespace music {

let numSoundsPlaying = 0;
const soundsLimit = 1;

/**
* Play a sound and wait until it finishes
* A sound.
* @param sound the sound
*/
//% blockId=music_sound_picker block="%sound" shim=TD_ID
//% sound.fieldEditor="music"
//% weight=0 blockHidden=1
//% group="Sounds"
export function __soundPicker(sound: Sound): Sound {
return sound;
}

/**
* Start playing a sound and wait until it finishes.
* @param sound the sound to play
*/
//% blockId=music_play_sound_effect_until_done block="play sound effect %sound=music_sound_picker|until done"
//% weight=98 blockGap=8
//% help=music/play-sound-effect-until-done
//% group="Sounds"
export function playSoundEffectUntilDone(sound: Sound) {
if (!sound || numSoundsPlaying >= soundsLimit) return;
numSoundsPlaying++;
sound.play();
numSoundsPlaying--;
}

/**
* A sound
* @param sound the sound
*/
//% blockId=music_sound_picker block="%sound" shim=TD_ID
//% sound.fieldEditor="music"
//% weight=0 blockHidden=1
export function __soundPicker(sound: Sound): 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=music_sound_picker"
//% blockId=music_play_sound_effect block="play sound effect %sound=music_sound_picker|in background"
//% weight=99 blockGap=8
//% help=music/play-sound-effect
//% group="Sounds"
export function playSoundEffect(sound: Sound) {
if (!sound || numSoundsPlaying >= soundsLimit) return;
numSoundsPlaying++;
Expand Down
Loading