Skip to content
Browse files

some safeties to noisemaker to avoid starting multople copies of same…

… loop_id
  • Loading branch information...
1 parent 348c190 commit 94214c31a625b2c525fc1a735762f459c26dafe1 Eero af Heurlin committed May 10, 2012
Showing with 11 additions and 5 deletions.
  1. +3 −3 software/middleware/middleware.py
  2. +8 −2 software/noisemaker/noisemaker.py
View
6 software/middleware/middleware.py
@@ -76,7 +76,7 @@ def config_reloaded(self):
self.rod_servo_map[rodx][rody] = (servo_idx, board)
- def simulation_reset(self):
+ def simulation_reset(self, sender):
"""Simulation has been reset, reset our state too"""
# Remove all active loops
loops = self.nm('list_loops')
@@ -120,8 +120,8 @@ def cell_melted(self, x, y, z, sender):
def aliased_report_received(self, alias, state, time, sender):
"""If we seem to have missed a state change signal trigger one based on the report (better late than never...)"""
- if ( not self.self.alias_state_cache.has_key(alias)
- or self.self.alias_state_cache[alias] != state):
+ if ( not self.alias_state_cache.has_key(alias)
+ or self.alias_state_cache[alias] != state):
return self.aliased_signal_received(alias, state, sender)
return
View
10 software/noisemaker/noisemaker.py
@@ -57,14 +57,20 @@ def play_sample(self, sample_name):
def start_sequence(self, sequence_name, loop_id):
"""Will play the configured start sample of sequnce and then start looping the loop, caller must provide also the identifier that will be used for stopping the sequence"""
sequence = self.config['sequences'][sequence_name]
+ if self.active_loops.has_key(loop_id):
+ # loop already active
+ return False
self.active_loops[loop_id] = noisemaker_sequence(sequence, self, loop_id)
- self.active_loops[loop_id].start()
+ return self.active_loops[loop_id].start()
@dbus.service.method('fi.hacklab.noisemaker', in_signature='s')
def stop_sequence(self, loop_id):
"""Will stop playing the loop identified with loop_id and then play the end sample of the corresponding sequence"""
+ if not self.active_loops.has_key(loop_id):
+ # loop no longer active
+ return True
self.active_loops[loop_id].stop_at_next()
- # Note that the sequence object will handle unloading since it can finish the loop by itself as well
+ # Note that the sequence object will handle unloading from active_loops since it can finish the loop by itself as well
@dbus.service.method('fi.hacklab.noisemaker')
def list_loops(self):

0 comments on commit 94214c3

Please sign in to comment.
Something went wrong with that request. Please try again.