}, false);
}
+window.onresize = function() {
+ if (document.getElementById("sectSound").classList.contains("active")) {
+ gModSound.resize();
+ }
+}
+
function updateStardate() {
+ // Stardate rules foggy at best. See http://en.wikipedia.org/wiki/Stardate
+ // and the Memory Alpha article linked there for more details.
+ // We roughly lean on TNG scale by splitting an Earth year into exactly 1000
+ // units, but we put the 0 point at the TV premiere of The Original Series.
if (!gStardate)
gStardate = document.getElementById("stardate");
var gModSound = {
activate: function() {
//gSounds.scan.play();
- if (navigator.getUserMedia) {
+ if (navigator.getUserMedia && (window.AudioContext || window.webkitAudioContext)) {
document.getElementById("soundunavail").style.display = "none";
document.getElementById("soundavail").style.display = "block";
navigator.getUserMedia({ audio: true },
// Could put a filter in between like in http://webaudioapi.com/samples/microphone/
gModSound.mDisplay.canvas = document.getElementById("soundcanvas");
gModSound.mDisplay.context = gModSound.mDisplay.canvas.getContext("2d");
- gModSound.mDisplay.canvas.height = document.getElementById("soundavail").clientHeight - 2;
- gModSound.mDisplay.canvas.width = document.getElementById("soundavail").clientWidth;
- gModSound.mAudio.frequencySlices = (gModSound.mDisplay.canvas.width > 512) ?
- 512 :
- Math.pow(2, Math.floor(Math.log(gModSound.mDisplay.canvas.width) / Math.LN2));
- console.log("slices: " + gModSound.mAudio.frequencySlices);
- gModSound.mAudio.analyzer = gModSound.mAudio.context.createAnalyser();
- // Make the FFT four times as large as needed as the upper three quarters turn out to be useless.
- gModSound.mAudio.analyzer.fftSize = gModSound.mAudio.frequencySlices * 4;
- console.log("FFT: " + gModSound.mAudio.analyzer.fftSize);
- gModSound.mAudio.input.connect(gModSound.mAudio.analyzer);
- gModSound.mDisplay.context.setTransform(1, 0, 0, -(gModSound.mDisplay.canvas.height/256), 0, gModSound.mDisplay.canvas.height);
- gModSound.mDisplay.active = true;
- window.requestAnimationFrame(gModSound.paintAnalyzerFrame);
+ gModSound.rebuildCanvas();
},
function(err) {
document.getElementById("soundunavail").style.display = "block";
document.getElementById("soundavail").style.display = "none";
}
},
+ rebuildCanvas: function() {
+ if (gModSound.mDisplay.AFRequestID) {
+ window.cancelAnimationFrame(gModSound.mDisplay.AFRequestID);
+ gModSound.mDisplay.AFRequestID = 0;
+ }
+ gModSound.mDisplay.canvas.height = document.getElementById("soundavail").clientHeight - 4;
+ gModSound.mDisplay.canvas.width = document.getElementById("soundavail").clientWidth;
+ gModSound.mAudio.frequencySlices = (gModSound.mDisplay.canvas.width > 512) ?
+ 512 :
+ Math.pow(2, Math.floor(Math.log(gModSound.mDisplay.canvas.width) / Math.LN2));
+ //console.log("slices: " + gModSound.mAudio.frequencySlices);
+ gModSound.mAudio.analyzer = gModSound.mAudio.context.createAnalyser();
+ // Make the FFT four times as large as needed as the upper three quarters turn out to be useless.
+ gModSound.mAudio.analyzer.fftSize = gModSound.mAudio.frequencySlices * 4;
+ //console.log("FFT: " + gModSound.mAudio.analyzer.fftSize);
+ gModSound.mAudio.input.connect(gModSound.mAudio.analyzer);
+ gModSound.mDisplay.context.setTransform(1, 0, 0, -(gModSound.mDisplay.canvas.height/256), 0, gModSound.mDisplay.canvas.height);
+ gModSound.mDisplay.active = true;
+ gModSound.mDisplay.AFRequestID = window.requestAnimationFrame(gModSound.paintAnalyzerFrame);
+ },
mAudio: {
frequencySlices: 32, // Must be a multiple of 2 (see AnalyserNode.fftSize)
},
gModSound.mDisplay.context.fillRect(i*wid, 0, wid, data[i]);
}
if (gModSound.mDisplay.active)
- window.requestAnimationFrame(gModSound.paintAnalyzerFrame);
+ gModSound.mDisplay.AFRequestID = window.requestAnimationFrame(gModSound.paintAnalyzerFrame);
+ },
+ resize: function() {
+ gModSound.rebuildCanvas();
},
deactivate: function() {
if (gModSound.mDisplay.active) {
},
}
+var gModEnv = {
+ activate: function() {
+ gSounds.scan.play();
+ document.getElementById("envunavail").style.display = "none";
+ document.getElementById("envavail").style.display = "block";
+ window.addEventListener("devicelight", this.lightEvent, true);
+ window.addEventListener("deviceproximity", this.proxEvent, true);
+ setTimeout(function() {
+ if ((document.getElementById("envLight").textContent == "...") &&
+ (document.getElementById("envDistance").textContent == "...")) {
+ gModEnv.deactivate();
+ }
+ }, 5000);
+ try {
+ for (var cameraId of window.navigator.mozCameras.getListOfCameras()) {
+ window.navigator.mozCameras.getCamera({camera: cameraId}, function(aCamera) {
+ if (aCamera.capabilities.flashModes.indexOf('torch') !== -1) {
+ this.flashCamera = aCamera;
+ }
+ });
+ }
+ if (this.flashCamera) {
+ document.getElementById("envFlashOn").onclick = gModEnv.switchFlashlight(true);
+ document.getElementById("envFlashOff").onclick = gModEnv.switchFlashlight(false);
+ document.getElementById("envFlashUnavail").style.display = "none";
+ document.getElementById("envFlashAvail").style.display = "block";
+ }
+ } catch (e) {
+ // camera api not supported
+ document.getElementById("envFlashUnavail").style.display = "block";
+ document.getElementById("envFlashAvail").style.display = "none";
+ }
+ },
+ deactivate: function() {
+ gSounds.scan.pause();
+ window.removeEventListener("devicelight", this.lightEvent, true);
+ window.removeEventListener("deviceproximity", this.proxEvent, true);
+ document.getElementById("envunavail").style.display = "block";
+ document.getElementById("envavail").style.display = "none";
+ document.getElementById("envLight").textContent = "...";
+ document.getElementById("envDistance").textContent = "...";
+ },
+ lightEvent: function(lightData) {
+ // See http://www.w3.org/TR/ambient-light/
+ document.getElementById("envLight").textContent = lightData.value + " lux";
+ },
+ proxEvent: function(proxData) {
+ // See http://www.w3.org/TR/2012/WD-proximity-20120712/
+ if (proxData.value >= proxData.max) {
+ document.getElementById("envDistance").textContent = "(maximum, >= " + proxData.value + " cm)";
+ }
+ else if (proxData.value <= proxData.min) {
+ document.getElementById("envDistance").textContent = "(minimum, <= " + proxData.value + " cm)";
+ }
+ else {
+ document.getElementById("envDistance").textContent = proxData.value + " cm";
+ }
+ },
+ flashCamera: null,
+ switchFlashlight: function(aEnabled) {
+ if (this.flashCamera) {
+ this.flashCamera.flashMode = aEnabled ? 'torch' : 'off';
+ }
+ }
+}
+
var gModDev = {
activate: function() {
gSounds.scan.play();