experchange > javascript

Jonas Thörnvall (08-15-18, 11:52 PM)
I tried program these functions and i thought i knew what they did, but apparently i don't. First it tries grab midi object and returns success and failure that much i get.

var output;var input;var inputs;var outputs;var mid; var onMIDIMessage; varmessage;

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

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

function success (midi) {
mid=midi;
inputs = mid.inputs.values();
console.log("Undefined value?="+inputs[0]);
// 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?
input.value.onmidimessage = onMIDIMessage;
}
}

So I thought above success function grabbed The midi object whatever that is listened to incomingmessages on the last port because "next".
So it is basicly some sort of port listener, well it seem weird to me, but who am i to judge?

And that below function listed outputs ports in portout "object array?" andinput ports in portin "object array?"

function selectPorts(){
portout = mid.outputs.values();
portin = mid.inputs.values();

for (input = portin.next(); input && !input.done; input = portin.next()) {
var deviceIn = input.value.name;
var optin = document.createElement("option");
optin.text = deviceIn;
document.getElementById("in_portsel").add(optin);
}
for (output = portout.next(); output && !output.done; output = portout.next()) {
var deviceOut = output.value.name;
//console.log(deviceOut);
var optout = document.createElement("option");
optout.text = deviceOut;
document.getElementById("out_portsel").add(optout) ;
}
}

So I thought it scrolled thru input ports and output ports added them to anoption list. And i thought that the "input" would be the last one scrolledthru and the output would be the last scrolled thru. And i could read midimessages from that input and echo them to that output.

Because so it seemed on win XP, not so much on win 7,8 and 10.

function onMIDIMessage (message) {
playbackPort(message);
}

Don't ask me how message get a value above because i am baffeled myself...

function playbackPort(message){
var noteMessage = [message.data[0], message.data[1], message.data[2]];
output.send(noteMessage);
}

So can anyone explain "what i try to do" and "what i fail todo"?
I really would like to make my rudimentary sequenser, but since i do not understand the logic of ports above i am stuck in undefined land when i try.

output.send(noteMessage) undefined...
Jonas Thörnvall (08-16-18, 12:11 AM)
Den onsdag 15 augusti 2018 kl. 23:52:35 UTC+2 skrev Jonas Thörnvall:
[..]
> So can anyone explain "what i try to do" and "what i fail todo"?
> I really would like to make my rudimentary sequenser, but since i do not understand the logic of ports above i am stuck in undefined land when i try..
> output.send(noteMessage) undefined...


The whole thing looping over the inputs seem weird to me "is there another way to make a listener on the port?", but that is how i find it done in examples.



onMIDISuccess: function(midiAccess) {
midi = midiAccess;

var inputs = midi.inputs.values();
// loop over all available inputs and listen for any MIDI input
for (var input = inputs.next(); input && !input.done; input = inputs.next()) {
// each time there is a midi message call the onMIDIMessage function
console.log("detected input: " + input.value.manufacturer + " "+ input.value.name);
input.value.onmidimessage = ChordSpeller.onMIDIMessage;
}
},
Jonas Thörnvall (08-16-18, 12:16 AM)
Den torsdag 16 augusti 2018 kl. 00:11:15 UTC+2 skrev Jonas Thörnvall:
[..]
> input.value.onmidimessage = ChordSpeller.onMIDIMessage;
> }
> },


If i just want to listen to one specified port? They are all doing this using next.
Jonas Thörnvall (08-16-18, 01:00 AM)
Den torsdag 16 augusti 2018 kl. 00:16:28 UTC+2 skrev Jonas Thörnvall:
> Den torsdag 16 augusti 2018 kl. 00:11:15 UTC+2 skrev Jonas Thörnvall:
> If i just want to listen to one specified port? They are all doing this using next.
>


One would thought that something like
input = midi.inputs.get(0);
Would get/set the port but no way Sir!
No it some lollypopping, that came up with the syntax for that.
Jonas Thörnvall (08-16-18, 01:03 AM)
Den torsdag 16 augusti 2018 kl. 01:00:28 UTC+2 skrev Jonas Thörnvall:
> Den torsdag 16 augusti 2018 kl. 00:16:28 UTC+2 skrev Jonas Thörnvall:
> One would thought that something like
> input = midi.inputs.get(0);
> Would get/set the port but no way Sir!
> No it some lollypopping, that came up with the syntax for that.


