Uint8Array
15 | 2. Instantiate a new parser instance
16 | 3. Call the parse()
method to parse the SoundFont file
17 | 4. Use the getPresets()
and getInstruments()
methods to access preset and instrument data
18 | 5. Sample data is stored in the parser's sample
member variable
19 |
20 | ### Example Code ###
21 |
22 | // Utility function to load a SoundFont file from a URL using XMLHttpRequest.
23 | // The same origin policy will apply, as for all XHR requests.
24 | function loadSoundFont(url, success, error) {
25 | var xhr = new XMLHttpRequest();
26 | xhr.open("GET", url, true);
27 | xhr.responseType = "arraybuffer";
28 | xhr.onreadystatechange = function () {
29 | if (xhr.readyState === 4) {
30 | if (xhr.status === 200) {
31 | success(new Uint8Array(xhr.response));
32 | } else {
33 | if (options.error) {
34 | options.error(xhr.statusText);
35 | }
36 | }
37 | }
38 | };
39 | xhr.send();
40 | }
41 |
42 | // Load and parse a SoundFont file.
43 | loadSoundFont("sf_GMbank.sf2", function (sfData) {
44 | var parser = new sf2.Parser(sf2Data);
45 | parser.parse();
46 |
47 | // Do something with the parsed SoundFont data.
48 | });
49 |
50 | Summary of Changes from the Original
51 | ------------------------------------
52 |
53 | * Separated out the SoundFont parsing library from the rest of the sf2synth synthesizer
54 | * Removed the dependence on Google Closure
55 | * Renamed the namespace to sf2
for brevity
56 | * Added boilerplate to support most JS module loaders, including CommonJS, AMD, Node.js and browser globals
57 | * Added a Grunt-based build process
58 | * Created Bower and npm packages
59 |
60 | To Do
61 | -----
62 |
63 | * Improve the API of the parser by making it stateless
64 | * Add support for parsing in a Web Worker so that the main browser thread doesn't block
65 | * Massively extend the unit test coverage
66 | * Add support for running the unit tests in Node.js
67 |
--------------------------------------------------------------------------------
/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "sf2-parser",
3 | "version": "1.0.0",
4 | "main": "dist/sf2-parser.min.js",
5 | "ignore": [
6 | "tests",
7 | "Gruntfile.js",
8 | "MIT-LICENSE.txt",
9 | "package.json"
10 | ]
11 | }
12 |
--------------------------------------------------------------------------------
/dist/sf2-parser-all.js:
--------------------------------------------------------------------------------
1 | /*! JavaScript SoundFont 2 Parser. Copyright 2013-2015 imaya/GREE Inc and Colin Clark. Licensed under the MIT License. */
2 |
3 | /*
4 | * JavaScript SoundFont 2 Parser
5 | *
6 | * Copyright 2013 imaya/GREE Inc
7 | * Copyright 2015 Colin Clark
8 | *
9 | * Based on code from the "SoundFont Synthesizer for WebMidiLink"
10 | * https://github.com/gree/sf2synth.js
11 | *
12 | * Licensed under the MIT License.
13 | */
14 |
15 | /*global require*/
16 |
17 | (function (root, factory) {
18 | if (typeof exports === "object") {
19 | // We're in a CommonJS-style loader.
20 | root.sf2 = exports;
21 | factory(exports);
22 | } else if (typeof define === "function" && define.amd) {
23 | // We're in an AMD-style loader.
24 | define(["exports"], function (exports) {
25 | root.sf2 = exports;
26 | return (root.sf2, factory(exports));
27 | });
28 | } else {
29 | // Plain old browser.
30 | root.sf2 = {};
31 | factory(root.sf2);
32 | }
33 | }(this, function (exports) {
34 | "use strict";
35 |
36 | var sf2 = exports;
37 |
38 | sf2.Parser = function (input, options) {
39 | options = options || {};
40 | /** @type {ByteArray} */
41 | this.input = input;
42 | /** @type {(Object|undefined)} */
43 | this.parserOptions = options.parserOptions;
44 |
45 | /** @type {Array.