MIDI.js icon indicating copy to clipboard operation
MIDI.js copied to clipboard

Piano ok, synth_drum ok but other instruments ?

Open canado opened this issue 11 years ago • 14 comments

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

canado avatar Sep 02 '14 18:09 canado

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.

mscuthbert avatar Sep 02 '14 19:09 mscuthbert

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); } }); };

canado avatar Sep 02 '14 19:09 canado

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

canado avatar Sep 02 '14 20:09 canado

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);
    }
});

canado avatar Sep 03 '14 13:09 canado

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

canado avatar Sep 03 '14 13:09 canado

Working now, I change the window.onload with the document.ready of jquery and it's working fine

canado avatar Sep 03 '14 14:09 canado

Canado - How did you generate your own .js from a .sf2 file? Do you have a guide somewhere that I can use?

mb2140 avatar Sep 07 '14 14:09 mb2140

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

canado avatar Sep 07 '14 14:09 canado

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?

mb2140 avatar Sep 07 '14 14:09 mb2140

I don't have the zip with me right now, I ll give you the info later : )

canado avatar Sep 07 '14 14:09 canado

here you go https://github.com/gleitz/midi-js-soundfonts

canado avatar Sep 08 '14 18:09 canado

Wow, that's a huge collection! Thanks so much!

mb2140 avatar Sep 08 '14 21:09 mb2140

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);
    }
});

thesandlord avatar Jun 22 '15 22:06 thesandlord

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) }

acosme avatar Jun 26 '16 03:06 acosme