Csound Csound-dev Csound-tekno Search About

[Cs-dev] Python question

Date2011-02-02 02:31
From"Art Hunkins"
Subject[Cs-dev] Python question
Still having trouble with a timer in Python.

Can anyone come up with a couple of lines of Python code that will let me
know when an already-playing csd has finished, so I can call something else?

(I assume it will call the Csound Python API; and, FWIW, csndsugui is
available.)

Art Hunkins


----- Original Message ----- 
From: "Art Hunkins" 
To: 
Sent: Thursday, January 20, 2011 10:57 PM
Subject: Fw: csndsugui/python question


> Should the following Python code recognize when a .csd has finished 
> performing?
>
>  self.timer = False
>
>  if self.w.score_time():
>     self.timer = True
>  else:
>     if self.timer == True:
>       self.timer = False
>       [now .csd finished; go do something]
>
> w.score_time() is a function from csndsugui which does simply:
> return self.csound.GetScoreTime()
>
> The csound.GetScoreTime() function doesn't seem to be doing anything for 
> me. My assumption is that after csndsugui's play(self) function starts 
> playing a .csd, the above routine would start checking the score time and 
> return to zero when the score finishes. Am I mistaken?
>
> Alternately, what are other ways in which Python can know when a .csd has 
> come to a normal conclusion?
>
> Art Hunkins
>
> ----- Original Message ----- 
> From: "Art Hunkins" 
> To: 
> Sent: Thursday, January 13, 2011 5:02 PM
> Subject: csndsugui/python question
>
>
>>A question mostly for Victor - but any other help greatly appreciated:
>>
>> The following Python/csndsugui code (for a Sugar-on-a-Stick project of 
>> mine)
>> works nicely: pressing the callback button  alternates between starting 
>> and
>> stopping an ongoing .csd performance.
>>
>> For this particular project, however, the .csd - unlike previous 
>> projects - may well
>> run to completion, and I'd like to simulate a "callback-button-off press" 
>> when the .csd
>> ends. (This way the user doesn't need to press the button twice.)
>>
>> Here's the original code that works:
>>
>> def playcsd(self, widget):
>>   if self.p == False:
>>     self.p = True
>>     self.w.play()
>>     self.but.child.set_label("STOP !")
>>     self.but.child.set_use_markup(True)
>>     self.but.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0xFFFF, 0, 0))
>>     self.but.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.Color(0xFFFF, 0, 0))
>>   else:
>>     self.p = False
>>     self.w.recompile()
>>     self.w.channels_reinit()
>>     self.send_data()
>>     self.but.child.set_label("START !")
>>     self.but.child.set_use_markup(True)
>>     self.but.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0, 0x7700, 0))
>>     self.but.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.Color(0, 0x7700, 0))
>>
>>   self.p = False
>>   self.but = self.w.cbbutton(self.b7, self.playcsd, "START !")
>>   self.but.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0, 0x7700, 0))
>>   self.but.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.Color(0, 0x7700, 0))
>>
>>
>> I've added the code below to try to call playcsd (with self.p == True) 
>> when
>> the .csd concludes, but it doesn't work. (The code follows immediately 
>> after the above snippet, and is loosely adapted from Victor's PlayMIDI 
>> activity.) Obviously I'm not working with the timer (from
>> csndsugui) correctly. Can someone correct the following? Many thanks.
>>
>>   self.time = self.w.score_time()
>>   self.w.set_timer(100, self.time_callback, self)
>>   if self.w.stopcb == True:
>>     self.p == True
>>     self.playcsd(self.but)
>>
>> def time_callback(self, data):
>>   self.time = self.w.score_time()
>>   return True
>>
>> Art Hunkins
>>
> 


------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2011-04-29 22:18
FromChuckk Hubbard
SubjectRe: [Cs-dev] Python question
Hi Art.
If you use the CppSound class, with a CsoundPerformanceThread, you can
run .isPlaying() on the performance thread, and, if I recall
correctly, it returns 0 for yes and 1 for no.
I used it like this:

    def scoreloc(self):
        self.flag = 1
        try:
            while self.flag:
                if self.perf.isRunning():
                    self.flag = 0
                    try:
                        self.cbsock.sendall('ENDCB')
                    except:
                        print "............................................"
                        pass
                else:
                    time.sleep(.125)
                    loc = self.GetChannel("rattime")
                    if loc:
                        self.cbsock.sendall('%fCB' % loc)
        except:
            print "Socket problems in audio engine, line 110."
            print "............................................"
        print "scoreloc thread ending"

