Instrument time gate

how could I make a time gate for a csound instrument?

e.g. I want that my instrument 1 if it receives 2 “i” in less than 1second, the second “i” is discarded.

what is this “i”? can you provide a bit of code to look at?
(because there is not only one solution, but it depends on the situation
you are in.)

For exemple:

<CsInstruments>

instr 1
print 1
endin

</CsInstruments>
<CsScore>
i 1 0 1
i 1 .25 1
i 1 .35 1
e
</CsScore>

I want to call the first instruction (i 1 0 1) and automatically discard all the others (i 1 .25 1, i 1 .35 1) of the score because they’re called within 1 seconds the first call.

I want to use this for livecoding, so this merely an idea (i’m sorry, it’s almost dumb), but I want to control too many accumulation in time of certain instrument instruction through UDP.

ok, got it.
you can set a variable which holds the previous time, and compare with it.
for instance (ksmps=64 here):

//set a variable for the last time instr 2 was playing
giPlayed init -1

instr 1
//trigger instr 2 irregularily
if rnd:k(100) < 1 then
schedulek(2,0,1)
endif
endin
schedule(1,0,100)

instr 2
//calculate time difference to last activation
iDiff = times:i() - giPlayed
//activate this instrument depending on this
if iDiff >= 1 then
//do something
outall(poscil:a(transeg:a(.2,p3,-3,0),random:i(400,800)))
//set variable to current time
giPlayed = times:i()
//print
prints(“time = .3f, note activated\n",times:i()) else //print what has been skipped prints(" time = .3f, note NOT activated\n”,times:i())
endif
endin

that’s wonderful and precise.
Thank you Joachim.

I make if iDiff >= gigatems then so that at the declaration of the variables, i put giPlayed init gigatems. In this way I can change the time and at the beginning I can start livecoding immediately if gigatems is very long!

glad to know it’s working for you.
it is also possible to use chnset/chnget, by the way. it is perhaps even
more flexible, and the channel might be used to display the value, for
instance. this is the code:

chnset(-1,“prevTime”)
instr 1
if rnd:k(100) < 1 then
schedulek(2,0,1)
endif
endin
schedule(1,0,100)
instr 2
iDiff = times:i() - chnget:i(“prevTime”)
if iDiff >= 1 then
chnset(times:i(),“prevTime”)
prints(“time = .3f, note activated\n",times:i()) else prints(" time = .3f, note NOT activated\n”,times:i())
endif
endin