The MIDI Forum

  1. Jonas
  2. Sherlock Holmes
  3. Creating with MIDI
  4. Tuesday, 10 September 2019
  5.  Subscribe via email
Is there a way to restart "close webMidi API" i put my navigator midiaccess request in a file to be able to reload and select inports. "Because i am clueless howto drop an attached port". So i thought i just make a new call requesting midi after i listed inports with checkboxes selected.

However i noticed the new navigator midiaccess request is just layered above the old one double, tripple, quadrupple notes and so on....

So my checkbox solution, to reload midi do not work it is just layered on top, how to one close the requested midiAccess?
If not possible how do one drop a port?

//MIDI ACCESS TO PORTS INITIATED
function midiInitiation(){
if (navigator.requestMIDIAccess) {
navigator.requestMIDIAccess(
{sysex: true}
)
.then(success,failure );
}
}

//IF MIDI ACCESS FAIL
function failure() {
console.error('No access to your midi devices.' + +msg)
}

//IF MIDI ACCESS INITIATED
function success(midi) {
mid = midi;
if (firstrun==true){listInPorts(mid);listOutPorts(mid);init();firstrun=false;}
checkInPorts(mid);
outputs = mid.outputs.values();
for (var output = outputs.next(); output && !output.done; output = outputs.next()) {
outportarr.push(output.value);
}
}

function listInPorts(){
console.log("***********************listInPorts()";);
var x=0; portstring="<table border='1' bgcolor=cyan width='199'>";
inputs = mid.inputs.values();
//List ports in and out
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);
portstring=portstring+"<tr><td align=right><b>"+optin.text+"<input id='inBox"+x+"' type='checkbox' onChange='midiInitiation()' checked></b></td></tr> ";
x++;
}
document.getElementById("ports";).innerHTML=portstring+"</table>";
}

function checkInPorts(mid){
var x=0;
inputs = mid.inputs.values();
for (var input = inputs.next(); input && !input.done; input = inputs.next()) {
varString="document.getElementById('inBox"+x+"').checked";
console.log("********"+varString);
var myVar = eval(varString);
if(myVar==false){ }
else if(myVar==true){ input.value.onmidimessage = onMIDIMessage; }
x++;
}
}

//LISTPORTS AFTER MIDI SUCCESS "CALLED FROM MAIN INIT"
function listOutPorts() {
PORTout = outportarr[outportindex];
Lportout = mid.outputs.values();
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);
}
}
Comment
There are no comments made yet.
Accepted Answer
Accepted Answer Pending Moderation
0
Votes
Undo
try input.value.onmidimessage = null;
or input.value.onmidimessage = function(){};

Does that help?
Comment
There are no comments made yet.
  1. more than a month ago
  2. Creating with MIDI
  3. # Permalink
Accepted Answer Pending Moderation
0
Votes
Undo
WebMidi doesn't drop ports.

Once you have MIDI access you can list the In and Out ports as often as you like. This is useful in new ports or added or old ones removed.

If you decide to relist the ports in a table (I think that is what you are doing here) then it's important to either clear the table or perform a lookup between the existing data in the table and the data that is returned and update accordingly.

I hope that helps? If not do you have a JSFiddle of the issue that can be reviewed?

Andrew
Comment
There are no comments made yet.
  1. more than a month ago
  2. Creating with MIDI
  3. # 1
Accepted Answer Pending Moderation
0
Votes
Undo
It is like this, i looked all over the web, for howto release the listener "at a port" -> input.value.onmidimessage = onMIDIMessage will create one.

But i can not find any example or howto release the listener at port.

So i thought i sidestep it by reinitiate whole requestMIDIAccess however that just create a new instance as you can hear in the example check/uncheck inports.

See URL

So i would like to know howto release listener

1. releases input.value.onmidimessage = onMIDIMessage;

OR/AND

2. release/reinitiate requestMIDIAccess (drop the object create new one)

So why? When use "hookup" external softwaresynth you need to hook it up to a loopback.
But the loopback will loop infinitly if loopback in open.

I hope that explain my troubles.

Best regards Jonas Thörnvall

"Basicly it is a chicken, egg problem i can't know what ports to listen to until i checked them"

Of course i could wait initiate the listener until user checked ports and confirmed. But courtesy to user the ports probably should be open at load.
And there must be away to remove the listener at a inport, OR?????????
References
  1. https://midisequenser.000webhostapp.com/
Comment
There are no comments made yet.
  1. more than a month ago
  2. Creating with MIDI
  3. # 2
Accepted Answer Pending Moderation
0
Votes
Undo
try input.value.onmidimessage = null;
or input.value.onmidimessage = function(){};

Does that help?



Thank you very much Andrew worked perfectly, do not know why i did not try it.
I generate the inport checkboxes dynamically, if checked i load the listener.
Now one should be able connect a software synth like Timidity or SyFonOne using a virtual midi loopback cable i use loopmidi.
If you turn off loopback in port and attach software synth to loopback out.

Thanks again Andrew! Have a good day.

function checkInPorts(){
var x=0;
inputs = mid.inputs.values();
for (var input = inputs.next(); input && !input.done; input = inputs.next()) {
input.value.onmidimessage = null;
var myVar = document.getElementById("inBox" + x).checked;
if(myVar==false){ }
else if(myVar==true){ input.value.onmidimessage = onMIDIMessage;}
x++;
}
}
References
  1. https://midisequenser.000webhostapp.com
Comment
There are no comments made yet.
  1. more than a month ago
  2. Creating with MIDI
  3. # 3
  • Page :
  • 1


There are no replies made for this post yet.
Be one of the first to reply to this post!