moduleCsound.py

from os import system
from time import sleep

L = []

startSyn,stopSyn='<CsoundSynthesizer>','</CsoundSynthesizer>'
startOpt,stopOpt='<CsOptions>','</CsOptions>'
startIns,stopIns='<CsInstruments>','</CsInstruments>'
startSco,stopSco='<CsScore>','</CsScore>'

def add(*b):
    """
    Adding terms to csd file
    """
    L.extend(b)

def header(sr=44100,ksmps=10,nch=2,amp=1):
    """
    Generates 4 headers in the orchesta section
    """
    L.append('sr = %d' % sr)
    L.append('ksmps = %d' % ksmps)
    L.append('nchnls = %d' % nch)
    L.append('0dbfs = %d' % amp)

def writeRun(fname, run=True):
    """
    Write out the csd file and perform it
    """
    fname = fname[:-3]
    OutL=[Lu + '\n' for Lu in L]
    out = open('%s.csd' % fname,'w')
    out.writelines(OutL)
    out.close()
    sleep(1)
    cmd = 'csound -W -o %s.wav %s.csd' % (fname,fname)
    if run:
        status=system(cmd)
        if status!=0: raise Exception ('Could not write wav file')

def tags(k):
    """
    Enter tags.
    """
    if k == 1:
        add(startSyn,startIns)
    elif k == 2:
        add(stopIns,startSco)
    elif k == 3:
        add(stopSco,stopSyn)

No comments:

Post a Comment

ex3A05. Audio Vector