Mercurial > hg > webaudioevaluationtool
changeset 3059:01ca365f350d
Merge branch 'vnext' into Dev_main
author | Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk> |
---|---|
date | Tue, 31 Oct 2017 11:30:27 +0000 |
parents | 05fa3ce95015 (current diff) 824c8539fd02 (diff) |
children | b17a3e5e469b |
files | js/core.js |
diffstat | 2 files changed, 75 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/interfaces/ordinal.css Tue Oct 31 10:55:09 2017 +0000 +++ b/interfaces/ordinal.css Tue Oct 31 11:30:27 2017 +0000 @@ -34,3 +34,10 @@ .ordinal-element-label { font-size: 2em; } +div#outside-reference-holder { + display: flex; + align-content: center; + justify-content: center; + margin-bottom: 5px; + min-height: 20px; +}
--- a/js/core.js Tue Oct 31 10:55:09 2017 +0000 +++ b/js/core.js Tue Oct 31 11:30:27 2017 +0000 @@ -1845,6 +1845,7 @@ this.timer = new timer(); this.loopPlayback = audioHolderObject.loop; this.synchPlayback = audioHolderObject.synchronous; + interfaceContext.keyboardInterface.resetKeyBindings(); }; this.checkAllPlayed = function () { @@ -1985,7 +1986,13 @@ this.interfaceDOM.error(); return; } - this.storeDOM.setAttribute('presentedId', interfaceObject.getPresentedId()); + var presentedId = interfaceObject.getPresentedId(); + this.storeDOM.setAttribute('presentedId', presentedId); + + // Key-bindings + if (presentedId.length == 1) { + interfaceContext.keyboardInterface.registerKeyBinding(presentedId, this); + } }; this.listenStart = function (setTime) { @@ -2366,6 +2373,66 @@ loadTest(audioHolderObject, store); }; + this.keyboardInterface = (function () { + var keyboardInterfaceController = { + keys: [], + registerKeyBinding: function (key, audioObject) { + if (typeof key != "string" || key.length != 1) { + throw ("Key must be a singular character"); + } + var included = this.keys.findIndex(function (k) { + return k.key == key + }) >= 0; + if (included) { + throw ("Key " + key + " already bounded!"); + } + this.keys.push({ + key: key, + audioObject: audioObject + }); + return true; + }, + deregisterKeyBinding: function (key) { + var index = this.keys.findIndex(function (k) { + return k.key == key; + }); + if (index == -1) { + throw ("Key " + key + " not bounded!"); + } + this.keys.splice(index, 1); + return true; + }, + resetKeyBindings: function () { + this.keys = []; + }, + handleEvent: function (e) { + function isPlaying() { + return audioEngineContext.audioObjects.some(function (a) { + return a.playing; + }); + } + + function keypress(key) { + var index = this.keys.findIndex(function (k) { + return k.key == key + }); + if (index >= 0) { + audioEngineContext.play(this.keys[index].audioObject.id); + } + } + if (e.key === " ") { + if (isPlaying()) { + audioEngineContext.stop(); + } + } else { + keypress.call(this, e.key); + } + } + }; + document.addEventListener("keydown", keyboardInterfaceController, false); + return keyboardInterfaceController; + })(); + // Bounded by interface!! // Interface object MUST have an exportXMLDOM method which returns the various DOM levels // For example, APE returns the slider position normalised in a <value> tag.