2016-11-27 06:51:16 +01:00
|
|
|
var player; // Define "player" var to make my code linter happy
|
2016-03-04 18:41:03 +01:00
|
|
|
|
2016-11-27 06:51:16 +01:00
|
|
|
function start() { // Start Web Worker & send song data to player
|
|
|
|
var logs = document.getElementById('logs'); // Define log element
|
2016-03-04 18:41:03 +01:00
|
|
|
|
2016-11-27 06:51:16 +01:00
|
|
|
// Create Web Worker if it doesn't already exist
|
2016-11-27 06:13:23 +01:00
|
|
|
if (window.Worker && typeof(player) == "undefined") {
|
|
|
|
var player = new Worker("worker.js");
|
|
|
|
window.player = player; // Make variable Global
|
|
|
|
player.onmessage = function(event) {
|
|
|
|
var data = event.data;
|
|
|
|
window.logs.value += data;
|
|
|
|
};
|
2016-03-04 18:41:03 +01:00
|
|
|
|
2016-11-27 06:51:16 +01:00
|
|
|
// Send song data to player
|
2016-11-27 06:13:23 +01:00
|
|
|
var song = document.getElementById("tones").innerHTML;
|
|
|
|
player.postMessage(song);
|
2016-03-08 05:58:24 +01:00
|
|
|
}
|
2016-03-04 18:41:03 +01:00
|
|
|
}
|
|
|
|
|
2016-11-27 06:51:16 +01:00
|
|
|
function end() { // Stops the Web Worker
|
2016-11-27 06:13:23 +01:00
|
|
|
player.terminate();
|
2016-03-04 18:41:03 +01:00
|
|
|
}
|
2016-11-24 05:12:26 +01:00
|
|
|
|
|
|
|
function pause(time) {
|
|
|
|
window.logs.value += "\nPaused / " + time*.001 + " seconds";
|
|
|
|
var dt = new Date();
|
|
|
|
while ((new Date()) - dt <= time) { /* Do nothing */ }
|
|
|
|
}
|