comparison js/core.js @ 2823:25027b8665a2

Implementation for #209
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Tue, 09 May 2017 14:52:00 +0100
parents 6b38dc641812
children 28a5504db337 0228ab1777d9
comparison
equal deleted inserted replaced
2822:394b5e20d78f 2823:25027b8665a2
1715 this.play = function (id) { 1715 this.play = function (id) {
1716 // Start the timer and set the audioEngine state to playing (1) 1716 // Start the timer and set the audioEngine state to playing (1)
1717 if (typeof id !== "number" || id < 0 || id > this.audioObjects.length) { 1717 if (typeof id !== "number" || id < 0 || id > this.audioObjects.length) {
1718 throw ('FATAL - Passed id was undefined - AudioEngineContext.play(id)'); 1718 throw ('FATAL - Passed id was undefined - AudioEngineContext.play(id)');
1719 } 1719 }
1720 var maxPlays = this.audioObjects[id].specification.maxNumberPlays || this.audioObjects[id].specification.parent.maxNumberPlays || specification.maxNumberPlays;
1721 if (maxPlays !== undefined && this.audioObjects[id].numberOfPlays >= maxPlays) {
1722 interfaceContext.lightbox.post("Error", "Cannot play this fragment more than " + maxPlays + " times");
1723 return;
1724 }
1720 if (this.status === 1) { 1725 if (this.status === 1) {
1721 this.timer.startTest(); 1726 this.timer.startTest();
1722 interfaceContext.playhead.setTimePerPixel(this.audioObjects[id]); 1727 interfaceContext.playhead.setTimePerPixel(this.audioObjects[id]);
1723 if (this.synchPlayback && this.loopPlayback) { 1728 if (this.synchPlayback && this.loopPlayback) {
1724 // Traditional looped playback 1729 // Traditional looped playback
1848 } 1853 }
1849 1854
1850 function audioObject(id) { 1855 function audioObject(id) {
1851 // The main buffer object with common control nodes to the AudioEngine 1856 // The main buffer object with common control nodes to the AudioEngine
1852 1857
1858 var playCounter = 0;
1859
1853 this.specification = undefined; 1860 this.specification = undefined;
1854 this.id = id; 1861 this.id = id;
1855 this.state = 0; // 0 - no data, 1 - ready 1862 this.state = 0; // 0 - no data, 1 - ready
1856 this.url = null; // Hold the URL given for the output back to the results. 1863 this.url = null; // Hold the URL given for the output back to the results.
1857 this.metric = new metricTracker(this); 1864 this.metric = new metricTracker(this);
1944 this.interfaceDOM.stopPlayback(); 1951 this.interfaceDOM.stopPlayback();
1945 }; 1952 };
1946 1953
1947 this.play = function (startTime) { 1954 this.play = function (startTime) {
1948 if (this.bufferNode === undefined && this.buffer.buffer !== undefined) { 1955 if (this.bufferNode === undefined && this.buffer.buffer !== undefined) {
1956 playCounter++;
1949 this.bufferNode = audioContext.createBufferSource(); 1957 this.bufferNode = audioContext.createBufferSource();
1950 this.bufferNode.owner = this; 1958 this.bufferNode.owner = this;
1951 this.bufferNode.connect(this.outputGain); 1959 this.bufferNode.connect(this.outputGain);
1952 this.bufferNode.buffer = this.buffer.buffer; 1960 this.bufferNode.buffer = this.buffer.buffer;
1953 this.bufferNode.loop = audioEngineContext.loopPlayback; 1961 this.bufferNode.loop = audioEngineContext.loopPlayback;
2023 this.storeDOM.appendChild(this.commentDOM.exportXMLDOM(this)); 2031 this.storeDOM.appendChild(this.commentDOM.exportXMLDOM(this));
2024 } 2032 }
2025 } 2033 }
2026 this.metric.exportXMLDOM(this.storeDOM.getElementsByTagName('metric')[0]); 2034 this.metric.exportXMLDOM(this.storeDOM.getElementsByTagName('metric')[0]);
2027 }; 2035 };
2036
2037 Object.defineProperties(this, {
2038 "numberOfPlays": {
2039 'get': function () {
2040 return playCounter;
2041 },
2042 'set': function () {
2043 return playCounter;
2044 }
2045 }
2046 });
2028 } 2047 }
2029 2048
2030 function timer() { 2049 function timer() {
2031 /* Timer object used in audioEngine to keep track of session timings 2050 /* Timer object used in audioEngine to keep track of session timings
2032 * Uses the timer of the web audio API, so sample resolution 2051 * Uses the timer of the web audio API, so sample resolution