{"id":13768184,"url":"https://github.com/danigb/soundfont-player","last_synced_at":"2025-05-10T23:31:04.445Z","repository":{"id":30348698,"uuid":"33901134","full_name":"danigb/soundfont-player","owner":"danigb","description":"Quick soundfont loader and player for browser","archived":true,"fork":false,"pushed_at":"2023-05-16T17:00:54.000Z","size":1994,"stargazers_count":462,"open_issues_count":44,"forks_count":61,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-04-21T09:09:31.796Z","etag":null,"topics":["midi","player","sampler","soundfonts"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danigb.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2015-04-14T00:13:49.000Z","updated_at":"2025-04-14T09:09:15.000Z","dependencies_parsed_at":"2023-01-14T16:48:36.989Z","dependency_job_id":"bcd6344d-ca74-4ef8-b976-9af52aab1871","html_url":"https://github.com/danigb/soundfont-player","commit_stats":{"total_commits":94,"total_committers":16,"mean_commits":5.875,"dds":"0.24468085106382975","last_synced_commit":"93e5a9a41064d18d91ed9c35fa6e29e332ac1099"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danigb%2Fsoundfont-player","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danigb%2Fsoundfont-player/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danigb%2Fsoundfont-player/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danigb%2Fsoundfont-player/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danigb","download_url":"https://codeload.github.com/danigb/soundfont-player/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253497296,"owners_count":21917683,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["midi","player","sampler","soundfonts"],"created_at":"2024-08-03T16:01:17.679Z","updated_at":"2025-05-10T23:31:03.923Z","avatar_url":"https://github.com/danigb.png","language":"JavaScript","funding_links":[],"categories":["Sound assets"],"sub_categories":["SoundFonts"],"readme":"# soundfont-player [![npm](https://img.shields.io/npm/v/soundfont-player.svg?style=flat-square)](https://www.npmjs.com/package/soundfont-player)\n\n[![Build Status](https://img.shields.io/travis/danigb/soundfont-player/master.svg?style=flat-square)](https://travis-ci.org/danigb/soundfont-player)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) [![license](https://img.shields.io/npm/l/soundfont-player.svg?style=flat-square)](https://www.npmjs.com/package/soundfont-player)\n\n⚠️ Archived. There are better alternatives. This is one of it: https://github.com/danigb/smplr Thanks for the fish! ⚠️\n\n\nA soundfont loader/player to play MIDI sounds using WebAudio API.\n\nIt loads Benjamin Gleitzman's package of\n[pre-rendered sound fonts](https://github.com/gleitz/midi-js-soundfonts) by default with no server setup. Just a few lines of javascript:\n\n```js\nSoundfont.instrument(new AudioContext(), 'acoustic_grand_piano').then(function (piano) {\n  piano.play('C4')\n})\n```\n\nIt is a much simpler and lightweight replacement for [MIDI.js](https://github.com/mudcube/MIDI.js) soundfont loader (MIDI.js is much bigger, capable of play midi files, for example, but it weights an order of magnitude more).\n\n## Features\n\n- Load soundfont files in MIDI.js format or json format.\n- Unlimited poliphony (and stop all sounds with a single function call)\n- Use midi note numbers. Accepts decimal points to detune.\n- Easily connect to a Web MIDI API `MidiInput`\n- Schedule a list of notes\n\nIt uses [audio-loader](https://github.com/danigb/audio-loader) to load soundfont files and [sample-player](https://github.com/danigb/sample-player) to play the sounds.\n\n## Install\n\nVia npm: `npm install --save soundfont-player`\n\nOr download the [minified code](https://raw.githubusercontent.com/danigb/soundfont-player/master/dist/soundfont-player.min.js) and include it in your html:\n\n```html\n\u003cscript src=\"soundfont-player.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  Soundfont.instrument(new AudioContext(), 'marimba').then(function (marimba) {\n  })\n\u003c/script\u003e\n```\n\n## Usage\n\n__The soundfont loader__\n\nOut of the box are two Soundfonts available: MusyngKite and FluidR3_GM (MusyngKite by default: has more quality, but also weights more). You can load them with `instrument` function:\n\n```js\nSoundfont.instrument(ac, 'clavinet').then(function (clavinet) {\n  clavinet.play('C4')\n})\n// or use FluidR3_GM\nSoundfont.instrument(ac, 'clavinet', { soundfont: 'FluidR3_GM' }).then(function (clavinet) {\n  clavinet.play('C4')\n})\n```\n\nYou can load your own Soundfont files passing the .js path or url:\n\n```js\nSoundfont.instrument(ac, '/soundfonts/clavinet-mp3.js').then(...)\n// or\nSoundfont.instrument(ac, 'clavinet-mp3.js', { from: 'server.com/soundfonts/' })\n```\n\n__The soundfont player__\n\nOnce you have an instrument you can:\n\n```js\n// The first step is always create an instrument:\nSoundfont.instrument(ac, 'clavinet').then(function (clavinet) {\n  // Then you can play a note using names or midi numbers:\n  clavinet.play('C4')\n  clavinet.play(69)\n  // float point midi numbers are accepted (and notes are detuned):\n  clavinet.play(60.5) // =\u003e 500 cents over C4\n\n  // you can stop all playing notes\n  clavinet.stop()\n  // or stop only one\n  clavinet.play('C4').stop(ac.currentTime + 0.5)\n  // or pass a duration argument to `play`\n  clavinet.play('C4', ac.currentTime, { duration: 0.5})\n\n\n  // You can connect the instrument to a midi input:\n  window.navigator.requestMIDIAccess().then(function (midiAccess) {\n    midiAccess.inputs.forEach(function (midiInput) {\n      clavinet.listenToMidi(midiInput)\n    })\n  })\n\n  // Or schedule events at a given time\n  clavinet.schedule(ac.currentTime + 5, [ { time: 0, note: 60}, { time: 0.5, note: 61}, ...])\n})\n```\n\n## API\n\n__\u003c 0.9.x users__: The API in the 0.9.x releases has been changed and some features are going to be removed (like oscillators). While 0.9.0 adds warnings to the deprecated API, the 1.0.0 will remove the support.\n\n\n\u003ca name=\"instrument\"\u003e\u003c/a\u003e\n\n## instrument(ac, name, options) ⇒ \u003ccode\u003ePromise\u003c/code\u003e\nLoad a soundfont instrument. It returns a promise that resolves to a\ninstrument object.\n\nThe instrument object returned by the promise has the following properties:\n\n- name: the instrument name\n- play: A function to play notes from the buffer with the signature\n`play(note, time, duration, options)`\n\nThe valid options are:\n\n- `format`: can be 'mp3' or 'ogg'\n- `soundfont`: can be 'FluidR3_GM' or 'MusyngKite'\n- `nameToUrl`: a function to convert from instrument names to URL\n- `destination`: by default Soundfont uses the `audioContext.destination` but you can override it.\n- `gain`: the gain (volume) of the player (1 by default)\n- `attack`: the attack time of the amplitude envelope\n- `decay`: the decay time of the amplitude envelope\n- `sustain`: the sustain gain value of the amplitude envelope\n- `release`: the release time of the amplitude envelope\n- `adsr`: the amplitude envelope as array of `[attack, decay, sustain, release]`. It overrides other options.\n- `loop`: set to true to loop audio buffers\n- `notes`: an array of the notes to decode. It can be an array of strings\nwith note names or an array of numbers with midi note numbers. This is a\nperformance option: since decoding mp3 is a cpu intensive process, you can limit\nlimit the number of notes you want and reduce the time to load the instrument.\n\n| Param | Type | Description |\n| --- | --- | --- |\n| ac | \u003ccode\u003eAudioContext\u003c/code\u003e | the audio context |\n| name | \u003ccode\u003eString\u003c/code\u003e | the instrument name. For example: 'acoustic_grand_piano' |\n| options | \u003ccode\u003eObject\u003c/code\u003e | (Optional) the same options as Soundfont.loadBuffers |\n\n**Example**  \n```js\nvar Soundfont = require('soundfont-player')\nvar ac = new AudioContext()\nSoundfont.instrument(ac, 'marimba', { soundfont: 'MusyngKite' }).then(function (marimba) {\n  marimba.play('C4')\n})\n```\n\n\u003ca name=\"player\"\u003e\u003c/a\u003e\n### The player\n\nThe player object returned by the promise has the following functions:\n\n\u003ca name=\"player.start\"\u003e\u003c/a\u003e\n#### player.play\nAn alias for `player.start`\n\n\u003ca name=\"player.start\"\u003e\u003c/a\u003e\n#### player.start(name, when, options) ⇒ \u003ccode\u003eAudioNode\u003c/code\u003e\nStart a sample buffer. The returned object has a function `stop(when)` to stop the sound.\n\nValid options are:\n\n- `gain`: float between 0 to 1\n- `attack`: the attack time of the amplitude envelope\n- `decay`: the decay time of the amplitude envelope\n- `sustain`: the sustain gain value of the amplitude envelope\n- `release`: the release time of the amplitude envelope\n- `adsr`: an array of `[attack, decay, sustain, release]`. Overrides other parameters.\n- `duration`: set the playing duration in seconds of the buffer(s)\n- `loop`: set to true to loop the audio buffer\n\n\u003ca name=\"player.stop\"\u003e\u003c/a\u003e\n#### player.stop(when, nodes) ⇒ \u003ccode\u003eArray\u003c/code\u003e\nStop some or all samples\n\n\u003ca name=\"player.on\"\u003e\u003c/a\u003e\n#### player.on(event, callback) ⇒ \u003ccode\u003e[player](#player)\u003c/code\u003e\nAdds a listener of an event\n\n\u003ca name=\"player.connect\"\u003e\u003c/a\u003e\n#### player.connect(destination) ⇒ \u003ccode\u003eAudioPlayer\u003c/code\u003e\nConnect the player to a destination node\n\n\u003ca name=\"player.schedule\"\u003e\u003c/a\u003e\n#### player.schedule(when, events) ⇒ \u003ccode\u003eArray\u003c/code\u003e\nSchedule a list of events to be played at specific time.\n\n\u003ca name=\"player.listenToMidi\"\u003e\u003c/a\u003e\n#### player.listenToMidi(input, options) ⇒ \u003ccode\u003e[player](#player)\u003c/code\u003e\nConnect a player to a midi input\n\nSee [soundfont-player](https://github.com/danigb/soundfont-player) for more information.\n\n\u003ca name=\"nameToUrl\"\u003e\u003c/a\u003e\n## nameToUrl(name, soundfont, format) ⇒ \u003ccode\u003eString\u003c/code\u003e\nGiven an instrument name returns a URL to to the Benjamin Gleitzman's\npackage of [pre-rendered sound fonts](https://github.com/gleitz/midi-js-soundfonts)\n\n**Returns**: \u003ccode\u003eString\u003c/code\u003e - the Soundfont file url  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| name | \u003ccode\u003eString\u003c/code\u003e | instrument name |\n| soundfont | \u003ccode\u003eString\u003c/code\u003e | (Optional) 'FluidR3_GM' or 'MusyngKite' ('MusyngKite' by default) |\n| format | \u003ccode\u003eString\u003c/code\u003e | (Optional) Can be 'mp3' or 'ogg' (mp3 by default) |\n\n**Example**  \n```js\nvar Soundfont = require('soundfont-player')\nSoundfont.nameToUrl('marimba', null, 'ogg') // =\u003e http://gleitz.github.io/midi-js-soundfonts/FluidR3_GM/marimba-ogg.js\n```\n\n## Run the tests, examples and build the library distribution file\n\nFirst clone this repo and install dependencies: `npm i`\n\nTo run tests use npm: `npm test`\n\nThe `dist` folder contains ready to use file for browser. You can use the dist file from the repo, but if you want to build you own run: `npm run dist`\n\nTo run the html example start a local http server. For example:\n\n```bash\nnpm install -g http-server\nhttp-server\n```\n\nAnd open [http://localhost:8080/examples](http://localhost:8080/examples)\n\nTo run pure javascript examples `npm install -g beefy` then `beefy examples/marimba.js` and navigate to http://localhost:9966/\n\n\n## Available instruments\n\nBy default it loads Benjamin Gleitzman's\n[pre-rendered SoundFonts](https://github.com/gleitz/midi-js-soundfonts).\n\n__Instrument names__\n\nYou can download the names of the instruments as a .json file:\n  - [FluidR3_GM](https://raw.githubusercontent.com/danigb/soundfont-player/master/names/fluidR3.json)\n  - [MusyngKite](https://raw.githubusercontent.com/danigb/soundfont-player/master/names/musyngkite.json)\n\nOr require them:\n\n```js\nvar fluidNames = require('soundfont-player/names/fuildR3.json')\nvar musyngNames = require('soundfont-player/names/musyngkite.json')\n```\n\n## Resources\n\n- SoundFont technical specification: http://freepats.zenvoid.org/sf2/sfspec24.pdf\n\n## License\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanigb%2Fsoundfont-player","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanigb%2Fsoundfont-player","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanigb%2Fsoundfont-player/lists"}