Skip to content

create

Creates a new instrument definition, instrument instance, or opcode object.

Syntax

var:InstrDef = create(code:S)
var:Instr = create(instr:InstrDef)
var:Opcode = create(opc:OpcodeDef[,overload:i])
var:Opcode[] = create(opc:OpcodeDef,len:i[,overload:i])
var:InstrDef create Scode
var:Instr create instr:InstrDef
var:Opcode create opc:OpcodeDef[,ioverload] 
var:Opcode[]  create opc:OpcodeDef,ilen[,ioverload] 

Initialization

code -- String containing Csound language code for an instrument.

instr -- compiled instrument definition.

opc -- opcode definition, supplied directly or looked up by name with opcoderef

overload -- (optional, defaults to 0) opcode overload (version) (see opcodeinfo)

len -- opcode object array length.

All forms run at initialization. The string form takes an instrument body without instr or endin, compiles it and returns an InstrDef. createinstr is another name for this form.

create(definition) allocates an Instr instance without scheduling it. Use init to initialize it, then perf to run it from the calling instrument. For an instance that Csound performs automatically, use play or schedule.

The Opcode form creates one object from the chosen overload. The array form creates a one-dimensional Opcode[] with len independent objects. Use a nonnegative integer for len. Creating an opcode object does not run its initialization or performance code. Use run, or separate init and perf calls, to execute it.

Arrange delete in the owning instrument for cleanup. The object guide explains lifetimes and gives examples of each form.

Examples

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

Examples of the create opcode.
<CsoundSynthesizer>
<CsOptions>
-o dac
</CsOptions>
<CsInstruments>
0dbfs = 1

opcode Osci(a:k,f:k):a
  xout oscili(a,f)
endop

instr One

 // run at i-time
  myInstr:InstrDef = create({{ out Osci(p4,p5) }})
  myInstance:Instr = create(myInstr)
  err1:i = init(myInstance)

  // env, gliss
  env:k = linen(0.5,0.1,p3,0.1)
  slid:k = expon(440, p3, 880)

  // set p5
  setp(myInstance, 5, slid)
  // run at perf-time, set p4
  err2:k = perf(myInstance,env)

  // run at deinit time
  delete(myInstance) 
  delete(myInstr)

  // schedule instr def
  schedule(Two,0,2,0.5,1000)

endin

instr Two
 obj:Opcode = create(oscili)
 sig:a = init(obj, p4, p5)
 sig:a = perf(obj, p4, p5)
   out(sig*adsr(0.1,0.1,0.5,0.1))
 event_i("e", 0, 3)
endin

schedule(One,0,1)

</CsInstruments>
<CsScore>
</CsScore>
</CsoundSynthesizer>

See also

Instrument definitions, instances and opcode objects, delete, init, perf

Credits

Author: Victor Lazzarini
Maynooth University
Ireland
Csound 7, 2024