Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Synth.activity/csndsugui.py
diff options
context:
space:
mode:
Diffstat (limited to 'Synth.activity/csndsugui.py')
-rwxr-xr-xSynth.activity/csndsugui.py345
1 files changed, 168 insertions, 177 deletions
diff --git a/Synth.activity/csndsugui.py b/Synth.activity/csndsugui.py
index 803152e..eb84ec0 100755
--- a/Synth.activity/csndsugui.py
+++ b/Synth.activity/csndsugui.py
@@ -38,65 +38,61 @@ import math
import locale
import os
-# Basic GUI with boxes, sliders, spins, buttons etc
-# using pygtk/sugar, from which GUI classes
-# can be derived for Csound use
-class BasicGUI:
- # basic bus channel setting method,
- # should be overriden for full-functionality
+class BasicGUI:
+ """Basic GUI with boxes, sliders, spins, buttons etc
+ using pygtk/sugar, from which GUI classes
+ can be derived for Csound use."""
+
def set_channel(self,name, val):
- print "channel:%s, value:%.1f" % (name,val)
+ """basic bus channel setting method,
+ should be overriden for full-functionality."""
+ print "channel:%s, value:%.1f" % (name,val)
- # basic filename channel setting method
- # should be overriden for full-functionality
def set_filechannel(self,chan,name):
+ """basic filename channel setting method
+ should be overriden for full-functionality."""
print "channel:%s, filename:%s" % (chan,name)
- # basic message setting method
- # should be overriden for full-functionality
+
def set_message(self, mess):
+ """basic message setting method
+ should be overriden for full-functionality."""
print mess
- # returns the slider value
- #
- # name: slider name (which should also be
- # the attached bus channel name)
def get_slider_value(self,name):
+ """returns the slider value
+ name: slider name (which should also be the attached bus channel name"""
for i in self.sliders:
if i[1] == name:
return i[2]
return 0
- # returns the button value (0 or 1)
- #
- # name: button name (which should also be
- # the attached bus channel name)
+
def get_button_value(self,name):
+ """returns the button value (0 or 1)
+ name: button name (which should also be the attached bus channel name)"""
for i in self.buttons:
if i[1] == name:
return i[2]
return 0
- # returns the slider widget instance
- #
- # name: slider name
def get_slider(self,name):
+ """returns the slider widget instance
+ name: slider name"""
for i in self.sliders:
if i[1] == name:
return i[0]
return 0
-
- # returns the button widget instance
- #
- # name: button name
+
def get_button(self,name):
+ """returns the button widget instance
+ name: button name"""
for i in self.sliders:
if i[1] == name:
return i[0]
return 0
- # internal button callback
def buttcallback(self, widget, data=None):
for i in self.buttons:
if i[0] == widget:
@@ -110,13 +106,11 @@ class BasicGUI:
i[0].modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.Color(0xFFFF,0,0, 2))
self.set_channel(i[1], i[2])
- # internal button callback
def mbuttcallback(self, widget, data=None):
for i in self.buttons:
if i[0] == widget:
self.set_message(i[2])
- # internal slider callback
def slidcallback(self,adj,widget):
for i in self.sliders:
if i[0] == widget:
@@ -131,14 +125,12 @@ class BasicGUI:
i[3].set_text("%.3f" % value)
pass
- # internal spin callback
def spincallback(self,adj,widget):
for i in self.spins:
if i[0] == widget:
i[2] = adj.value
self.set_channel(i[1],i[2])
- # internal callback
def filecallback(self,widget):
name = self.curfile[0].get_filename()
self.set_filechannel(self.curfile[1], name)
@@ -156,13 +148,13 @@ class BasicGUI:
chooser.cancel_button.connect("clicked", lambda h: chooser.destroy())
chooser.show()
- # creates a callbackbutton ()
- #
- # box: parent box
- # callback: click callback
- # title: if given, the button name
- # returns the widget instance
+
def cbbutton(self,box,callback,title=""):
+ """Creates a callbackbutton
+ box: parent box
+ callback: click callback
+ title: if given, the button name
+ returns the widget instance"""
self.cbbutts = self.cbbutts + 1
butt = gtk.Button(" %s " % title)
box.pack_start(butt, False, False, 5)
@@ -171,18 +163,18 @@ class BasicGUI:
butt.show()
return butt
- # creates a button (on/off)
- #
- # box: parent box
- # title: if given, the button name,
- # which will also be the bus channel
- # name. Otherwise a default name is
- # given, BN, where N is button number
- # in order of creation.
- # label: if given, an alternative button name,
- # which will be displayed instead of title
- # returns the widget instance
+
def button(self,box, title="",label=""):
+ """Creates a button (on/off)
+ box: parent box
+ title: if given, the button name,
+ which will also be the bus channel
+ name. Otherwise a default name is
+ given, BN, where N is button number
+ in order of creation.
+ label: if given, an alternative button name,
+ which will be displayed instead of title
+ returns the widget instance"""
self.butts = self.butts + 1
if title == "":
title = "B%d" % self.butts
@@ -197,15 +189,14 @@ class BasicGUI:
butt.show()
return butt
- # creates a mbutton (sending a message)
- #
- # box: parent box
- # title: if given, the button name, otherwise a default name is
- # given, BN, where N is button number
- # in order of creation.
- # mess: message to be sent when button is clicked
- # returns the widget instance
def mbutton(self,box,mess,title=""):
+ """Creates a mbutton (for sending a message)
+ box: parent box
+ title: if given, the button name, otherwise a default name is
+ given, BN, where N is button number
+ in order of creation.
+ mess: message to be sent when button is clicked
+ returns the widget instance"""
self.mbutts = self.mbutts + 1
if title == "":
title = "B%d" % self.mbutts
@@ -217,15 +208,14 @@ class BasicGUI:
butt.connect("clicked", self.mbuttcallback)
butt.show()
return butt
-
- # creates a box
- #
- # vert: True, creates a vertical box; horiz.
- # otherwise
- # parent: parent box, None if this is a toplevel box
- # padding: box padding
- # returns the widget instance
+
def box(self,vert=True, parent=None, padding=5):
+ """creates a box
+ vert: True, creates a vertical box; horiz.
+ otherwise
+ parent: parent box, None if this is a toplevel box
+ padding: box padding
+ returns the widget instance"""
if vert:
box = gtk.VBox()
else:
@@ -238,12 +228,12 @@ class BasicGUI:
box.show()
return box
- # creates a filechooser button
- # title: button name, also file bus channel name
- # box: parent box
- # label: if given, alternative name, for display purposes only
- # otherwise button will display its title
def filechooser(self,box,title,label=""):
+ """Creates a filechooser button
+ title: button name, also file bus channel name
+ box: parent box
+ label: if given, alternative name, for display purposes only
+ otherwise button will display its title."""
if label == "": name = title
else: name = label
butt = gtk.Button(name)
@@ -255,24 +245,23 @@ class BasicGUI:
butt.show()
return butt
- # creates a slider
- #
- # init: initial value
- # start, end: start and end of slider range
- # x, y: x and y sizes of slider
- # box: parent box
- # title: if given, the slider name,
- # which will also be the bus channel
- # name. Otherwise a default name is
- # given, SN, where N is slider number
- # in order of creation.
- # vert: vertical slider (True), else horiz.
- # linear: linear response (True), else exponential (zero or negative
- # ranges are not allowed)
- # dwid: display width in pixels
- # label: if given, the alternative slider name, for display only
- # returns the widget instance
def slider(self,init, start, end, x, y, box, title="",vert=True,linear=True,dwid=100,label=""):
+ """Creates a slider
+ init: initial value
+ start, end: start and end of slider range
+ x, y: x and y sizes of slider
+ box: parent box
+ title: if given, the slider name,
+ which will also be the bus channel
+ name. Otherwise a default name is
+ given, SN, where N is slider number
+ in order of creation.
+ vert: vertical slider (True), else horiz.
+ linear: linear response (True), else exponential (zero or negative
+ ranges are not allowed)
+ dwid: display width in pixels
+ label: if given, the alternative slider name, for display only
+ returns the widget instance"""
self.slids = self.slids + 1
if title == "":
title = "S%d" % self.slids
@@ -328,22 +317,20 @@ class BasicGUI:
self.set_channel(title, init)
return slider
-
- # creates a spin button
- #
- # init: initial value
- # start, end: start and end of slider range
- # step, page: small and large step sizes
- # box: parent box
- # accel: acceleration or 'climb rate' (0.0-1.0)
- # title: if given, the spin button name,
- # which will also be the bus channel
- # name. Otherwise a default name is
- # given, SPN, where N is spin number
- # in order of creation.
- # label: if given, the alternative name for the widget, for display only.
- # returns the widget instance
def spin(self,init, start, end, step, page, box, accel=0,title="",label=""):
+ """Creates a spin button
+ init: initial value
+ start, end: start and end of slider range
+ step, page: small and large step sizes
+ box: parent box
+ accel: acceleration or 'climb rate' (0.0-1.0)
+ title: if given, the spin button name,
+ which will also be the bus channel
+ name. Otherwise a default name is
+ given, SPN, where N is spin number
+ in order of creation.
+ label: if given, the alternative name for the widget, for display only.
+ returns the widget instance"""
self.spinbs = self.spinbs + 1
if title == "":
title = "SP%d" % self.spinbs
@@ -370,14 +357,12 @@ class BasicGUI:
self.set_channel(title, init)
return spin
-
- # creates a static text label
- #
- # name: text label
- # box: parent box, None if text is to be placed toplevel
- # colour: RGB values in a tuple (R,G,B)
- # returns the widget instance
def text(self, name, box=None,colour=(0,0,0)):
+ """Creates a static text label
+ name: text label
+ box: parent box, None if text is to be placed toplevel
+ colour: RGB values in a tuple (R,G,B)
+ returns the widget instance"""
label = gtk.Label(name)
label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.Color(colour[0],colour[1],colour[2], 0))
if box:
@@ -387,15 +372,14 @@ class BasicGUI:
label.show()
return label
- # creates a frame box
- #
- # name: text label
- # vert: vertical (True) box, else horiz.
- # parent: parent box, if None, this is a toplevel box
- # colour: RGB values in a tuple (R,G,B)
- # padding: padding space
- # returns the box widget instance
def framebox(self, name, vert=True, parent=None, colour=(0,0,0), padding=5):
+ """Creates a frame box
+ name: text label
+ vert: vertical (True) box, else horiz.
+ parent: parent box, if None, this is a toplevel box
+ colour: RGB values in a tuple (R,G,B)
+ padding: padding space
+ returns the box widget instance"""
frame = gtk.Frame(name)
frame.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(colour[0],colour[1],colour[2], 0))
frame.get_label_widget().modify_fg(gtk.STATE_NORMAL, gtk.gdk.Color(colour[0],colour[1],colour[2], 0))
@@ -412,58 +396,52 @@ class BasicGUI:
box.show()
return box
-
- # creates a vertical slider bank
- #
- # items: number of sliders
- # init: initial value
- # start, end: start and end of slider range
- # x, y: x and y sizes of slider
- # box: parent box
def vsliderbank(self,items,init, start, end, x, y, box):
+ """Creates a vertical slider bank
+ items: number of sliders
+ init: initial value
+ start, end: start and end of slider range
+ x, y: x and y sizes of slider
+ box: parent box"""
slid = self.slids
for i in range(slid, slid+items):
cbox = self.box(parent=box)
self.slider(init,start,end,x,y,cbox)
- # creates a horizontal slider bank
- #
- # items: number of sliders
- # init: initial value
- # start, end: start and end of slider range
- # x, y: x and y sizes of slider
- # box: parent box
def hsliderbank(self,items,init, start, end, x, y, box):
+ """Creates a horizontal slider bank
+ items: number of sliders
+ init: initial value
+ start, end: start and end of slider range
+ x, y: x and y sizes of slider
+ box: parent box"""
slid = self.slids
for i in range(slid, slid+items):
cbox = self.box(False,box)
self.slider(init,start,end,x,y,cbox,"",False)
-
- # creates a button bank
- #
- # items: number of sliders
- # box: parent box
def buttonbank(self,items, box):
+ """Creates a button bank
+ items: number of sliders
+ box: parent box."""
start = self.butts
for i in range(start, start+items):
self.button(box)
- # internal callback
def delete_event(self, widget, event, data=None):
return False
- # get the toolbox
def get_toolbox(self):
+ """Returns the Activity toolbox"""
return self.toolbox
- # constructor
- # act: activity object
- # colour: bg colour RGB tuple (R,G, B)
- # vert: True for vertical topmost arrangement, horiz. otherwise
- # toolbox: activity toolbox object, if None (default) a
- # standard toolbox will be supplied
def __init__(self,act,colour=(-1,-1,-1),vert=True,toolbox=None):
+ """Constructor
+ act: activity object
+ colour: bg colour RGB tuple (R,G, B)
+ vert: True for vertical topmost arrangement, horiz. otherwise
+ toolbox: activity toolbox object, if None (default) a
+ standard toolbox will be supplied"""
self.sliders = []
self.slids = 0
self.spins = []
@@ -478,7 +456,7 @@ class BasicGUI:
self.filenames = dict()
self.window = act
if toolbox == None:
- self.toolbox = activity.ActivityToolbox(self.window)
+ self.toolbox = activity.ActivityToolbox(self.window)
else: self.toolbox = toolbox
self.window.set_toolbox(self.toolbox)
self.toolbox.show()
@@ -493,18 +471,16 @@ class BasicGUI:
self.data_path = os.path.join(act.get_activity_root(),"data/")
self.outbox.show()
-# A class inheriting from BasicGUI
-# containing a Csound instance and
-# a performance thread instance
+
class CsoundGUI(BasicGUI):
-
- # overrides the base method
- # sets the bus channel value
- # called by the widget callbacks
- # channel names 'play', 'pause' and
- # 'reset' are reserved for these
- # respective uses
+ """A class inheriting from BasicGUI containing a Csound instance and a performance
+ thread instance."""
+
def set_channel(self,name,val):
+ """overrides the base method.
+ sets the bus channel value, called by the widget callbacks
+ channel names 'play', 'pause' and
+ 'reset' are reserved for these respective uses"""
if not self.ready:
if name == "play":
self.play()
@@ -516,22 +492,19 @@ class CsoundGUI(BasicGUI):
else:
BasicGUI.set_channel(self,name,val)
- # overrides the base method
- # sets the file bus channel string
def set_filechannel(self,chan,name):
+ """overrides the base method, setting the channel string"""
if not self.ready:
self.csound.SetChannel(chan,name)
else:
BasicGUI.set_filechannel(self,chan,name)
-
- # overrides the base method
- # sends a score message
def set_message(self, mess):
+ """overrides the base method, sends a score message"""
self.perf.InputMessage(mess)
- # starts a performance
def play(self):
+ """Starts a performance. """
if not self.on:
if self.paused: return
self.on = True
@@ -540,8 +513,8 @@ class CsoundGUI(BasicGUI):
self.on = False
self.perf.Pause()
- # pauses a performance
def pause(self):
+ """Pauses a performance. """
if self.on:
self.on = False
self.paused = True
@@ -551,12 +524,11 @@ class CsoundGUI(BasicGUI):
self.paused = False
self.perf.Play()
- # sets the source CSD and compiles it
- #
- # name: CSD filename
- # extra: one extra parameter
- # returns zero if successful
def csd(self, name, extra=None):
+ """Sets the source CSD and compiles it.
+ name: CSD filename
+ extra: a single extra parameter
+ returns zero if successful"""
self.extra = extra
path = activity.get_bundle_path()
if self.ready:
@@ -569,24 +541,44 @@ class CsoundGUI(BasicGUI):
self.name = name
return res
- # recompiles csound with the set CSD
- # returns zero if successful
def recompile(self):
+ """Recompiles the set CSD.
+ returns zero if successful"""
if not self.ready and self.name != "0":
self.perf.Stop()
self.perf.Join()
self.on = False
self.paused = False
self.perf = csnd.CsoundPerformanceThread(self.csound)
- if self.extra != None:
+ if self.arglist != None:
+ res = self.csound.Compile(self.arglist.argc(),self.arglist.argv())
+ elif self.extra != None:
res = self.csound.Compile("%s/%s" % (self.path,self.name), self.extra)
else:
res = self.csound.Compile("%s/%s" % (self.path,self.name))
if(res): self.ready = True
return res
+
+ def compile(self,name,args):
+ """Compiles Csound code.
+ name: CSD filename
+ args: list of arguments (as strings)
+ returns 0 if successful , non-zero if not."""
+ if self.ready:
+ self.arglist = csnd.CsoundArgVList()
+ self.path = activity.get_bundle_path()
+ self.name = name
+ self.arglist.Append("csound")
+ self.arglist.Append("%s/%s" % (self.path,self.name))
+ for i in args:
+ self.arglist.Append(i)
+ res = self.csound.Compile(self.arglist.argc(),self.arglist.argv())
+ if not res: self.ready = False
+ return res
# resets Csound ready for a new CSD
def reset(self):
+ """Resets Csound, ready for a new CSD"""
if not self.ready:
self.perf.Stop()
self.perf.Join()
@@ -594,17 +586,16 @@ class CsoundGUI(BasicGUI):
self.pause = False
self.perf = csnd.CsoundPerformanceThread(self.csound)
self.ready = True
-
- # internal callback
+
def close(self, event):
self.reset()
sys.exit(0)
- # constructor
- # act: activity object
- # colour: bg colour RGB tuple (R,G, B)
- # vert: True for vertical topmost arrangement, horiz. otherwise
def __init__(self,act,colour=(-1,-1,-1),vert=True):
+ """constructor
+ act: activity object
+ colour: bg colour RGB tuple (R,G, B)
+ vert: True for vertical topmost arrangement, horiz. otherwise."""
locale.setlocale(locale.LC_NUMERIC, 'C')
self.csound = csnd.Csound()
self.perf = csnd.CsoundPerformanceThread(self.csound)
@@ -613,4 +604,4 @@ class CsoundGUI(BasicGUI):
self.on = False
self.paused = False
self.name = "0"
-
+ self.arglist = None