The purpose is to move a playback cursor while the score is running
and return to the beginning when it finishes. This is part of a class
based on csnd.CppSound, and the attribute self.perf is a
CsoundPerformanceThread.
Is that useful for you?

-Chuckk

On Wed, Feb 2, 2011 at 4:31 AM, Art Hunkins  wrote:
> Still having trouble with a timer in Python.
>
> Can anyone come up with a couple of lines of Python code that will let me
> know when an already-playing csd has finished, so I can call something else?
>
> (I assume it will call the Csound Python API; and, FWIW, csndsugui is
> available.)
>
> Art Hunkins
>
>
> ----- Original Message -----
> From: "Art Hunkins" 
> To: 
> Sent: Thursday, January 20, 2011 10:57 PM
> Subject: Fw: csndsugui/python question
>
>
>> Should the following Python code recognize when a .csd has finished
>> performing?
>>
>>  self.timer = False
>>
>>  if self.w.score_time():
>>     self.timer = True
>>  else:
>>     if self.timer == True:
>>       self.timer = False
>>       [now .csd finished; go do something]
>>
>> w.score_time() is a function from csndsugui which does simply:
>> return self.csound.GetScoreTime()
>>
>> The csound.GetScoreTime() function doesn't seem to be doing anything for
>> me. My assumption is that after csndsugui's play(self) function starts
>> playing a .csd, the above routine would start checking the score time and
>> return to zero when the score finishes. Am I mistaken?
>>
>> Alternately, what are other ways in which Python can know when a .csd has
>> come to a normal conclusion?
>>
>> Art Hunkins
>>
>> ----- Original Message -----
>> From: "Art Hunkins" 
>> To: 
>> Sent: Thursday, January 13, 2011 5:02 PM
>> Subject: csndsugui/python question
>>
>>
>>>A question mostly for Victor - but any other help greatly appreciated:
>>>
>>> The following Python/csndsugui code (for a Sugar-on-a-Stick project of
>>> mine)
>>> works nicely: pressing the callback button  alternates between starting
>>> and
>>> stopping an ongoing .csd performance.
>>>
>>> For this particular project, however, the .csd - unlike previous
>>> projects - may well
>>> run to completion, and I'd like to simulate a "callback-button-off press"
>>> when the .csd
>>> ends. (This way the user doesn't need to press the button twice.)
>>>
>>> Here's the original code that works:
>>>
>>> def playcsd(self, widget):
>>>   if self.p == False:
>>>     self.p = True
>>>     self.w.play()
>>>     self.but.child.set_label("STOP !")
>>>     self.but.child.set_use_markup(True)
>>>     self.but.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0xFFFF, 0, 0))
>>>     self.but.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.Color(0xFFFF, 0, 0))
>>>   else:
>>>     self.p = False
>>>     self.w.recompile()
>>>     self.w.channels_reinit()
>>>     self.send_data()
>>>     self.but.child.set_label("START !")
>>>     self.but.child.set_use_markup(True)
>>>     self.but.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0, 0x7700, 0))
>>>     self.but.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.Color(0, 0x7700, 0))
>>>
>>>   self.p = False
>>>   self.but = self.w.cbbutton(self.b7, self.playcsd, "START !")
>>>   self.but.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0, 0x7700, 0))
>>>   self.but.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.Color(0, 0x7700, 0))
>>>
>>>
>>> I've added the code below to try to call playcsd (with self.p == True)
>>> when
>>> the .csd concludes, but it doesn't work. (The code follows immediately
>>> after the above snippet, and is loosely adapted from Victor's PlayMIDI
>>> activity.) Obviously I'm not working with the timer (from
>>> csndsugui) correctly. Can someone correct the following? Many thanks.
>>>
>>>   self.time = self.w.score_time()
>>>   self.w.set_timer(100, self.time_callback, self)
>>>   if self.w.stopcb == True:
>>>     self.p == True
>>>     self.playcsd(self.but)
>>>
>>> def time_callback(self, data):
>>>   self.time = self.w.score_time()
>>>   return True
>>>
>>> Art Hunkins
>>>
>>
>
>
> ------------------------------------------------------------------------------
> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
> Finally, a world-class log management solution at an even better price-free!
> Download using promo code Free_Logger_4_Dev2Dev. Offer expires
> February 28th, so secure your free ArcSight Logger TODAY!
> http://p.sf.net/sfu/arcsight-sfd2d
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel
>



-- 
http://www.badmuthahubbard.com

------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/l