How to implement MIDI player of MIDI.js for notes sequence

橙三吉。 提交于 2019-12-12 00:53:16

问题


I am using MIDI.js in my project, here is my code for playing sequence of MIDI notes

for (var repeat = 0; repeat < melodyrepititions; repeat++)
        {
            for (var i = 0; i < composition.length; i++)
            {
                for (var j = 0; j < composition[i].length; j++)
                {
                    if (composition[i][j] != 0)
                    {

                        MIDI.noteOn(0, composition[i][j] + scale, velocity,delay );
                        MIDI.noteOff(0, composition[i][j] + scale, delay+onlynotationsofeachbeatbracketdelay[i][j]);
                    }
                    else if (composition[i][j] == 0)
                    {
                       MIDI.noteOff(0, composition[i][j] + scale, delay);
                    }
                    delay = delay + onlynotationsofeachbeatbracketdelay[i][j];
                }
            }
        }

I want to implement MIDI.js player for this sequence to start,pause,stop the melody while playing. I am not able to figure out how can I use MIDI.js player functions for such sequence. Please guide.


回答1:


use https://github.com/surikov/SSSynthesiser.js instead of MIDI.js.

SSSynthesiser.js has full controls over what is playing. You can change in realtime all instrument samples, melody etc.

Update

this is old answer.

Use https://github.com/surikov/webaudiofont instead of it.

Read docs, look to examples. See example for MIDI-player here https://surikov.github.io/webaudiofont/examples/midiplayer.html




回答2:


I think it is not possible to implement MIDI player directly to sequence of notes, so solution I got is, one need to convert sequence of notes into MIDI file & then you can input MIDI file to player. Here is link which gives more details on conversion of MIDI file

http://mudcu.be/journal/2011/11/base64-soundfonts/

Library which helps to convert sequence of notes in MIDI file https://github.com/sergi/jsmidi



来源:https://stackoverflow.com/questions/30980448/how-to-implement-midi-player-of-midi-js-for-notes-sequence

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!