Mercurial > hg > webaudioevaluationtool
comparison js/core.js @ 2712:eece6007daa5
Finished #180
author | Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk> |
---|---|
date | Fri, 31 Mar 2017 10:47:27 +0100 |
parents | 898a6da5ff6c |
children | 23f84278dc2a |
comparison
equal
deleted
inserted
replaced
2711:898a6da5ff6c | 2712:eece6007daa5 |
---|---|
2427 this.lightbox.blanker.className = "testHalt"; | 2427 this.lightbox.blanker.className = "testHalt"; |
2428 this.lightbox.blanker.id = "lightbox-blanker"; | 2428 this.lightbox.blanker.id = "lightbox-blanker"; |
2429 document.getElementsByTagName("body")[0].appendChild(this.lightbox.root); | 2429 document.getElementsByTagName("body")[0].appendChild(this.lightbox.root); |
2430 document.getElementsByTagName("body")[0].appendChild(this.lightbox.blanker); | 2430 document.getElementsByTagName("body")[0].appendChild(this.lightbox.blanker); |
2431 | 2431 |
2432 this.commentBoxes = new function () { | 2432 this.commentBoxes = (function () { |
2433 this.boxes = []; | 2433 var commentBoxes = {}; |
2434 this.injectPoint = null; | 2434 commentBoxes.boxes = []; |
2435 this.elementCommentBox = function (audioObject) { | 2435 commentBoxes.injectPoint = null; |
2436 commentBoxes.elementCommentBox = function (audioObject) { | |
2436 var element = audioObject.specification; | 2437 var element = audioObject.specification; |
2437 this.audioObject = audioObject; | 2438 this.audioObject = audioObject; |
2438 this.id = audioObject.id; | 2439 this.id = audioObject.id; |
2439 var audioHolderObject = audioObject.specification.parent; | 2440 var audioHolderObject = audioObject.specification.parent; |
2440 // Create document objects to hold the comment boxes | 2441 // Create document objects to hold the comment boxes |
2477 this.trackComment.style.width = boxwidth + "px"; | 2478 this.trackComment.style.width = boxwidth + "px"; |
2478 this.trackCommentBox.style.width = boxwidth - 6 + "px"; | 2479 this.trackCommentBox.style.width = boxwidth - 6 + "px"; |
2479 }; | 2480 }; |
2480 this.resize(); | 2481 this.resize(); |
2481 }; | 2482 }; |
2482 this.createCommentBox = function (audioObject) { | 2483 commentBoxes.createCommentBox = function (audioObject) { |
2483 var node = new this.elementCommentBox(audioObject); | 2484 var node = new this.elementCommentBox(audioObject); |
2484 this.boxes.push(node); | 2485 this.boxes.push(node); |
2485 audioObject.commentDOM = node; | 2486 audioObject.commentDOM = node; |
2486 return node; | 2487 return node; |
2487 }; | 2488 }; |
2488 this.sortCommentBoxes = function () { | 2489 commentBoxes.sortCommentBoxes = function () { |
2489 this.boxes.sort(function (a, b) { | 2490 this.boxes.sort(function (a, b) { |
2490 return a.id - b.id; | 2491 return a.id - b.id; |
2491 }); | 2492 }); |
2492 }; | 2493 }; |
2493 | 2494 |
2494 this.showCommentBoxes = function (inject, sort) { | 2495 commentBoxes.showCommentBoxes = function (inject, sort) { |
2495 this.injectPoint = inject; | 2496 this.injectPoint = inject; |
2496 if (sort) { | 2497 if (sort) { |
2497 this.sortCommentBoxes(); | 2498 this.sortCommentBoxes(); |
2498 } | 2499 } |
2499 this.boxes.forEach(function (box) { | 2500 this.boxes.forEach(function (box) { |
2500 inject.appendChild(box.trackComment); | 2501 inject.appendChild(box.trackComment); |
2501 }); | 2502 }); |
2502 }; | 2503 }; |
2503 | 2504 |
2504 this.deleteCommentBoxes = function () { | 2505 commentBoxes.deleteCommentBoxes = function () { |
2505 if (this.injectPoint !== null) { | 2506 if (this.injectPoint !== null) { |
2506 this.boxes.forEach(function (box) { | 2507 this.boxes.forEach(function (box) { |
2507 this.injectPoint.removeChild(box.trackComment); | 2508 this.injectPoint.removeChild(box.trackComment); |
2508 }, this); | 2509 }, this); |
2509 this.injectPoint = null; | 2510 this.injectPoint = null; |
2510 } | 2511 } |
2511 this.boxes = []; | 2512 this.boxes = []; |
2512 }; | 2513 }; |
2513 }; | 2514 return commentBoxes; |
2515 })(); | |
2514 | 2516 |
2515 this.commentQuestions = []; | 2517 this.commentQuestions = []; |
2516 | 2518 |
2517 this.commentBox = function (commentQuestion) { | 2519 this.commentBox = function (commentQuestion) { |
2518 this.specification = commentQuestion; | 2520 this.specification = commentQuestion; |
2831 this.outsideReferenceHolder.textContent = "Error"; | 2833 this.outsideReferenceHolder.textContent = "Error"; |
2832 this.outsideReferenceHolder.style.backgroundColor = "#F00"; | 2834 this.outsideReferenceHolder.style.backgroundColor = "#F00"; |
2833 }; | 2835 }; |
2834 }; | 2836 }; |
2835 | 2837 |
2836 this.playhead = new function () { | 2838 this.playhead = (function () { |
2837 this.object = document.createElement('div'); | 2839 var playhead ={}; |
2838 this.object.className = 'playhead'; | 2840 playhead.object = document.createElement('div'); |
2839 this.object.align = 'left'; | 2841 playhead.object.className = 'playhead'; |
2842 playhead.object.align = 'left'; | |
2840 var curTime = document.createElement('div'); | 2843 var curTime = document.createElement('div'); |
2841 curTime.style.width = '50px'; | 2844 curTime.style.width = '50px'; |
2842 this.curTimeSpan = document.createElement('span'); | 2845 playhead.curTimeSpan = document.createElement('span'); |
2843 this.curTimeSpan.textContent = '00:00'; | 2846 playhead.curTimeSpan.textContent = '00:00'; |
2844 curTime.appendChild(this.curTimeSpan); | 2847 curTime.appendChild(playhead.curTimeSpan); |
2845 this.object.appendChild(curTime); | 2848 playhead.object.appendChild(curTime); |
2846 this.scrubberTrack = document.createElement('div'); | 2849 playhead.scrubberTrack = document.createElement('div'); |
2847 this.scrubberTrack.className = 'playhead-scrub-track'; | 2850 playhead.scrubberTrack.className = 'playhead-scrub-track'; |
2848 | 2851 |
2849 this.scrubberHead = document.createElement('div'); | 2852 playhead.scrubberHead = document.createElement('div'); |
2850 this.scrubberHead.id = 'playhead-scrubber'; | 2853 playhead.scrubberHead.id = 'playhead-scrubber'; |
2851 this.scrubberTrack.appendChild(this.scrubberHead); | 2854 playhead.scrubberTrack.appendChild(playhead.scrubberHead); |
2852 this.object.appendChild(this.scrubberTrack); | 2855 playhead.object.appendChild(playhead.scrubberTrack); |
2853 | 2856 |
2854 this.timePerPixel = 0; | 2857 playhead.timePerPixel = 0; |
2855 this.maxTime = 0; | 2858 playhead.maxTime = 0; |
2856 | 2859 |
2857 this.playbackObject = undefined; | 2860 playhead.playbackObject = undefined; |
2858 | 2861 |
2859 this.setTimePerPixel = function (audioObject) { | 2862 playhead.setTimePerPixel = function (audioObject) { |
2860 //maxTime must be in seconds | 2863 //maxTime must be in seconds |
2861 this.playbackObject = audioObject; | 2864 this.playbackObject = audioObject; |
2862 this.maxTime = audioObject.buffer.buffer.duration; | 2865 this.maxTime = audioObject.buffer.buffer.duration; |
2863 var width = 490; //500 - 10, 5 each side of the tracker head | 2866 var width = 490; //500 - 10, 5 each side of the tracker head |
2864 this.timePerPixel = this.maxTime / 490; | 2867 this.timePerPixel = this.maxTime / 490; |
2867 } else { | 2870 } else { |
2868 this.curTimeSpan.textContent = '00:00'; | 2871 this.curTimeSpan.textContent = '00:00'; |
2869 } | 2872 } |
2870 }; | 2873 }; |
2871 | 2874 |
2872 this.update = function () { | 2875 playhead.update = function () { |
2873 // Update the playhead position, startPlay must be called | 2876 // Update the playhead position, startPlay must be called |
2874 if (this.timePerPixel > 0) { | 2877 if (this.timePerPixel > 0) { |
2875 var time = this.playbackObject.getCurrentPosition(); | 2878 var time = this.playbackObject.getCurrentPosition(); |
2876 if (time > 0 && time < this.maxTime) { | 2879 if (time > 0 && time < this.maxTime) { |
2877 var width = 490; | 2880 var width = 490; |
2897 } | 2900 } |
2898 } | 2901 } |
2899 } | 2902 } |
2900 }; | 2903 }; |
2901 | 2904 |
2902 this.interval = undefined; | 2905 playhead.interval = undefined; |
2903 | 2906 |
2904 this.start = function () { | 2907 playhead.start = function () { |
2905 if (this.playbackObject !== undefined && this.interval === undefined) { | 2908 if (this.playbackObject !== undefined && this.interval === undefined) { |
2906 if (this.maxTime < 60) { | 2909 if (this.maxTime < 60) { |
2907 this.interval = window.setInterval(function () { | 2910 this.interval = window.setInterval(function () { |
2908 interfaceContext.playhead.update(); | 2911 interfaceContext.playhead.update(); |
2909 }, 10); | 2912 }, 10); |
2912 interfaceContext.playhead.update(); | 2915 interfaceContext.playhead.update(); |
2913 }, 100); | 2916 }, 100); |
2914 } | 2917 } |
2915 } | 2918 } |
2916 }; | 2919 }; |
2917 this.stop = function () { | 2920 playhead.stop = function () { |
2918 window.clearInterval(this.interval); | 2921 window.clearInterval(this.interval); |
2919 this.interval = undefined; | 2922 this.interval = undefined; |
2920 this.scrubberHead.style.left = '0px'; | 2923 this.scrubberHead.style.left = '0px'; |
2921 if (this.maxTime < 60) { | 2924 if (this.maxTime < 60) { |
2922 this.curTimeSpan.textContent = '0.00'; | 2925 this.curTimeSpan.textContent = '0.00'; |
2923 } else { | 2926 } else { |
2924 this.curTimeSpan.textContent = '00:00'; | 2927 this.curTimeSpan.textContent = '00:00'; |
2925 } | 2928 } |
2926 }; | 2929 }; |
2927 }; | 2930 return playhead; |
2928 | 2931 })(); |
2929 this.volume = new function () { | 2932 |
2933 this.volume = (function () { | |
2930 // An in-built volume module which can be viewed on page | 2934 // An in-built volume module which can be viewed on page |
2931 // Includes trackers on page-by-page data | 2935 // Includes trackers on page-by-page data |
2932 // Volume does NOT reset to 0dB on each page load | 2936 // Volume does NOT reset to 0dB on each page load |
2933 this.valueLin = 1.0; | 2937 var volume = {}; |
2934 this.valueDB = 0.0; | 2938 volume.valueLin = 1.0; |
2935 this.root = document.createElement('div'); | 2939 volume.valueDB = 0.0; |
2936 this.root.id = 'master-volume-root'; | 2940 volume.root = document.createElement('div'); |
2937 this.object = document.createElement('div'); | 2941 volume.root.id = 'master-volume-root'; |
2938 this.object.className = 'master-volume-holder-float'; | 2942 volume.object = document.createElement('div'); |
2939 this.object.appendChild(this.root); | 2943 volume.object.className = 'master-volume-holder-float'; |
2940 this.slider = document.createElement('input'); | 2944 volume.object.appendChild(volume.root); |
2941 this.slider.id = 'master-volume-control'; | 2945 volume.slider = document.createElement('input'); |
2942 this.slider.type = 'range'; | 2946 volume.slider.id = 'master-volume-control'; |
2943 this.valueText = document.createElement('span'); | 2947 volume.slider.type = 'range'; |
2944 this.valueText.id = 'master-volume-feedback'; | 2948 volume.valueText = document.createElement('span'); |
2945 this.valueText.textContent = '0dB'; | 2949 volume.valueText.id = 'master-volume-feedback'; |
2946 | 2950 volume.valueText.textContent = '0dB'; |
2947 this.slider.min = -60; | 2951 |
2948 this.slider.max = 12; | 2952 volume.slider.min = -60; |
2949 this.slider.value = 0; | 2953 volume.slider.max = 12; |
2950 this.slider.step = 1; | 2954 volume.slider.value = 0; |
2951 this.handleEvent = function (event) { | 2955 volume.slider.step = 1; |
2956 volume.handleEvent = function (event) { | |
2952 if (event.type == "mousemove") { | 2957 if (event.type == "mousemove") { |
2953 this.valueDB = Number(this.slider.value); | 2958 this.valueDB = Number(this.slider.value); |
2954 this.valueLin = decibelToLinear(this.valueDB); | 2959 this.valueLin = decibelToLinear(this.valueDB); |
2955 this.valueText.textContent = this.valueDB + 'dB'; | 2960 this.valueText.textContent = this.valueDB + 'dB'; |
2956 audioEngineContext.outputGain.gain.value = this.valueLin; | 2961 audioEngineContext.outputGain.gain.value = this.valueLin; |
2961 | 2966 |
2962 if (event.stopPropagation) { | 2967 if (event.stopPropagation) { |
2963 event.stopPropagation(); | 2968 event.stopPropagation(); |
2964 } | 2969 } |
2965 }; | 2970 }; |
2966 this.onmouseup = function () { | 2971 volume.onmouseup = function () { |
2967 var storePoint = testState.currentStore.XMLDOM.getElementsByTagName('metric')[0].getAllElementsByName('volumeTracker'); | 2972 var storePoint = testState.currentStore.XMLDOM.getElementsByTagName('metric')[0].getAllElementsByName('volumeTracker'); |
2968 if (storePoint.length === 0) { | 2973 if (storePoint.length === 0) { |
2969 storePoint = storage.document.createElement('metricresult'); | 2974 storePoint = storage.document.createElement('metricresult'); |
2970 storePoint.setAttribute('name', 'volumeTracker'); | 2975 storePoint.setAttribute('name', 'volumeTracker'); |
2971 testState.currentStore.XMLDOM.getElementsByTagName('metric')[0].appendChild(storePoint); | 2976 testState.currentStore.XMLDOM.getElementsByTagName('metric')[0].appendChild(storePoint); |
2976 node.setAttribute('test-time', audioEngineContext.timer.getTestTime()); | 2981 node.setAttribute('test-time', audioEngineContext.timer.getTestTime()); |
2977 node.setAttribute('volume', this.valueDB); | 2982 node.setAttribute('volume', this.valueDB); |
2978 node.setAttribute('format', 'dBFS'); | 2983 node.setAttribute('format', 'dBFS'); |
2979 storePoint.appendChild(node); | 2984 storePoint.appendChild(node); |
2980 }; | 2985 }; |
2981 this.slider.addEventListener("mousemove", this); | 2986 volume.slider.addEventListener("mousemove", volume); |
2982 this.root.addEventListener("mouseup", this); | 2987 volume.root.addEventListener("mouseup", volume); |
2983 | 2988 |
2984 var title = document.createElement('div'); | 2989 var title = document.createElement('div'); |
2985 title.innerHTML = '<span>Master Volume Control</span>'; | 2990 title.innerHTML = '<span>Master Volume Control</span>'; |
2986 title.style.fontSize = '0.75em'; | 2991 title.style.fontSize = '0.75em'; |
2987 title.style.width = "100%"; | 2992 title.style.width = "100%"; |
2988 title.align = 'center'; | 2993 title.align = 'center'; |
2989 this.root.appendChild(title); | 2994 volume.root.appendChild(title); |
2990 | 2995 |
2991 this.root.appendChild(this.slider); | 2996 volume.root.appendChild(volume.slider); |
2992 this.root.appendChild(this.valueText); | 2997 volume.root.appendChild(volume.valueText); |
2993 | 2998 |
2994 this.resize = function (event) { | 2999 volume.resize = function (event) { |
2995 if (window.innerWidth < 1000) { | 3000 if (window.innerWidth < 1000) { |
2996 this.object.className = "master-volume-holder-inline"; | 3001 this.object.className = "master-volume-holder-inline"; |
2997 } else { | 3002 } else { |
2998 this.object.className = 'master-volume-holder-float'; | 3003 this.object.className = 'master-volume-holder-float'; |
2999 } | 3004 } |
3000 }; | 3005 }; |
3001 }; | 3006 return volume; |
3007 })(); | |
3002 | 3008 |
3003 this.calibrationModuleObject = null; | 3009 this.calibrationModuleObject = null; |
3004 this.calibrationModule = function () { | 3010 this.calibrationModule = function () { |
3005 // This creates an on-page calibration module | 3011 // This creates an on-page calibration module |
3006 this.storeDOM = storage.document.createElement("calibration"); | 3012 this.storeDOM = storage.document.createElement("calibration"); |
3012 var f0 = 62.5; | 3018 var f0 = 62.5; |
3013 this.holder = document.createElement("div"); | 3019 this.holder = document.createElement("div"); |
3014 this.holder.className = "calibration-holder"; | 3020 this.holder.className = "calibration-holder"; |
3015 this.calibrationNodes = []; | 3021 this.calibrationNodes = []; |
3016 while (f0 < 20000) { | 3022 while (f0 < 20000) { |
3023 /* jshint loopfunc: true */ | |
3017 var obj = { | 3024 var obj = { |
3018 root: document.createElement("div"), | 3025 root: document.createElement("div"), |
3019 input: document.createElement("input"), | 3026 input: document.createElement("input"), |
3020 oscillator: audioContext.createOscillator(), | 3027 oscillator: audioContext.createOscillator(), |
3021 gain: audioContext.createGain(), | 3028 gain: audioContext.createGain(), |
3256 var range = audioEngineContext.audioObjects.reduce(function (a, b) { | 3263 var range = audioEngineContext.audioObjects.reduce(function (a, b) { |
3257 var v = b.interfaceDOM.getValue(); | 3264 var v = b.interfaceDOM.getValue(); |
3258 return { | 3265 return { |
3259 min: Math.min(a.min, v), | 3266 min: Math.min(a.min, v), |
3260 max: Math.max(a.max, v) | 3267 max: Math.max(a.max, v) |
3261 } | 3268 }; |
3262 }, { | 3269 }, { |
3263 min: 100, | 3270 min: 100, |
3264 max: 0 | 3271 max: 0 |
3265 }); | 3272 }); |
3266 if (range.min > scales.min) { | 3273 if (range.min > scales.min) { |
3267 str += "At least one fragment must be below the " + range.min + " mark."; | 3274 str += "At least one fragment must be below the " + range.min + " mark."; |
3268 state = false; | 3275 state = false; |
3269 } else if (range.max < sacles.max) { | 3276 } else if (range.max < scales.max) { |
3270 str += "At least one fragment must be above the " + range.max + " mark."; | 3277 str += "At least one fragment must be above the " + range.max + " mark."; |
3271 state = false; | 3278 state = false; |
3272 } | 3279 } |
3273 if (state === false) { | 3280 if (state === false) { |
3274 console.log(str); | 3281 console.log(str); |