[Sugar-devel] Object Chooser (selecting user-created audio objects from the Journal)
abhunkin at uncg.edu
Tue Dec 21 21:54:24 EST 2010
I'd like to thank all those who helped me get Object Chooser in the Journal
up and running in my FileMix activity. I'd also like to share my results, in
case the code could be helpful to others.
from sugar.graphics.objectchooser import ObjectChooser
from sugar import mime
self.jname1 = "0"
self.jobject1 = 0
release = open("/etc/fedora-release").read()
if release.find("OLPC release 9 ") == -1:
# Insert here code relevent to Sugar 0.84 and higher
# I use this to only display Object Chooser callback buttons only for >=
# Clicking one of the displayed buttons calls the choose1 method
def choose1(self, widget):
chooser = ObjectChooser(parent=self, what_filter=mime.GENERIC_TYPE_AUDIO)
result = chooser.run()
if result == gtk.RESPONSE_ACCEPT:
jobject = chooser.get_selected_object()
if jobject and jobject.file_path:
self.jobject1 = jobject
self.jname1 = str(jobject.get_file_path())
self.jname1 = "0"
1) I exclude Sugar 0.82 for two reasons (which means, unfortunately, "no
user soundfiles for 0.82"):
a) its version of Object Chooser does not allow filtering for the audio
b) Sugar 0.82's Csound (5.08) - or more specifically its version of
libsndfile - does not handle ogg vorbis soundfiles, the type that the Record
activity creates. Record is the most likely/accessible means that children
would use to create their own soundfiles. (The whole idea behind using
Object Chooser here is to select user files that have been placed in the
Journal [as Record does by default] for performance in FileMix.)
c) In addition, earlier versions of Record (<v64 or so) create ogg SPEEX
soundfiles; even the recent versions of Csound (actually, libsndfile) do not
handle this (lo-fi) format.
I found that a search for "OLPC release 9 " in /etc/fedora-release
identifies all current 0.82 incarnations of Sugar of which I'm aware.
2) jname1 stores the soundfile name (complete path); jobject1 stores the
object itself. This is key to being able (in Csound) to locate and load the
selected soundfile. jname1 is then a channel opened to send the named
soundfile to Csound.
3) If the user closes the Object Chooser box instead of clicking on a sound
object, the result is not accepted, and jname1 reverts to "0" - which is a
flag (in Csound) to revert to the default soundfile included in FileMix.
4) The str() cast for self.jname1 converts the filename to the usual path
format readable by Csound (this too is required).
More information about the Sugar-devel