Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: gree/smfplayer.js
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: logue/smfplayer.js
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
Loading
Showing with 10,154 additions and 4,079 deletions.
  1. +9 −0 .editorconfig
  2. +3 −0 .env.sample
  3. +1 −0 .gitattributes
  4. +2 −0 .github/CODEOWNERS
  5. +36 −0 .github/workflows/deploy-gh-pages.yml
  6. +7 −0 .gitignore
  7. +6 −0 .prettierignore
  8. +11 −0 .prettierrc.yml
  9. +15 −0 .stylelintrc.yml
  10. +22 −28 LICENSE
  11. +0 −1 LICENSE.min
  12. +157 −51 README.md
  13. +4 −0 TODO.md
  14. +0 −7 bin/smf.parser.min.js
  15. +0 −8 bin/smf.parser.min.js.map
  16. +0 −30 bin/smfplayer.min.js
  17. +0 −8 bin/smfplayer.min.js.map
  18. +0 −115 build.xml
  19. +0 −1,488 closure-primitives/base.js
  20. +0 −11 closure-primitives/deps.js
  21. +0 −202 closure-primitives/depswriter.py
  22. +0 −114 closure-primitives/source.py
  23. +0 −78 closure-primitives/treescan.py
  24. +0 −15 define/typedarray/hybrid.js
  25. +0 −9 define/typedarray/use.js
  26. +92 −0 eslint.config.js
  27. +0 −9 export/smf.parser.js
  28. +0 −22 export/smf.player.js
  29. +883 −0 index.html
  30. +9 −0 jsconfig.json
  31. +112 −0 package.json
  32. +3,670 −0 pnpm-lock.yaml
  33. +462 −0 public/assets/debug.js
  34. +312 −0 public/assets/sf2.js
  35. +197 −0 public/debug.html
  36. BIN public/favicon.ico
  37. BIN public/files/3MLE_Sample.zip
  38. BIN public/files/A-Train.zip
  39. BIN public/files/A-Train_Global.zip
  40. BIN public/files/Alundra.zip
  41. BIN public/files/Breath_of_Fire_4.zip
  42. BIN public/files/Chrono_Trigger.zip
  43. BIN public/files/Dragon_Warrior_2.zip
  44. BIN public/files/Dragon_Warrior_3.zip
  45. BIN public/files/Dragon_Warrior_4.zip
  46. BIN public/files/Final_Fantasy_10.zip
  47. BIN public/files/Final_Fantasy_11.zip
  48. BIN public/files/Final_Fantasy_4.zip
  49. BIN public/files/Final_Fantasy_5.zip
  50. BIN public/files/Final_Fantasy_6.zip
  51. BIN public/files/Final_Fantasy_7.zip
  52. BIN public/files/Final_Fantasy_8.zip
  53. BIN public/files/Final_Fantasy_9.zip
  54. BIN public/files/Legend_of_Mana.zip
  55. BIN public/files/Lemmings.zip
  56. BIN public/files/MabiIcco_Sample.zip
  57. BIN public/files/MakimabiSequence_Sample.zip
  58. BIN public/files/Marathon1.zip
  59. BIN public/files/Midi01.zip
  60. BIN public/files/Midi03.zip
  61. BIN public/files/Midi04.zip
  62. BIN public/files/Outrun.zip
  63. BIN public/files/PSO.zip
  64. BIN public/files/Secret_of_Mana.zip
  65. BIN public/files/Silent_Hill.zip
  66. BIN public/files/SimCity2000.zip
  67. BIN public/files/Sonic_the_Hedgehog.zip
  68. BIN public/files/Star_Ocean_the_second_story.zip
  69. BIN public/files/Super_Donkey_Kong.zip
  70. BIN public/files/UO_MIDI_Music.zip
  71. BIN public/files/Valkyrie_Profile.zip
  72. BIN public/files/YAMAHA mididata library.zip
  73. BIN public/files/YMO.zip
  74. BIN public/files/Zelda_3_-_A_Link_to_the_Past.zip
  75. BIN public/files/ms2mml_sample.zip
  76. BIN public/files/sor.zip
  77. BIN public/files/適当詰め合わせ.zip
  78. BIN public/icon.png
  79. +770 −0 src-docs/index.js
  80. +78 −0 src-docs/style.scss
  81. +26 −0 src/index.js
  82. +191 −0 src/mabi_mml_parser/3mle.js
  83. +311 −0 src/mabi_mml_parser/PSGConverter.js
  84. +21 −0 src/mabi_mml_parser/index.js
  85. +208 −0 src/mabi_mml_parser/mmi.js
  86. +223 −0 src/mabi_mml_parser/mms.js
  87. +75 −0 src/mabi_mml_parser/ms2mml.js
  88. +130 −62 src/midi_event.js
  89. +870 −813 src/mld.js
  90. +778 −395 src/player.js
  91. +100 −79 src/riff.js
  92. +267 −327 src/smf.js
  93. +0 −5 src/typedef.js
  94. +0 −202 vendor/google-closure-compiler/COPYING
  95. BIN vendor/google-closure-compiler/compiler.jar
  96. +96 −0 vite.config.js
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
3 changes: 3 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
VITE_GOOGLE_ANALYTICS_ID=
VITE_WML_URL=wml.html
VITE_SOUNDFONT_URL=Yamaha XG Sound Set Ver.2.0.sf2
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf encoding=utf-8
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Generated by CODEOWNERS.com

