Code Monkey home page Code Monkey logo

soundfont-player's Introduction

soundfont-player npm

Build Status js-standard-style license

⚠️ Archived. There are better alternatives. This is one of it: https://github.com/danigb/smplr Thanks for the fish! ⚠️

A soundfont loader/player to play MIDI sounds using WebAudio API.

It loads Benjamin Gleitzman's package of pre-rendered sound fonts by default with no server setup. Just a few lines of javascript:

Soundfont.instrument(new AudioContext(), 'acoustic_grand_piano').then(function (piano) {
  piano.play('C4')
})

It is a much simpler and lightweight replacement for MIDI.js soundfont loader (MIDI.js is much bigger, capable of play midi files, for example, but it weights an order of magnitude more).

Features

  • Load soundfont files in MIDI.js format or json format.
  • Unlimited poliphony (and stop all sounds with a single function call)
  • Use midi note numbers. Accepts decimal points to detune.
  • Easily connect to a Web MIDI API MidiInput
  • Schedule a list of notes

It uses audio-loader to load soundfont files and sample-player to play the sounds.

Install

Via npm: npm install --save soundfont-player

Or download the minified code and include it in your html:

<script src="soundfont-player.js"></script>
<script>
  Soundfont.instrument(new AudioContext(), 'marimba').then(function (marimba) {
  })
</script>

Usage

The soundfont loader

Out 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:

Soundfont.instrument(ac, 'clavinet').then(function (clavinet) {
  clavinet.play('C4')
})
// or use FluidR3_GM
Soundfont.instrument(ac, 'clavinet', { soundfont: 'FluidR3_GM' }).then(function (clavinet) {
  clavinet.play('C4')
})

You can load your own Soundfont files passing the .js path or url:

Soundfont.instrument(ac, '/soundfonts/clavinet-mp3.js').then(...)
// or
Soundfont.instrument(ac, 'clavinet-mp3.js', { from: 'server.com/soundfonts/' })

The soundfont player

Once you have an instrument you can:

// The first step is always create an instrument:
Soundfont.instrument(ac, 'clavinet').then(function (clavinet) {
  // Then you can play a note using names or midi numbers:
  clavinet.play('C4')
  clavinet.play(69)
  // float point midi numbers are accepted (and notes are detuned):
  clavinet.play(60.5) // => 500 cents over C4

  // you can stop all playing notes
  clavinet.stop()
  // or stop only one
  clavinet.play('C4').stop(ac.currentTime + 0.5)
  // or pass a duration argument to `play`
  clavinet.play('C4', ac.currentTime, { duration: 0.5})


  // You can connect the instrument to a midi input:
  window.navigator.requestMIDIAccess().then(function (midiAccess) {
    midiAccess.inputs.forEach(function (midiInput) {
      clavinet.listenToMidi(midiInput)
    })
  })

  // Or schedule events at a given time
  clavinet.schedule(ac.currentTime + 5, [ { time: 0, note: 60}, { time: 0.5, note: 61}, ...])
})

API

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

instrument(ac, name, options) ⇒ Promise

Load a soundfont instrument. It returns a promise that resolves to a instrument object.

The instrument object returned by the promise has the following properties:

  • name: the instrument name
  • play: A function to play notes from the buffer with the signature play(note, time, duration, options)

The valid options are:

  • 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)
  • attack: the attack time of the amplitude envelope
  • decay: the decay time of the amplitude envelope
  • sustain: the sustain gain value of the amplitude envelope
  • release: the release time of the amplitude envelope
  • adsr: the amplitude envelope as array of [attack, decay, sustain, release]. It overrides other options.
  • loop: set to true to loop audio buffers
  • notes: an array of the notes to decode. It can be an array of strings with note names or an array of numbers with midi note numbers. This is a performance option: since decoding mp3 is a cpu intensive process, you can limit limit the number of notes you want and reduce the time to load the instrument.
Param Type Description
ac AudioContext the audio context
name String the instrument name. For example: 'acoustic_grand_piano'
options Object (Optional) the same options as Soundfont.loadBuffers

Example

var Soundfont = require('soundfont-player')
var ac = new AudioContext()
Soundfont.instrument(ac, 'marimba', { soundfont: 'MusyngKite' }).then(function (marimba) {
  marimba.play('C4')
})

The player

The player object returned by the promise has the following functions:

player.play

An alias for player.start

