experchange > javascript

Jonas Thörnvall (10-07-18, 07:06 PM)
I am trying to get my sequenser to handle sysex messages. The procedure is pretty simple
if (navigator.requestMIDIAccess) {
navigator.requestMIDIAccess(
{sysex: true} //Yeah it is just to set sysex : true
)
.then(success, failure);
}

Problem is that the sysex : true generate a message box event. that have to be answered.

file: /// wants to use your midi device

But the program runs on so it gets success and try to read in ports, but apparently the midiobject is not accessible until the alert box event answered.

How can i sidestep that problem or somehow wait for the alert box to be closed, because i guess that is the problem with the ports within midiobjects not accessible. Works fine when sysex false.
Jonas Thörnvall (10-08-18, 01:12 AM)
Den söndag 7 oktober 2018 kl. 19:06:57 UTC+2 skrev Jonas Thörnvall:
[..]
> file: /// wants to use your midi device
> But the program runs on so it gets success and try to read in ports, but apparently the midiobject is not accessible until the alert box event answered.
> How can i sidestep that problem or somehow wait for the alert box to be closed, because i guess that is the problem with the ports within midiobjects not accessible. Works fine when sysex false.


One start to think that Javascript may not be doing so good nowadays when it is practically impossible to find working examples.

If anyone find a working example of sysex true that manage to list ports, do not hesitate to post the link, and we will see if i can decipher the convoluted code structure.
JJ (10-08-18, 06:45 AM)
On Sun, 7 Oct 2018 10:06:51 -0700 (PDT), Jonas Thörnvall wrote:
[..]
> Problem is that the sysex : true generate a message box event. that have
> to be answered.
> file: /// wants to use your midi device


That message box is part of the web browser security system. It can't be
bypassed unless the site in added into the allow list.

> But the program runs on so it gets success and try to read in ports, but
> apparently the midiobject is not accessible until the alert box event
> answered.


`requestMIDIAccess()` is an asynchronous method. If the script tries to
access the resource without waiting for the resourse to be available, then
it's guaranteed to fail.

> How can i sidestep that problem or somehow wait for the alert box to be
> closed, because i guess that is the problem with the ports within
> midiobjects not accessible. Works fine when sysex false.


You're asking about hacking a security system. The answer would obviously be
no.
Jonas Thörnvall (10-08-18, 07:58 AM)
Den måndag 8 oktober 2018 kl. 06:45:35 UTC+2 skrev JJ:
> On Sun, 7 Oct 2018 10:06:51 -0700 (PDT), Jonas Thörnvall wrote:
> That message box is part of the web browser security system. It can't be
> bypassed unless the site in added into the allow list.
> `requestMIDIAccess()` is an asynchronous method. If the script tries to
> access the resource without waiting for the resourse to be available, then
> it's guaranteed to fail.


Well that is my question JJ how do i build the "structure" accesspath so that it wait for user input to get ready.

Right now i load "the main script" like list ports, via HTML function body onLoad. The access part midiaccess.js is loaded in HTML file.

But of course when i read in the HTML file it first import midiaccess.js, but right after it start to load main, before the user have the chance to answer the alert box. So how can i have the HTML body onLoad main.js wait foruser input?

> > How can i sidestep that problem or somehow wait for the alert box to be
> > closed, because i guess that is the problem with the ports within
> > midiobjects not accessible. Works fine when sysex false.

> You're asking about hacking a security system. The answer would obviouslybe
> no.


No i just want to wait for the user to handle the alert box, i want to waitfor user input before loading the "main program that call listports" that use the midiaccess object that is not ready.

Lets say this is my midiaccess file, how can i list ports after, the alert box been resolved. So how do i know when the alert box resolved, where do icall the listports(); or alternatively how do i wait until alert box resolved?

Thanks JJ

if (navigator.requestMIDIAccess) {
navigator.requestMIDIAccess(
{sysex: false}
)
.then(success,failure );
}

function failure() {
console.error('No access to your midi devices.' + +msg)
}

function success(midi) {
mid = midi;
inputs = midi.inputs.values();
// inputs outputs are Iterators
for (input = inputs.next(); input && !input.done; input = inputs.next()) {
// each time there is a midi message call the onMIDIMessage function
console.log(input);
input.value.onmidimessage = onMIDIMessage;
}
}

function listPorts() {
// Grab an array of all available devices
var iter = mid.outputs.values();
for (var i = iter.next(); i && !i.done; i = iter.next()) {
outportarr.push(i.value);
}
PORTout = outportarr[outportindex];

//List ports in and out
Lportout = mid.outputs.values();
Lportin = mid.inputs.values();
for (listinput = Lportin.next(); listinput && !listinput.done; listinput = Lportin.next()) {
var deviceIn = listinput.value.name;
var optin = document.createElement("option");
optin.text = deviceIn;
document.getElementById("in_portsel").add(optin);
}
for (listoutput = Lportout.next(); listoutput && !listoutput.done; listoutput = Lportout.next()) {
var deviceOut = listoutput.value.name;
var optout = document.createElement("option");
optout.text = deviceOut;
document.getElementById("out_portsel").add(optout) ;
}
}
Jonas Thörnvall (10-08-18, 08:13 AM)
Den måndag 8 oktober 2018 kl. 06:45:35 UTC+2 skrev JJ:
> On Sun, 7 Oct 2018 10:06:51 -0700 (PDT), Jonas Thörnvall wrote:
> That message box is part of the web browser security system. It can't be
> bypassed unless the site in added into the allow list.
> `requestMIDIAccess()` is an asynchronous method. If the script tries to
> access the resource without waiting for the resourse to be available, then
> it's guaranteed to fail.
> You're asking about hacking a security system. The answer would obviouslybe
> no.


