Csound Csound-dev Csound-tekno Search About

Re: [Cs-dev] python swig wrapper

Date2006-12-26 05:34
From"Michael Gogins"
SubjectRe: [Cs-dev] python swig wrapper
What I find is as follows. My favorite GUI development environment is Boa 
Constructor, a GUI builder for wxPython that generates code. The Python 
Csound API will run smoothly in a Boa Constructor GUI in a separate thread 
if, and only if, I:

1. Launch a plain Python thread...
2. That puts together the Csound score and orchestra and command line, and 
launches a csnd.CsoundPerformanceThread.

Don't ask me why this two-stage launch is required. This is what 
wxController.py does.

Plain Python threading does work, it's just not nearly as responsive as the 
CsoundPerformanceThread kind of thread. This evidently is because 
CsoundPerformanceThread launches a thread in C or C++ code after releasing 
the Python Global Interpreter Lock, which works better than launching a 
plain Python thread.

I've been told this is because a plain Python thread really isn't a thread, 
but a form of cooperative multitasking. I hope somebody else knows more 
about it than I do.

Regards,
Mike
----- Original Message ----- 
From: "Carlos Pita" 
To: "Developer discussions" 
Sent: Monday, December 25, 2006 7:16 PM
Subject: Re: [Cs-dev] python swig wrapper


> Thank you for your detailed answers Michael and Victor.
>
> I managed myself to get csound running directed by python generated
> realtime events (including channel value changes).
>
> One thing I'm still not completely sure is about threading. Can I use
> python native threading mechanisms or should I strictly use csound
> threads instead? Albeit I successfully ran both versions below, I've a
> feeling that the first one could be seen as being bad practice.
>
> Version 1
> [...]
> def performThread():
>    while True:
>        csound.PerformKsmps()
> thread = threading.Thread(None, performThread)
> thread.start()
> thread.join()
>
> Version 2
> [...]
> thread = csnd.CsoundPerformanceThread(csound)
> thread.InputMessage("i 1 0 40 660")
> thread.Play()
> thread.Join()
>
> Also, the wxController2.py example confuses me a bit, because it starts
> a new threading.Thread thread that runs a routine that itself starts a
> new CsoundPerformanceThread thread. Is this really necessary?
>
> Thank you in advance.
> Cheers,
> Carlos.
>
> On Mon, 2006-12-25 at 15:17 -0500, Michael Gogins wrote:
>> What platform are you on?
>>
>> There are actually a number of APIs involved.
>>
>> In general, the binding is not meant to be used like the C API. It is,
>> rather, meant to be used like the C++ binding for the C API, CppSound. 
>> This
>> is because SWIG is most suited to wrapping object-oriented interfaces, 
>> not
>> procedural interfaces.
>>
>> The original Python interface is CsoundVST (by me) which is high level 
>> and
>> includes extensive support for algorithmic composition. See
>> examples/lindenmayer.py.
>>
>> The csnd interface is lower level and was created later (by others as 
>> well
>> as myself) for those on platforms where CsoundVST is not supported or not
>> desired. See examples/koch.py.
>>
>> CppSound (available in both CsoundVST and csnd) includes internal Csound
>> file storage and management.
>>
>> csnd.Csound wraps Csound.hpp and is similar to CppSound but slightly 
>> lower level.
>>
>> The csound.h interface is even lower level.
>>
>> Also see the introduction to CsoundAPI.pdf.
>>
>> Also note, that thread management with the Python interface is tricky
>> because of the Python global interpreter lock. The 
>> examples/wxController.py
>> example demonstrates how to get around this with the very useful
>> csnd.CsoundPerformanceThread class by Istvan Varga.
>>
>> If you wish to help with the Python interface, please study these issues
>> first and consult with me. Or, if there are a few things you would like 
>> to
>> change, let me know and I will try to do it. I am the originator of the
>> Python interface and one of its major maintainers.
>>
>> Hope this helps,
>> Mike
>>
>> ----- Original Message ----- 
>> From: "Carlos Pita" 
>> To: "Developer discussions" 
>> Sent: Monday, December 25, 2006 2:50 PM
>> Subject: Re: [Cs-dev] python swig wrapper
>>
>>
>> > Oh, shame on me, I've just found out class CsoundArgVList in
>> > cs_glue.hpp. But still, is there any basic example of python binding
>> > usage? In general, should I use CppSound api or plain csound.h? A 
>> > simple
>> > example showing expected practices would be very valuable to get
>> > started.
>> > Thank you in advance.
>> > Cheers,
>> > Carlos
>> >
>> >
>> >> Hi all,
>> >> I've been toying a bit with csound 5 python interface. The binding 
>> >> feels
>> >> quite low level, with all those char** and int* directly exposed to
>> >> python. Perhaps I'm facing it the wrong way but as I haven't found any
>> >> example I just assumed that the binding is meant to be used just like
>> >> the C host api. Anyway as neither cpointer.i nor carrays.i are 
>> >> included
>> >> in the swig interface definition I see no way to create those char**
>> >> that signatures like that of csoundInitialize expect. I'm pretty
>> >> comfortable with swig, I've written a number of advanced bindings, so 
>> >> I
>> >> think I could help improving the python binding if this is desired. 
>> >> What
>> >> do you say?
>> >> Cheers,
>> >> Carlos
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> __________________________________________________
>> >> Pregunt. Respond. Descubr.
>> >> Todo lo que queras saber, y lo que ni imaginabas,
>> >> est en Yahoo! Respuestas (Beta).
>> >> Probalo ya!
>> >> http://www.yahoo.com.ar/respuestas
>> >>
>> >>
>> >>
>> >> -------------------------------------------------------------------------
>> >> 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
>> >> https://lists.sourceforge.net/lists/listinfo/csound-devel
>> >
>> >
>> >
>> >
>> >
>> >
>> > __________________________________________________
>> > Preguntá. Respondé. Descubrí.
>> > Todo lo que querías saber, y lo que ni imaginabas,
>> > está en Yahoo! Respuestas (Beta).
>> > ¡Probalo ya!
>> > http://www.yahoo.com.ar/respuestas
>> >
>> >
>> >
>> >
>>
>>
>> --------------------------------------------------------------------------------
>>
>>
>> > -------------------------------------------------------------------------
>> > 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
>> > https://lists.sourceforge.net/lists/listinfo/csound-devel
>> >
>>
>>
>>
>>
>> -------------------------------------------------------------------------
>> 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
>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>
>
>
>
>
>
> __________________________________________________
> Pregunt. Respond. Descubr.
> Todo lo que queras saber, y lo que ni imaginabas,
> est en Yahoo! Respuestas (Beta).
> Probalo ya!
> http://www.yahoo.com.ar/respuestas
>
>
>
>


--------------------------------------------------------------------------------


> -------------------------------------------------------------------------
> 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
> https://lists.sourceforge.net/lists/listinfo/csound-devel
> 


-------------------------------------------------------------------------
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
https://lists.sourceforge.net/lists/listinfo/csound-deve