player.start(name, when, options) ⇒ AudioNode

Start a sample buffer. The returned object has a function stop(when) to stop the sound.

Valid options are:

  • gain: float between 0 to 1
  • attack: the attack time of the amplitude envelope
  • decay: the decay time of the amplitude envelope
  • sustain: the sustain gain value of the amplitude envelope
  • release: the release time of the amplitude envelope
  • adsr: an array of [attack, decay, sustain, release]. Overrides other parameters.
  • duration: set the playing duration in seconds of the buffer(s)
  • loop: set to true to loop the audio buffer

player.stop(when, nodes) ⇒ Array

Stop some or all samples

player.on(event, callback) ⇒ player

Adds a listener of an event

player.connect(destination) ⇒ AudioPlayer

Connect the player to a destination node

player.schedule(when, events) ⇒ Array

Schedule a list of events to be played at specific time.

player.listenToMidi(input, options) ⇒ player

Connect a player to a midi input

See soundfont-player for more information.

nameToUrl(name, soundfont, format) ⇒ String

Given an instrument name returns a URL to to the Benjamin Gleitzman's package of pre-rendered sound fonts

Returns: String - the Soundfont file url

Param Type Description
name String instrument name
soundfont String (Optional) 'FluidR3_GM' or 'MusyngKite' ('MusyngKite' by default)
format String (Optional) Can be 'mp3' or 'ogg' (mp3 by default)

Example

var Soundfont = require('soundfont-player')
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

First clone this repo and install dependencies: npm i

To run tests use npm: npm test

The 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

To run the html example start a local http server. For example:

npm install -g http-server
http-server

And open http://localhost:8080/examples

To run pure javascript examples npm install -g beefy then beefy examples/marimba.js and navigate to http://localhost:9966/

Available instruments

By default it loads Benjamin Gleitzman's pre-rendered SoundFonts.

Instrument names

You can download the names of the instruments as a .json file:

Or require them:

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

Resources

License

MIT License

soundfont-player's People

Contributors

benwiley4000 avatar danigb avatar dengarcia avatar dependabot[bot] avatar frankbaele avatar jathak avatar jjgonecrypto avatar jottenlips avatar kirlen avatar mattbierner avatar mcomghall avatar mk-pmb avatar rakannimer avatar sslotsky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

soundfont-player's Issues

instrument.play() is not a function?

Running the following code seems to be returning a "Uncaught TypeError: marimba.play is not a function".

var marimba = soundfont.instrument(new AudioContext(), 'marimba');
marimba.play('C4');

Seems as though every time I try to set a variable to an instrument I cannot play. Any suggestions?

‘Buffer null not found.’

This may be related to #28. The player is not working in Safari, but only on some machines.

The console contains the message ‘Buffer null not found’. What can I do to help debug this?

Soundfont.instrument with options.destination not taken into account

When we load an instrument using Soundfont.instrument with the options.destination set to a node a create (for example GainNode), it is not taken into account.

The doc tells us about the option destination which is not used:

Here what I changed in the code to make it work:

`function instrument (ac, name, options) {
if (arguments.length === 1) return function (n, o) { return instrument(ac, n, o) }
var opts = options || {}
var isUrl = opts.isSoundfontURL || isSoundfontURL
var toUrl = opts.nameToUrl || nameToUrl
var url = isUrl(name) ? name : toUrl(name, opts.soundfont, opts.format)

return load(ac, url, { only: opts.only || opts.notes }).then(function (buffers) {
var p = player(ac, buffers, opts).connect(opts.destination ? opts.destination : ac.destination)
p.url = url
p.name = name
return p
})
}
`

instead of this code
`function instrument (ac, name, options) {
if (arguments.length === 1) return function (n, o) { return instrument(ac, n, o) }
var opts = options || {}
var isUrl = opts.isSoundfontURL || isSoundfontURL
var toUrl = opts.nameToUrl || nameToUrl
var url = isUrl(name) ? name : toUrl(name, opts.soundfont, opts.format)

return load(ac, url, { only: opts.only || opts.notes }).then(function (buffers) {
var p = player(ac, buffers, opts).connect(ac.destination)
var p = player(ac, buffers, opts).connect(opts.destination ? opts.destination : ac.destination)
p.url = url
p.name = name
return p
})
}
`

Play midi file inside arraybuffer.

