Csound Csound-dev Csound-tekno Search About

[Cs-dev] Python Callbacks

Date2007-01-31 15:42
FromVictor Lazzarini
Subject[Cs-dev] Python Callbacks
Following up a recent discussion on the other list, I have added
a mechanism for using callbacks in Python (as well as C++)
to the CsoundPerformanceThread class.

Here's a trivial example (I have added this to the sources as well):

import csnd
import time

# create & compile instance
cs = csnd.Csound()
cs.Compile("cb.csd")

# define callback
def callback(csound):
     a = csound.GetChannel("freq")
     if(a < 1000): a = a+0.1
     else: a = 100.0
     csound.SetChannel("freq", a)

# set an initial value for freq
cs.SetChannel("freq", 100)

# create the thread object
perf = csnd.CsoundPerformanceThread(cs)

# set the callback
perf.SetProcessCallback(callback, cs)

# play
perf.Play()

# wait for 30 secs
time.sleep(30)

###############
Here's the CSD (cb.csd):



-odac -d




; bus channel
gkfreq chnexport "freq", 3

instr 1
   a1 oscil 10000, gkfreq, 1
   out a1
endin





f1 0 16384 10 1
; run for 30 secs
i1 0 30







NB: The callback is called *before* csoundPerformKsmps() by the
processing loop.



Victor Lazzarini
Music Technology Laboratory
Music Department
National University of Ireland, Maynooth 


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2007-01-31 22:27
From"Oeyvind Brandtsegg"
SubjectRe: [Cs-dev] Python Callbacks
AttachmentsNone