index.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. timeWarp: 1,
  38. }
  39. var currentTime = 0
  40. var MIDI = window.MIDI
  41. MIDI.loadPlugin({
  42. soundfontUrl: "./soundfont/",
  43. // instrument: ["acoustic_grand_piano", "synth_drum"],
  44. onsuccess: function () {
  45. console.log(MIDI)
  46. window.handleRendered && window.handleRendered()
  47. // MIDI.setInstrument(0, MIDI.GM.byName['synth_drum'].number)
  48. // MIDI.setInstrument(1, MIDI.GM.byName['acoustic_grand_piano'].number)
  49. }
  50. });
  51. // 播放音符
  52. function playNote(note, delay) {
  53. MIDI.noteOn(0, note, 100, 0);
  54. MIDI.noteOff(0, note, delay);
  55. }
  56. // MIDI.Player.currentTime = 100000
  57. // MIDI.Player.timeWarp = 0.6289308176100629
  58. // setInterval(() => {
  59. // // console.log(MIDI.Player.currentTime / 1000, MIDI.Player.restart)
  60. // }, 100)
  61. var playBtn = document.getElementById('playBtn')
  62. // var pauseBtn = document.getElementById('pauseBtn')
  63. // var stopBtn = document.getElementById('stopBtn')
  64. // var skipBtn = document.getElementById('skipBtn')
  65. playBtn.addEventListener('click', () => {
  66. MIDI.noteOn(0, 50, 50, 0);
  67. MIDI.noteOff(0, 50, 1);
  68. MIDI.noteOn(0, 50, 100, 1);
  69. MIDI.noteOff(0, 50, 2);
  70. console.log(MIDI)
  71. })
  72. // pauseBtn.onclick = function () {
  73. // MIDI.Player.pause();
  74. // }
  75. // stopBtn.onclick = function () {
  76. // MIDI.Player.currentTime = 100000
  77. // MIDI.Player.resume();
  78. // console.log(MIDI)
  79. // }
  80. // skipBtn.onchange = function (e) {
  81. // var timeWarp = Number(e.target.value) / 100
  82. // // MIDI.Player.stop()
  83. // // const oldCurrent = MIDI.Player.currentTime
  84. // // const ab = MIDI.Player.replayer.getData()
  85. // // console.log(ab)
  86. // MIDI.Player.loadMidiFile(() => {
  87. // MIDI.Player.timeWarp = 1 / timeWarp
  88. // console.log('播放倍数', 1 / timeWarp, Number(e.target.value))
  89. // MIDI.Player.resume();
  90. // })
  91. // }
  92. </script>
  93. </body>
  94. </html>