Skip to content

onbeat

Returns the time interval in seconds for the clock to reach the next beat n in a bar.

Syntax

iseconds onbeat [ibeatnum, ibarlen]
iseconds = onbeat([ibeatnum] [,ibarlen])

Usage

onbeat is useful to align scheduled events within the concept of a 'bar'.

Beat numbering in a bar starts at zero, thus to trigger an events in a bar of length 4, use beats '0, 1, 2, 3'. Fractional beats are permitted.

onbeat observes the global tempo.


Outputs and arguments

iseconds -- the time in seconds until the next beat in the bar.

ibeatnum (optional, default=0) -- The number of the beat in the bar, starting from zero.

ibarlen (optional, default=1) -- The length of the bar

Example

onbeat.orc

Example using onbeat
temposet 110

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

  schedule "Sound101",onbeat(0, 4),tempodur(1.1),0.5,cpstuni(ipit, gi_CurrentScale)
  schedule "Sound101",onbeat(1.75, 4),tempodur(1.1),0.5,cpstuni(ipit + 2, gi_CurrentScale)
  schedule "Sound101",onbeat(2, 4),tempodur(1.1),0.5,cpstuni(ipit + 4, gi_CurrentScale)
  schedule "Sound101",onbeat(2.5, 4),tempodur(1.1),0.5,cpstuni(ipit + 4 + 7, gi_CurrentScale)  
  schedule "Sound101",onbeat(3, 4),tempodur(1.1),0.5,cpstuni(ipit-7, gi_CurrentScale)

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

turnoff ; no need for a k-rate pass
endin

schedule "Sched11",0,1