I have wrote code which encodes Doom's Mus into Midi and cannot find a method to play this inside javascript in a clean and simple way. Can this take an array buffer of midi data?

Using .sf2 files

I am trying to use samples from a .sf2 file that I downloaded from http://www.flamestudios.org/free/Soundfonts.
I am serving the file from my server and trying to call it like this:
Soundfont.instrument(this.fbs.audioContext, "IBNZSteelString.sf2", { from: 'http://localhost:3000/' }).then((instrument)=> {this.fbs.instrument = instrument;})

I'm getting the following error in the console: https://gleitz.github.io/midi-js-soundfonts/MusyngKite/IBNZSteelString.sf2-mp3.js 404 Not Found. It doesn't look like soundfont-player is making the call to my server, but rather to the default gleitz github.

What am I doing wrong?

instrument.play() works, how do I turn a note off?

How do I turn a note off or set the duration of the note?
for notes on:
piano.play(event.noteName, ac.currentTime, {gain:event.velocity/5});
I have a midi off event, I would like to turn the note off
I tried piano.stop(event.noteName, ac.currentTime, {}); but this obviously doesn't work.
Any suggestions would be appreciated.
Thanks for your help.

note list in MIDI note numbers not working

The comments for Soundfont.instrument() imply that you can supply a notes list to load in the options, using MIDI note numbers. However if you do that nothing is loaded.

I don't see any code which would map the note numbers to names before handing them to the audio-loader.

My test case is:

