Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #35484

Re: Explain explicity what function does

Newsgroups comp.lang.javascript
Date 2018-08-15 15:11 -0700
References <c33bd026-ee20-4e30-b43b-ee30be5b5fb1@googlegroups.com>
Message-ID <f7be12ea-91eb-47e7-b38d-aeea83ce3146@googlegroups.com> (permalink)
Subject Re: Explain explicity what function does
From Jonas Thörnvall <jonas.thornvall@gmail.com>

Show all headers | View raw


Den onsdag 15 augusti 2018 kl. 23:52:35 UTC+2 skrev Jonas Thörnvall:
> 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; var message;
> 
> 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?" and input 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 an option list. And i thought that the "input" would be the last one scrolled thru 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...

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.

https://gist.github.com/rudle/1007b15e84d70423fb59675182d3c4e0

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

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Explain explicity what function does Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-08-15 14:52 -0700
  Re: Explain explicity what function does Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-08-15 15:11 -0700
    Re: Explain explicity what function does Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-08-15 15:16 -0700
      Re: Explain explicity what function does Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-08-15 16:00 -0700
        Re: Explain explicity what function does Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-08-15 16:03 -0700
  Re: Explain explicity what function does JJ <jj4public@vfemail.net> - 2018-08-16 06:47 +0700
    Re: Explain explicity what function does Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-08-15 21:43 -0700
      Re: Explain explicity what function does Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-08-15 23:13 -0700
        Re: Explain explicity what function does Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-08-15 23:18 -0700
          Re: Explain explicity what function does Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-08-15 23:23 -0700
    Re: Explain explicity what function does Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-08-15 23:44 -0700
      Re: Explain explicity what function does Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-08-15 23:49 -0700
        Re: Explain explicity what function does Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-08-16 01:26 -0700
          Re: Explain explicity what function does Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-08-17 01:49 -0700
            Re: Explain explicity what function does Flng Fck <nothanks@invalid.invalid> - 2018-08-17 16:02 +0200
              Re: Explain explicity what function does Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-08-17 11:29 -0700
                Re: Explain explicity what function does Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-08-17 11:33 -0700
                Re: Explain explicity what function does Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-08-17 11:36 -0700
              Re: Explain explicity what function does Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-08-19 11:22 -0700
                Re: Explain explicity what function does "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2018-08-19 22:52 +0200
                Re: Explain explicity what function does Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-08-20 00:15 +0200
                Re: Explain explicity what function does Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-08-19 15:21 -0700
                Re: Explain explicity what function does Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-08-20 00:27 +0200
                Re: Explain explicity what function does Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-08-19 15:43 -0700
                Re: Explain explicity what function does Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-08-19 15:48 -0700

csiph-web