Skip to content

iterArr

yield values from an array on successive calls.

Syntax

iout iterArr i/kArr[],Sid [,idirection] [,ist] [,iend]
iout = iterArr(i/kArr[],Sid [,idirection] [,ist] [,iend])

Usage

iterArr yields values in sequential order from an array. Each successive evaluation increments an index to return the next value in the array. When the end of the array is reached, the index wraps around to the beginning of the array. A channel id stores the index of where iterArr is up to. The Channel name can be anything as long as it is unique.


Outputs and arguments

iout -- The output value yielded from this evaluation.

Sid -- A channel name ID. Should be unique.

idirection (optional, default=1) -- The direction of the iteration through the array. idirection can be fractional, where values will be repeated until the index increments to the next slot in the array. idirection can be negative, which will reverse the direction of the index iteration.

ist(optional, default=0) -- The index wrap point for the start of the array. When greater than zero, this effectively slices off the start of the array.

iend(optional, default=array length) -- The index wrap point for the end of the array. This effectively slices off the end of the array. iend can be negative, in which case it counts backwards from the end of the array.

Example

See the example for tempo.orc

iterArr
instr Sound101
  ;; Audio source

  ares fmrhode p4,p5,5,0.5,0.01,3,-1,-1,-1,-1,-1
  ares declickr ares

send ares
endin

patchsig "Sound101", "outs"

instr Sched11
  ;; Event trigger  - a temporal recursion instrument

  ipit = iterArr(fillarray(0,1,4,3,4,5), "ostinato1",0.27)
  ;; iterate through an array of pitches

  schedule "Sound101",0,tempodur(1.1),0.5,cpstuni(ipit, gi_CurrentScale)
  ;; trigger our audio source. Note that tempodur converts beats to durations in seconds.

  schedule p1, nextbeat(1), 1
  ;; re-trigger this recursion instrument in 1 beat.

turnoff ; no need for a k-rate pass
endin

instr Sched12
  ;; another temporal resursion instrument

  itempo tempoget
  ;; get the current tempo

  temposet wrap:i(itempo + 3, 60,510)
  ;; increment the value within a range, and update the tempo.

  ;; re-trigger in 0.5 beats time.
  schedule p1, nextbeat(0.5), 1

turnoff
endin

schedule "Sched11", 0,1 ;; launch the event trigger instrument.

schedule "Sched12", 0,1 ;; launch the tempo setting instrument.