36 changes: 36 additions & 0 deletions .github/workflows/deploy-gh-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: NodeJS with Vite

on:
push:
branches: ['develop']
pull_request:
branches: ['develop']

jobs:
cache-and-install:
runs-on: ubuntu-latest

steps:
- name: Checkout ✔
uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
name: Install pnpm 📦
with:
run_install: false

- name: Install Node.js ⚡️
uses: actions/setup-node@v4
with:
cache: 'pnpm'

- name: Build 🔧
run: |
pnpm install
pnpm build:docs
- name: Deploy to gh-pages 🚀
uses: JamesIves/github-pages-deploy-action@v4.6.4
with:
branch: gh-pages # The branch the action should deploy to.
folder: docs # The folder the action should deploy.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.yarn/*
!/.yarn/releases
/node_modules
/dist
/src/meta.js
/docs
.env
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.husky/
.vscode/
.yarn/
dist/
docs/
pnpm-lock.yaml
11 changes: 11 additions & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
printWidth: 80
tabWidth: 2
useTabs: false
semi: true
singleQuote: true
trailingComma: es5
bracketSpacing: true
bracketSameLine: false
arrowParens: avoid
htmlWhitespaceSensitivity: ignore
endOfLine: lf
15 changes: 15 additions & 0 deletions .stylelintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
extends:
- stylelint-config-recommended-scss
- stylelint-config-prettier
plugins:
- stylelint-order
- stylelint-prettier
- stylelint-scss
ignoreFiles:
- 'dist/**/*'
rules:
prettier/prettier: true
color-function-notation: legacy
function-no-unknown: null
scss/no-global-function-names: null
no-descending-specificity: null
50 changes: 22 additions & 28 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
/**
* @license
* smfplayer.js
* Standard MIDI File Player in JavaScript
* https://github.com/gree/smfplayer.js
*
* The MIT License
*
* Copyright (c) 2013 imaya / GREE Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
MIT License

Copyright (c) 2013 imaya / GREE Inc.
Copyright (c) 2013-2025 Masashi Yoshikawa

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 0 additions & 1 deletion LICENSE.min

This file was deleted.

208 changes: 157 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,182 @@
# smfplayer.js

smfplayer.js
============
[![jsdelivr CDN](https://data.jsdelivr.com/v1/package/npm/@logue/smfplayer/badge?style=rounded)](https://www.jsdelivr.com/package/npm/@logue/smfplayer)
[![NPM Downloads](https://img.shields.io/npm/dm/@logue/smfplayer.svg?style=flat)](https://www.npmjs.com/package/@logue/smfplayer)
[![Open in unpkg](https://img.shields.io/badge/Open%20in-unpkg-blue)](https://uiwjs.github.io/npm-unpkg/#/pkg/@logue/smfplayer/file/README.md)
[![npm version](https://img.shields.io/npm/v/@logue/smfplayer.svg)](https://www.npmjs.com/package/@logue/smfplayer)
[![Open in Gitpod](https://shields.io/badge/Open%20in-Gitpod-green?logo=Gitpod)](https://gitpod.io/#https://github.com/logue/@logue/smfplayer)
[![Twitter Follow](https://img.shields.io/twitter/follow/logue256?style=plastic)](https://twitter.com/logue256)

smfplayer.js [WebMidiLink](http://www.g200kg.com/en/docs/webmidilink/) 対応シンセサイザを用いた標準 MIDI ファイルプレイヤーです。
smfplayer.js is standard MIDI file player using a [WebMidiLink](http://www.g200kg.com/en/docs/webmidilink/) compatible synthesizer.

This program is side of sequencer. Tone Generator side is [sf2synth.js](https://github.com/logue/sf2synth.js).

## 使い方
## Usage

```js
var player = new SMF.Player();

window.addEventListener('DOMContentLoaded', function() {
/** @type {boolean} */
var loop = true;
/** @type {boolean} */
var cc111 = true;
/** @type {boolean} */
var falcom = true;
/** @type {boolean} */
var mfi = true;
/** @type {number} */
var tempo = 1.0;
/** @type {number} 0-16383 */
var volume = 16383 * 0.5;

