Web · Wiki · Activities · Blog · Lists · Chat · Meeting · Bugs · Git · Translate · Archive · People · Donate

Commit c96694fce7eebd63a7b1abe27446d677e08a5af0

Added support for sound to the memorize activity using csound.
  
1313 Thread.__init__(self)
1414 self.csound = csnd.Csound()
1515
16 def start(self):
16 def start(self):
1717 self.perf = csnd.CsoundPerformanceThread(self.csound)
1818 uniorcpath = os.path.join( os.path.dirname(__file__), 'univorc.csd')
1919 if not os.path.exists(uniorcpath):
2020 _logger.error('univorc not found %s'%uniorcpath)
2121 else:
22 self.csound.Compile(uniorcpath)
22 if self.csound.Compile(uniorcpath) == -1:
23 _logger.debug('error compiling csound orchestra %s'%uniorcpath)
24 return 1
2325 self.perf.Play()
24 _logger.debug('start csound performance %s'%uniorcpath)
25
26 return 0
27
2628 def pause(self):
2729 self.perf.Stop()
2830 self.perf.Join()
  
11<CsoundSynthesizer>
22<CsOptions>
3-+rtaudio=alsa -odac -m0 -d -b1024 -B4096
3-+rtaudio=alsa -odac -m0 -d -b2048 -B4096
44</CsOptions>
55<CsInstruments>
66sr=22050
game.py
(30 / 2)
  
2222import logging
2323import gobject
2424import time
25import gtk
2526
2627from sugar import profile
2728from dbus.service import method, signal
7272 self.messenger = None
7373 self.sentitive = True
7474 self.model = Model(os.path.dirname(__file__))
75
76 # create csound instance to play sound files
77 self.sound = 0
78 try:
79 import csnd
80 self.sound = 1
81 _logger.error(' [Check for module csnd] found.')
82 except:
83 _logger.error(' [Check for module csnd] not found. There will be no sound.')
84
85 if self.sound == 1:
86 from csound.csoundserver import CsoundServer
87 self.cs = CsoundServer()
88 gtk.gdk.threads_init()
89 if self.cs.start() != 0:
90 _logger.error(' Error starting csound performance.')
91 self.sound = 0
7592
93
7694 def load_game(self, game_name, size):
7795 if self.model.read(game_name) == 0:
7896 self.model.def_grid(size)
141141 if self.last_flipped <> -1 and id < (len(self.model.grid)/2):
142142 return
143143 self.model.data['running'] = 'True'
144
144
145 # play sound in any case if available
146 if self.sound == 1:
147 snd = self.model.grid[id].get('snd', None)
148 if snd == None:
149 _logger.debug('Audio: no sound in this game.')
150 else:
151 self.cs.perform('i 108 0.0 3.0 "%s" 1 0.9 0.5 0'%(snd))
152 _logger.debug('Audio: play sound=%s'%snd)
153
145154 # First card case
146155 if self.last_flipped == -1:
147156 self.last_flipped = id
168168 self.emit('set-border', self.last_flipped, stroke_color, fill_color)
169169 self.increase_point(self.current_player)
170170 self.model.grid[id]['state'] = '1'
171 self.emit('flip-card', id)
171 self.emit('flip-card', id)
172172 if self.model.data['divided'] == '1':
173173 self.card_highlighted(widget, -1, False)
174174 if not signal:
  
1616 <pair aimg="guitar4_2.jpg" asnd="flashcomp2b.aiff" bimg="guitar4_2.jpg" bsnd="flashcomp2b.aiff" color="100" />
1717
1818 <pair aimg="guitar5_2.jpg" asnd="gedaempft.aiff" bimg="guitar5_2.jpg" bsnd="gedaempft.aiff" color="100" />
19 <pair aimg="guitar6_2.jpg" asnd="gedaempft.aiff" bimg="guitar6_2.jpg" bsnd="gedaempft.aiff" color="100" />
20 <pair aimg="guitar7_2.jpg" asnd="ungedaempft.aiff" bimg="guitar7_2.jpg" bsnd="ungedaempft.aiff" color="100" />
19 <pair aimg="guitar6_2.jpg" asnd="ungedaempft.aiff" bimg="guitar6_2.jpg" bsnd="ungedaempft.aiff" color="100" />
20 <pair aimg="guitar7_2.jpg" asnd="git_hit1.aiff" bimg="guitar7_2.jpg" bsnd="git_hit1.aiff" color="100" />
2121 <pair aimg="guitar8_2.jpg" asnd="jimi4.aiff" bimg="guitar8_2.jpg" bsnd="jimi4.aiff" color="100" />
2222
2323</memosono>
model.py
(4 / 2)
  
221221 if self.pairs[key].props.aimg != None:
222222 elem['img'] = os.path.join(self.data['pathimg'], self.pairs[key].props.aimg)
223223 if self.pairs[key].props.asnd != None:
224 elem['snd'] = os.path.join(self.data['pathsnd'], self.pairs[key].props.asnd)
224 if os.path.isfile(os.path.join(self.data['pathsnd'], self.pairs[key].props.asnd)):
225 elem['snd'] = os.path.join(self.data['pathsnd'], self.pairs[key].props.asnd)
225226 if self.pairs[key].props.achar != None:
226227 elem['char'] = self.pairs[key].props.achar
227228 elem['charalign'] = self.pairs[key].props.acharalign
236236 if self.pairs[key].props.bimg != None:
237237 elem['img'] = os.path.join(self.data['pathimg'], self.pairs[key].props.bimg)
238238 if self.pairs[key].props.bsnd != None:
239 elem['snd'] = os.path.join(self.data['pathsnd'], self.pairs[key].props.bsnd)
239 if os.path.isfile(os.path.join(self.data['pathsnd'], self.pairs[key].props.bsnd)):
240 elem['snd'] = os.path.join(self.data['pathsnd'], self.pairs[key].props.bsnd)
240241 if self.pairs[key].props.bchar != None:
241242 elem['char'] = self.pairs[key].props.bchar
242243 elem['charalign'] = self.pairs[key].props.bcharalign