Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Commit

Permalink
Add support to MusyngKite soundfont
Browse files Browse the repository at this point in the history
  • Loading branch information
danigb committed Jun 6, 2016
1 parent 3d6a36e commit 122836c
Show file tree
Hide file tree
Showing 17 changed files with 874 additions and 161 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
@@ -1,10 +1,16 @@
CHANGELOG

[0.10.0]
- Add support to MusyngKite soundfonts.
- `instrument` can be partially applied with an AudioContext instance
- Deprecate noteToMidi

[0.9.2] Update sample-player
[0.9.1] Use sample-player
[0.9.0]
- Load soundfonts directly from github.io (https://github.com/gleitz/midi-js-soundfonts/issues/9)
- New API
- Deprecate old API

[0.8.4]
- Use audio-loader
- Use note-parser instead of note-midi and note-freq
Expand Down
27 changes: 17 additions & 10 deletions README.md
Expand Up @@ -23,6 +23,8 @@ It is a much simpler and lightweight replacement for [MIDI.js](https://github.co
- Easily connect to a Web MIDI API `MidiInput`
- Schedule a list of notes

It 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.

## Usage

[Download the distribution file](https://raw.githubusercontent.com/danigb/soundfont-player/master/dist/soundfont-player.min.js) and include it in your html...
Expand Down Expand Up @@ -63,10 +65,11 @@ The instrument object returned by the promise has the following properties:
- play: A function to play notes from the buffer with the signature
`play(note, time, duration, options)`


The valid options are:

- `nameToUrl` <Function>: a function to convert from instrument names to URL
- `format`: can be 'mp3' or 'ogg'
- `soundfont`: can be 'FluidR3_GM' or 'MusyngKite'
- `nameToUrl`: a function to convert from instrument names to URL
- `destination`: by default Soundfont uses the `audioContext.destination` but you can override it.
- `gain`: the gain (volume) of the player (1 by default)
- `adsr`: the amplitude envelope as array of `[attack, decay, sustain, release]`
Expand All @@ -85,7 +88,8 @@ limit the number of notes you want and reduce the time to load the instrument.
**Example**
```js
var Soundfont = require('sounfont-player')
Soundfont.instrument('marimba').then(function (marimba) {
var ac = new AudioContext()
Soundfont.instrument(ac, 'marimba', { soundfont: 'MusyngKite' }).then(function (marimba) {
marimba.play('C4')
})
```
Expand Down Expand Up @@ -126,22 +130,22 @@ Connect a player to a midi input
See [sample-player](https://github.com/danigb/sample-player) for more information.

<a name="nameToUrl"></a>
## nameToUrl(name, format) ⇒ <code>String</code>
## nameToUrl(name, soundfont, format) ⇒ <code>String</code>
Given an instrument name returns a URL to to the Benjamin Gleitzman's
package of [pre-rendered sound fonts](https://github.com/gleitz/midi-js-soundfonts)

**Kind**: global function
**Returns**: <code>String</code> - the Soundfont file url

| Param | Type | Description |
| --- | --- | --- |
| name | <code>String</code> | instrument name |
| soundfont | <code>String</code> | (Optional) 'FluidR3_GM' or 'MusyngKite' ('FluidR3_GM' by default) |
| format | <code>String</code> | (Optional) Can be 'mp3' or 'ogg' (mp3 by default) |

**Example**
```js
var Soundfont = require('soundfont-player')
Soundfont.nameToUrl('marimba', 'mp3')
Soundfont.nameToUrl('marimba', null, 'ogg') // => http://gleitz.github.io/midi-js-soundfonts/FluidR3_GM/marimba-ogg.js
```

## Run the tests, examples and build the library distribution file
Expand All @@ -166,14 +170,17 @@ To run pure javascript examples `npm install -g beefy` then `beefy examples/pian

## Available instruments

You can grab a [json file](https://github.com/danigb/soundfont-player/blob/master/instruments.json) with all the instrument names, or require it:
Download the json files:
- [FluidR3_GM]()
- [MusyngKite]()

Or require it:

```js
var instrumentNames = require('soundfont-player/instruments.json')
var fluidNames = require('soundfont-player/names/fuildR3.json')
var musyngNames = require('soundfont-player/names/musyngkite.json')
```

The complete list [is here](https://github.com/danigb/soundfont-player/blob/master/INSTRUMENTS.md)

## Resources

- SoundFont technical specification: http://freepats.zenvoid.org/sf2/sfspec24.pdf
Expand Down
7 changes: 5 additions & 2 deletions dist/soundfont-player.js
Expand Up @@ -61,15 +61,18 @@ function isSoundfontURL (name) {
* package of [pre-rendered sound fonts](https://github.com/gleitz/midi-js-soundfonts)
*
* @param {String} name - instrument name
* @param {String} soundfont - (Optional) the soundfont name. One of 'FluidR3_GM'
* or 'MusyngKite' ('FluidR3_GM' by default)
* @param {String} format - (Optional) Can be 'mp3' or 'ogg' (mp3 by default)
* @returns {String} the Soundfont file url
* @example
* var Soundfont = require('soundfont-player')
* Soundfont.nameToUrl('marimba', 'mp3')
*/
function nameToUrl (name, format) {
function nameToUrl (name, sf, format) {
format = format === 'ogg' ? format : 'mp3'
return 'http://gleitz.github.io/midi-js-soundfonts/FluidR3_GM/' + name + '-' + format + '.js'
sf = sf === 'MusyngKite' ? sf : 'FluidR3_GM'
return 'http://gleitz.github.io/midi-js-soundfonts/' + sf + '/' + name + '-' + format + '.js'
}

// In the 1.0.0 release it will be:
Expand Down
2 changes: 1 addition & 1 deletion dist/soundfont-player.min.js

Large diffs are not rendered by default.

130 changes: 130 additions & 0 deletions examples/assets/fluidR3.json
@@ -0,0 +1,130 @@
[
"accordion",
"acoustic_bass",
"acoustic_grand_piano",
"acoustic_guitar_nylon",
"acoustic_guitar_steel",
"agogo",
"alto_sax",
"applause",
"bagpipe",
"banjo",
"baritone_sax",
"bassoon",
"bird_tweet",
"blown_bottle",
"brass_section",
"breath_noise",
"bright_acoustic_piano",
"celesta",
"cello",
"choir_aahs",
"church_organ",
"clarinet",
"clavinet",
"contrabass",
"distortion_guitar",
"drawbar_organ",
"dulcimer",
"electric_bass_finger",
"electric_bass_pick",
"electric_grand_piano",
"electric_guitar_clean",
"electric_guitar_jazz",
"electric_guitar_muted",
"electric_piano_1",
"electric_piano_2",
"english_horn",
"fiddle",
"flute",
"french_horn",
"fretless_bass",
"fx_1_rain",
"fx_2_soundtrack",
"fx_3_crystal",
"fx_4_atmosphere",
"fx_5_brightness",
"fx_6_goblins",
"fx_7_echoes",
"fx_8_scifi",
"glockenspiel",
"guitar_fret_noise",
"guitar_harmonics",
"gunshot",
"harmonica",
"harpsichord",
"helicopter",
"honkytonk_piano",
"kalimba",
"koto",
"lead_1_square",
"lead_2_sawtooth",
"lead_3_calliope",
"lead_4_chiff",
"lead_5_charang",
"lead_6_voice",
"lead_7_fifths",
"lead_8_bass__lead",
"marimba",
"melodic_tom",
"music_box",
"muted_trumpet",
"oboe",
"ocarina",
"orchestra_hit",
"orchestral_harp",
"overdriven_guitar",
"pad_1_new_age",
"pad_2_warm",
"pad_3_polysynth",
"pad_4_choir",
"pad_5_bowed",
"pad_6_metallic",
"pad_7_halo",
"pad_8_sweep",
"pan_flute",
"percussive_organ",
"piccolo",
"pizzicato_strings",
"recorder",
"reed_organ",
"reverse_cymbal",
"rock_organ",
"seashore",
"shakuhachi",
"shamisen",
"shanai",
"sitar",
"slap_bass_1",
"slap_bass_2",
"soprano_sax",
"steel_drums",
"string_ensemble_1",
"string_ensemble_2",
"synth_bass_1",
"synth_bass_2",
"synth_brass_1",
"synth_brass_2",
"synth_choir",
"synth_drum",
"synth_strings_1",
"synth_strings_2",
"taiko_drum",
"tango_accordion",
"telephone_ring",
"tenor_sax",
"timpani",
"tinkle_bell",
"tremolo_strings",
"trombone",
"trumpet",
"tuba",
"tubular_bells",
"vibraphone",
"viola",
"violin",
"voice_oohs",
"whistle",
"woodblock",
"xylophone"
]
130 changes: 130 additions & 0 deletions examples/assets/musyngkite.json
@@ -0,0 +1,130 @@
[
"accordion",
"acoustic_bass",
"acoustic_grand_piano",
"acoustic_guitar_nylon",
"acoustic_guitar_steel",
"agogo",
"alto_sax",
"applause",
"bag_pipe",
"banjo",
"baritone_sax",
"bassoon",
"bird_tweet",
"blown_bottle",
"brass_section",
"breath_noise",
"bright_acoustic_piano",
"celesta",
"cello",
"choir_aahs",
"church_organ",
"clarinet",
"clavichord",
"contrabass",
"distortion_guitar",
"drawbar_organ",
"dulcimer",
"electric_bass_finger",
"electric_bass_pick",
"electric_grand_piano",
"electric_guitar_clean",
"electric_guitar_jazz",
"electric_guitar_muted",
"electric_piano_1",
"electric_piano_2",
"english_horn",
"fiddle",
"flute",
"french_horn",
"fretless_bass",
"fx_1_rain",
"fx_2_soundtrack",
"fx_3_crystal",
"fx_4_atmosphere",
"fx_5_brightness",
"fx_6_goblins",
"fx_7_echoes",
"fx_8_scifi",
"glockenspiel",
"guitar_fret_noise",
"guitar_harmonics",
"gunshot",
"harmonica",
"harpsichord",
"helicopter",
"honkytonk_piano",
"kalimba",
"koto",
"lead_1_square",
"lead_2_sawtooth",
"lead_3_calliope",
"lead_4_chiff",
"lead_5_charang",
"lead_6_voice",
"lead_7_fifths",
"lead_8_bass_lead",
"marimba",
"melodic_tom",
"music_box",
"muted_trumpet",
"oboe",
"ocarina",
"orchestra_hit",
"orchestral_harp",
"overdriven_guitar",
"pad_1_new_age",
"pad_2_warm",
"pad_3_polysynth",
"pad_4_choir",
"pad_5_bowed",
"pad_6_metallic",
"pad_7_halo",
"pad_8_sweep",
"pan_flute",
"percussive_organ",
"piccolo",
"pizzicato_strings",
"recorder",
"reed_organ",
"reverse_cymbal",
"rock_organ",
"seashore",
"shakuhachi",
"shamisen",
"shanai",
"sitar",
"slap_bass_1",
"slap_bass_2",
"soprano_sax",
"steel_drums",
"string_ensemble_1",
"string_ensemble_2",
"synth_bass_1",
"synth_bass_2",
"synth_drum",
"synth_voice",
"synthbrass_1",
"synthbrass_2",
"synthstrings_1",
"synthstrings_2",
"taiko_drum",
"tango_accordion",
"telephone_ring",
"tenor_sax",
"timpani",
"tinkle_bell",
"tremolo_strings",
"trombone",
"trumpet",
"tuba",
"tubular_bells",
"vibraphone",
"viola",
"violin",
"voice_oohs",
"whistle",
"woodblock",
"xylophone"
]
2 changes: 1 addition & 1 deletion examples/local-piano.js
Expand Up @@ -7,7 +7,7 @@ document.body.innerHTML = '<h1>Local piano</h1>' +
'<p>If you can\'t hear the piano, open the development console</p>'

function localUrl (name) {
return 'examples/' + name + '-ogg.js'
return 'examples/assets/' + name + '-ogg.js'
}
sf.instrument(ac, 'acoustic_grand_piano', {
nameToUrl: localUrl,
Expand Down

0 comments on commit 122836c

Please sign in to comment.