This repository has been archived by the owner on Feb 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Add the Sound library #53
Open
sarajoiner
wants to merge
7
commits into
master
Choose a base branch
from
add-sound-library
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
33411c2
Add basic structure for Sound library
sarajoiner e955419
Implementation of Sound.PlayClick
sarajoiner 672526d
Add documentation for PlayClick
sarajoiner 4afcdcb
Add strings for the rest of the Sound APIs
sarajoiner 26b4100
Fix Sound.Play strings
sarajoiner 6bcc162
Add structure for the rest of the Sound APIs
sarajoiner 8e65ba2
Add unit tests for the Sound library
sarajoiner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ISoundLibraryPlugin } from "../../../compiler/runtime/libraries/sound"; | ||
|
||
export class SoundLibraryPlugin implements ISoundLibraryPlugin { | ||
|
||
public playAudio(audioFile: string): void { | ||
if (audioFile !== "") | ||
{ | ||
let audio = new Audio(audioFile); | ||
audio.play(); | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { LibraryTypeInstance, LibraryMethodInstance, LibraryPropertyInstance, LibraryEventInstance } from "../libraries"; | ||
import { SoundLibraryPlugin } from "../../../app/components/common/sound-plugin"; | ||
|
||
export const ClickSound = require("../../../app/content/sounds/click.wav"); | ||
export const ChimeSound = require("../../../app/content/sounds/chime.wav"); | ||
export const ChimesSound = require("../../../app/content/sounds/pause.wav"); | ||
export const BellRingSound = require("../../../app/content/sounds/bellring.wav"); | ||
|
||
enum Sound { | ||
Click, | ||
Chime, | ||
Chimes, | ||
BellRing | ||
} | ||
|
||
export interface ISoundLibraryPlugin { | ||
playAudio(audioFile : string): void; | ||
} | ||
|
||
export class SoundLibrary implements LibraryTypeInstance { | ||
private _pluginInstance: ISoundLibraryPlugin | undefined; | ||
|
||
public get plugin(): ISoundLibraryPlugin { | ||
if (!this._pluginInstance) { | ||
this._pluginInstance = new SoundLibraryPlugin(); | ||
} | ||
|
||
return this._pluginInstance; | ||
} | ||
|
||
public set plugin(plugin: ISoundLibraryPlugin) { | ||
this._pluginInstance = plugin; | ||
} | ||
|
||
private executePlayStockSound(soundName: Sound): void { | ||
let audioFile : string = ""; | ||
switch (soundName) { | ||
case Sound.Click: | ||
audioFile = ClickSound; | ||
break; | ||
case Sound.Chime: | ||
audioFile = ChimeSound; | ||
break; | ||
case Sound.Chimes: | ||
audioFile = ChimesSound; | ||
break; | ||
case Sound.BellRing: | ||
audioFile = BellRingSound; | ||
break; | ||
} | ||
|
||
this.plugin.playAudio(audioFile); | ||
} | ||
|
||
public readonly methods: { readonly [name: string]: LibraryMethodInstance } = { | ||
PlayClick: { execute: this.executePlayStockSound.bind(this, Sound.Click) }, | ||
PlayClickAndWait: { execute: () => { throw new Error("Not Implemented yet."); } }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest not adding the NYI methods until they're actually functional. No need to show it in the UI and crash afterwards if they're not implemented yet. |
||
PlayChime: { execute: this.executePlayStockSound.bind(this, Sound.Chime) }, | ||
PlayChimeAndWait: { execute: () => { throw new Error("Not Implemented yet."); } }, | ||
PlayChimes: { execute: this.executePlayStockSound.bind(this, Sound.Chimes) }, | ||
PlayChimesAndWait: { execute: () => { throw new Error("Not Implemented yet."); } }, | ||
PlayBellRing: { execute: this.executePlayStockSound.bind(this, Sound.BellRing) }, | ||
PlayBellRingAndWait: { execute: () => { throw new Error("Not Implemented yet."); } }, | ||
PlayMusic: { execute: () => { throw new Error("Not Implemented yet."); } }, | ||
Play: { execute: () => { throw new Error("Not Implemented yet."); } }, | ||
PlayAndWait: { execute: () => { throw new Error("Not Implemented yet."); } }, | ||
Pause: { execute: () => { throw new Error("Not Implemented yet."); } }, | ||
Stop: { execute: () => { throw new Error("Not Implemented yet."); } } | ||
}; | ||
|
||
public readonly properties: { readonly [name: string]: LibraryPropertyInstance } = {}; | ||
|
||
public readonly events: { readonly [name: string]: LibraryEventInstance } = {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import "jasmine"; | ||
import { Compilation } from "../../../../src/compiler/compilation"; | ||
import { ExecutionEngine, ExecutionMode, ExecutionState } from "../../../../src/compiler/execution-engine"; | ||
import { TestSoundLibraryPlugin } from "../../helpers"; | ||
import { ClickSound, ChimeSound, ChimesSound, BellRingSound } from "../../../../src/compiler/runtime/libraries/sound"; | ||
|
||
describe("Compiler.Runtime.Libraries.Sound", () => { | ||
it("plays a clicking sound", () => { | ||
const compilation = new Compilation(` | ||
Sound.PlayClick()`); | ||
|
||
const plugin = new TestSoundLibraryPlugin(); | ||
const engine = new ExecutionEngine(compilation); | ||
|
||
engine.libraries.Sound.plugin = plugin; | ||
engine.execute(ExecutionMode.RunToEnd); | ||
|
||
expect(plugin.getLastAudioPlayed()).toBe(ClickSound); | ||
expect(engine.state).toBe(ExecutionState.Terminated); | ||
expect(engine.exception).toBeUndefined(); | ||
}); | ||
|
||
it("plays a chiming sound", () => { | ||
const compilation = new Compilation(` | ||
Sound.PlayChime()`); | ||
|
||
const plugin = new TestSoundLibraryPlugin(); | ||
const engine = new ExecutionEngine(compilation); | ||
|
||
engine.libraries.Sound.plugin = plugin; | ||
engine.execute(ExecutionMode.RunToEnd); | ||
|
||
expect(plugin.getLastAudioPlayed()).toBe(ChimeSound); | ||
expect(engine.state).toBe(ExecutionState.Terminated); | ||
expect(engine.exception).toBeUndefined(); | ||
}); | ||
|
||
it("plays the chimes sound", () => { | ||
const compilation = new Compilation(` | ||
Sound.PlayChimes()`); | ||
|
||
const plugin = new TestSoundLibraryPlugin(); | ||
const engine = new ExecutionEngine(compilation); | ||
|
||
engine.libraries.Sound.plugin = plugin; | ||
engine.execute(ExecutionMode.RunToEnd); | ||
|
||
expect(plugin.getLastAudioPlayed()).toBe(ChimesSound); | ||
expect(engine.state).toBe(ExecutionState.Terminated); | ||
expect(engine.exception).toBeUndefined(); | ||
}); | ||
|
||
it("plays a ringing bell sound", () => { | ||
const compilation = new Compilation(` | ||
Sound.PlayBellRing()`); | ||
|
||
const plugin = new TestSoundLibraryPlugin(); | ||
const engine = new ExecutionEngine(compilation); | ||
|
||
engine.libraries.Sound.plugin = plugin; | ||
engine.execute(ExecutionMode.RunToEnd); | ||
|
||
expect(plugin.getLastAudioPlayed()).toBe(BellRingSound); | ||
expect(engine.state).toBe(ExecutionState.Terminated); | ||
expect(engine.exception).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you document where did we get the sound files from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sound files come from the Desktop copy of the code -- do you know where that got it from? I don't recall seeing any comments.