Skip to content

cntcreate

Create a counter object.

📝 Note

Up to Csound 6, this opcode was called cntCreate.

Plugin opcode in counter.

Syntax

icnt = cntcreate([imax, imin, inc])
icnt cntCreate [imax, imin, inc]

Initialization

imax -- optional maximum value for the counter, defaulting to 1.

imin -- optional minimun value for the counter, defaulting to 0.

inc -- optional increment for the counter, defaulting to 1.

icnt -- a handle for the counter.

Performance

Creates a counter object which loops between imin and imax in steps of inc. Used without an argument, using the defaults creates a flip-flop.

Examples

Here is an example of the cndcreate opcode. It uses the file counter-modern.csd.

Example of the cntcreate opcode.
<CsoundSynthesizer>
<CsOptions>
-odac -Mhw:1,0,0
</CsOptions>

<CsInstruments>

cnt@global:i = cntcreate(1)     ; a toggle
cntNote@global:i = cntcreate(1) ; ignore note-off message to turn MIDI notes into toggles

instr 1
  key:k = sensekey()
  note:i = notnum()

  if key == 97 then
    k1 = count(cnt)
    if k1 == 0 then
      event("i", 2, 0, -1)
    else
      event("d", 2, 0, -1)
    endif
  endif

  print(note)
  if note == 60 then
    i2 = count_i(cntNote)
    print(i2)
    if i2 == 0 then
      eventi("i", 3, 0, -1)
    else
      eventi("d", 3, 0, -1)
    endif
  endif
endin

instr 2
  out(poscil(10000, 440))
endin

instr 3
  out(poscil(5000, 880))
endin

</CsInstruments>

<CsScore>
i1 0 z
e
</CsScore>

</CsoundSynthesizer>

A musical example featuring the cntcreate opcode: NervousHappyBirthday_Cucchi-modern.csd by Stefano Cucchi.

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

Example of the cntCreate opcode.
<CsoundSynthesizer>
<CsOptions>
-odac -Mhw:1,0,0
</CsOptions>

<CsInstruments>
 gicnt cntCreate 1     ; a toggle
 gicntNote cntCreate 1 ; ignore note-off message to turn MIDI notes into toggles


instr 1

kkey sensekey

inote notnum

if (kkey == 97) then
 k1 count gicnt
 if k1==0 then
  event "i", 2, 0, -1
 else
  event "d", 2, 0, -1
 endif
endif

print  inote
if (inote == 60) then
 i2 count_i gicntNote
 print i2
 if i2==0 then
  event_i "i", 3, 0, -1
 else
  event_i "d", 3, 0, -1
 endif
endif
endin

instr 2
asig oscil 10000, 440
out asig
endin

instr 3
asig oscil 5000, 880
out asig
endin

</CsInstruments>


<CsScore>
i1 0 z
e

</CsScore>

</CsoundSynthesizer>

A musical example featuring the cntCreate opcode: NervousHappyBirthday_Cucchi.csd by Stefano Cucchi.

See also

Program Flow Control: Counter

Credits

By: John ffitch June 2020

New in version 6.15