Skip to content

Commit

Permalink
ローダーのバグ修正。
Browse files Browse the repository at this point in the history
SoundFontの上書きがうまくいかないバグ修正。
  • Loading branch information
logue committed Oct 15, 2023
1 parent a8d21ff commit 85a1dd6
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 74 deletions.
31 changes: 22 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ <h1 class="h2">
import SoundFont from '/src/index';

/** sf2synth.js Option */
const options = {
let options = {
...{
// URL to SoundFont File
// url: 'Yamaha XG Sound Set.sf2',
// url: 'https://cdn.jsdelivr.net/npm/@logue/sf2synth@latest/dist/Yamaha XG Sound Set.sf2',
// Show Keyboard
drawSynth: true,
// Target dom id
Expand All @@ -128,8 +128,12 @@ <h1 class="h2">
colorMode: 'auto',
},
...qs.parse(window.location.search),
...qs.parse(window.location.hash),
};

/** @type {typeof import("./src/wml").WebMidiLink } WebMidiLink */
const wml = new SoundFont.WebMidiLink(options);

document.addEventListener(
'DOMContentLoaded',
event => {
Expand All @@ -144,19 +148,17 @@ <h1 class="h2">
/** @type {HTMLSelectElement} */
// const selector = document.getElementById('selector');

// Apply build time
build.dateTime = SoundFont.build;
build.innerText = new Date(SoundFont.build).toLocaleString();

/** @type {typeof import("./src/wml").WebMidiLink } WebMidiLink */
const wml = new SoundFont.WebMidiLink(options);

wml.setLoadCallback(() => {
dragArea.classList.remove('bg-info');
document.getElementById('soundfont').innerText = decodeURIComponent(
wml.getUrl()
).match('.+/(.+?)([?#;].*)?$')[1];
});

// Apply build time
build.dateTime = SoundFont.build;
build.innerText = new Date(SoundFont.build).toLocaleString();

wml.setup();

// Keep an eye out for System Light/Dark Mode Changes
Expand Down Expand Up @@ -250,6 +252,17 @@ <h1 class="h2">
},
false
);

window.addEventListener(
'hashchange',
() => {
const url = qs.parse(window.location.hash);
if (url) {
wml.setup(url);
}
},
false
);
</script>
</body>
</html>
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,20 @@
"lodash": "^4.17.21"
},
"devDependencies": {
"@types/node": "^20.8.2",
"@types/node": "^20.8.6",
"@types/webmidi": "^2.0.8",
"eslint": "^8.50.0",
"eslint": "^8.51.0",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^9.0.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-prettier": "^5.0.1",
"husky": "^8.0.3",
"lint-staged": "^14.0.1",
"lint-staged": "^15.0.1",
"prettier": "^3.0.3",
"query-string": "^8.1.0",
"rimraf": "^5.0.5",
"sass": "1.69.0",
"sass": "1.69.3",
"stylelint": "^15.10.3",
"stylelint-config-recommended-scss": "^13.0.0",
"stylelint-order": "^6.0.3",
Expand Down
5 changes: 1 addition & 4 deletions src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,12 @@ export default class Loader {
* @private
*/
onError(error = undefined) {
requestAnimationFrame(function () {
requestAnimationFrame(() => {
this.alert.className = 'alert alert-danger';
this.message.innerText =
'An error occurred while loading SoundFont. See the console log for details. In addition, it may be cured by deleting the cache of the browser.';
this.progressOuter.style.display = 'none';
});
if (error) {
throw Error(error.message);
}
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/wml.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default class WebMidiLink {
this.option.colorMode = option.colorMode ?? 'auto';
/** @type {string} SoundFont URL */
this.url =
option.url ??
'https://cdn.jsdelivr.net/npm/@logue/sf2synth@latest/dist/Yamaha XG Sound Set.sf2';

/** @type {HTMLDivElement} */
Expand All @@ -63,7 +64,7 @@ export default class WebMidiLink {
* @param {string?} url SoundFont URL
* @public
*/
async setup(url) {
async setup(url = undefined) {
// DOMをクリア
while (this.placeholder.firstChild) {
this.placeholder.removeChild(this.placeholder.firstChild);
Expand All @@ -78,7 +79,7 @@ export default class WebMidiLink {
this.url,
this.placeholder,
this.option.cache,
buffer => this.setupByBuffer(buffer)
(/** @type {ArrayBuffer} */ buffer) => this.setupByBuffer(buffer)
);
await loader.fetch();
}
Expand Down
Loading

0 comments on commit 85a1dd6

Please sign in to comment.