index.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  5. <title>MIDI.js - Sequencing in Javascript.</title>
  6. <!-- midi.js css -->
  7. <!-- shim -->
  8. <script src="./inc/shim/Base64.js" type="text/javascript"></script>
  9. <script src="./inc/shim/Base64binary.js" type="text/javascript"></script>
  10. <script src="./inc/shim/WebAudioAPI.js" type="text/javascript"></script>
  11. <script src="./inc/shim/WebMIDIAPI.js" type="text/javascript"></script>
  12. <!-- jasmid package -->
  13. <script src="./inc/jasmid/stream.js"></script>
  14. <script src="./inc/jasmid/midifile.js"></script>
  15. <script src="./inc/jasmid/replayer.js"></script>
  16. <!-- midi.js package -->
  17. <script src="./js/midi/audioDetect.js" type="text/javascript"></script>
  18. <script src="./js/midi/gm.js" type="text/javascript"></script>
  19. <script src="./js/midi/loader.js" type="text/javascript"></script>
  20. <script src="./js/midi/plugin.audiotag.js" type="text/javascript"></script>
  21. <script src="./js/midi/plugin.webaudio.js" type="text/javascript"></script>
  22. <script src="./js/midi/plugin.webmidi.js" type="text/javascript"></script>
  23. <script src="./js/midi/player.js" type="text/javascript"></script>
  24. <script src="./js/midi/synesthesia.js" type="text/javascript"></script>
  25. <!-- utils -->
  26. <script src="./js/util/dom_request_xhr.js" type="text/javascript"></script>
  27. <script src="./js/util/dom_request_script.js" type="text/javascript"></script>
  28. </head>
  29. <body>
  30. <button id="playBtn">播放</button>
  31. <button id="pauseBtn">暂停</button>
  32. <button id="stopBtn">跳跃</button>
  33. <input type="range" id="skipBtn" value="100" min="45" max="200" />
  34. <script type="text/javascript">
  35. var midiData = {
  36. src: ''
  37. }
  38. var MIDI = window.MIDI
  39. MIDI.loadPlugin({
  40. soundfontUrl: "./soundfont/",
  41. // instrument: "synth_drum",
  42. onprogress: function (state, progress) {
  43. console.log(1, state, progress);
  44. },
  45. });
  46. // 加载midi文件
  47. function handleLoadFile(src, loaded = () => { }) {
  48. if (!midiData.src) {
  49. midiData.src = src
  50. }
  51. MIDI.Player.loadFile(src, loaded)
  52. }
  53. // 播放
  54. function hanldePlay() {
  55. MIDI.Player.resume()
  56. }
  57. // 暂停
  58. function handlePause() {
  59. MIDI.Player.pause();
  60. }
  61. // 跳转
  62. function skipTime(time) {
  63. MIDI.Player.currentTime = time * 1000
  64. MIDI.Player.resume();
  65. }
  66. // 设置播放速度
  67. function setTimeWarp(timeWarp) {
  68. MIDI.Player.loadMidiFile(() => {
  69. MIDI.Player.timeWarp = 1 / timeWarp
  70. MIDI.Player.resume();
  71. console.log('播放倍数', 1 / timeWarp)
  72. })
  73. }
  74. handleLoadFile("https://cloud-coach.ks3-cn-beijing.ksyuncs.com/1669293957359紫罗兰永恒花园ED1——《みちしるべ》.mid")
  75. MIDI.Player.currentTime = 100000
  76. // MIDI.Player.timeWarp = 0.6289308176100629
  77. setInterval(() => {
  78. // console.log(MIDI.Player.currentTime / 1000, MIDI.Player.restart)
  79. }, 100)
  80. var playBtn = document.getElementById('playBtn')
  81. var pauseBtn = document.getElementById('pauseBtn')
  82. var stopBtn = document.getElementById('stopBtn')
  83. var skipBtn = document.getElementById('skipBtn')
  84. playBtn.addEventListener('click', () => {
  85. console.log(MIDI)
  86. MIDI.Player.resume()
  87. })
  88. pauseBtn.onclick = function () {
  89. MIDI.Player.pause();
  90. }
  91. stopBtn.onclick = function () {
  92. MIDI.Player.currentTime = 100000
  93. MIDI.Player.resume();
  94. console.log(MIDI)
  95. }
  96. skipBtn.onchange = function (e) {
  97. var timeWarp = Number(e.target.value) / 100
  98. // MIDI.Player.stop()
  99. // const oldCurrent = MIDI.Player.currentTime
  100. // const ab = MIDI.Player.replayer.getData()
  101. // console.log(ab)
  102. MIDI.Player.loadMidiFile(() => {
  103. MIDI.Player.timeWarp = 1 / timeWarp
  104. console.log('播放倍数', 1 / timeWarp, Number(e.target.value))
  105. MIDI.Player.resume();
  106. })
  107. }
  108. </script>
  109. <script>
  110. console.log(MIDI)
  111. </script>
  112. </body>
  113. </html>