Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for xhr #2

Closed
frankbaele opened this issue May 6, 2016 · 0 comments
Closed

Support for xhr #2

frankbaele opened this issue May 6, 2016 · 0 comments

Comments

@frankbaele
Copy link
Contributor

frankbaele commented May 6, 2016

Are you willing to add xhr support for getting the midi files? The file upload api is a little limiting. In my current application im solving this by the following snippet:

    function getMidiStream(url, callback) {
        var xhr = new XMLHttpRequest();
        xhr.open('GET', url);
        xhr.overrideMimeType('text/plain; charset=x-user-defined');
        xhr.onreadystatechange = function () {
            if (this.readyState === 4) {
                if (this.status === 200) {
                    var t = this.responseText || '';
                    var ff = [];
                    var mx = t.length;
                    var scc = String.fromCharCode;
                    for (var z = 0; z < mx; z++) {
                        ff[z] = scc(t.charCodeAt(z) & 255);
                    }
                    callback(ff.join(''));
                } else {
                    onerror && onerror('Unable to load MIDI file');
                }
            }
        };
        xhr.send();
    }

    getMidiStream(url, function (stream) {
           var midi = MidiConvert.parseParts(stream, options);
    })

I wanted to create a pull request but had no idea where to put the code. Btw this code is heavily inspired by how midijs solves this. Its kind of a hack to get a blob.

Frank

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant