Comments (10)
I have some questions about the functionality of this:
It seems to me programChange
sets one instrument on a channel but loadPlugin
can load multiple soundfonts with the instruments
attribute.
How would programChange
be called in a way that when noteOn
get called it can sound with different instrument types?
from midi.js.
Hi, you'd want to hack MIDI.js to support multiple instruments. You could either load multiple instrument packs, or combine the packs into one .js file. Most of the coding would be done in MIDI.Plugin.js and MIDI.loadPlugin.js—I think that the root.programChange is actually already being called (to switch instruments), so the part on the jasmid should already be working. For webaudio, you'd probably add another level to "audioBuffers" so instead of audioBuffers[noteID] it would be audioBuffers[instrumentID][noteID]. Hope that helps a little bit ;)
from midi.js.
Thanks for reply! Maybe I'll put pull request later :-)
from midi.js.
Hi. Did you have a look at implementing multiple instrument support? That would be a great addition to MIDI.js
from midi.js.
Hi! Yes, I did it, but there is a problem - HTML5 audio permormance. MIDI.js uses multiple timers for playing notes simultaneously. And if a midi file has a lot of tracks it is very harmful for browsers, especialy for Chrome. Firefox performance is much better. For me HTML5 is a priority because Web Audio sounds bad in Ubuntu and now with a new Chrome 20.x version default MIDI.js Web Audio implementation not works (I tested on Mac OS). I think @mudcube could fix it, I didn't try.
from midi.js.
Hi mbektimirov,
Unfortunately, HTML5 Audio will never sound perfect due to it's inability to deliver perfect timing (this makes the computer sound like it's been drinking ;). Web Audio API is pretty recent, but definitely the way to go for best performance in the long run, so we'll have to wait for the kinks to be worked out on Ubuntu.
I'm testing MIDI.js on Chrome 20.x and it seems to be working on Mac—are you getting an error message?
from midi.js.
Hi there,
Great library. It has been fun to work with - good job mudcube. I found myself also needing support for multiple instruments and decided to dig into the code myself. At this point I have it working for web audio and html5. I also have a windows script that given a .sf2 file can generate a .js file with every note for every instrument (although it's not a one step process - yet). The format is as you suggested:
{
"1":
"A0": ...
"A1": ...
....
"2":
....
}
The sound font can be indexed by instrument (0-127) followed by a note, like a 2 dimensional array. One problem here is the file is quite large, about 1.5 mb per instrument so 1.5*128 mb total. Of course, you don't need to generate for all the instruments. I added a default such that if a specific instrument isn't there you play the default. To get the instrument data I added a check for the program change event and map the instrument to the channel. When playing a note the channel is also passed in and then mapped to it's most recent instrument. I'm aware that the instrumentName and midiChannelPrefix meta events can also give instrument information together, but am ignoring them for now.
To actually generate the sounds for the .js I needed to make changes to jsmidi.js and add in support for the program change event in the midi so different instruments could be outputted.
Finally I also added a switch to avoid percussion, just a bool. It avoids channel 9 and dramatically improves sound quality for tracks with percussion.
At this point not all instruments sound good. For example, instrument 075, the pan flute, sounds considerably worse than say a piano because the note goes longer, I am still working on this.
from midi.js.
Wow, these changes sound amazing—there's been a lot of interest for moving MIDI.js onto supporting multiple instruments. I really appreciate you taking the initiative to help push this project forwards. It sounds like you're pretty comfortable in the MIDI.js codebase, but if you run into any problems, I'm more than happy to help out :)
from midi.js.
The latest MIDI.js has multi-instrument support.
from midi.js.
Excellent, thanks for the update.
from midi.js.
Related Issues (20)
- very long notes are truncated HOT 2
- pitch bending in webaudio HOT 2
- How can i send a note to specific stereo channel? HOT 1
- tracks
- Audio Mobile App : MIDI.js or Native ? HOT 2
- k
- Is it impossible to pause when using noteon noteoff instead of player HOT 3
- How to disable sound in Player.js?
- There is no sound when I am playing my own midi file HOT 2
- Question, Piano Layout HOT 1
- Midi files with multi channels doesn't work using MIDI.Player.Loadfile HOT 3
- How to play file.mid HOT 4
- can i use midi.js to create a online piano and guitar? HOT 1
- Color piano not found in chrome web store HOT 2
- Playing midi file with the wrong tempo HOT 1
- ReferenceError: Base64Binary is not defined HOT 1
- Current Position / Event Listener
- Loading all GM instruments for midi file HOT 25
- Slow start of playing HOT 3
- Bug: MIDI events not being fired HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from midi.js.