Suggestions for listening to one specified port?

//for (input = inputs.next(); input && !input.done; input = inputs.next()) {
// each time there is a midi message call the onMIDIMessage function
input = midi.inputs.get(0);
input.value.onmidimessage = onMIDIMessage;
//}
JJ (08-16-18, 01:47 AM)
On Wed, 15 Aug 2018 14:52:28 -0700 (PDT), Jonas Thörnvall wrote:
> Because so it seemed on win XP, not so much on win 7,8 and 10.


MIDI implementation on web browsers is still at an early stage, it seems.

In my Window 7 system, `requestMIDIAccess()` doesn't recognize any port at
all, under both FF Quantum and Chromium. The Windows' own Microsoft Virtual
GS Wavetable Synth doesn't get listed even if I specifically requested
Software synthesizer.

> Don't ask me how message get a value above because i am baffeled myself...


You'll need a MIDI source which is connected to the selected MIDI input
port, then play something. If the MIDI input port is a hardware port on your
sound card, you'll need a MIDI keyboard connected to that port then play
something.

> I really would like to make my rudimentary sequenser, but since i do not
> understand the logic of ports above i am stuck in undefined land when i
> try.
> output.send(noteMessage) undefined...


`send()` doesn't return anything. So, the value retrieved from that function
call will always be `undefined`.
Jonas Thörnvall (08-16-18, 06:43 AM)
Den torsdag 16 augusti 2018 kl. 01:47:30 UTC+2 skrev JJ:
[..]
> something.
> `send()` doesn't return anything. So, the value retrieved from that function
> call will always be `undefined`.


Well i have an external USB midi cable attached and i basicly want to return in back to the device, "and thru to a model".

And i have no problem doing it using win XP and Opera latest version "for XP" and the lates version of Chrome available, but when i run the "code" script on my win 10 machine it seem the output port is undefined?

output.send(noteMessage) undefined...

What do you mean it will be undefined? On my XP machine it takes the input via

for (input = inputs.next(); input && !input.done; input = inputs.next()) {
// each time there is a midi message call the onMIDIMessage function?
input.value.onmidimessage = onMIDIMessage;
}

And echo it out to the selected port with no undefined message, i have an option list where i select output port. Beside the thing that i can not reach outport "undefined", because it do listen to input port even in win 10.

I also wonder about the code loop above how can i set a specific port without loop thru with next as above?

It seem weird that the outport is undefined in win 10 but work fine in win XP, there must be some change to the API between the versions of windows orbrowser?
Jonas Thörnvall (08-16-18, 08:13 AM)
Den torsdag 16 augusti 2018 kl. 06:43:09 UTC+2 skrev Jonas Thörnvall:
[..]
> And echo it out to the selected port with no undefined message, i have anoption list where i select output port. Beside the thing that i can not reach outport "undefined", because it do listen to input port even in win 10.
> I also wonder about the code loop above how can i set a specific port without loop thru with next as above?
> It seem weird that the outport is undefined in win 10 but work fine in win XP, there must be some change to the API between the versions of windows or browser?


This is the string i use to set outport, and it do work in XP outportindex is just an integer initiated to outportindex=0, and it seem to initiate just fine using the following string.

output = mid.outputs.get(outportindex);

But when i try so send messages to it, it is undefined in windows 10?
Can you explain again why, and how i can assign the output?

So that i can use send to
output port.

output.send(noteMessage)

Because in windows XP, the above work just fine in conjunction with "see below", i really need to understand *WHY* the port is undefined in win 10

function onMIDIMessage (message) {
playbackPort(message);
}

function playbackPort(message){
var noteMessage = [message.data[0], message.data[1], message.data[2]];
output.send(noteMessage);
}
Jonas Thörnvall (08-16-18, 08:18 AM)
Den torsdag 16 augusti 2018 kl. 08:13:25 UTC+2 skrev Jonas Thörnvall:
[..]
> var noteMessage = [message.data[0], message.data[1], message.data[2]];
> output.send(noteMessage);
> }


