-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
399 additions
and
170 deletions.
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
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,62 @@ | ||
/** | ||
* @typedef { | ||
* "noteon"| | ||
* "noteoff"| | ||
* "pitchwheel"| | ||
* "controllerchange"| | ||
* "programchange"| | ||
* "drumchange"} EventTypes | ||
*/ | ||
export class EventHandler | ||
{ | ||
/** | ||
* A new synthesizer event handler | ||
*/ | ||
constructor() { | ||
/** | ||
* The main list of events | ||
* @type {Object<EventTypes, function(Object)[]>} | ||
*/ | ||
this.events = {}; | ||
} | ||
|
||
/** | ||
* Adds a new event listener | ||
* @param name {EventTypes} | ||
* @param callback {function(Object)} | ||
*/ | ||
addEvent(name, callback) | ||
{ | ||
if(this.events[name]) | ||
{ | ||
this.events[name].push(callback); | ||
} | ||
else | ||
{ | ||
this.events[name] = [callback]; | ||
} | ||
} | ||
|
||
/** | ||
* Removes an event listener | ||
* @param name {EventTypes} | ||
* @param callback {function(Object)} | ||
*/ | ||
removeEvent(name, callback) | ||
{ | ||
this.events[name].splice(this.events[name].findIndex(c => c === callback), 1); | ||
} | ||
|
||
/** | ||
* Calls the given event | ||
* @param name {EventTypes} | ||
* @param eventData {Object} | ||
*/ | ||
callEvent(name, eventData) | ||
{ | ||
if(this.events[name]) | ||
{ | ||
this.events[name].forEach(ev => ev(eventData)); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.