Skip to content

Commit

Permalink
Support MSX-DOS format MML.
Browse files Browse the repository at this point in the history
  • Loading branch information
okaxaki committed Nov 6, 2023
1 parent 659f214 commit 0d38cd5
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
13 changes: 7 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "msxplay-js",
"version": "1.6.0",
"version": "1.6.1",
"description": "",
"type": "module",
"engines": {
Expand All @@ -16,6 +16,7 @@
"mgsrc-js": "^2.0.0",
"prettier": "^2.8.4",
"rimraf": "^4.4.1",
"utf16-to-sjis": "^1.1.1",
"webaudio-stream-player": "github:digital-sound-antiques/webaudio-stream-player",
"webpack": "^5.76.2",
"webpack-bundle-analyzer": "^4.8.0",
Expand Down
5 changes: 5 additions & 0 deletions public/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@
<div class="subtext" lang="ja">テキスト形式でダウンロード</div>
<div class="subtext" lang="en">Download as a plain text file.</div>
</li>
<li data-value="mml-for-msx">
<div class="title">MML (for MSX-DOS)</div>
<div class="subtext" lang="ja">テキスト形式(MSX-DOS用)をダウンロード</div>
<div class="subtext" lang="en">Download as a text file for MSX-DOS.</div>
</li>
<li data-value="mgs">
<div class="title">MGS</div>
<div class="subtext" lang="ja">MGS形式でダウンロード</div>
Expand Down
10 changes: 9 additions & 1 deletion public/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,13 @@ function downloadAudio(type, rate, kbps, quality) {

function downloadMML() {
var blob = new Blob([editor.getValue()], { type: "text/plain" });
saveAs(blob, lastCompiledName || Date.now() + ".mml");
saveAs(blob, (lastCompiledName || Date.now()) + ".mml");
}

function downloadMMLforMSX() {
const mml4msx = MSXPlayUI.convertToMSXDOSText(editor.getValue());
var blob = new Blob([mml4msx], { type: "text/plain" });
saveAs(blob, (lastCompiledName || Date.now()) + ".mus");
}

function downloadMGS() {
Expand Down Expand Up @@ -796,6 +802,8 @@ function download() {
showDialog("download-type", function (e) {
if (e === "mml") {
downloadMML();
} if (e === "mml-for-msx") {
downloadMMLforMSX();
} else if (e === "mgs") {
downloadMGS();
} else if (e === "vgm") {
Expand Down
9 changes: 9 additions & 0 deletions src/msxplay-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { MSXPlay } from "./msxplay.js";
import { mgs2mml, getJumpMarkerCount } from "mgsrc-js";
import packageJson from "../package.json";
import { isSafari, isIOS } from "./utils.js";
import { convert as Utf16toSjis } from 'utf16-to-sjis';

function zeroPadding(num) {
return ("00" + num).slice(-2);
Expand Down Expand Up @@ -99,6 +100,14 @@ export class MSXPlayUI {
return this.msxplay.toVGM(data, duration, loop, callback);
}

convertToMSXDOSText(text) {
const data = Utf16toSjis(text.replace(/\n/g, '\r\n'));
const res = new Uint8Array(data.length + 1);
res.set(data);
res.set([0x1A], data.length); // append EOF
return res;
}

audio_encode(type, data, song, callback, opts) {
this.msxplay.audio_encode(type, data, song, callback, opts);
}
Expand Down

0 comments on commit 0d38cd5

Please sign in to comment.