Git Product home page Git Product logo

Comments (7)

mudcube avatar mudcube commented on August 16, 2024

Hi Danny,
You're reloading the plugin each time "click" is called, you should only need to run noteOn/noteOff. It should look something like this:

MIDI.loadPlugin({
    soundfontUrl: "./soundfont/",
    instrument: "acoustic_grand_piano",
    callback: 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);
        $("#play").click(function () {
            MIDI.noteOn(0, note, velocity, delay);
            MIDI.noteOff(0, note, delay + 0.75);
        });
    }
});

from midi.js.

JoshTheDerf avatar JoshTheDerf commented on August 16, 2024

@mudcube, is there a way to load an additional instrument without reloading the plugin itself? That is how I'm doing it at http://tribex.derfers.us/index.php?page=MIDI_Piano but after loading 10 or 12 instruments, it fails with the same error as the OP.

function loadInstrument(id) {
    MIDI.loadPlugin({
        soundfontUrl: "./soundfonts/",
        instrument: id,
        callback: function () {
            //Set the instrument to the channel 0 so we can actually hear it.
            MIDI.programChange(0, id);
                },
       })
};
...
...
...
<p class="selection" onclick="loadInstrument(0)">Acoustic Grand Piano</p>

(I hope you don't mind a reply to a closed thread)

from midi.js.

artfoundry avatar artfoundry commented on August 16, 2024

Load all the instruments in one go when you load the plugin. Then have your onclick call a program change instead of an instrument load.

from midi.js.

JoshTheDerf avatar JoshTheDerf commented on August 16, 2024

Unfortunately, that requires sending about 347.3MB to the client, and it would all be loaded in order, so the client would have to wait until the instrument he wanted to actually use was loaded.

The way I have it now, only the instruments that the client actually wants are loaded when he selects an item from a list.

(The code example above is very shortened. I actually have a list of all the instruments that is automagically generated).

from midi.js.

artfoundry avatar artfoundry commented on August 16, 2024

Ah ok, yeah that's a lot of data to send. Mine is only a tenth of that amount. Well, I still think the way you have it now is fine.

from midi.js.

Silverwolf90 avatar Silverwolf90 commented on August 16, 2024

@tribex Sorry about trying to contact you via this issue. I couldn't seem to find an email to reach you on your website (am I blind?).

Did you create all those base64 encoded soundfonts? Are they available to the public? It's quite an impressive list!

Edit: Did some more sleuthing and I found the https://github.com/gleitz/midi-js-soundfonts :) So you can disregard.

from midi.js.

JoshTheDerf avatar JoshTheDerf commented on August 16, 2024

@Silverwolf90 No you're not blind, The website is still VERY fresh and I haven't finished adding all the content.

And no, I got them from the link you posted.

from midi.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.