mudcube / MIDI.js

:musical_keyboard: 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.
http://mudcu.be/midi-js/
MIT License
3.79k stars 640 forks source link

Bug: MIDI events not being fired #273

Open batata004 opened 1 year ago

batata004 commented 1 year ago

Hi,

I am using the code below, exactly as suggested in the documentation and example. When I press keys on my midi keyboard they are not being recognized by the library (I created the event using addListener as suggested in the docs but it never fires. Is this a bug or am I doing something wrong?

<!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="../inc/shim/Base64.js" type="text/javascript"></script>
    <script src="../inc/shim/Base64binary.js" type="text/javascript"></script>
    <script src="../inc/shim/WebAudioAPI.js" type="text/javascript"></script>
    <!-- midi.js package -->
    <script src="../js/midi/audioDetect.js" type="text/javascript"></script>
    <script src="../js/midi/gm.js" type="text/javascript"></script>
    <script src="../js/midi/loader.js" type="text/javascript"></script>
    <script src="../js/midi/plugin.audiotag.js" type="text/javascript"></script>
    <script src="../js/midi/plugin.webaudio.js" type="text/javascript"></script>
    <script src="../js/midi/plugin.webmidi.js" type="text/javascript"></script>
    <script src="../js/midi/player.js" type="text/javascript"></script>
    <!-- utils -->
    <script src="../js/util/dom_request_xhr.js" type="text/javascript"></script>
    <script src="../js/util/dom_request_script.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">

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

                MIDI.Player.removeListener(); // removes current listener.
                MIDI.Player.addListener(function(data) { // set it to your own function!
                    var now = data.now; // where we are now
                    var end = data.end; // time when song ends
                    var channel = data.channel; // channel note is playing on
                    var message = data.message; // 128 is noteOff, 144 is noteOn
                    var note = data.note; // the note
                    var velocity = data.velocity; // the velocity of the note
                    // then do whatever you want with the information!

                     $("body").append('<div>' + note + '|' + velocity + '</div>');

                });

        }
    });

};

</script>
</body>
</html>
mscuthbert commented 1 year ago

Look at the updated midicube Readme for up-to-date instructions:

https://github.com/mscuthbert/midicube

<script src="releases/midicube.js"></script>
<script>
MIDI.loadPlugin({
    // ...
});
</script>

Not sure if the configuration you have will work perfectly with that, but it's much closer to being correct. Can you point to part of this repo that features the old 20-script-tag configuration?

acosme commented 1 year ago

hi @mscuthbert what about open the tab 'issues' to your repo in https://github.com/mscuthbert/midicube to let community start to talk there?

it's a nice work!

mscuthbert commented 1 year ago

hi @mscuthbert what about open the tab 'issues' to your repo in https://github.com/mscuthbert/midicube to let community start to talk there?

it's a nice work!

Thank you -- it doesn't seem to let me add "issues" -- maybe because it's forked from a Repo that had it disabled?

acosme commented 1 year ago

hi @mscuthbert what about open the tab 'issues' to your repo in https://github.com/mscuthbert/midicube to let community start to talk there? it's a nice work!

Thank you -- it doesn't seem to let me add "issues" -- maybe because it's forked from a Repo that had it disabled?

It is possible inside 'settings' > 'features' > 'issues' or 'settings' > 'general' > 'issues';

mscuthbert commented 1 year ago

It is possible inside 'settings' > 'features' > 'issues' or 'settings' > 'general' > 'issues';

Aha! I've never turned it off before, so I didn't know how to turn it on. It's on now!