Orchestra Syntax
Prev | Python Opcodes | Next

#### Orchestra Syntax

Blocks of Python code, and indeed entire scripts, can be embedded in Csound orchestras using the {{ and }} directives to enclose the script, as follows:

    sr=44100
    kr=4410
    ksmps=10
    nchnls=1
    pyinit

    giSinusoid	ftgen	0,	0, 8192, 10,	1

    pyruni {{
    import random

    pool = [(1 + i/10.0) ** 1.2 for i in range(100)]

    def get_number_from_pool(n, p):
        if random.random() < p:
            i = int(random.random() * len(pool))
            pool[i] = n
        return random.choice(pool)
    }}

    instr 1
    	k1	oscil	1, 3, giSinusoid
    	k2	pycall1	"get_number_from_pool", k1 + 2, p4
    		printk	0.01, k2
    endin

##### Credits

Copyright (c) 2002 by Maurizio Umberto Puxeddu. All rights reserved.

Portions copyright (c) 2004 and 2005 by Michael Gogins.

Prev | Up | Next
Python Opcodes | Home | Faust Opcodes