[Csnd] running python with maintop() inside csound
Date | 2017-12-17 07:01 |
From | alexmitchellmus |
Subject | [Csnd] running python with maintop() inside csound |
I'm experimenting with using Python as a way to generate GUI's, however I am unable to get mainloop() running without blocking Csound execution? Here is my test code: |
Date | 2017-12-18 00:00 |
From | Roger Kelly |
Subject | Re: [Csnd] running python with maintop() inside csound |
I am not exactly sure what your app does, but you definitely will block the Csound thread like this. You should look at the Python 'threading" module or "process". It might help here. You would have to spin up your Mainloop in a Python process likely. On Sun, Dec 17, 2017 at 1:01 AM, alexmitchellmus <alex.w.mitchell@gmail.com> wrote: I'm experimenting with using Python as a way to generate GUI's, however I am |
Date | 2017-12-18 01:00 |
From | Michael Gogins |
Subject | Re: [Csnd] running python with maintop() inside csound |
There are examples to look at like https://github.com/csound/csound/blob/develop/examples/python/drone.py (requires python-tk and tix). Regards, Mike ----------------------------------------------------- Michael Gogins Irreducible Productions http://michaelgogins.tumblr.com Michael dot Gogins at gmail dot com On Sun, Dec 17, 2017 at 7:00 PM, Roger Kelly |
Date | 2017-12-18 01:52 |
From | alexmitchellmus |
Subject | Re: [Csnd] running python with maintop() inside csound |
Thanks for suggestions. I understand that python can call the Csound API, but wanted to see if running a python GUI from within csound was possible. -- Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here |
Date | 2017-12-18 03:45 |
From | Michael Gogins |
Subject | Re: [Csnd] running python with maintop() inside csound |
It MIGHT be possible but instead of calling the main loop you should try calling some sort of message dispatch function every kperiod. In other words Csound has become the main thread. To receive and dispatch GUI messages you will have to do what the GUI main loop usually does. I think in Tikinter it would be something like "root.update()." This should happen on some sort of Csound timer opcode, you should experiment to see what is the proper interval and if there are any other problems. Hope this helps, Mike ----------------------------------------------------- Michael Gogins Irreducible Productions http://michaelgogins.tumblr.com Michael dot Gogins at gmail dot com On Sun, Dec 17, 2017 at 8:52 PM, alexmitchellmus |
Date | 2017-12-18 03:45 |
From | Michael Gogins |
Subject | Re: [Csnd] running python with maintop() inside csound |
Probably you want to define an instrument that is "always on" to run the Tkinter dispatching. ----------------------------------------------------- Michael Gogins Irreducible Productions http://michaelgogins.tumblr.com Michael dot Gogins at gmail dot com On Sun, Dec 17, 2017 at 10:45 PM, Michael Gogins |
Date | 2017-12-18 08:29 |
From | alexmitchellmus |
Subject | Re: [Csnd] running python with maintop() inside csound |
Thanks Michael, I will give that a try. I'm not a huge user of Tkinter, (however much less 1990's OOP than WXWidgets) but was interested in seeing how this could work in Csound (as a CSD- not as a PY). -- Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here |
Date | 2017-12-18 17:05 |
From | Michael Gogins |
Subject | Re: [Csnd] running python with maintop() inside csound |
The same principle would apply in wx. Instead of calling MainLoop, set up an alwayson instrument and in it, set up a timer that repeatedly calls wx. Not tested, but something like this. In your always on instrument set up your own "event loop" by executing this Python: self.evtloop = wx.GUIEventLoop() wx.EventLoop.SetActive(self.evtloop) self.run = True Then in your Csound timer block execute this python periodically to handle GUI events: if self.run == True: while self.evtloop.Pending(): # if there is at least one event to be processed self.evtloop.Dispatch() # process one event else: # no UI events self.ticks += 1 if self.ticks >= self.idle_ticks: self.evtloop.ProcessIdle() self.ticks = 0 On Dec 18, 2017 3:29 AM, "alexmitchellmus" <alex.w.mitchell@gmail.com> wrote: Thanks Michael, |