Cabbage Logo
Back to Cabbage Site

Timer/Timeout in Sound

Hello,

I have a variable, that gets set by an incoming osc message. If there is no incoming osc message for a certain time, I want to set it to 0. Is there a more elegant solution than the following code?

instr 1
    kvar init 0
    kcount init 1000
    nxtmsg:
    kk OSClisten gihandle, "/adress", "f", kvar
    if (kk == 0) goto ex
        print 0, kvar
        kcount = 1000
        kgoto nxtmsg
    ex:
  
    kcount = count - 1
    if (kcount == 0) then
          kvar = 0
    endif

    outletk "outlet", kvar
endin

This approach seems fine to me. You could also trigger a dummy instrument with an event opcode, and then check when it’s finished using the active opcode, but all roads lead the same way. :slight_smile: