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

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

len -- opcode object array length.

The first version takes Csound code on a string, compiles it, and returns an instrument definition. The second takes an instrument definition and instantiates it, returning the instrument instance. The third creates an opcode object from one of the predefined opcode overloads. The final version creates an array of opcode objects of the same OpcodeDef type and overload.

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>

Credits

Author: Victor Lazzarini
Maynooth University
Ireland
Csound 7, 2024