// player settings
player.setLoop(loop); // Player Loop
player.setCC111Loop(cc111); // CC#111 Loop
player.setFalcomLoop(falcom); // Ys2 Eternal Loop
player.setMFiLoop(mfi); // MFi Loop
player.setTempoRate(tempo); // Playback tempo rate
player.setMasterVolume(volume); // Master Volume
player.setWebMidiLink('http://www.g200kg.com/en/docs/gmplayer/');

// load standard MIDI file
loadSMF('hoge.mid');
}, false);
import SMF from '@logue/smfplayer';

const player = new SMF.Player();

window.addEventListener(
'DOMContentLoaded',
() => {
/** @type {boolean} */
const loop = true;
/** @type {boolean} */
const cc111 = true;
/** @type {boolean} */
const falcom = true;
/** @type {boolean} */
const mfi = true;
/** @type {number} */
const tempo = 1.0;
/** @type {number} 0-16383 */
const volume = 16383 * 0.5;

// player settings
player.setLoop(loop); // Player Loop
player.setCC111Loop(cc111); // CC#111 Loop
player.setFalcomLoop(falcom); // Ys2 Eternal Loop
player.setMFiLoop(mfi); // MFi Loop
player.setTempoRate(tempo); // Playback tempo rate
player.setMasterVolume(volume); // Master Volume
player.setWebMidiLink('https://logue.dev/smfplayer.js/wml.html');

// load standard MIDI file
loadSMF('hoge.mid');
},
false
);