One could think of it like this we create another function that main that will wait for the alert box to get resolved. Let us call it waitAlertBox(); from the we will call our "main.js which call listport function.

Now the question become how do we know the state of the alert box? I have no idea have you? It must have some property value "resolved true or false"?
Jonas Thörnvall (10-08-18, 05:09 PM)
Den måndag 8 oktober 2018 kl. 08:14:06 UTC+2 skrev Jonas Thörnvall:
> Den måndag 8 oktober 2018 kl. 06:45:35 UTC+2 skrev JJ:
> One could think of it like this we create another function that main that will wait for the alert box to get resolved. Let us call it waitAlertBox(); from the we will call our "main.js which call listport function.
> Now the question become how do we know the state of the alert box? I haveno idea have you? It must have some property value "resolved true or false"?


Well i will put in on hold, most functionality of synth is reachable without. I think it is only the dumprequests needing sysex, and thereby the file dialog. So one probably just open sysex when dumping data.
JJ (10-10-18, 12:39 AM)
On Sun, 7 Oct 2018 22:58:12 -0700 (PDT), Jonas Thörnvall wrote:
> No i just want to wait for the user to handle the alert box, i want to
> wait for user input before loading the "main program that call listports"
> that use the midiaccess object that is not ready.
> Lets say this is my midiaccess file, how can i list ports after, the
> alert box been resolved. So how do i know when the alert box resolved,
> where do i call the listports(); or alternatively how do i wait until
> alert box resolved?


The the arguments passed to the `then()` method is the result of the MIDI
access request. It'll succeed if the user allow it, or it'll rejected if
otherwise. By the time any is executed, the confirmation box has been
responded by user. In your case, call `listPorts()` during or after
`success()` is executed.
Jonas Thörnvall (10-10-18, 06:50 AM)
Den onsdag 10 oktober 2018 kl. 00:39:38 UTC+2 skrev JJ:
> On Sun, 7 Oct 2018 22:58:12 -0700 (PDT), Jonas Thörnvall wrote:
> The the arguments passed to the `then()` method is the result of the MIDI
> access request. It'll succeed if the user allow it, or it'll rejected if
> otherwise. By the time any is executed, the confirmation box has been
> responded by user. In your case, call `listPorts()` during or after
> `success()` is executed.


Well weither it is correct or not i tried to move the main(); call into the success method. It was not a good idea. Because for some reason then the alertbox "dialog" "allow block" is no longer ready, but open. Probably the script try to load resources after success that will not be available untili answered the alert box.

It seem to be a catch 22 situation.
JJ (10-11-18, 03:40 PM)
On Tue, 9 Oct 2018 21:50:13 -0700 (PDT), Jonas Thörnvall wrote:
> Well weither it is correct or not i tried to move the main(); call into
> the success method. It was not a good idea. Because for some reason then
> the alertbox "dialog" "allow block" is no longer ready, but open.


As long as MIDI access hasn't been granted, MIDI resources are not
available.

> Probably the script try to load resources after success that will not be
> available until i answered the alert box.


How come you don't know your own code?
Jonas Thörnvall (10-12-18, 12:11 AM)
Den torsdag 11 oktober 2018 kl. 15:40:33 UTC+2 skrev JJ:
> On Tue, 9 Oct 2018 21:50:13 -0700 (PDT), Jonas Thörnvall wrote:
> As long as MIDI access hasn't been granted, MIDI resources are not
> available.
> How come you don't know your own code?


I don't think that is the problem as long you have not pushed allow or block resources not available, and the error is not recoverable.

But i am not as fast clicking as the computer throwing up the window. What i do want is wait call main until alert resolved. But i do not know how to know when alert resolved, how do i know and call main after "block or unblock".
Jonas Thörnvall (10-15-18, 05:56 AM)
Den fredag 12 oktober 2018 kl. 00:11:57 UTC+2 skrev Jonas Thörnvall:
> Den torsdag 11 oktober 2018 kl. 15:40:33 UTC+2 skrev JJ:
> I don't think that is the problem as long you have not pushed allow or block resources not available, and the error is not recoverable.
> But i am not as fast clicking as the computer throwing up the window. What i do want is wait call main until alert resolved. But i do not know how to know when alert resolved, how do i know and call main after "block or unblock".


Well sysex on should probably somehow be invoked at later stage, because only needed when dump from what i understand. So then the question become canyou change state of it? How, it is not available after midiaccess success?
Similar Threads