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

MIDI.Player.loadFile not working,

Open gkfrog opened this issue 9 years ago • 18 comments

MIDI.noteOn and MIDI.noteOff are working, but in the same onsuccess function, the MIDI.Player.loadFile does nothing. I'm on Chrome 51.0

I am passing the file name of the midi file directly to loadFile. Is that correct?

MIDI.loadPlugin({ soundfontUrl: "soundfont/", instrument: "acoustic_grand_piano", onsuccess: 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);

                MIDI.Player.loadFile("mysong.mid");
                MIDI.Player.start();
            }

gkfrog avatar Jul 18 '16 23:07 gkfrog

loadFile doesn't block. You are probably calling start() too soon.

hmoffatt avatar Jul 18 '16 23:07 hmoffatt

Is this correct?

function callback(){ MIDI.Player.start(); }

MIDI.Player.loadFile("mysong.mid",callback);

On Mon, Jul 18, 2016 at 5:39 PM, hmoffatt [email protected] wrote:

loadFile doesn't block. You are probably calling start() too soon.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mudcube/MIDI.js/issues/186#issuecomment-233491115, or mute the thread https://github.com/notifications/unsubscribe-auth/ATk1PGXTXr3KebgLdAI_yf1eLddV7fdyks5qXA6jgaJpZM4JPPkW .

gkfrog avatar Jul 19 '16 01:07 gkfrog

Yes, although you can just write

MIDI.Player.loadFile("mysong.mid",MIDI.Player.start);

hmoffatt avatar Jul 19 '16 04:07 hmoffatt

Yes, but nothing happens. No errors either.

On Mon, Jul 18, 2016 at 10:36 PM, hmoffatt [email protected] wrote:

Yes, although you can just write

MIDI.Player.loadFile("mysong.mid",MIDI.Player.start);

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mudcube/MIDI.js/issues/186#issuecomment-233528077, or mute the thread https://github.com/notifications/unsubscribe-auth/ATk1PLFXSDW98jDsXoRaLKhFu5dnp6xSks5qXFRbgaJpZM4JPPkW .

gkfrog avatar Jul 19 '16 11:07 gkfrog

Did you load the instruments needed by your MIDI file?

hmoffatt avatar Jul 19 '16 12:07 hmoffatt

Like this? MIDI.loadPlugin({ soundfontUrl: "soundfont/", instrument: "acoustic_grand_piano", onsuccess: 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); MIDI.Player.loadFile("mysong.mid",MIDI.Player.start); } });

On Tue, Jul 19, 2016 at 6:30 AM, hmoffatt [email protected] wrote:

Did you load the instruments needed by your MIDI file?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mudcube/MIDI.js/issues/186#issuecomment-233617119, or mute the thread https://github.com/notifications/unsubscribe-auth/ATk1PKCTV9PsdjCehZ2IkcrdEFdcFUWUks5qXMNigaJpZM4JPPkW .

gkfrog avatar Jul 19 '16 12:07 gkfrog

Does your mysong.mid only need the grand piano? You have to load all the instruments that your file needs - MIDI.js won't fall back to other instruments for ones that are missing, it'll just play silence.

Does the MIDI.noteOn/noteOff produce sounds?

hmoffatt avatar Jul 19 '16 23:07 hmoffatt

Yes on the noteOn and notteOff.

The midi files do not have an instrument change. I never coded for that.

On Tue, Jul 19, 2016 at 5:55 PM, hmoffatt [email protected] wrote:

Does your mysong.mid only need the grand piano? You have to load all the instruments that your file needs - MIDI.js won't fall back to other instruments for ones that are missing, it'll just play silence.

Does the MIDI.noteOn/noteOff produce sounds?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mudcube/MIDI.js/issues/186#issuecomment-233801141, or mute the thread https://github.com/notifications/unsubscribe-auth/ATk1PMDaARqY6-_pUF9NS8hfiaSwMMzWks5qXWPpgaJpZM4JPPkW .

gkfrog avatar Jul 20 '16 00:07 gkfrog

On 20/07/16 10:34, gkfrog wrote:

Yes on the noteOn and notteOff.

The midi files do not have an instrument change. I never coded for that.

What channels do you use? MIDI.js actually defaults to channel 1 instrument 1, channel 2 instrument 2, etc. (in js/midi/GM.js).

hmoffatt avatar Jul 20 '16 00:07 hmoffatt

I do have a program change I was using instrument 2. I changed my parameters for the program change to Instrument 1 and using Channel 1. Still no sound. $nChannel = 1; $nInstrument = 1;

On Tue, Jul 19, 2016 at 6:39 PM, hmoffatt [email protected] wrote:

On 20/07/16 10:34, gkfrog wrote:

Yes on the noteOn and notteOff.

The midi files do not have an instrument change. I never coded for that.

