One push button sends a sequence of values?

Error gone. Hurray! :partying_face: Thank you!


Here is my custom module (the whole custom module) that does what I showed in the video, minus the error (if somebody else is interested):

File:
Control Velocity Sequence - module 3.js (4.5 KB)
image

Code
function controlSequence(host, port, address, preArgs, sequence) {

    var i = 0
    var timer = setInterval(()=>{
        send(host, port, '/note', ...preArgs, sequence[i])
        i += 1
        if (i == sequence.length) clearInterval(timer)
    }, 50) // set here the time interval

}

module.exports = {
    
    oscOutFilter: function(data) {

        var {address, args, host, port} = data

        if (address == '/switch_2')
        {
            if (args[0].value == 1) 
            {
            controlSequence(host, port, '/note', [2, 3], [127, 0]) // select marker 1
            controlSequence(host, port, '/note', [2, 2], [0, 127]) // set locators
            return
            }
        
            
            if (args[0].value == 2) 
            {
            controlSequence(host, port, '/note', [2, 4], [127, 0]) // select marker 2
            controlSequence(host, port, '/note', [2, 2], [0, 127]) // set locators
            return
            }
           
            if (args[0].value == 3) 
            {
            controlSequence(host, port, '/note', [2, 5], [127, 0]) // select marker 3
            controlSequence(host, port, '/note', [2, 2], [0, 127]) // set locators
            return
            }

            if (args[0].value == 4) 
            {
            controlSequence(host, port, '/note', [2, 6], [127, 0]) // select marker 4
            controlSequence(host, port, '/note', [2, 2], [0, 127]) // set locators
            return
            }

            if (args[0].value == 5) 
            {
            controlSequence(host, port, '/note', [2, 7], [127, 0]) // select marker 5
            controlSequence(host, port, '/note', [2, 2], [0, 127]) // set locators
            return
            }

            if (args[0].value == 6) 
            {
            controlSequence(host, port, '/note', [2, 8], [127, 0]) // select marker 6
            controlSequence(host, port, '/note', [2, 2], [0, 127]) // set locators
            return
            }

            if (args[0].value == 7) 
            {
            controlSequence(host, port, '/note', [2, 9], [127, 0]) // select marker 7
            controlSequence(host, port, '/note', [2, 2], [0, 127]) // set locators
            return
            }

            if (args[0].value == 8) 
            {
            controlSequence(host, port, '/note', [2, 10], [127, 0]) // select marker 8
            controlSequence(host, port, '/note', [2, 2], [0, 127]) // set locators
            return
            }

            if (args[0].value == 9) 
            {
            controlSequence(host, port, '/note', [2, 11], [127, 0]) // select marker 9
            controlSequence(host, port, '/note', [2, 2], [0, 127]) // set locators
            return
            }

            if (args[0].value == 10) 
            {
            controlSequence(host, port, '/note', [2, 12], [127, 0]) // select marker 10
            controlSequence(host, port, '/note', [2, 2], [0, 127]) // set locators
            return
            }

            if (args[0].value == 11) 
            {
            controlSequence(host, port, '/note', [2, 13], [127, 0]) // select marker 11
            controlSequence(host, port, '/note', [2, 2], [0, 127]) // set locators
            return
            }

            if (args[0].value == 12) 
            {
            controlSequence(host, port, '/note', [2, 14], [127, 0]) // select marker 12
            controlSequence(host, port, '/note', [2, 2], [0, 127]) // set locators
            return
            }

            if (args[0].value == 13) 
            {
            controlSequence(host, port, '/note', [2, 15], [127, 0]) // select marker 13
            controlSequence(host, port, '/note', [2, 2], [0, 127]) // set locators
            return
            }

            if (args[0].value == 14) 
            {
            controlSequence(host, port, '/note', [2, 16], [127, 0]) // select marker 14
            controlSequence(host, port, '/note', [2, 2], [0, 127]) // set locators
            return
            }

            if (args[0].value == 15) 
            {
            controlSequence(host, port, '/note', [2, 17], [127, 0]) // select marker 15
            controlSequence(host, port, '/note', [2, 2], [0, 127]) // set locators
            return
            }

            if (args[0].value == 16) 
            {
            controlSequence(host, port, '/note', [2, 18], [127, 0]) // select marker 16
            controlSequence(host, port, '/note', [2, 2], [0, 127]) // set locators
            return
            }
        }
        return {address, args, host, port}

    }
}
2 Likes

Thanks so much for sharing! Just from a coding perspective, and as I’m always looking to learn, I wonder if @jean-emmanuel you might advise how this script could be tidied up. It seems a lot of the code is repeated with only minimal changes.

Thanks again!

I think @jean-emmanuel helped enough. I wouldn’t dare asking more. Actually, there’s one thing that would make me happier while I’m using the website. I’d like to switch the theme of the site to dark.

Look what @discobot said:

Hi! To find out what I can do, say @discobot display help.

Dark theme is now available in your preferences.

1 Like

thanks for sharing.

I learned a new javascript operator today.

You’re welcome, @Greenman. Thank you also for sharing the link to that operator you learned. Can you give us more information on how it is helping you?