/**
* @param {string} url
*/
function loadSMF(url) {
var xhr = new XMLHttpRequest();

xhr.open('GET', url, true);
xhr.addEventListener('load', function (event) {
/** @type {Uint8Array} */
var input = new Uint8Array(event.target.response);

// load MIDI file
player.loadMidiFile(input);
player.play();
}, false);
xhr.responseType = 'arraybuffer';
xhr.send();
fetch(url)
.then(response => {
if (!response.ok) {
throw new Error('HTTP error, status = ' + response.status);
}
return response.arrayBuffer();
})
.then(arraybuffer => {
/** @type {string} */
const ext = url.split('.').pop();
switch (ext) {
case 'midi':
case 'mid':
// Load MIDI file
player.loadMidiFile(arraybuffer);
break;
case 'mld':
// Load Polyphonic Ringtone File
player.loadMldFile(arraybuffer);
break;
case 'ms2mml':
// Load Maple Story 2 MML File
player.loadMs2MmlFile(arraybuffer);
break;
case 'mms':
// Load MakiMabi Sequence MML File
player.loadMakiMabiSequenceFile(arraybuffer);
break;
case 'mml':
// Load 3MLE MML File
player.load3MleFile(arraybuffer);
break;
case 'mmi':
// Load Mabicco MML File
player.loadMabiIccoFile(arraybuffer);
break;
default:
throw new Error('Unsupported format:' + ext);
}
player.play();
})
.catch(e => console.error(e));
}
```

For more details, please refer to the source code in [demo](./src/demo/). (Although there are many [Bootstrap](https://getbootstrap.com/) dependent codes)

## 対応ブラウザ
### CDN

Entry point is `SMF`.

```html
<script src="https://cdn.jsdelivr.net/npm/@logue/smfplayer@latest/dist/smfplayer.iife.min.js"></script>
<script>
const player = new SMF.Player();
// ...
</script>
```

## Methods

| Method | Description |
| ------------------------------------- | --------------------------------------------------------------- |
| play() | Play Sequence |
| stop() | Stop Sequence |
| sendAllSoundOff() | Send AllSoundOff to WML |
| sendGmReset(`lv`) | Send GM Reset SysEx to WML. (Set `lv` to `true` for GM Level2.) |
| sendRawMidiMessage() | Send Midi message directly (such as `F0,7E,7F.09.01,F7`) |
| load3MleFile(ArrayBuffer) | Load 3MLE(\*.mml)format MML file. |
| loadMakiMabiSequenceFile(ArrayBuffer) | Load MakiMabi Sequence(\*.mms)MML file. |
| loadMidiFile(ArrayBuffer) | Load Standard MIDI file.(SMF1, SMF2 both supported) |
| loadMldFile(ArrayBuffer) | Load Docomo Ringtone Melody(\*.mld)file. |
| loadMabiIccoFile(ArrayBuffer) | Load MabiIcco(\*.mmi)MML file. |
| loadMs2MmlFile(ArrayBuffer) | Load MapleStory2 MML(\*.ms2mml)file. |
| setCC111Loop(boolean) | Enable loop by ControlChange No.111 |
| setFalcomLoop(boolean) | Enable Falcom loop (Used MIDI text) |
| setLoop(boolean) | Enable Loop |
| setMFiLoop(boolean) | Enable Mfi meta data loop. |
| setMasterVolume(number) | Set Master volume(0~1) |
| setPosition(number) | Jump sequence position. |
| setTempoRate(number) | Set Tempo Rate |
| setWebMidiLink(string) | Set WML url. |
| getCopyright() | Get Copyright meta data. |
| getLength() | Get Sequence Length. |
| getLyrics() | Get Lyrics meta data of current position. [^1] |
| getPosition() | Get current position. |
| getSequenceName() | Get Sequence name. (usually contains the song title.) |
| getTextEvent() | Get the TextEvent of current position. |
| getWebMidiLink() | Get WebMidiLink URL |
| getTempo() | Get current tempo. |
| getTime(number) | Output current playing time (hh:mm:ss) |
| getTotalTime() | Output playing time of MIDI file.[^2] |

[^1] This program does not parse karaoke data. ([KAR](http://gnese.free.fr/Projects/KaraokeTime/Fichiers/karfaq.html), [XF](https://jp.yamaha.com/files/download/other_assets/7/321757/xfspc.pdf), etc.)
[^2] Since it is calculated based on the current tempo, if the tempo changes in the middle of the song, the value here will also change.

### Restrictions when reading MML

When reading the following files, the program change values match those of MSXspirit.dls and are not compatible with GM. Download `MSXspirit.sf2` from [MabiMmlEmu](https://github.com/logue/MabiMmlEmu/) and load it into wml.html to use it.

| Extension | Description |
| --------- | ------------------------------------------------------ |
| \*.mms | [MakiMabi Sequence](https://booth.pm/ja/items/2372062) |
| \*.mml | [3MLE](http://3ml.jp/) |
| \*.mmi | [MabiIcco](https://github.com/fourthline/mmlTools) |

When reading an MML file (\*.ms2mml) from [MapleStory2](https://maplestory2.nexon.co.jp/), the program change is not included in the file format, so the instrument will be 0 (fixed to piano). increase.

## Compatibility

- Firefox 7+
- Google Chrome 7+
- Safari 5.1+
- Edge

## TODO

## WebMidiLink 対応
Recomposer file (\*.rcm) support.

sf2synth.js は WebMidiLink の Link Level 1 にのみ対応しています。
## License

Copyright &copy; 2013 imaya / GREE Inc.
Copyright &copy; 2013-2025 by Logue.

## ライセンス
[PSGConverter.js](https://github.com/logue/PSGConverter) Copyright &copy; 2006-2012 by Logue.

Copyright &copy; 2013 imaya / GREE Inc.
Licensed under the MIT License.
Licensed under the [MIT](LICENSE) License.
4 changes: 4 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# TODO

- Adjusting Midi playback location.
- Worker Mode.
Loading