Skip to content

setp

Set the value of an instrument parameter.

Syntax

setp(ins:Instr,num:k,val:k)
setp ins:Instr,knum,kval

Performance

ins -- instrument instance

num -- positive integer p-field number, such as 4 for p4 or 5 for p5

val -- parameter value

The opcode sets the value of a parameter (pfield) defined by an instrument at performance time. If the parameter has not been defined, the opcode is a non-op. This opcode can modify the value of a parameter during an instrument performance. If the parameter is only used at i-time (e.g. p3 setting duration), then there will be no effect at performance time.

Examples

The controller changes p5 during performance. The poscil inside Tone reads p5 for its frequency on each control cycle. It uses instance-controls.csd.

Change the pitch of an existing voice
<CsoundSynthesizer>
<CsOptions>
-odac -d -m0
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 1
0dbfs = 1

instr Tone
  aTone poscil p4, p5
  out aTone
endin

instr 1
  voice:Instr = play(Tone, 0.1, 440)
  self:Instr = getinstance()
  running:b = isactive(self)
  if running then
    prints "Controller is active\n"
  endif

  kTime timeinsts
  ; Pause from half a second to one second, then resume.
  kPause = (kTime >= 0.5 && kTime < 1) ? 1 : 0
  pause(voice, kPause)

  activeNow:B = isactive(voice)
  if activeNow then
    kActive = 1
  else
    kActive = 0
  endif
  printk2 kActive

  ; The instance reads its frequency from p5 during performance.
  kFrequency line 440, p3, 660
  setp(voice, 5, kFrequency)
  kAmplitude linseg 0, 0.01, 0.1, p3 - 0.02, 0.1, 0.01, 0
  setp(voice, 4, kAmplitude)

  ; play has no duration argument. The controller owns its cleanup.
  delete(voice)
endin
</CsInstruments>
<CsScore>
i 1 0 1.5
e
</CsScore>
</CsoundSynthesizer>

See also

play, pause, Instrument definitions, instances and opcode objects