assurance-tunnel
assurance-tunnel
assurance-tunnel
assurance-tunnel

Javascript comparing values inside array


  • Beta Gold

    Hi there,

    I did a value sampler with JS so I can "record" my live operations I do with my midi controller and play it back automatically afterward.

    It's working nice, but as I have different instances of it connected to different faders, I would like to test what's inside the array and if all the values are the same (which mean I didn't record this fader but another one) don't return the recorded values but the "live" input. Unfortunately this does not work yet and so when i'm playing back some recorded values, all my faders are muted, instead of just the one doing the playback...

    If someone as some clue I would be glad, cause i've turned around my code for some time and can't figure out why it's not working...

    (For comprehension purpose, the "time" input is counter with pulse generator)

    Thanks! :)

    Here is my code:

    var rec = new Array();
    function main()
    {
    var bypass = arguments[0];
    var value = arguments[1];
    var time = arguments[2];
    if(bypass==1){
    rec[time] = value;
    return [value,time];
    }
    // test for playback starts here
    else if(bypass==2){
    for(var i=1; i<rec.length; i++){
    if(rec[0]!= rec[i]){
    return [rec[time],time, rec[0],100]
    }else{
        return [value,time,]
        }
      }
    }
    //end of test for playback
    else if(bypass==0){
    return[value,0]
      }else{}
    }

  • Tech Staff

    Take a look at the 'every()' method.

    https://www.w3schools.com/jsre...

    You can do something like:

    else if(bypass==2 && rec.every(checkNotEmpty)){

  • Beta Gold

    @DusX That worked! thanks a lot!