EzDevInfo.com

MIDI.js

Making life easy to create a MIDI-app on the web. Includes a library to program synesthesia into your app for memory recognition or for creating trippy effects. Convert soundfonts for Guitar, Bass, Drums, ect. into code that can be read by the browser. Supports multiple simultaneous instruments and perfect timing. MIDI.js - Sequencing in Javascript.

Loading midi.js soundfonts dynamically

I just started using midi.js and so far it seems really neat. I am currently loading all of my sounds fonts at once like so:

    MIDI.loadPlugin({
    soundfontUrl: "js/MIDI/soundfont/FluidR3_GM/",
    instrument: instruments,
    callback: function() {
        app.MIDIManager.midiLoaded = true;
        console.log("DONE LOADING");
    }
});

As I grow the instruments array it is starting to take quite some time to finish loading. Is there a way to dynamically load instruments only when they are needed? The only way I could find to load instruments is in the call to loadPlugin. I also couldn't find any comprehensive API documentation (I looked on the demo page and github) so if I am just missing that I'd love a link to the full documentation.


Source: (StackOverflow)

how do I use midi.js and jasmid.js?

I'm trying to create a variation of the color piano site at http://mudcu.be/piano/ and am really struggling to find a good working example of how to parse a MIDI file, drawing graphical elements and playing MIDI notes.

Does anyone know how the color piano site was created?

I'm first just trying to get a specific midi file playing - with no luck.

The code below doesn't do anything and it doesn't show an error.

<!DOCTYPE html>
<html xmlns = "http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <!-- polyfill -->
        <script src="static/Base64.js" type="text/javascript"></script>
        <script src="static/Base64binary.js" type="text/javascript"></script>
        <script src="static/WebAudioAPI.js" type="text/javascript"></script>
        <!-- midi.js package -->
        <script src="static/audioDetect.js" type="text/javascript"></script>
        <script src="static/gm.js" type="text/javascript"></script>
        <script src="static/loader.js" type="text/javascript"></script>
        <script src="static/player.js" type="text/javascript"></script>
        <script src="static/event.js" type="text/javascript"></script>
        <script src="static/plugin.audiotag.js" type="text/javascript"></script>
        <script src="static/plugin.webaudio.js" type="text/javascript"></script>
        <script src="static/plugin.webmidi.js" type="text/javascript"></script>
        <!-- jasmid just in case-->
        <script src="static/stream.js"></script>
        <script src="static/midifile.js"></script>
        <script src="static/replayer.js"></script>
        <!-- utils -->
        <script src="static/dom_request_xhr.js" type="text/javascript"></script>
        <script src="static/dom_request_script.js" type="text/javascript"></script>
    </head>
    <body>
    <script type="text/javascript">
        window.onload = function () {
        MIDI.loadPlugin({
        soundfontUrl: "static/",
        instrument: "acoustic_grand_piano",
        callback: function() {
            MIDI.Player.loadFile("static/mario.mid", MIDI.Player.start);
            }
        });
    }

    </script>
    </body>
</html>

Source: (StackOverflow)

Advertisements

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

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.


Source: (StackOverflow)

Arrays / loops with midi.js

I am looking to use a playsound function in midi.js to loop an array, with chords that i select, maybe 4 diff ones. But i can't figure it out. I can get it to do a single array, but not multiple, and it does not loop, only plays the amount of time I set it to (now 8).

window.onload = function () {
MIDI.loadPlugin({
    soundfontUrl: "../MIDI.js/examples/soundfont/",
    instrument: "acoustic_grand_piano",
    onprogress: function(state, progress) {
        console.log(state, progress);
    },


    onsuccess: function () {
               for (var i = 0; i < 9; i++){

               playsound([37,59,61,71,80])}

}});

var delay =1;   
function playsound($chords)
{
        var velocity = 127;
        MIDI.setVolume(0, 127);
        MIDI.chordOn(0, $chords, velocity, delay);
        MIDI.chordOff(0, $chords, delay+1);
        delay += 1;

}

Source: (StackOverflow)

How to send data from a javascript function to MIDI.noteOn() in the MIDI.js API

I am familiar with C++ and MIDI protocol but I am a beginner with javascript. I have successfully run the example Basic.html https://github.com/mudcube/MIDI.js/blob/master/examples/Basic.html from git hub below:

<body>
<script type="text/javascript">
window.onload = function () {
MIDI.loadPlugin({
    soundfontUrl: "./soundfont/",
    instrument: "acoustic_grand_piano",
    onprogress: function(state, progress) {
        console.log(state, progress);
    },
    onsuccess: function() {
        var delay = 0; // play one note every quarter second
        var note = 50; // the MIDI note
        var velocity = 127; // how hard the note hits
        // play the note
        MIDI.setVolume(0, 127);
        MIDI.noteOn(0, note, velocity, delay);
        MIDI.noteOff(0, note, delay + 0.75);
    }
});
};
</script>
</body>

I would like to load the plugin when the window loads. Then I would like to have my own javascript function send a specified note value to MIDI.noteOn() and MIDI.noteOff(). I am embarassed to ask such a simple question, but I am getting nowhere with my attempts. Thanks for any suggestions.


Source: (StackOverflow)