As you can see i just try to echo the signal thru from inport to outport, but it is impossible if the outport is not defined. It do read and echo the messages from the inport via console.
Jonas Thörnvall (08-16-18, 08:23 AM)
Den torsdag 16 augusti 2018 kl. 08:18:28 UTC+2 skrev Jonas Thörnvall:
> Den torsdag 16 augusti 2018 kl. 08:13:25 UTC+2 skrev Jonas Thörnvall:
> As you can see i just try to echo the signal thru from inport to outport,but it is impossible if the outport is not defined. It do read and echo the messages from the inport via console.


I've been looking on this for a month or two on and off, and i will not solve it because i do not understand the problem, can someone explain the problem for me it seem rudimentary but is beyond my ability to grasp?
Jonas Thörnvall (08-16-18, 08:44 AM)
Den torsdag 16 augusti 2018 kl. 01:47:30 UTC+2 skrev JJ:
[..]
> something.
> `send()` doesn't return anything. So, the value retrieved from that function
> call will always be `undefined`.


Well i also noted that the GS wavetable not get listed, but it is probably because of latency issues? But of course if you want to make a midiplayer you want it listed as output port.
Jonas Thörnvall (08-16-18, 08:49 AM)
Den torsdag 16 augusti 2018 kl. 08:44:42 UTC+2 skrev Jonas Thörnvall:
> Den torsdag 16 augusti 2018 kl. 01:47:30 UTC+2 skrev JJ:
> Well i also noted that the GS wavetable not get listed, but it is probably because of latency issues? But of course if you want to make a midiplayeryou want it listed as output port.


Well if anyone would be so kind make a simple example where the input port/ports "echoed" to an output port in windows i would be overwhelmed.

As you see i am also interested of howto listen to a single port, without looping thru using next. So if your example also show that GREAT

I think it really should not be more then 20 lines of code, most of them can be copied straight off examples, but "howto echo to the output port is the challenge"
Jonas Thörnvall (08-16-18, 10:26 AM)
Den torsdag 16 augusti 2018 kl. 08:49:38 UTC+2 skrev Jonas Thörnvall:
> Den torsdag 16 augusti 2018 kl. 08:44:42 UTC+2 skrev Jonas Thörnvall:
> Well if anyone would be so kind make a simple example where the input port/ports "echoed" to an output port in windows i would be overwhelmed.
> As you see i am also interested of howto listen to a single port, withoutlooping thru using next. So if your example also show that GREAT
> I think it really should not be more then 20 lines of code, most of them can be copied straight off examples, but "howto echo to the output port is the challenge"


I would think that echo the midi inport to the outport is roughly to add/change two lines of code, to my example above.
First line assign the output port.
Second line send a message to it whenever a message event received.
input.value.onmidimessage = onMIDIMessage;
By using the onMIDIMessage function.

HINTS, HELP with the two lines needed.

But i am totally clueless howto write them in win 10, anyone?
Jonas Thörnvall (08-17-18, 10:49 AM)
Den torsdag 16 augusti 2018 kl. 10:26:35 UTC+2 skrev Jonas Thörnvall:
> Den torsdag 16 augusti 2018 kl. 08:49:38 UTC+2 skrev Jonas Thörnvall:
> I would think that echo the midi inport to the outport is roughly to add/change two lines of code, to my example above.
> First line assign the output port.
> Second line send a message to it whenever a message event received.
> input.value.onmidimessage = onMIDIMessage;
> By using the onMIDIMessage function.
> HINTS, HELP with the two lines needed.
> But i am totally clueless howto write them in win 10, anyone?


An example howto echo midiin port to midiout port please.
Flng Fck (08-17-18, 04:02 PM)
Il 17/08/2018 10:49, Jonas Thörnvall ha scritto:
> Den torsdag 16 augusti 2018 kl. 10:26:35 UTC+2 skrev Jonas Thörnvall:
>> But i am totally clueless howto write them in win 10, anyone?

> An example howto echo midiin port to midiout port please.


You want fries with that, sir?