Skip to content

loopgt

Construction of looping operations.

📝 Note

Up to Csound 6, this opcode was called loop_gt.

Syntax

loopgt(indx, idecr, imin, label)
loopgt(kndx, kdecr, kmin, label)
loop_gt indx, idecr, imin, label
loop_gt kndx, kdecr, kmin, label

Initialization

indx -- i-rate variable to count loop.

idecr -- value to decrement the loop.

imin -- minimum value of loop index.

Performance

kndx -- k-rate variable to count loop.

kdecr -- value to decrement the loop.

kmin -- minimum value of loop index.

The actions of loopgt are equivalent to the code

indx  =  indx - idecr
if (indx > imin) igoto label

or

kndx  =  kndx - kdecr
if (kndx > kmin) kgoto label

📝 Note

Adviced is to use the 'modern' while or until opcodes for looping constructions.

Examples

Here is an example of the loopgt opcode. It uses the file loopgt.csd.

Example of the loopgt opcode.
<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac     ;;;realtime audio out
;-iadc    ;;;uncomment -iadc if RT audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o loop_gt.wav -W ;;; for file output any platform

; By Stefano Cucchi - 2021

</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

saw@global:i = ftgen(3, 0, 16384, 10, 0, 0.2, 0, 0.4, 0, 0.6, 0, 0.8, 0, 1, \
                     0, 0.8, 0, 0.6, 0, 0.4, 0, 0.2)

instr 1 ;master instrument
  ndxFreq:i = p5
loop:
  freq:i = p4 + ndxFreq
  print(freq)
  amp:i = 0.5/((p5-p7)/p6)
  eventi("i", 10, 0, p3, amp, freq)
  loopgt(ndxFreq, p6, p7, loop)
endin

instr 10
  sig:a = oscili(p4, p5, saw)
  sig = butterhp(sig, 50)
  declick:k =linseg(0, 0.1, 1, p3-0.2, 1, 0.1, 0)
  out(sig * declick, sig * declick)
endin

</CsInstruments>
<CsScore>

i1 0 2 200 10 3 1
i1 2 2 200 4 0.3 1
i1 4 2 200 55 7 1
i1 6 2 200 3 0.2 1

e
</CsScore>
</CsoundSynthesizer>

Here is an example of the loop_gt opcode. It uses the file loop_gt.csd.

Example of the loop_gt opcode.
<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac     ;;;realtime audio out
;-iadc    ;;;uncomment -iadc if RT audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o loop_gt.wav -W ;;; for file output any platform

; By Stefano Cucchi - 2021

</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

gisaw  ftgen 3, 0, 16384, 10, 0, .2, 0, .4, 0, .6, 0, .8, 0, 1, 0, .8, 0, .6, 0, .4, 0,.2 

instr 1 ;master instrument

indxFreq = p5

loop:

ifreq = p4 + indxFreq
print ifreq
iamp = 0.5/((p5-p7)/p6)
event_i "i", 10, 0, p3, iamp, ifreq
loop_gt indxFreq, p6, p7, loop

endin


instr 10

asig  oscili p4, p5, gisaw
asig butterhp asig, 50
kdeclick linseg 0, 0.1, 1, p3-0.2, 1, 0.1, 0
outs asig * kdeclick, asig * kdeclick

endin

</CsInstruments>
<CsScore>


i1 0 2 200 10 3 1

i1 2 2 200 4 0.3 1

i1 4 2 200 55 7 1

i1 6 2 200 3 0.2 1

e
</CsScore>
</CsoundSynthesizer>

See also

Program Flow Control: Looping Constructions

More information on this opcode: http://www.csoundjournal.com/2006summer/controlFlow_part2.html written by Steven Yi, and in the Floss Manuals: https://flossmanual.csound.com/csound-language/control-structures

Credits

Istvan Varga.

New in Csound version 5.01