Csndsugui: Difference between revisions

From OLPC
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
csndsugui is a toolkit for Csound-sugar activity development
csndsugui is a toolkit for Csound-sugar activity development


Writing activities using csndsugui
== Writing activities using csndsugui ==


In general, Activities are building according to the basic
1. Import the relevant modules
procedures outlined in [[Activity tutorial]].

== Basics ==

1. Import the relevant modules


import csndsugui
import csndsugui
from sugar.activity import activity
from sugar.activity import activity


2. Create an empty activity class, such as
2. Create an empty activity class such as


class MyCsoundActivity(activity.Activity):
class MyCsoundActivity(activity.Activity):
Line 15: Line 20:
activity.Activity.__init__(self, handle)
activity.Activity.__init__(self, handle)


3. Instantiate a CsoundGUI object, passing the

3. Instantiate a CsoudGUI object, passing the
activity instance as an argument:
activity instance as an argument:


Line 31: Line 35:
successful.
successful.


== Adding Widgets ==
5. Use boxes to format and contain widgets, child boxes can be

Use boxes to format and contain widgets, child boxes can be
contained within parent boxes. The top-level box does not have
contained within parent boxes. The top-level box does not have
any parents.
any parents.
Line 39: Line 45:
See the documentation on PyGTK on how boxes are used to
See the documentation on PyGTK on how boxes are used to
set the formatting. CsoundGUI will take care of all the
set the formatting. CsoundGUI will take care of all the
packing for you.
packing for you. You can then add widgets to it, ie:

6. You can then add widgets to it, ie:


win.button(box,"oscil")
win.button(box,"oscil")
win.slider(1.0,0.25,4.0,90,250,box,"pitch", linear=False)
win.slider(1.0,0.25,4.0,90,250,box,"pitch", linear=False)

== Making the connection to Csound ==
7. In your Csound code, you can retrieve the value

In your Csound code, you can retrieve the value
of each of the controls in channels of the software bus:
of each of the controls in channels of the software bus:


Line 55: Line 61:
"pitch" in the example above)
"pitch" in the example above)


8. Most widgets will work within the principle outlined
Most widgets will work within the principle outlined
above. Important exceptions are:
above. Important exceptions are:


8.1 Message button:
Message button:
mbutton(self,box,mess,title="")
mbutton(self,box,mess,title="")


Line 65: Line 71:
but f-statements are also possibilities).
but f-statements are also possibilities).


8.2 Callback button:
Callback button:
cbbutton(self,box,callback,title="")
cbbutton(self,box,callback,title="")


Line 71: Line 77:
be invoked when the button is clicked.
be invoked when the button is clicked.


8.3 Special button names: "play", "pause" and
Special button names: "play", "pause" and
"reset". These are assigned special messages that are
"reset". These are assigned special messages that are
not captured by the software bus. Instead, they
not captured by the software bus. Instead, they

Revision as of 20:05, 18 March 2008

csndsugui is a toolkit for Csound-sugar activity development

Writing activities using csndsugui

In general, Activities are building according to the basic procedures outlined in Activity tutorial.

Basics

1. Import the relevant modules

import csndsugui
from sugar.activity import activity

2. Create an empty activity class such as

class MyCsoundActivity(activity.Activity):

def __init__(self, handle):
   activity.Activity.__init__(self, handle) 

3. Instantiate a CsoundGUI object, passing the activity instance as an argument:

   win = csndsugui.CsoundGUI(self)

4. Set and compile Csound code:

    win.CSD("mycode.csd")

It is CRUCIAL that Csound compiles successfully before the widgets below are created. Otherwise they will not be assigned channels in the software bus and thus will not communicate with Csound. This method returns 0 if successful.

Adding Widgets

Use boxes to format and contain widgets, child boxes can be contained within parent boxes. The top-level box does not have any parents.

  box = win.box()

See the documentation on PyGTK on how boxes are used to set the formatting. CsoundGUI will take care of all the packing for you. You can then add widgets to it, ie:

   win.button(box,"oscil")
   win.slider(1.0,0.25,4.0,90,250,box,"pitch", linear=False) 

Making the connection to Csound

In your Csound code, you can retrieve the value of each of the controls in channels of the software bus:

   kosc  chnget "oscil"   
   kpit  chnget "pitch"

Channel names will be linked to widget labels ("oscil" and "pitch" in the example above)

Most widgets will work within the principle outlined above. Important exceptions are:

Message button:

 mbutton(self,box,mess,title="")

where mess is a RT score event or message to be sent to Csound (in most cases an i-statement, but f-statements are also possibilities).

Callback button:

 cbbutton(self,box,callback,title="")

where callback is a Python function that will be invoked when the button is clicked.

Special button names: "play", "pause" and "reset". These are assigned special messages that are not captured by the software bus. Instead, they can control Csound performance, starting, pausing and reset Csound performance (they are linked to CsoundGUI.play(), CsoundGUI.pause() and CsoundGUI.reset() methods.)

On-line help can be obtained by importing the csndsugui module and involking help(csndsugui).