parseOrc

Contents

parseOrc#

csoundengine.csoundlib.parseOrc(code, keepComments=True)[source]#

Parse orchestra code into blocks

Each block is either an instr, an opcode, a header line, a comment or an instr0 line

Return type:

list[ParsedBlock]

Example

>>> from csoundengine import csoundlib
>>> orc = r'''
... sr = 44100
... nchnls = 2
... ksmps = 32
... 0dbfs = 1
... seed 0
...
... opcode AddSynth,a,i[]i[]iooo
...  /* iFqs[], iAmps[]: arrays with frequency ratios and amplitude multipliers
...  iBasFreq: base frequency (hz)
...  iPtlIndex: partial index (first partial = index 0)
...  iFreqDev, iAmpDev: maximum frequency (cent) and amplitude (db) deviation */
...  iFqs[], iAmps[], iBasFreq, iPtlIndx, iFreqDev, iAmpDev xin
...  iFreq = iBasFreq * iFqs[iPtlIndx] * cent(rnd31:i(iFreqDev,0))
...  iAmp = iAmps[iPtlIndx] * ampdb(rnd31:i(iAmpDev,0))
...  aPartial poscil iAmp, iFreq
...  if iPtlIndx < lenarray(iFqs)-1 then
...   aPartial += AddSynth(iFqs,iAmps,iBasFreq,iPtlIndx+1,iFreqDev,iAmpDev)
...  endif
...  xout aPartial
... endop
...
... ;frequency and amplitude multipliers for 11 partials of Risset's bell
... giFqs[] fillarray  .56, .563, .92, .923, 1.19, 1.7, 2, 2.74, 3, 3.74, 4.07
... giAmps[] fillarray 1, 2/3, 1, 1.8, 8/3, 5/3, 1.46, 4/3, 4/3, 1, 4/3
...
... instr Risset_Bell
...  ibasfreq = p4
...  iamp = ampdb(p5)
...  ifqdev = p6 ;maximum freq deviation in cents
...  iampdev = p7 ;maximum amp deviation in dB
...  aRisset AddSynth giFqs, giAmps, ibasfreq, 0, ifqdev, iampdev
...  aRisset *= transeg:a(0, .01, 0, iamp/10, p3-.01, -10, 0)
...  out aRisset, aRisset
... endin
... ''')
>>> csoundlib.parseOrc(orc)
[ParsedBlock(kind='header'P, text='sr = 44100', startLine=1, endLine=1, name='sr',
             attrs={'value': '44100'}),
 ParsedBlock(kind='header', text='ksmps = 32', startLine=2, endLine=2, name='ksmps', attrs={'value': '32'}),
 ParsedBlock(kind='header', text='nchnls = 2', startLine=3, endLine=3, name='nchnls', attrs={'value': '2'}),
 ParsedBlock(kind='header', text='0dbfs = 1', startLine=4, endLine=4, name='0dbfs', attrs={'value': '1'}),
 ParsedBlock(kind='instr0', text='seed 0', startLine=6, endLine=6, name='', attrs=None),
 ParsedBlock(kind='opcode', text='opcode AddSynth,a,i[]i[]iooo\n iFqs[], iAmps[], iBasFreq, iPtlIndx, <...>',
             name='AddSynth', attrs={'outargs': 'a', 'inargs': 'i[]i[]iooo'}),
 ParsedBlock(kind='comment', text=";frequency and amplitude multipliers for 11 partials of Risset's bell",
             startLine=19, endLine=19, name='', attrs=None),
 ParsedBlock(kind='instr0', text='giFqs[] fillarray  .56, .563, .92, .923, 1.19, 1.7, 2, 2.74, 3, 3.74, 4.07', startLine=20, endLine=20, name='', attrs=None),
 ParsedBlock(kind='instr0', text='giAmps[] fillarray 1, 2/3, 1, 1.8, 8/3, 5/3, 1.46, 4/3, 4/3, 1, 4/3', startLine=21, endLine=21, name='', attrs=None),
 ParsedBlock(kind='instr', text='instr Risset_Bell\n ibasfreq = p4\n iamp = ampdb(p5)\n <...>'
             startLine=23, endLine=31, name='Risset_Bell', attrs=None)]