fbpx
Skip to main content

MIDI Forum

Drop requested midi...
 
Notifications
Clear all

Drop requested midiAcces, or drop attached port?

5 Posts
2 Users
0 Reactions
13.4 K Views
Jonas
Posts: 207
Reputable Member
Topic starter
 

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="

";
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+"

";
x++;
}
document.getElementById("ports").innerHTML=portstring+"

"+optin.text+"

";
}

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

 
Posted : 10/09/2019 12:20 pm
Andrew Mee
Posts: 52
Admin
 

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

 
Posted : 10/09/2019 10:46 pm
Jonas
Posts: 207
Reputable Member
Topic starter
 

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?????????

 
Posted : 11/09/2019 12:45 am
Andrew Mee
Posts: 52
Admin
 

try input.value.onmidimessage = null;
or input.value.onmidimessage = function(){};

Does that help?

 
Posted : 11/09/2019 9:51 pm
Jonas
Posts: 207
Reputable Member
Topic starter
 

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

 
Posted : 11/09/2019 11:05 pm
Share: