Skip to content

nextrh

Yield the duration to the next beat in an array on successive calls.

Syntax

iseconds nextrh i/krhythm[], [,Sid [,idirection]
iseconds = nextrh(i/krhythm[], Sid [,idirection])

Usage

nextrh iterates and cycles through an array of rhythms (in beats), returning the duration in seconds to schedule the next event in the array. Thus an array of beat values [0.25, 0.5, 0.75, 0.5], will first return the time in seconds to reach the next 1/4 beat on the clock. Each subsequent evaluation returns a half beat (0.5), then a 3/4 beat, then a 1/2 beat again before returning to a 1/4 beat.


Outputs and arguments

iseconds -- output in seconds to the next beat value in the array.

krhythm[] -- input array of rhythms in beats.

Sid (optional, default="nrh[p1]") is a string used as a handle identifier. This can be anything but ideally is unique. nextrh uses this handle internally to keep track of which item is next to yield a result upon evaluation. Without explicitly providing the Sid, the default behaviour is to create a string based on p1 in the instrument in which it's called, however this can cause problems if multiple nextrh calls are present in the instrument definition.

idirection (optional, default=1) - Specifies the direction to iterate through the array. Can be negative and fractional.

Example

nextrh.orc

nextrh
temposet 90

instr Sound101
  ;; Audio source

  ares fmrhode p4,p5,2,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,-2,-3), "ostinato1",1)
  ;; iterate through an array of pitches

  schedule "Sound101",0,tempodur(0.3),0.5,cpstuni(ipit, gi_CurrentScale)
  ;; play the note.

  irh nextrh fillarray(0.25,0.15,1/3,1/2),"rhid1"
  schedule p1, irh, 1
  ;; re-trigger this according to irh rhythms.

  turnoff ; no need for a k-rate pass
endin

schedule "Sched11",0,1