I think the problem is that you have one interpreter engine in XSI and defining your function there, but when Csound goes to run python code using pyruni, it creates its own Python interpreter engine. When you import csnd and use the objects and methods from there, you're actually interacting with a C object. Within the C object, when it goes to run python, it has no knowledge of what host environment the C object is in. There are obvious advantages to doing so though. It might be worth investigating an API addition in a generic fashion, perhaps something like: csoundDefineInterpreter(char * engineName, void * interpreter) sets an engine for interpretation, giving a name (i.e. "python", "lisp") csoundGetInterpreter(char * engineName) retrieve an engine by name Going even further, it would be great to have a generic scripting environment call method; in the Java world, there is a standard interface coming for scripting engines to plug in for evaling statements, etc. which might be a nice model. So instead of pycall, we could have something like kout engineCall1 "engineName", "function", value Possibilities from here are then endless; one could then call into common lisp music, nyquist, ruby, etc. A drawback is that it'd also be a step towards making projects not "just run" for any other Csounder, though. steven On 4/26/06, Jonathan Mackenzie wrote: > Thanks for your swift reply, and sorry for double posting. > > You do not need to import explicitly in XSI, all objects are created prior to the script executing, and if > you dir() you get a massive list of them. > > No, I think the problem is deeper than this. Below is a minimal test program to show what I mean. > I'm defining a function 'poopfn' in the global python namespace. When I run this with standalone python > the line 'pyruni "print dir()"' prints out: > > ['__builtins__', '__doc__', '__file__', '__name__', 'csnd', 'csound', 'poopfn'] > > as expected. > > However, when I run this from within XSI in the embedded python, I get > > ['__builtins__', '__doc__', '__name__'] > > ie it is not picking up the global namespace, perhaps only creating a local one? > > > Does this give you any more ideas? > Thanks again, > Mac > > > import csnd > csound = csnd.CppSound() > csound.setPythonMessageCallback() > csound.setCommand('csound -h -m128 -d -odac -B256 -b1024 temp.orc temp.sco') > > def poopfn(x): > return 2.0*x > > csound.setOrchestra(''' > sr = 24000 > kr = 2400 > ksmps = 10 > nchnls = 1 > > pyruni "print dir()" > > instr 1 > kamp = 30000 > > kcps pycall1 "poopfn" ,1 > > a1 loscil kamp, kcps, 1, 1, 1, 0, 85530 > out a1 > endin > ''') > > # Set the Csound score. > csound.setScore(''' > ; Table #1: an audio file. > f 1 0 131072 1 "C:/Mac/Media/Audio/_SAMPLES/MUSIC/devils haircut.aif" 0 4 0 > > ; Play Instrument #1 for 3 seconds. > i 1 0 3 > > e > > ''') > # Export the Csound orchestra and score for performance. > csound.exportForPerformance() > # Perform the exported orchestra and score. > csound.perform() > > > > > >In your Python code, did you import all the XSI modules that you need? Even if Python embedded in an app that has a Python console or interpreter, you normally still need to import all modules you intend to use. Of course, I assume you have done this. > >Another thing is different styles of import. "from namespace import *" is not the same as "import namespace". In the former case, you call "function(args)" in the latter case you call "namespace.function(args)". Possibly inside SoftImage, one style is used and you are trying to call using the other style. > >However, it may additionally be the case that XSI has a dynamically built namespace. In other words, classes are defined at some point during run time, not in an import statement. If so, you need to find WHEN that happens. If you identify this and gain access to the class objects, you can dir them to see what methods are available. You can do a top-level 'dir()' to see what modules have been loaded or built. > >Also, of course, you could submit your question to SoftImage lists or forums. > > >Regards, > >Mike > > >-----Original Message----- > >>From: Jonathan Mackenzie > >>Sent: Apr 26, 2006 6:49 AM > >>To: csound-devel@lists.sourceforge.net > >>Subject: [Cs-dev] python namespace > >> > >>Hello, > >> > >>I'm trying to run csound 5 from within Softimage XSI via python. XSI > >>has an an embedded python interpreter for scripting, and I can import > >>csnd, load orchestras and perform OK from there. (This seems to me why > >>python is such a good thing!) > >> > >>My plan is to use the python opcodes pyrun and pyeval to communicate > >>with XSI objects so that I can synchronise sound synthesis with graphics > >>animation. However, the XSI python namespace is not available to the > >>python I call with the opcodes. This is true whether or not I use > >>pyinit. I have no problems getting the python opcodes to see the > >>namespace of other python code when I run a standalone python program. I > >>can only guess the problem is something to do with XSI already embedding > >>Python. Could anyone give me some pointers on how I might solve this? > >> > >>Any help much appreciated, > >>Mac > >> > >> > >------------------------------------------------------- > >Using Tomcat but need to do more? Need to support web services, security? > >Get stuff done quickly with pre-integrated technology to make your job easier > >Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > >http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > >_______________________________________________ > >Csound-devel mailing list > >Csound-devel@lists.sourceforge.net > >https://lists.sourceforge.net/lists/listinfo/csound-devel > > > > > > ------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Csound-devel mailing list > Csound-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/csound-devel > ------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642 _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net