Csound Csound-dev Csound-tekno Search About

[Csnd] Re: Re: Re: Re: More csndsugui

Date2009-04-04 00:19
From"Art Hunkins"
Subject[Csnd] Re: Re: Re: Re: More csndsugui
Victor,

OK - classes.

I feel I'm getting there. The widgets are now displaying correctly 
on-screen.

However, the files won't play (they compile fine). Seems like a problem with 
the playcsd function (specifically, self.w.play(). Is it OK for both 
version1 and version2 to call playcsd?) Python indicates it can't deal with 
audio at the beginning of the performance (and it aborts with a segmentation 
violation).

My most recent attempt follows (please comment):


import csndsugui
from sugar.activity import activity

class Waves(activity.Activity):

 def __init__(self, handle):

   activity.Activity.__init__(self, handle)

   win = csndsugui.CsoundGUI(self)

   box = win.box(True)
   win.text("Click on a version:", box)
   win.cbbutton(box, self.version1, "CSD 1 ?")
   win.cbbutton(box, self.version2, "CSD 2 ?")
   self.b = box
   self.w = win

 def version1(self, widget):
    self.w.csd("CSD1.csd")
    self.w.button(self.b, "pan1", "Pan Control CSD 1?")
    self.but1 = self.w.cbbutton(self.b, self.playcsd, "PLAY!")

 def version2(self, widget):
    self.w.csd("CSD2.csd")
    self.w.button(self.b, "pan2", "Pan Control CSD 2?")
    self.but2 = self.w.cbbutton(self.b, self.playcsd, "PLAY!")

 def playcsd(self, widget):
    self.w.play()


TIA -

Art Hunkins

----- Original Message ----- 
From: "victor" 
To: 
Sent: Friday, April 03, 2009 3:31 AM
Subject: [Csnd] Re: Re: Re: More csndsugui


> You need to add 'self' to the argument list of the class
> methods 'version1' and 'version2'. You will also need
> to create the members of the class as 'self.*' : self.win, etc
> and refer to them like that.
>
> Read about classes in the Python reference manual. It's well
> explained there.
>
> Victor
> ----- Original Message ----- 
> From: "Art Hunkins" 
> To: 
> Sent: Friday, April 03, 2009 12:27 AM
> Subject: [Csnd] Re: Re: More csndsugui
>
>
>> Victor -
>>
>> OK, callback it is.
>>
>> Could you please critique the following revised code? Things start going 
>> wrong (according to the log) with my "global name: version1".
>>
>> import csndsugui
>> from sugar.activity import activity
>>
>> class Waves(activity.Activity):
>>
>> def __init__(self, handle):
>>
>>   activity.Activity.__init__(self, handle)
>>
>>   win = csndsugui.CsoundGUI(self)
>>
>>   box = win.box(True)
>>   win.text("Click on a version:", box)
>>   but1 = win.cbbutton(box, version1, "CSD 1 ?")
>>   but2 = win.cbbutton(box, version2, "CSD 2 ?")
>>
>> def version1(but1):
>>    win.csd("CSD1.csd")
>>    win.button(box, "pan1", "Pan Control CSD 1?")
>>    win.cbbutton(box, playcsd, "PLAY!")
>>
>> def version2(but2):
>>    win.csd("CSD2.csd")
>>    win.button("pan2", "Pan Control CSD 2?")
>>    win.cbbutton(box, playcsd, "PLAY!")
>>
>> def playcsd():
>>    win.play()
>>
>> Thanks again -
>>
>> Art Hunkins
>>
>> ----- Original Message ----- 
>> From: "victor" 
>> To: 
>> Sent: Thursday, April 02, 2009 5:22 PM
>> Subject: [Csnd] Re: More csndsugui
>>
>>
>>>I think you probably want a different method: callback button. See
>>> the midi example at
>>> http://git.sugarlabs.org/projects/csndsugui/repos/mainline/blobs/master/Playmidi.activity/playmidi.py
>>>
>>> this line creates a callback button, which is used to load a CSD with
>>> a particular midifile and create some play buttons etc.:
>>>
>>> self.but = win.cbbutton(bbox, self.fcall, "load")
>>>
>>> Victor
>>>
>>> ----- Original Message ----- 
>>> From: "Art Hunkins" 
>>> To: 
>>> Sent: Thursday, April 02, 2009 10:08 PM
>>> Subject: [Csnd] More csndsugui
>>>
>>>
>>>> I'd appreciate help with the following code from anyone familiar with 
>>>> csndsugui and Python.
>>>>
>>>> This (vastl,y simplified) code does not work for me in Sugar (OLPC):
>>>>
>>>>
>>>> import csndsugui
>>>> from sugar.activity import activity
>>>>
>>>> class Waves(activity.Activity):
>>>>
>>>> def __init__(self, handle):
>>>>
>>>>   activity.Activity.__init__(self, handle)
>>>>
>>>>   win = csndsugui.CsoundGUI(self)
>>>>
>>>>   box = win.box(True)
>>>>   win.text("Click on a version:", box)
>>>>   win.button(box, "button1", "CSD 1 ?")
>>>>   win.button(box, "button2", "CSD 2 ?")
>>>>   v1 = win.get_button_value("button1")
>>>>   v2 = win.get_button_value("button2")
>>>>   if v1:
>>>>    win.csd("CSD1.csd")
>>>>    win.button(box, "pan1", "Pan Control CSD 1?")
>>>>    win.button(box, "play1", "PLAY!")
>>>>    v1play = win.get_button_value("play1")
>>>>    if v1play: win.play()
>>>>   elif v2:
>>>>    win.csd("CSD2.csd")
>>>>    win.button("pan2", "Pan Control CSD 2?")
>>>>    win.button("play2", "PLAY!")
>>>>    v2play = win.get_button_value("play2")
>>>>    if v2play: win.play()
>>>>
>>>> The problem is with my GUI code (above); I'm relatively sure of what 
>>>> I'm doing with my .csd's, including their chnexport statements. I 
>>>> suspect the problems are with the v1 and v2 variables, as well as 
>>>> v1play and v2play above.
>>>>
>>>> The idea of the code is this: "button1" and "button2" wait for the user 
>>>> to press one - which selects the .csd to be performed. I'm completely 
>>>> unaware of how this API button_value may behave when a .csd is not yet 
>>>> compiled (as it is as yet unchosen).
>>>>
>>>> The play1 and play2 buttons also don't perform. The two pan controls 
>>>> are i-time variables and must be selected before play commences. Hence, 
>>>> play1/2 also must sit there, waiting. Neither button currently 
>>>> initiates play (even in a completely different version of this code 
>>>> which does not have a "button1" and "button2").
>>>>
>>>> Of course, what I'm trying to do may be impossible. As things stand, I 
>>>> do need two sets of GUI buttons that wait patiently for user presses 
>>>> before going on, and this is what I don't know how to do. FWIW, I've 
>>>> tried many variants of the above - including testing direct returns 
>>>> from the buttons, and designating v1/v2, for example, as win.v1 (or 
>>>> win.v2).
>>>>
>>>> TIA for a rescue (OLPCsound, not economic) -
>>>>
>>>> Art Hunkins
>>>>
>>>>
>>>>
>>>> Send bugs reports to this list.
>>>> To unsubscribe, send email sympa@lists.bath.ac.uk with body 
>>>> "unsubscribe csound"
>>>
>>>
>>>
>>> Send bugs reports to this list.
>>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe 
>>> csound"
>>
>>
>>
>> Send bugs reports to this list.
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe 
>> csound"
>
>
>
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe 
> csound"