Skip to content

loopcode

Generate repeated evaluations of arbitrary Csound code.

Syntax

loopcode i/klooptimes[], Sid, Scode [, istatus]
loopcode i, Sid, Scode [, istatus]
loopcode(i/klooptimes[], Sid, Scode, istatus)
loopcode(i, Sid, Scode [, istatus])

Usage

Many of the examples in this guide have been using a technique known as temporal recursion. In Csound this is done with an instrument that schedules it's own instance to run after some time delay. The recursive instrument holds all the algorithms and logic flow to generate events in a (hopefully) interesting pattern. livecode is a convenient temporal recursion wrapper. It executes any Csound code specified in a multi-line string, and uses an array of time values to specify the times between executions. One restriction to note with loopcode is that he Csound code in the string needs to run at i-time.


Arguments

i/klooptimes[] -- Relative onset beat intervals between events. The selected value for the next event iterates sequentially through this array. Negative values signify a rest, and an event will not be generated at the specified time.

Sid -- A String used as a unique identifier handle. Any string can be used as long as it is unique.

Scode -- Your Csound code. Must run at i-time.

  • iLOOPDUR is a reserved variable available in Scode: iLOOPDUR holds the current looptime assigned. This is useful for tying event durations in Scode to the loop duration.

istatus (optional, default=1) -- An on/off switch. If istatus=0, the loop stops. If istatus=1, the loop starts.

Example

loopcode.orc

loopcode
instr Sound101
  ;; Sound source
  ares vco2 p4,p5
  kfr transeg 8000, 0.2, -5, p5*4, p3-0.4, 2, p5  
  ares moogladder2 ares,kfr,0.4

send ares
endin

patchsig "Sound101", "outs"

loopcode fillarray(3,6), "loopid1",{{

  ipitch = iterArr(fillarray(0,-2),"pitches")
  arpi fillarray_i(n("Sound101"),0,cosr(12)+0.1,0.5,ipitch), fillarray_i(-2,0,2,4,6,8), fillarray_i(1/8),iLOOPDUR-0.01,0,-0.8,0.4
  ;; a mix of chords and a gentle accelerando on a sequence. 

  loopevent fillarray_i(n("Sound101")+0.1,0,0.5,0.5,ipitch - 14), fillarray_i(0), fillarray_i(0.75, 0.25),0
  ;; steady bass

}},1
;; loopcode starts the show upon evaluation.