jazz-soft/JZZ

how to use web midi permission in html file

watersoft123 opened this issue · 9 comments

When I use "JZZ.js" in android app, debugging show "Web MIDI will ask a permission to use", how to set or write in html file?

This may depend on the browser, but Web MIDI API normally asks for the user's permission when called.
This is a browser security feature and it cannot be changed via HTML or JavaScript.

I've found that Chrome will only prompt the user for MIDI access if you set sysexEnabled to true.

I've heard that Chrome is planning to make their policy more paranoiac, so, in the future, you may need the user's permission even if you don't require SysEx.

I want to display a dialog and wait for user's permission(agree or reject),but without a dialog being displayed. how to show this dialog in html and associate with JZZ.js?
Use Send(),how to specify a midi instrument, such as organ. In addition, how to make a note continue to play for a period of time?

You want to display a dialog, but without a dialog being displayed. Sorry, I did not get it.

To specify an instrument, use a "Program Change" MIDI message (Cx xx)
For more details, please see https://www.midi.org/specifications-old/item/table-2-expanded-messages-list-status-bytes

Hi jazz. many thanks.
Following your advice,I specify an instrument sucessfully. Now I have another question:

var port = JZZ().openMidiOut().or(function(){alert('Cannot open MIDI port!');});
function play(){
var _Note = [[60,2000],[80,2000]]; /This is just a test, the actual array length is long/
for(var i=0;i<_Note.length;i++){
port.program(0, 5).send(0x90,_Note[i][0],100).wait(_Note[i][1]).send(0x80,_Note[i][0],0);
}
}

When I run,the playing time of the first note is much shorter than the second, although both are set to wait(2000),
I do not know the reason. Also, the sound of playing two notes is stranger than playing one alone.

There may be a delay playing the first note due to the underlying MIDI system "warming up".
You can try to insert a little wait() before playing the first note.

Thank you jazz, After some searching and trying,I solved the problem by using async function and await.

Excellent!