Skip to content

Commit

Permalink
Update pxt.json, flexFX.ts, test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
GrandpaBond committed Aug 4, 2023
1 parent 3746137 commit 9db372c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
26 changes: 16 additions & 10 deletions flexFX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,19 @@ namespace flexFX {
function player() {
let play = new Play;
while (playList.length > 0) { // play everything on the playList in turn
play = playList.shift();
let sound = "";
play = playList.shift();
if (play.parts[0].charAt(0) == 'p'){
// this is just a pause, so doesn't count as "PLAYING"
sound = play.parts.shift();
pause(parseInt(sound.slice(1, sound.length)));
} else {
control.raiseEvent(FLEXFX_ACTIVITY_ID, PLAYER.STARTING);
playerPlaying = true;
while (play.parts.length > 0) { // play its sounds in turn
sound = play.parts.shift();
if (sound.charAt(0) == ' ') {
// this is a gap within a sound, so DOES count as still "PLAYING"
pause(parseInt(sound.slice(1, sound.length)));
} else {
music.playSoundEffect(sound, SoundExpressionPlayMode.UntilDone)
Expand All @@ -291,19 +297,19 @@ namespace flexFX {
control.raiseEvent(FLEXFX_ACTIVITY_ID, PLAYER.ALLPLAYED);
playerActive = false;
}

}
// ---- UI BLOCKS ----
/**
* Add a silent pause to the play-list
*/
export function performSilence(ms: number, waiting: boolean) {
let play = new Play;
play.parts.push(" "+ convertToText(Math.floor(ms)));
playList.push(play);
activatePlayer(); // make sure it gets played
if (waiting) { // ours was the lastest Play, so simply await completion of player.
control.waitForEvent(FLEXFX_ACTIVITY_ID, PLAYER.ALLPLAYED);
}
let play = new Play;
play.parts.push("p"+ convertToText(Math.floor(ms)));
playList.push(play);
activatePlayer(); // make sure it gets played
if (waiting) { // ours was the lastest Play, so simply await completion of player.
control.waitForEvent(FLEXFX_ACTIVITY_ID, PLAYER.ALLPLAYED);
}
}

/**
Expand Down Expand Up @@ -483,4 +489,4 @@ namespace flexFX {
target.silentPartB(startPitchBPercent / 100, startVolBPercent / 100, timeGapPercent / 100);
target.setPartC(waveB, attackB, effectB, endPitchBPercent / 100, endVolBPercent / 100, (100 - timePercentA - timeGapPercent) / 100);
}
}
}
2 changes: 1 addition & 1 deletion pxt.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "pxt-newflexFX",
"name": "pxt-flexFX",
"version": "1.0.0",
"description": "",
"dependencies": {
Expand Down
23 changes: 11 additions & 12 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ flexFX.performFlexFX("Violin", Note.A4, 250, 900, false);

//flexFX.startPlaying();
while (flexFX.isActive()) { // jiggle a note around
images.iconImage(IconNames.QuarterNote).showImage(-2, 150);
images.iconImage(IconNames.QuarterNote).showImage(-1, 150);
images.iconImage(IconNames.QuarterNote).showImage(0, 150);
images.iconImage(IconNames.QuarterNote).showImage(1, 150);
images.iconImage(IconNames.QuarterNote).showImage(0, 150);
images.iconImage(IconNames.QuarterNote).showImage(-1, 150);
}

//flexFX.finish(); // make sure everything has finished playing
Expand All @@ -110,13 +110,12 @@ flexFX.performSilence(400, false);
flexFX.performFlexFX("SIREN", 600, 250, 1000, false);
flexFX.performSilence(400, false);
flexFX.performFlexFX("SIREN", 800, 250, 1000, false);
// choreograph faces to sounds: 600ms for icon display + 800ms = 1000ms + 400ms
basic.showIcon(IconNames.Happy);
pause(800);
basic.showIcon(IconNames.Sad);
pause(800);
basic.showIcon(IconNames.Confused);
pause(800);
basic.showIcon(IconNames.Angry);
pause(800);
basic.showIcon(IconNames.Surprised);

// choreograph faces to sounds:
while (flexFX.isActive) {
basic.showIcon(IconNames.Happy);
control.waitForEvent(FLEXFX_ACTIVITY_ID, PLAYER.STARTING);
basic.showIcon(IconNames.Surprised);
control.waitForEvent(FLEXFX_ACTIVITY_ID, PLAYER.FINISHED);
}
basic.showIcon(IconNames.Happy);

0 comments on commit 9db372c

Please sign in to comment.