Piano ok, synth_drum ok but other instruments ?
Hi,
I m not sure if I did the changes correctly. I would like to have the flute instrument, so in the file demo-WhitneyMusicBox.html I changed acoustic_grand_piano to flute
then in soundfont I added, flute-mp3.js and flute-ogg.js and also a directory of all the flute-mp3
The page is loading correctly, the circle with colors also, but there is no sound. What am I missing ? thanks
Send a MIDI.programChange(0, x) where x is the 0-based general midi code for flute (41? I can't remember off the top of my head) note that it's zero-based. If you have a list that goes 1-128 subtract one from the instrument code.
the instrument code for flute is 74
I changed for flute see below, but you mean that note 50 correspond to piano and that I have to find the corresponding note for flute ?
window.onload = function () { MIDI.loadPlugin({ soundfontUrl: "./soundfont/", instrument: "flute", callback: function() { var delay = 0; // play one note every quarter second var note = 50; // the MIDI note var velocity = 127; // how hard the note hits // play the note MIDI.setVolume(0, 127); MIDI.noteOn(0, note, velocity, delay); MIDI.noteOff(0, note, delay + 0.75); } }); };
if I write
instrument: "74", instrument: "73", instrument: 74, instrument: 73,
it's not working either string version tries to open the 74-ogg.js file and the integer version try to open an object
Still nothing MIDI.loadPlugin({ soundfontUrl: "soundfont/", instrument: "flute", callback: function() {
var channel = 0,
instrumentFlute = 73,
note = 60,
velocity = 127, // how hard the note hits, from 0-127
delay = 0.5; // how long to hold the note, in seconds
MIDI.programChange(0, instrumentFlute);
MIDI.setVolume(0, 127);
MIDI.noteOn(0, note, velocity, delay);
MIDI.noteOn(0, 50, velocity, 2);
MIDI.noteOff(0, note, delay + 0.75);
}
});
Just try another instrument
MIDI.loadPlugin({ soundfontUrl: "soundfont/", instrument: "glockenspiel", callback: function() { MIDI.programChange(0, 10); MIDI.noteOn(0, 35, 127, 0); } });
which is working fine, so I don't know
Working now, I change the window.onload with the document.ready of jquery and it's working fine
Canado - How did you generate your own .js from a .sf2 file? Do you have a guide somewhere that I can use?
I just used the package from mudcube/MIDI.js and for the flute there is another package with all the mp3 + js "generated sounds" which you can google it. it's about 250Mo
Thanks for the info. I'm trying to find a JS file that contains acoustic drums, have you had any luck tracking one of these down?
I don't have the zip with me right now, I ll give you the info later : )
here you go https://github.com/gleitz/midi-js-soundfonts
Wow, that's a huge collection! Thanks so much!
I'd really recommend adding this to the "basic" example.
Something like
var instrument_name = "glockenspiel";
MIDI.loadPlugin({
soundfontUrl: "soundfont/",
instrument: instrument_name ,
callback: function() {
//Add this line
MIDI.programChange(0, MIDI.GM.byName[instrument_name].number);
///////////////
MIDI.noteOn(0, 35, 127, 0);
}
});
To me works with onsuccess function:
onsuccess: function () { MIDI.programChange(0, MIDI.GM.byName["flaute"].number); console.log("success " + instrumentName + ", code: " + MIDI.GM.byName[instrumentName].number) }