Soundfont.instrument(ac, 'marimba', { destination: vca, notes: [70, 72] }).then(function (marimba) {

Player scheduler - register a callback to be invoked when note is played

This is a great little library, many thanks.

I would like to know if it's possible to register a function to be invoked when the scheduler plays each note. My use case is that I want to animate a UI element when each note plays.

Is this possible? If not, how might I go about implementing it?

Plug-in MIDI API

Is there any way I can throw data from the Web MIDI API into this library to play it? Any examples of this?

Start event listener triggered when scheduled, should be when the note starts

(I could use more documentation on how to use the player.on(event, callback) call. What are the acceptable values for "event", for instance?)

I'm trying to get a callback when a note is about to sound. When I use the player.on() method along with the player.schedule() method, I get all the start and started callbacks at once. The ended callbacks happen at the correct time, though.

As a test case, I created a new vue-cli app and replaced the Hello.vue file with this:

<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
<button @click="play">Play</button>
  </div>
</template>

<script>
  import Soundfont from "soundfont-player";
export default {
  name: 'hello',
  mounted() {
  	console.log("loading piano...");
  	const self = this;
  	self.ac = new AudioContext();
    Soundfont.instrument(self.ac, 'acoustic_grand_piano').then(function (piano) {
      self.piano = piano;
      self.piano.on('event', self.progress);
      console.log("piano loaded");
    });

  },
  data () {
    return {
    	piano: null,
      ac: null,
      msg: 'soundfont player test'
    }
  },
  methods: {
  	play: function(ev) {
  		console.log("play pushed");
  		//this.piano.play("C4");
      this.piano.schedule(this.ac.currentTime, [
        { note: 60, time: 0.2 },
        { note: 64, time: 0.2 },
        { note: 68, time: 1.4 },
        { note: 72, time: 2.6 },
        { note: 76, time: 2.6 },
        { note: 78, time: 6.6 },
      ]);
    },
    progress: function(ev, time, obj, opts) {
  		console.log("progress", this.ac.currentTime, ev, time);
    }
  }
}
</script>

My console looks like this:

loading piano...
piano loaded
play pushed
progress 6.88 schedule 6.88 
progress 6.88 start 7.08 60 
progress 6.88 started 7.08 0 
progress 6.88 start 7.08 64 
progress 6.88 started 7.08 1 
progress 6.88 start 8.28 68 
progress 6.88 started 8.28 2 
progress 6.88 start 9.48 72 
progress 6.88 started 9.48 3 
progress 6.88 start 9.48 76 
progress 6.88 started 9.48 4 
progress 6.88 start 13.48 78 
progress 6.88 started 13.48 5 
progress 10.112 ended 10.112 1 
progress 10.112 ended 10.112 0 
progress 11.296 ended 11.296 2 
progress 12.512 ended 12.512 4 
progress 12.512 ended 12.512 3 
progress 16.512 ended 16.512 5 

This first number is the time according to AudioContext and the second is the time the note should be scheduled.

I'd like to build a "bouncing ball" type application where I show something right when a note is started. Do I need to figure out the timing myself?

loading Soundfont player

Hello -
Please forgive my ignorance as I am relatively new to programming.

I am using the Soundfont player for a sketch in p5.js. I have created a play button to play my song after I have chosen my instruments. If I press the play button right away, the sound is a bit choppy. If I wait a second or two, it's fine. Is there a simple line I can add that will prevent the song from playing until the sound is fully loaded?
i.e. if (instrument.isLoaded()){instrument.play}
Thanks

not working in Safari

I don't get any sound from the demos (either examples/index.html, nor the page at https://danigb.github.io/soundfont-player/ ) in Safari, either on the Mac or on iOS 9.3.2.

Firstly Safari uses the deprecated name webkitAudioContext. Once I changed that, I still don't get any sound from the soundfont-player page; it seems the soundfont loaded .then() promise is never called. I couldn't see why,

.stop() not behaving as expected when pressed multiple times

Hey,
I'm having trouble with loading and handling the library in iOS (works fine on PC/Android devices)
I've stripped my engine to this super simple page:

<!DOCTYPE html>
<head>
	<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
	<script src="soundfont-player.min.js" type="text/javascript"></script>
</head>
<body>
	<button id="play" onclick="testNote()">click me to play a note</button>
	<button id="playAgain" onclick="playAgain()">click me to stop and play again</button>
<script>
var midiout, 
AudioContext;
$(document).ready(function(){
    AudioContext = window.AudioContext || window.webkitAudioContext;
	midiout = Soundfont.instrument(new AudioContext(), 'acoustic_grand_piano').then(function (piano) {
	midiout = piano;
        midiout.play(50);
	});
});
function testNote() {
	midiout.play(50);
}
function playAgain() {
    midiout.stop();
    midiout.play(50);
}
</script>
</body>
</html>

The issue: after a note starts playing, when the second button is clicked it behaves as expected, but only once.
I've connected my iPhone to a Mac for debugging through Safari develop mode - and the following error shows up in the console when clicking on #playAgain after it has been clicked once already:
InvalidStateError (DOM Exception 11): The object is in an invalid state. - in stop - soundfont-player.min.js:1:6434

When expanded, this is the information that's displayed:
screen shot 2017-08-23 at 13 16 26

Any light shed on the subject will be greatly appreciated.
Thanks in advance,

PS I unminified the library and 'line 1, column 6434' that is referenced in the error is in this line:

this._voltage.stop(endTime);

Flats seem to be broken

Hey, just loaded up your example and noticed that none of the flats seem to play (Chrome & FF). Trying to play Eb2 yields:

Uncaught TypeError: Failed to set the 'buffer' property on 'AudioBufferSourceNode': The provided value is not of type 'AudioBuffer'.
    at TypeError (native)
    at Object.instrument.play (http://localhost:8080/dist/soundfont-loader.js:81:20)
    at eval (eval at evaluate (unknown source), <anonymous>:1:7)
    at Object.InjectedScript._evaluateOn (<anonymous>:895:55)
    at Object.InjectedScript._evaluateAndWrap (<anonymous>:828:34)
    at Object.InjectedScript.evaluateOnCallFrame (<anonymous>:954:21)
    at http://localhost:8080/example/:24:9
    at Array.forEach (native)
    at HTMLAnchorElement.<anonymous> (http://localhost:8080/example/:23:35)

Strange because the object at that key (buffers.Eb2) is indeed an AudioBuffer. I don't have time to delve deeper right now, but I can later. Just thought I'd raise it now in case the fix was obvious.

Snare drum

Any plans to add a snare drum to the instruments list?

Better URL configuration

Currently the way to change the default url generation is by overriding a class method. While this is good for testing, it's not good for humans. Let's improve it.

Proposals:

  1. Pass the generateUrl function in the constructor: new Soundfont(ctx, function(name) { return ... })
  2. Add options to the constructor: new Soundfont(ctx, { base: 'http://...', format: 'mp3' })
  3. Combine both

Any ideas?

Change the default destination

Currently any instrument outputs to ctx.destination. It would be very useful allow to override this behaviour.

What I'm thinking:

var ctx = new AudioContext()
var soundfont = new Soundfont(ctx)
var gain = ctx.createGain()
gain.gain.value = 0.5
gain.destination = ctx.destination
var instrument = soundfont.instrument('acoustic_grand_piano', { destination: gain })

How to convert sf2 file?

Could you please provide a guide on how to convert a regular SoundFont file into a format supported by soundfont-player? I can only see pre-generated JS soundfonts, but could not find scripts to perform the conversion for existing sf2 files.

incorrect path in /examples/index.html

Gracias por su trabajo en este proyecto -

In /examples/index.html

the path to soundfont-player.js is relative to root vs /examples

<script src="/dist/soundfont-player.js"></script>

should be

<script src="../dist/soundfont-player.js"></script>

With that in place, /examples/index.html works wonderfully.

¡Ahora puedo pasar demasiado tiempo añadiendo sonido a las cosas!

Loading soundfont with Angular

I tried getting soundfont using Angular. I get this error:

Argument of type 'AudioContext' is not assignable to parameter of type '{ new (contextOptions?: AudioContextOptions): AudioContext; prototype: AudioContext; }'.
  Property 'prototype' is missing in type 'AudioContext' but required in type '{ new (contextOptions?: AudioContextOptions): AudioContext; prototype: AudioContext; }'.

This is my code:

const newPlayer = SoundFont.instrument(new AudioContext(), 'assets/soundfonts/acoustic_grand_piano-mp3.js');

error is in new AudioContext() part

Duration ignored

I'm not sure if this is the same as #7 but the duration parameter has no effect when playing a note. In this example (I'm loading in sounds locally), changing the duration from 2 to 200 to 2000 does nothing. It always plays the MP3 once and that's it.

      var ac = new AudioContext()
      Soundfont.instrument(ac, '/soundfont/cello-mp3.js').then(function (cello) {
        cello.play('C4', ac.currentTime, 2000)
      })

not loading midi files

Hi, how can i play a midi file like file.midi with the player? Should i use the web midi api?

[API] Take options on play() instead of instrument()

Thanks for the great library!

One small API problem I ran into for my project: right now instrument() is what takes the options parameter with the gain and destination information. I feel it would be more flexible to have options be an argument to play() instead:

var inst = soundfont.instrument('guitar_harmonics');
inst.play('c2', 1, 0.5, { gain: 0.2, destination: my_dest });

I need this functionality to play notes softer or louder depending on how hard a user strikes my virtual instrument's strings.

I'll submit a PR shortly and you can see if you agree with the API change.

play().stop() does not work

Your main readme file says I can do this:

  // or stop only one
  clavinet.play('C4').stop(ac.currentTime + 0.5)

but it doesn’t work, because play(), an alias for start(), does not return start()’s return value.

Changing

  player.play = function (n, w, o) { player.start(n, w, o) }

to

  player.play = function (n, w, o) { return player.start(n, w, o) }

makes it work.

I tried to file a pull request, but it’s not showing up. In any case, it had a mistake in it, in that it stopped microtones from working, so if the pull request does show up at some point it should be discarded.

Track with delta

My midi tracks with notes on have a delta value on them:

{
	byteIndex: 140
	channel: 2
	delta: 216
	name: "Note on"
	noteName: "D4"
	noteNumber: 62
	running: true
	tick: 2444
	track: 3
	velocity: 0
}

Where do I insert these delta values while playing? It sounds pretty bad as it is. I tried playing midi tracks with delta being all 0 and it sounds perfect. But as it is most of my midi have tracks with delta greater than 0 on them. Pls. help.

Heavy load cracks on Firefox and CPU never comes back flat

Hi have spent some time trying to understand where the difference comes from in Firefox and Chrome and I am now reaching to you for help.

I run the following code that works well on Chrome (no crack and CPU comes back near flat after the test) but in Firefox it cracks and CPU is high and never goes back down even a few minutes after the test is finished.

Is that a bug in Firefox or is that a bug in the library?

The code will execute play on the instrument (woodblock) every 0.1 second for 20 seconds.

<html>
	<head>
		<title>test heavy load</title>
		<script type="text/javascript" src="soundfont-player.min.js"></script>
		<script type="text/javascript">
			var audioContext = new AudioContext();
            Soundfont.instrument(audioContext, 'woodblock', {
                    destination: audioContext.destination,
                    loop: false,
                    notes: ["C4"] })
                .then(function (instrument) {
                    // console.log("instrument loaded");
                    var interval = 20; // in second
                    var iter = 10 * interval;
                    for(var i=0 ; i<iter ; i++) {
                        var time = audioContext.currentTime + interval/iter * i;
                        instrument.play("C4", time, time + 1);
                    }
                });
		</script>
		</head>
	<body>
	TEST PAGE
	</body>
</html>

crackles and performance issues on iOS

The marimba demo crackles on iOS after the first few notes start. You can hear the new notes starting slower too, until it catches up. I'm testing on an iPad mini (first generation).

I've noticed quite a lot of web audio applications behave this way especially on the older iPads. I think that the browser/CPU is not keeping up with the quantity of AudioBufferSourceNode nodes. I was able to make it work a bit better by

  1. adding a small start delay to all the notes
  2. adding a duration property to each note that is played so that they don't overlap

I'm interested to know if anything can be done to improve performance. The marimba demo doesn't actually seem to max out the CPU unlike some of the others I've seen but it's still not keeping up.

Some other apps I've noticed crackling issues with are MIDI.js (webaudio output is unusable on iOS) (CPU > 100% all the time), and even this simple sound effects demo http://webaudioapi.com/samples/rapid-sounds/

ToneJS bridge

Hi,
is it possible to use soundfontplayer linked sounds library in ToneJS and how?
Thank you

Note about using the library on iOS

Just a quick note about using this library on iOS: I do not believe that the default ogg files are supported, but you can use the mp3 versions just fine:

const loader = name =>
    'https://cdn.rawgit.com/gleitz/midi-js-Soundfonts/master/FluidR3_GM/' + name + '-mp3.js';

new Soundfont(ctx, loader);

It may be worth adding a note to the readme about this, or perhaps changing the default since I believe mp3 does have broader support:
http://caniuse.com/#feat=ogg-vorbis
http://caniuse.com/#feat=mp3

Illegal MIDI message warning from keyboard

Greetings! First, my gratitude for this great library. I tried several libraries for web MIDI and this is by far the most straightforward and usable that I've seen.

My setup seems to work but it's producing some warnings that I thought were worth reporting. I have two MIDI inputs that I'm listening to: a VMPK keyboard and a KORG-SP500 that hooks to my laptop with a MIDI-USB adapter.

Both of the inputs play sound in my browser, but when the KORG is connected I get these illegal message warnings in very quick succession. I'd be happy to drill in and gather more information for you, but I'm not sure what I'm looking for.

image

Thank you again for the great lib and for taking time to read through this issue.

Gain:0 should be off?

Hey man, great library. Both you and I seem to be interested in programming and music. I'm working on a MIDI player and am using this library for the sounds. I find that when I set gain to 0 the note still sounds. Would be be possible for the note to be silent in that case?

Here's the MIDI player I'm working on: http://grimmdude.com/MidiPlayerJS/

Thanks,
Garrett

envelopes / looping

Hi,

This looks like a great library; congrats! Any plans to support looping (for sustain)? I know the SoundFont spec supports including loop points in instruments, although the files included with MIDI.js don't have this info unfortunately.

I think it would make a huge difference in the quality of current browser-based SoundFonts if this could be supported at some point, but I imagine it would be a great deal of work... anyways, if you're looking for some future work, having "endless" sustain would be a great feature, especially for instruments like organ. - Charlie

Loading new soundfont

Please forgive me if I am not able to best ask this question - I am a relative novice and can't seem to figure this out.

I'm writing a p5.js sketch that uses the Soundfont player. I am wanting to load/use a different soundfont of my own creation. I have used the MIDI.js soundfont generator to render the soundfont into the .js format.

Before placing this newly created file into a repository, I was trying to load a different soundfont using the following line:

Soundfont.instrument (ac, "marimba-mp3.js", { from: "http://gleitz.github.io/midi-js-soundfonts/FatBoy/" }).then(function(play_marimba) { marimba = play_marimba})

I could not get the sound to load this way. As far as I know I have followed what you said to do in the readme file.

I also wondered if there was a way just to load the marimba-mp3.js file right into my sketch, but I couldn't figure that out either.

Sorry if my question is not clear enough.

Any help or clarification would be greatly appreciated!

Leo

from the README:
You can load your own Soundfont files passing the .js path or url:

Soundfont.instrument(ac, '/soundfonts/clavinet-mp3.js').then(...)
// or
Soundfont.instrument(ac, 'clavinet-mp3.js', { from: 'server.com/soundfonts/' })

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.