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

1.4k views Asked by At

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.

2

There are 2 answers

10
user1024 On

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

0
user3467180 On

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