What channels do you use? MIDI.js actually defaults to channel 1 instrument 1, channel 2 instrument 2, etc. (in js/midi/GM.js).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mudcube/MIDI.js/issues/186#issuecomment-233807479, or mute the thread https://github.com/notifications/unsubscribe-auth/ATk1PPRvlFYLhW5HYJB41heUY3QKY_hCks5qXW4tgaJpZM4JPPkW .

gkfrog avatar Jul 20 '16 01:07 gkfrog

On 20/07/16 11:17, gkfrog wrote:

I do have a program change I was using instrument 2. I changed my parameters for the program change to Instrument 1 and using Channel 1. Still no sound. $nChannel = 1; $nInstrument = 1;

Not sure what the above code means. By the way when I say channel 1 and instrument 1, I really mean channel and instrument 0.

Anyway, I think you'll need to open the debugger to work this out. Assuming you're using the webaudio output, stick a breakpoint on noteOn in js/midi/plugin.webaudio.js and see what it's doing.

hmoffatt avatar Jul 20 '16 01:07 hmoffatt

well 0 makes it work. The tempo is a bit slow, but I have notes!

Thanks for your great support.

Gary

On Tue, Jul 19, 2016 at 7:17 PM, Gary Harber [email protected] wrote:

I do have a program change I was using instrument 2. I changed my parameters for the program change to Instrument 1 and using Channel 1. Still no sound. $nChannel = 1; $nInstrument = 1;

On Tue, Jul 19, 2016 at 6:39 PM, hmoffatt [email protected] wrote:

On 20/07/16 10:34, gkfrog wrote:

Yes on the noteOn and notteOff.

The midi files do not have an instrument change. I never coded for that.

What channels do you use? MIDI.js actually defaults to channel 1 instrument 1, channel 2 instrument 2, etc. (in js/midi/GM.js).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mudcube/MIDI.js/issues/186#issuecomment-233807479, or mute the thread https://github.com/notifications/unsubscribe-auth/ATk1PPRvlFYLhW5HYJB41heUY3QKY_hCks5qXW4tgaJpZM4JPPkW .

gkfrog avatar Jul 20 '16 01:07 gkfrog

On 20/07/16 11:36, gkfrog wrote:

well 0 makes it work. The tempo is a bit slow, but I have notes!

The default example code overrides the tempo (dumb). Set MIDI.Player.BPM = 0 before loading your file.

hmoffatt avatar Jul 20 '16 01:07 hmoffatt

I'm running into the same problem. Not sure I understood the solution though, could you paste a code example @gkfrog please? :-)

oleiade avatar Jul 20 '16 10:07 oleiade

So in my case, the problem was that I did not properly import the inc/jasmid/*.js files Cheers

oleiade avatar Jul 20 '16 10:07 oleiade

what's with the first note missing?

On Wed, Jul 20, 2016 at 4:36 AM, Théo Crevon [email protected] wrote:

So in my case, the problem was that I did not properly import the inc/jasmid/*.js files Cheers

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mudcube/MIDI.js/issues/186#issuecomment-233913824, or mute the thread https://github.com/notifications/unsubscribe-auth/ATk1POE0l7M6zTaMHS48Tnkq84SIWLloks5qXfobgaJpZM4JPPkW .

gkfrog avatar Jul 20 '16 16:07 gkfrog

ok got it.

On Wed, Jul 20, 2016 at 10:17 AM, Gary Harber [email protected] wrote:

what's with the first note missing?

On Wed, Jul 20, 2016 at 4:36 AM, Théo Crevon [email protected] wrote:

So in my case, the problem was that I did not properly import the inc/jasmid/*.js files Cheers

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mudcube/MIDI.js/issues/186#issuecomment-233913824, or mute the thread https://github.com/notifications/unsubscribe-auth/ATk1POE0l7M6zTaMHS48Tnkq84SIWLloks5qXfobgaJpZM4JPPkW .

gkfrog avatar Jul 20 '16 21:07 gkfrog

This is an exceptional program you've put together. Exactly what I needed! I am impressed.

Thanks.

Gary

On Wed, Jul 20, 2016 at 3:37 PM, Gary Harber [email protected] wrote:

ok got it.

On Wed, Jul 20, 2016 at 10:17 AM, Gary Harber [email protected] wrote:

what's with the first note missing?

On Wed, Jul 20, 2016 at 4:36 AM, Théo Crevon [email protected] wrote:

So in my case, the problem was that I did not properly import the inc/jasmid/*.js files Cheers

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mudcube/MIDI.js/issues/186#issuecomment-233913824, or mute the thread https://github.com/notifications/unsubscribe-auth/ATk1POE0l7M6zTaMHS48Tnkq84SIWLloks5qXfobgaJpZM4JPPkW .

gkfrog avatar Jul 21 '16 14:07 gkfrog