From 9fbf91db06a6d4f4b5cd8bb45389a731bb86bf22 Mon Sep 17 00:00:00 2001 From: Richard Date: Sun, 13 Apr 2025 18:48:02 +0100 Subject: initial --- site/app/twirl/twirl.js | 479 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 479 insertions(+) create mode 100644 site/app/twirl/twirl.js (limited to 'site/app/twirl/twirl.js') diff --git a/site/app/twirl/twirl.js b/site/app/twirl/twirl.js new file mode 100644 index 0000000..5f201f6 --- /dev/null +++ b/site/app/twirl/twirl.js @@ -0,0 +1,479 @@ +window.twirl = { + debug: false, //window.location.href.startsWith("file://"), + themes: ["Default", "Basic", "Hacker", "Monoclassic", "Doze"], + audioTypes: ["audio/mpeg", "audio/mp4", "audio/ogg", "audio/vorbis", "audio/x-flac","audio/aiff","audio/x-aiff", "audio/vnd.wav", "audio/wave", "audio/x-wav", "audio/wav", "audio/flac"], + maxFileSize: 1e+8, // 100MB + latencyCorrection: 40, + storage: {}, + errorState: null, + audioContext: null, + _booted: false, + _initialised: false, + _remote: {sessionID: null, sending: false}, + _els: { + base: null, + toolTip: null, + prompt: {}, + loading: {}, + contextMenu: null + } +}; + +twirl.boot = function() { + if (twirl._booted) return; + twirl.audioContext = new AudioContext(); + twirl._booted = true; +}; + +twirl.init = function() { + if (twirl._initialised) return; + + var NoteData = function() { + var self = this; + this.data = null; + fetch("https://apps.csound.1bpm.net/app/twirl/notedata.json").then(function(r) { + r.json().then(function(j) { + self.data = j; + }); + }); + }; + twirl.noteData = new NoteData(); + + // storage + twirl.storage.data = localStorage.getItem("twirl"); + if (twirl.storage.data) { + twirl.storage.data = JSON.parse(twirl.storage.data); + } else { + twirl.storage.data = {}; + } + + // base + twirl._els.base = $("
").attr("id", "twirl").appendTo($("body")); + + // tooltip + twirl._els.toolTip = $("
").addClass("twirl_tooltip").appendTo(twirl._els.base); + + // context menu + twirl._els.contextMenu = $("
").addClass("twirl_contextmenu").appendTo(twirl._els.base); + + // prompt + var p = twirl._els.prompt; + p.base = $("
").attr("id", "twirl_prompt").appendTo(twirl._els.base); + $("
").attr("id", "twirl_prompt_background").appendTo(p.base); + var promptInner = $("
").attr("id", "twirl_prompt_inner").appendTo(p.base); + p.text = $("
").attr("id", "twirl_prompt_text").appendTo(promptInner); + p.button = $("