1

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 Answers2

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

user1024
  • 1,121
  • 1
  • 9
  • 17
  • Thank you, how can I use my own instruments in SSSynthesiser.js, I dont see any option to do that – user3467180 Sep 05 '15 at 05:28
  • SSSynthesiser.js plays Molgav (http://molgav.nn.ru) files. It consists thousands of instruments for all purposes. Also you can add you own samples into JSON file in raw format, see example of song at project page. – user1024 Sep 05 '15 at 08:44
  • I tried to understand this library, but I could not. here are some queries 1. What is molgav file? 2. From where it gets audio data, like in MIDI.js we provide soundfont js file. 2. If I want to use my own sound samples, how can I use?, please show some examples with code – user3467180 Sep 07 '15 at 06:45
  • 1. What is molgav file? - this is JSON file that produces Molgav service. 2. From where it gets audio data, like in MIDI.js we provide soundfont js file. - Save any song from Molgav and open it in text editor - it includes samples for all instruments used in song. Please read project description at https://github.com/surikov/SSSynthesiser.js - it has all info you need. – user1024 Sep 07 '15 at 07:02
  • "this is JSON file that produces Molgav service" does it means that it will play sounds from molgav.nn.ru or is it possible to use it locally without internet connection? – user3467180 Sep 07 '15 at 07:31
  • you can save any song from Molgav to local file. Each file consists notes and samples. You don't need internet for music playing via SSSynthesiser.js. See project info for help. – user1024 Sep 07 '15 at 07:42
  • It seems interesting, but please show me how to add my my own instrument, please refer link to to my website http://vishwamohini.com/music/demo-tabla.php Where you can listen tabla, which is Indian classical music instrument, how can I use this intsrument in malgov? – user3467180 Sep 07 '15 at 08:02
  • open any Molgav file (project example is http://molgav.nn.ru/x/sviridovtimeforward.molgav), fins a instrument sample raw data ("signed" : [0, 0, 0, 0, -2, -1, -2, -1, -1, -2, ...), replace this array with array of your sample data. – user1024 Sep 07 '15 at 08:20
  • My sound data is in base64 string format for each note, please refer MIDI.js sound format, how can I convert it to sample array you have shown – user3467180 Sep 07 '15 at 10:20
  • 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 – user1024 Sep 25 '18 at 15:51
0

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