mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-22 20:43:09 +02:00
fix: load libopenmpt on demand
This commit is contained in:
parent
d1f0fc6d5d
commit
0085305579
5 changed files with 41 additions and 11 deletions
|
@ -43,7 +43,6 @@ html
|
||||||
link(rel='stylesheet' href='/assets/phosphor-icons/bold/style.css')
|
link(rel='stylesheet' href='/assets/phosphor-icons/bold/style.css')
|
||||||
link(rel='stylesheet' href='/static-assets/fonts/sharkey-icons/style.css')
|
link(rel='stylesheet' href='/static-assets/fonts/sharkey-icons/style.css')
|
||||||
link(rel='modulepreload' href=`/vite/${clientEntry.file}`)
|
link(rel='modulepreload' href=`/vite/${clientEntry.file}`)
|
||||||
script(src='/client-assets/libopenmpt.js')
|
|
||||||
|
|
||||||
if !config.clientManifestExists
|
if !config.clientManifestExists
|
||||||
script(type="module" src="/vite/@vite/client")
|
script(type="module" src="/vite/@vite/client")
|
||||||
|
@ -73,7 +72,6 @@ html
|
||||||
script.
|
script.
|
||||||
var VERSION = "#{version}";
|
var VERSION = "#{version}";
|
||||||
var CLIENT_ENTRY = "#{clientEntry.file}";
|
var CLIENT_ENTRY = "#{clientEntry.file}";
|
||||||
window.libopenmpt = window.Module;
|
|
||||||
|
|
||||||
script(type='application/json' id='misskey_meta' data-generated-at=now)
|
script(type='application/json' id='misskey_meta' data-generated-at=now)
|
||||||
!= metaJson
|
!= metaJson
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,9 +1,12 @@
|
||||||
/* global libopenmpt UTF8ToString writeAsciiToMemory */
|
// @ts-nocheck
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
|
|
||||||
const ChiptuneAudioContext = window.AudioContext || window.webkitAudioContext;
|
const ChiptuneAudioContext = window.AudioContext || window.webkitAudioContext;
|
||||||
|
|
||||||
export function ChiptuneJsConfig (repeatCount: number, context: AudioContext) {
|
let libopenmpt
|
||||||
|
let libopenmptLoadPromise
|
||||||
|
|
||||||
|
export function ChiptuneJsConfig (repeatCount?: number, context?: AudioContext) {
|
||||||
this.repeatCount = repeatCount;
|
this.repeatCount = repeatCount;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
@ -20,6 +23,28 @@ export function ChiptuneJsPlayer (config: object) {
|
||||||
this.volume = 1;
|
this.volume = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ChiptuneJsPlayer.prototype.initialize = function() {
|
||||||
|
if (libopenmptLoadPromise) return libopenmptLoadPromise;
|
||||||
|
if (libopenmpt) return;
|
||||||
|
|
||||||
|
libopenmptLoadPromise = new Promise(async (resolve, reject) => {
|
||||||
|
try {
|
||||||
|
const { Module } = await import('./libopenmpt/libopenmpt.js');
|
||||||
|
await new Promise((resolve) => {
|
||||||
|
Module['onRuntimeInitialized'] = resolve;
|
||||||
|
})
|
||||||
|
libopenmpt = Module;
|
||||||
|
resolve()
|
||||||
|
} catch (e) {
|
||||||
|
reject(e)
|
||||||
|
} finally {
|
||||||
|
libopenmptLoadPromise = undefined;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return libopenmptLoadPromise;
|
||||||
|
}
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.constructor = ChiptuneJsPlayer;
|
ChiptuneJsPlayer.prototype.constructor = ChiptuneJsPlayer;
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.fireEvent = function (eventName: string, response) {
|
ChiptuneJsPlayer.prototype.fireEvent = function (eventName: string, response) {
|
||||||
|
@ -61,12 +86,12 @@ ChiptuneJsPlayer.prototype.seek = function (position: number) {
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.metadata = function () {
|
ChiptuneJsPlayer.prototype.metadata = function () {
|
||||||
const data = {};
|
const data = {};
|
||||||
const keys = UTF8ToString(libopenmpt._openmpt_module_get_metadata_keys(this.currentPlayingNode.modulePtr)).split(';');
|
const keys = libopenmpt.UTF8ToString(libopenmpt._openmpt_module_get_metadata_keys(this.currentPlayingNode.modulePtr)).split(';');
|
||||||
let keyNameBuffer = 0;
|
let keyNameBuffer = 0;
|
||||||
for (const key of keys) {
|
for (const key of keys) {
|
||||||
keyNameBuffer = libopenmpt._malloc(key.length + 1);
|
keyNameBuffer = libopenmpt._malloc(key.length + 1);
|
||||||
writeAsciiToMemory(key, keyNameBuffer);
|
libopenmpt.writeAsciiToMemory(key, keyNameBuffer);
|
||||||
data[key] = UTF8ToString(libopenmpt._openmpt_module_get_metadata(this.currentPlayingNode.modulePtr, keyNameBuffer));
|
data[key] = libopenmpt.UTF8ToString(libopenmpt._openmpt_module_get_metadata(this.currentPlayingNode.modulePtr, keyNameBuffer));
|
||||||
libopenmpt._free(keyNameBuffer);
|
libopenmpt._free(keyNameBuffer);
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
|
@ -84,7 +109,7 @@ ChiptuneJsPlayer.prototype.unlock = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.load = function (input) {
|
ChiptuneJsPlayer.prototype.load = function (input) {
|
||||||
return new Promise((resolve, reject) => {
|
return this.initialize().then(() => new Promise((resolve, reject) => {
|
||||||
if(this.touchLocked) {
|
if(this.touchLocked) {
|
||||||
this.unlock();
|
this.unlock();
|
||||||
}
|
}
|
||||||
|
@ -106,7 +131,7 @@ ChiptuneJsPlayer.prototype.load = function (input) {
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.play = function (buffer: ArrayBuffer) {
|
ChiptuneJsPlayer.prototype.play = function (buffer: ArrayBuffer) {
|
||||||
|
@ -180,7 +205,7 @@ ChiptuneJsPlayer.prototype.getPatternNumRows = function (pattern: number) {
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.getPatternRowChannel = function (pattern: number, row: number, channel: number) {
|
ChiptuneJsPlayer.prototype.getPatternRowChannel = function (pattern: number, row: number, channel: number) {
|
||||||
if (this.currentPlayingNode && this.currentPlayingNode.modulePtr) {
|
if (this.currentPlayingNode && this.currentPlayingNode.modulePtr) {
|
||||||
return UTF8ToString(libopenmpt._openmpt_module_format_pattern_row_channel(this.currentPlayingNode.modulePtr, pattern, row, channel, 0, true));
|
return libopenmpt.UTF8ToString(libopenmpt._openmpt_module_format_pattern_row_channel(this.currentPlayingNode.modulePtr, pattern, row, channel, 0, true));
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
8
packages/frontend/src/scripts/libopenmpt/libopenmpt.js
Normal file
8
packages/frontend/src/scripts/libopenmpt/libopenmpt.js
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue