diff --git a/flexFX.ts b/flexFX.ts index 1bcb1c1..43db30c 100644 --- a/flexFX.ts +++ b/flexFX.ts @@ -35,9 +35,9 @@ For the novice, a selection of interesting built-in FlexFX samples (musical or o namespace flexFX { // Simplify the selection of wave-shape... - enum Wave { + export enum Wave { //%block="Silence" - Silence = -1, // (special case for adding silent gaps) + Silence = -1, // (special case for queueing silent gaps onto the Play-list) //%block="Pure" Sine = WaveShape.Sine, //%block="Buzzy" @@ -50,7 +50,7 @@ namespace flexFX { Noise = WaveShape.Noise } // Simplify the selection of frequency interpolation trajectory... - enum Attack { + export enum Attack { //% block="Fast" Fast = InterpolationCurve.Logarithmic, //% block="Medium" @@ -61,7 +61,7 @@ namespace flexFX { Delayed = 99 // mapped to Sine or Cosine, depending on slope of profile } // Simplify (slightly) the selection of modulation-style... - enum Effect { + export enum Effect { //% block="None" None = SoundExpressionEffect.None, //% block="Vibrato" @@ -74,50 +74,50 @@ namespace flexFX { // list of built-in FlexFXs // **** must precicely match the ID array BuiltInId below **** - enum BuiltInFlexFX { + export enum BuiltInFlexFX { //% block="chime" - CHIME, + Chime, //% block="cry" - CRY, + Cry, //% block="flute" - FLUTE, + Flute, //% block="horn" - HORN, + Horn, //% block="hum" - HUM, + Hum, //% block="laugh" - LAUGH, + Laugh, //% block="miaow" - MIAOW, + Miaow, //% block="moan" - MOAN, + Moan, //% block="moo" - MOO, + Moo, //% block="motor" - MOTOR, + Motor, //% block="query" - QUERY, + Query, //% block="shout" - SHOUT, + Shout, //% block="siren" - SIREN, + Siren, //% block="snore" - SNORE, + Snore, //% block="ting" - TING, + Ting, //% block="tweet" - TWEET, + Tweet, //% block="uh-oh" - UHOH, + Uhoh, //% block="violin" - VIOLIN, + Violin, //% block="whale" - WHALE, + Whale, //% block="woof" - WOOF + Woof } // array of built-in FlexFX ids @@ -380,9 +380,9 @@ continuing seamlessly from where the previous one left off. //% vol.min=0 vol.max=255 vol.defl=200 //% ms.min=0 ms.max=10000 ms.defl=800 //% wait.defl=true - export function playBuiltInFlexFX(choice: BuiltInFlexFX, pitch: number = 0, - volume: number = 0, duration: number = 0, background: boolean = false) { - playFlexFX(builtInId[choice], pitch, volume, duration, background); + export function playBuiltInFlexFX(choice: BuiltInFlexFX, wait: boolean = false, + pitch: number = 0, volume: number = 0, duration: number = 0) { + playFlexFX(builtInId[choice], wait, pitch, volume, duration); } /** @@ -398,8 +398,8 @@ continuing seamlessly from where the previous one left off. //% vol.min=0 vol.max=255 vol.defl=200 //% ms.min=0 ms.max=10000 ms.defl=800 //% wait.defl=true - export function playFlexFX(id: string, pitchSteps: number = 0, - volumeLimit: number = 0, newDuration: number = 0, wait: boolean = true) { + export function playFlexFX(id: string, wait: boolean = true, + pitchSteps: number = 0, volumeLimit: number = 0, newDuration: number = 0) { let target: FlexFX = flexFXList.find(i => i.id === id); if (target != null) { // first compile and add our Play onto the playList diff --git a/test.ts b/test.ts index 8d14067..f945193 100644 --- a/test.ts +++ b/test.ts @@ -1,58 +1,61 @@ // *********** test codes ********** // perform a built-in FlexFX with all the defaults -flexFX.playBuiltInFlexFX(BuiltInFlexFX.WHALE) +flexFX.playBuiltInFlexFX(flexFX.BuiltInFlexFX.Whale, true); // perform the simple built-in chime flexFX -flexFX.playFlexFX("ting", 7, 180, 400, false); // up a fifth -flexFX.playFlexFX("ting", 4, 180, 400, false); // up a major 3rd -flexFX.playFlexFX("ting", 0, 250, 1600, false); +flexFX.playFlexFX("ting", 7, 180, 400, true); // up a fifth +flexFX.playFlexFX("ting", 4, 180, 400, true); // up a major 3rd +flexFX.playFlexFX("ting", 0, 250, 1600, true); pause(1000); // perform like a cat -flexFX.playFlexFX("miaow", 900, 255, 1000, false); +flexFX.playFlexFX("miaow", 900, 255, 1000, true); pause(300); -flexFX.playFlexFX("miaow", 1100, 255, 500, false); +flexFX.playFlexFX("miaow", 1100, 255, 500, true); pause(300); -flexFX.playFlexFX("miaow", 800, 255, 1500, false); +flexFX.playFlexFX("miaow", 800, 255, 1500, true); pause(1000); // perform "New World" theme on the 2-part horn flexFX -flexFX.playFlexFX("horn", Note.E3 - Note.C3, 255, 900, false); -flexFX.playFlexFX("horn", Note.G3 - Note.C3, 255, 300, false); -flexFX.playFlexFX("horn", Note.G3 - Note.C3, 255, 1200, false); -flexFX.playFlexFX("horn", Note.E3 - Note.C3, 255, 900, false); -flexFX.playFlexFX("horn", Note.D3 - Note.C3, 255, 300, false); -flexFX.playFlexFX("horn", Note.C3 - Note.C3, 255, 1200, false); -flexFX.playFlexFX("horn", Note.D3 - Note.C3, 255, 600, false); -flexFX.playFlexFX("horn", Note.E3 - Note.C3, 255, 600, false); -flexFX.playFlexFX("horn", Note.G3 - Note.C3, 255, 600, false); -flexFX.playFlexFX("horn", Note.E3 - Note.C3, 255, 600, false); -flexFX.playFlexFX("horn", Note.D3 - Note.C3, 255, 2400, false); +flexFX.playFlexFX("horn", Note.E3 - Note.C3, 255, 900, true); +flexFX.playFlexFX("horn", Note.G3 - Note.C3, 255, 300, true); +flexFX.playFlexFX("horn", Note.G3 - Note.C3, 255, 1200, true); +flexFX.playFlexFX("horn", Note.E3 - Note.C3, 255, 900, true); +flexFX.playFlexFX("horn", Note.D3 - Note.C3, 255, 300, true); +flexFX.playFlexFX("horn", Note.C3 - Note.C3, 255, 1200, true); +flexFX.playFlexFX("horn", Note.D3 - Note.C3, 255, 600, true); +flexFX.playFlexFX("horn", Note.E3 - Note.C3, 255, 600, true); +flexFX.playFlexFX("horn", Note.G3 - Note.C3, 255, 600, true); +flexFX.playFlexFX("horn", Note.E3 - Note.C3, 255, 600, true); +flexFX.playFlexFX("horn", Note.D3 - Note.C3, 255, 2400, true); pause(1000); -// create a double flexFX -flexFX.defineFlexFX("siren", - 95, 80, flexFX.Wave.SAWTOOTH, flexFX.Attack.SLOW, flexFX.Effect.NONE, 100, 100, - 70, 100, flexFX.Wave.SAWTOOTH, flexFX.Attack.SLOW, flexFX.Effect.NONE, 75, 80, 45, 10, - 800, 200, 1000); +// create a flexFX for a two-tone police-siren (middle part is silent) +flexFX.defineFlexFX("police", flexFX.Wave.Sawtooth, 760, 800, 160, 200, 450, + flexFX.Effect.None, flexFX.Attack.Even); +// (add a silent gap in the middle) +flexFX.extendFlexFX("police", flexFX.Wave.Silence, 0, 0, 100, + flexFX.Effect.None, flexFX.Attack.Even); +flexFX.extendFlexFX("police", flexFX.Wave.Sawtooth, 600, 160, 450, + flexFX.Effect.None, flexFX.Attack.Even); // queue-up a sequence of Plays on the Play-list (complete with Doppler-shift) -flexFX.playFlexFX("siren", 800, 16, 1000, true); -flexFX.playFlexFX("siren", 800, 32, 1000, true); -flexFX.playFlexFX("siren", 800, 64, 1000, true); -flexFX.playFlexFX("siren", 800, 128, 1000, true); -flexFX.playFlexFX("siren", 800, 255, 1000, true); -flexFX.playFlexFX("siren", 775, 255, 1000, true); -flexFX.playFlexFX("siren", 750, 128, 1000, true); -flexFX.playFlexFX("siren", 750, 64, 1000, true); -flexFX.playFlexFX("siren", 750, 32, 1000, true); -flexFX.playFlexFX("siren", 750, 16, 1000, true); +flexFX.playFlexFX("police", 800, 16, 1000, false); +flexFX.playFlexFX("police", 800, 32, 1000, false); +flexFX.playFlexFX("police", 800, 64, 1000, false); +flexFX.playFlexFX("police", 800, 128, 1000, false); +flexFX.playFlexFX("police", 800, 255, 1000, false); +flexFX.playFlexFX("police", 775, 255, 1000, false); +flexFX.playFlexFX("police", 750, 128, 1000, false); +flexFX.playFlexFX("police", 750, 64, 1000, false); +flexFX.playFlexFX("police", 750, 32, 1000, false); +flexFX.playFlexFX("police", 750, 16, 1000, false); // while the Play-list is playing, flash the blue light (sort of) while(flexFX.isActive()) {