Block outcoming OSC and MIDI messages based on a timer

Hello everybody. New O S C user here and I’m truly enjoying it. Thanks a lot!

Seems like I have an unusual kind of question here.
The thing is, currently my device has a problematic touchscreen, that sometimes goes totally crazy with ghost touches for a short amount of time. As a temporary solution, I would like to block outcoming OSC and MIDI messages based on a timer. My question is, can I limit O S C to send not more than 1 message in, say, 2 seconds? I know, this is a bit awkward, but it’s temporary, and hope this would make my problem less heavy for now.

Thanks beforehand!

Hi,
It is absolutely possible with a custom module, a user-written script that allows filtering incoming and outgoing messages. Here’s a very simple example that only let 1 message though every 2 seconds, you’ll most likely need to adjust it to fit your needs but hopefully it’ll get you started.

var lastMessageTime = 0,
    minimumTimeBetweenMessages = 2000 // in ms


module.exports = {

    oscOutFilter:function(data){
        // Filter outgoing osc messages

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

        var time = Date.now(),
            elapsedTimeSinceLastMessage = time - lastMessageTime

        if (elapsedTimeSinceLastMessage < minimumTimeBetweenMessages && lastMessageTime > 0) {

            // bypass message by returning nothing
            return

        }


        // update timestamp
        lastMessageTime = time

        // return data if you want the message to be and sent
        return {address, args, host, port}
    }

}
1 Like

I am very grateful, it worked like a charm.
Thanks a lot!