]> git.parisson.com Git - deefuzzer.git/commitdiff
add run mode, fix bad tests
authorGuillaume Pellerin <yomguy@parisson.com>
Fri, 4 Jun 2010 13:22:39 +0000 (13:22 +0000)
committerGuillaume Pellerin <yomguy@parisson.com>
Fri, 4 Jun 2010 13:22:39 +0000 (13:22 +0000)
tools/recorder.py
tools/station.py

index a1c63147ac93beaa8c0de64e3945e7c2e04f053b..2f8de3e10819d326af86ff50e7154afaade45b31 100644 (file)
@@ -50,6 +50,7 @@ class Recorder:
 
     def write(self, chunk):
         self.media.write(chunk)
+        self.media.flush()
 
     def close(self):
         self.media.close()
index 4eecc05cb815f802ea5d2a66d0470d2be3e4056a..710e1711b4473b22122d20c471c43351ce3f855f 100644 (file)
@@ -156,6 +156,10 @@ class Station(Thread):
             if self.record_mode == 1:
                 self.record_callback('/write', [1])
 
+        # Running
+        # mode = 0 means Off, mode = 1 means On
+        self.run_mode = 1
+
         # OSCing
         self.osc_control_mode = 0
         # mode = 0 means Off, mode = 1 means On
@@ -172,7 +176,13 @@ class Station(Thread):
                 self.osc_controller.add_method('/jingles', 'i', self.jingles_callback)
                 self.osc_controller.add_method('/record', 'i', self.record_callback)
                 self.osc_controller.add_method('/player', 'i', self.player_callback)
+                self.osc_controller.add_method('/run', 'i', self.run_callback)
 
+    def run_callback(self, path, value):
+        value = value[0]
+        self.run_mode = value
+        message = "Received OSC message '%s' with arguments '%d'" % (path, value)
+        self.logger.write_info(message)
 
     def media_next_callback(self, path, value):
         value = value[0]
@@ -433,13 +443,13 @@ class Station(Thread):
             self.stream = self.player.file_read_fast()
 
     def run(self):
-        while True:
+        while self.run_mode:
             self.q.get(1)
             self.next_media = 0
             self.media = self.get_next_media()
             self.counter += 1
 
-            if self.relay_mode == 1:
+            if self.relay_mode:
                 self.set_relay_mode()
             elif os.path.exists(self.media) and not os.sep+'.' in self.media:
                 if self.lp == 0:
@@ -449,7 +459,7 @@ class Station(Thread):
             self.q.task_done()
 
             self.q.get(1)
-            if (not (self.jingles_mode == 1 and (self.counter % 2) == 1) or self.relay_mode == 1) and self.twitter_mode == 1:
+            if (not (self.jingles_mode and (self.counter % 2)) or self.relay_mode) and self.twitter_mode:
                 artist_names = self.artist.split(' ')
                 artist_tags = ' #'.join(list(set(artist_names)-set(['&', '-'])))
                 message = '♫ %s %s on #%s #%s' % (self.prefix, self.song, self.short_name, artist_tags)
@@ -461,11 +471,11 @@ class Station(Thread):
 
             for self.chunk in self.stream:
                 self.q.get(1)
+                if self.next_media or not self.run_mode:
+                    break
                 try:
                     self.channel.send(self.chunk)
                     self.channel.sync()
-                    if self.next_media == 1:
-                        break
                 except:
                     self.channel.close()
                     self.logger.write_error('Station ' + self.short_name + ' : could not send the buffer to the server ')
@@ -476,7 +486,7 @@ class Station(Thread):
                         continue
                     continue
                 try:
-                    if self.record_mode == 1:
+                    if self.record_mode:
                         self.recorder.write(self.chunk)
                 except:
                     self.logger.write_error('Station ' + self.short_name + ' : could not write the buffer to the file ')