diff options
Diffstat (limited to 'broadcast.py')
| -rw-r--r-- | broadcast.py | 28 | 
1 files changed, 16 insertions, 12 deletions
diff --git a/broadcast.py b/broadcast.py index 2a3e352..1e52f14 100644 --- a/broadcast.py +++ b/broadcast.py @@ -11,7 +11,8 @@ from packet import Packet, CMD, itos  parser = optparse.OptionParser()  parser.add_option('-t', '--test', dest='test', action='store_true', help='Play a test tone (440, 880) on all clients in sequence (the last overlaps with the first of the next)') -parser.add_option('-T', '--sync-test', dest='sync_test', action='store_true', help='Don\'t wait for clients to play tones properly--have them all test tone at the same time') +parser.add_option('-T', '--transpose', dest='transpose', type='int', help='Transpose by a set amount of semitones (positive or negative)') +parser.add_option('--sync-test', dest='sync_test', action='store_true', help='Don\'t wait for clients to play tones properly--have them all test tone at the same time')  parser.add_option('-R', '--random', dest='random', type='float', help='Generate random notes at approximately this period')  parser.add_option('--rand-low', dest='rand_low', type='int', help='Low frequency to randomly sample')  parser.add_option('--rand-high', dest='rand_high', type='int', help='High frequency to randomly sample') @@ -28,7 +29,7 @@ parser.add_option('-r', '--route', dest='routes', action='append', help='Add a r  parser.add_option('-v', '--verbose', dest='verbose', action='store_true', help='Be verbose; dump events and actual time (can slow down performance!)')  parser.add_option('-W', '--wait-time', dest='wait_time', type='float', help='How long to wait for clients to initially respond (delays all broadcasts)')  parser.add_option('--help-routes', dest='help_routes', action='store_true', help='Show help about routing directives') -parser.set_defaults(routes=[], random=0.0, rand_low=80, rand_high=2000, live=None, factor=1.0, duration=1.0, volume=255, wait_time=0.25, play=[]) +parser.set_defaults(routes=[], random=0.0, rand_low=80, rand_high=2000, live=None, factor=1.0, duration=1.0, volume=255, wait_time=0.25, play=[], transpose=0)  options, args = parser.parse_args()  if options.help_routes: @@ -319,16 +320,19 @@ for fname in args:              if t <= 0:                  return              time.sleep(t) -        def run(self): -            nsq, cl = self._Thread__args -            for note in nsq: -                ttime = float(note.get('time')) -                pitch = int(note.get('pitch')) -                vel = int(note.get('vel')) -                dur = factor*float(note.get('dur')) -                while time.time() - BASETIME < factor*ttime: -                    self.wait_for(factor*ttime - (time.time() - BASETIME)) -                s.sendto(str(Packet(CMD.PLAY, int(dur), int((dur*1000000)%1000000), int(440.0 * 2**((pitch-69)/12.0)), vel*2)), cl) +	def run(self): +		nsq, cl = self._Thread__args +		for note in nsq: +			ttime = float(note.get('time')) +			pitch = int(note.get('pitch')) + options.transpose +			vel = int(note.get('vel')) +			dur = factor*float(note.get('dur')) +			while time.time() - BASETIME < factor*ttime: +				self.wait_for(factor*ttime - (time.time() - BASETIME)) +			s.sendto(str(Packet(CMD.PLAY, int(dur), int((dur*1000000)%1000000), int(440.0 * 2**((pitch-69)/12.0)), vel*2)), cl) +                        if options.verbose: +                            print (time.time() - BASETIME), cl, ': PLAY', pitch, dur, vel +			self.wait_for(dur - ((time.time() - BASETIME) - factor*ttime))                  if options.verbose:                      print (time.time() - BASETIME), cl, ': PLAY', pitch, dur, vel                  self.wait_for(dur - ((time.time() - BASETIME) - factor*ttime))  | 
