Git Product home page Git Product logo

Comments (10)

spencerhitch avatar spencerhitch commented on August 16, 2024 2

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.

mudcube avatar mudcube commented on August 16, 2024

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.

mbektimirov avatar mbektimirov commented on August 16, 2024

Thanks for reply! Maybe I'll put pull request later :-)

from midi.js.

dubmofiz avatar dubmofiz commented on August 16, 2024

Hi. Did you have a look at implementing multiple instrument support? That would be a great addition to MIDI.js

from midi.js.

mbektimirov avatar mbektimirov commented on August 16, 2024

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.

mudcube avatar mudcube commented on August 16, 2024

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.

forrestcoward avatar forrestcoward commented on August 16, 2024

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.

mudcube avatar mudcube commented on August 16, 2024

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.

mudcube avatar mudcube commented on August 16, 2024

The latest MIDI.js has multi-instrument support.

from midi.js.

dubmofiz avatar dubmofiz commented on August 16, 2024

Excellent, thanks for the update.

from midi.js.

Related Issues (20)

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.