- Convert a DLS soundfont into an SF2 one, online for free! Created by me using SpessaSynth + Convert a DLS soundfont into an SF2 one, online for free! Created by me using SpessaSynth
${e}`; } loadingMessage.innerHTML = `Error parsing soundfont:
${e}`; - } + }; await manager.ready; - - if(fileInput.files[0]) + + if (fileInput.files[0]) { await startMidi(fileInput.files); } else { fileInput.onclick = undefined; - fileInput.onchange = () => { - if(fileInput.files[0]) + fileInput.onchange = () => + { + if (fileInput.files[0]) { startMidi(fileInput.files).then(); } - } + }; } - - changeIcon(getCheckSvg(256)) + + changeIcon(getCheckSvg(256)); loadingMessage.textContent = localeManager.getLocaleString("locale.synthInit.done"); } async function fetchFont(url, callback) { let response = await fetch(url); - if(!response.ok) + if (!response.ok) { titleMessage.innerText = "Error downloading soundfont!"; throw response; @@ -232,16 +248,18 @@ async function fetchFont(url, callback) let done = false; let dataArray = new Uint8Array(parseInt(size)); let offset = 0; - do{ + do + { let readData = await reader.read(); - if(readData.value) { + if (readData.value) + { dataArray.set(readData.value, offset); offset += readData.value.length; } done = readData.done; let percent = Math.round((offset / size) * 100); callback(percent); - }while(!done); + } while (!done); return dataArray.buffer; } @@ -253,9 +271,9 @@ async function fetchFont(url, callback) */ async function startMidi(midiFiles) { - demoSongButton.style.display = "none" + demoSongButton.style.display = "none"; let fName; - if(midiFiles[0].name.length > 20) + if (midiFiles[0].name.length > 20) { fName = midiFiles[0].name.substring(0, 21) + "..."; } @@ -263,7 +281,7 @@ async function startMidi(midiFiles) { fName = midiFiles[0].name; } - if(midiFiles.length > 1) + if (midiFiles.length > 1) { fName += ` and ${midiFiles.length - 1} others`; } @@ -273,24 +291,24 @@ async function startMidi(midiFiles) * @type {MIDIFile[]} */ const parsed = []; - for(const file of midiFiles) + for (const file of midiFiles) { parsed.push({ binary: await file.arrayBuffer(), altName: file.name - }) + }); } manager.synth.setLogLevel(false, false, false, false); - if(manager.seq) + if (manager.seq) { manager.seq.loadNewSongList(parsed); - + } else { manager.play(parsed); } - + exportButton.style.display = "flex"; exportButton.onclick = window.manager.exportSong.bind(window.manager); } @@ -304,7 +322,7 @@ async function startMidi(midiFiles) function saveSettings(settingsData) { localStorage.setItem("spessasynth-settings", JSON.stringify(settingsData)); - SpessaSynthInfo("saved as", settingsData) + SpessaSynthInfo("saved as", settingsData); } // INIT STARTS HERE @@ -314,19 +332,20 @@ window.saveSettings = saveSettings; // load saved settings const saved = JSON.parse(localStorage.getItem("spessasynth-settings")); -if(saved !== null) +if (saved !== null) { /** * reads the settings * @type {Promise
${e}`; changeIcon(getExclamationSvg(256)); console.error(e); - } - loadingMessage.textContent = window.manager.localeManager.getLocaleString("locale.synthInit.startingSynthesizer"); + }; + loadingMessage.textContent = window.manager.localeManager.getLocaleString( + "locale.synthInit.startingSynthesizer"); await window.manager.reloadSf(soundFontBuffer); - if(window.manager.seq) + if (window.manager.seq) { window.manager.seq.currentTime -= 0.1; } - loadingMessage.textContent = window.manager.localeManager.getLocaleString("locale.synthInit.savingSoundfont"); + loadingMessage.textContent = window.manager.localeManager.getLocaleString( + "locale.synthInit.savingSoundfont"); await saveSoundFontToIndexedDB(soundFontBuffer); // wait to make sure that the animation has finished const elapsed = (performance.now() / 1000) - parseStart; await new Promise(r => setTimeout(r, 1000 - elapsed)); // DONE - changeIcon(getCheckSvg(256)) - loadingMessage.textContent = window.manager.localeManager.getLocaleString("locale.synthInit.done"); + changeIcon(getCheckSvg(256)); + loadingMessage.textContent = window.manager.localeManager.getLocaleString( + "locale.synthInit.done"); loading.classList.add("done"); document.documentElement.classList.add("no_scroll"); document.body.classList.add("no_scroll"); - setTimeout(() => { + setTimeout(() => + { loading.style.display = "none"; document.body.classList.remove("no_scroll"); document.documentElement.classList.remove("no_scroll"); - }, 1000) + }, 1000); }, ANIMATION_REFLOW_TIME); - } - demoSongButton.onclick = async () => { + }; + demoSongButton.onclick = async () => + { /** * @type {NotificationContent[]} */ @@ -459,20 +493,24 @@ demoInit(initLocale).then(() => { { type: "button", textContent: window.manager.localeManager.getLocaleString("locale.credits"), - onClick: () => { + onClick: () => + { window.open("https://github.com/spessasus/spessasynth-demo-songs#readme"); } }, { type: "button", textContent: "Bundled SoundFont Credits", - onClick: () => { + onClick: () => + { window.open("https://schristiancollins.com/generaluser.php"); } } ]; - titleMessage.textContent = window.manager.localeManager.getLocaleString("locale.synthInit.genericLoading"); - const songs = await ((await fetch("https://spessasus.github.io/spessasynth-demo-songs/demo_song_list.json")).text()); + titleMessage.textContent = window.manager.localeManager.getLocaleString( + "locale.synthInit.genericLoading"); + const songs = await ((await fetch( + "https://spessasus.github.io/spessasynth-demo-songs/demo_song_list.json")).text()); /** * @type {{ * name: string, @@ -480,24 +518,25 @@ demoInit(initLocale).then(() => { * }[]} */ const songsJSON = JSON.parse(songs); - for(const song of songsJSON) + for (const song of songsJSON) { contents.push({ type: "button", textContent: song.name, - onClick:async n => { + onClick: async n => + { closeNotification(n.id); await playDemoSong(song.fileName); } - },) + }); } - + showNotification( window.manager.localeManager.getLocaleString("locale.demoSongButton"), contents, 999999, true, undefined - ) + ); }; }); diff --git a/src/website/js/main/local_main.js b/src/website/js/main/local_main.js index 26ed3e4e..1e1c151e 100644 --- a/src/website/js/main/local_main.js +++ b/src/website/js/main/local_main.js @@ -1,9 +1,9 @@ -"use strict" +"use strict"; -import {Manager} from "../manager/manager.js"; -import { showNotification } from '../notification/notification.js' -import { LocaleManager } from '../locale/locale_manager.js' -import { SpessaSynthLogging } from '../../../spessasynth_lib/utils/loggin.js' +import { Manager } from "../manager/manager.js"; +import { showNotification } from "../notification/notification.js"; +import { LocaleManager } from "../locale/locale_manager.js"; +import { SpessaSynthLogging } from "../../../spessasynth_lib/utils/loggin.js"; /** * local_main.js @@ -50,7 +50,7 @@ window.SPESSASYNTH_VERSION = r; async function fetchFont(fileName, callback) { let response = await fetch(`${fileName}`); - if(!response.ok) + if (!response.ok) { titleMessage.innerText = "Error downloading soundfont!"; throw response; @@ -59,34 +59,38 @@ async function fetchFont(fileName, callback) let reader = await (await response.body).getReader(); let done = false; let dataArray; - try { + try + { dataArray = new Uint8Array(parseInt(size)); - } - catch (e) + } catch (e) { let message = `Your browser ran out of memory. Consider using Firefox or SF3 soundfont instead
${Object.keys(messageTypes) + text += `${this.decodeTextFix(raw.data.buffer)}${Object.keys(messageTypes) .find(k => messageTypes[k] === raw.type) - .replace(/([a-z])([A-Z])/g, '$1 $2')}:${this.decodeTextFix(raw.data.buffer)}
`; + .replace( + /([a-z])([A-Z])/g, + "$1 $2" + )}: