broadcast.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. import socket
  2. import sys
  3. import struct
  4. import time
  5. import xml.etree.ElementTree as ET
  6. import threading
  7. import thread
  8. import optparse
  9. import random
  10. import itertools
  11. from packet import Packet, CMD, itos
  12. parser = optparse.OptionParser()
  13. 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)')
  14. parser.add_option('--test-delay', dest='test_delay', type='float', help='Time for which to play a test tone')
  15. parser.add_option('-T', '--transpose', dest='transpose', type='int', help='Transpose by a set amount of semitones (positive or negative)')
  16. 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')
  17. parser.add_option('-R', '--random', dest='random', type='float', help='Generate random notes at approximately this period')
  18. parser.add_option('--rand-low', dest='rand_low', type='int', help='Low frequency to randomly sample')
  19. parser.add_option('--rand-high', dest='rand_high', type='int', help='High frequency to randomly sample')
  20. parser.add_option('-l', '--live', dest='live', help='Enter live mode (play from a controller in real time), specifying the port to connect to as "client,port"; use just "," to manually subscribe later')
  21. parser.add_option('-L', '--list-live', dest='list_live', action='store_true', help='List all the clients and ports that can be connected to for live performance')
  22. parser.add_option('--no-sustain', dest='no_sustain', action='store_true', help='Don\'t use sustain hacks in live mode')
  23. parser.add_option('-q', '--quit', dest='quit', action='store_true', help='Instruct all clients to quit')
  24. parser.add_option('-p', '--play', dest='play', action='append', help='Play a single tone or chord (specified multiple times) on all listening clients (either "midi pitch" or "@frequency")')
  25. parser.add_option('-P', '--play-async', dest='play_async', action='store_true', help='Don\'t wait for the tone to finish using the local clock')
  26. parser.add_option('-D', '--duration', dest='duration', type='float', help='How long to play this note for')
  27. parser.add_option('-V', '--volume', dest='volume', type='float', help='Master volume [0.0, 1.0]')
  28. parser.add_option('-s', '--silence', dest='silence', action='store_true', help='Instruct all clients to stop playing any active tones')
  29. parser.add_option('-S', '--seek', dest='seek', type='float', help='Start time in seconds (scaled by --factor)')
  30. parser.add_option('-f', '--factor', dest='factor', type='float', help='Rescale time by this factor (0<f<1 are faster; 0.5 is twice the speed, 2 is half)')
  31. parser.add_option('-r', '--route', dest='routes', action='append', help='Add a routing directive (see --route-help)')
  32. parser.add_option('-v', '--verbose', dest='verbose', action='store_true', help='Be verbose; dump events and actual time (can slow down performance!)')
  33. parser.add_option('-W', '--wait-time', dest='wait_time', type='float', help='How long to wait for clients to initially respond (delays all broadcasts)')
  34. parser.add_option('-B', '--bind-addr', dest='bind_addr', help='The IP address (or IP:port) to bind to (influences the network to send to)')
  35. parser.add_option('--repeat', dest='repeat', action='store_true', help='Repeat the file playlist indefinitely')
  36. parser.add_option('-n', '--number', dest='number', type='int', help='Number of clients to use; if negative (default -1), use the product of stream count and the absolute value of this parameter')
  37. parser.add_option('-G', '--gui', dest='gui', default='', help='set a GUI to use')
  38. parser.add_option('--pg-fullscreen', dest='fullscreen', action='store_true', help='Use a full-screen video mode')
  39. parser.add_option('--pg-width', dest='pg_width', type='int', help='Width of the pygame window')
  40. parser.add_option('--pg-height', dest='pg_height', type='int', help='Width of the pygame window')
  41. parser.add_option('--help-routes', dest='help_routes', action='store_true', help='Show help about routing directives')
  42. parser.set_defaults(routes=[], test_delay=0.25, random=0.0, rand_low=80, rand_high=2000, live=None, factor=1.0, duration=1.0, volume=1.0, wait_time=0.25, play=[], transpose=0, seek=0.0, bind_addr='', pg_width = 0, pg_height = 0, number=-1)
  43. options, args = parser.parse_args()
  44. if options.help_routes:
  45. print '''Routes are a way of either exclusively or mutually binding certain streams to certain playback clients. They are especially fitting in heterogenous environments where some clients will outperform others in certain pitches or with certain parts.
  46. Routes are fully specified by:
  47. -The attribute to be routed on (either type "T", or UID "U")
  48. -The value of that attribute
  49. -The exclusivity of that route ("+" for inclusive, "-" for exclusive)
  50. -The stream group to be routed there.
  51. The syntax for that specification resembles the following:
  52. broadcast.py -r U:bass=+bass -r U:treble1,U:treble2=+treble -r T:BEEP=-beeps,-trk3,-trk5 -r U:noise=0
  53. The specifier consists of a comma-separated list of attribute-colon-value pairs, followed by an equal sign. After this is a comma-separated list of exclusivities paired with the name of a stream group as specified in the file. The above example shows that stream groups "bass", "treble", and "beeps" will be routed to clients with UID "bass", "treble", and TYPE "BEEP" respectively. Additionally, TYPE "BEEP" will receive tracks 4 and 6 (indices 3 and 5) of the MIDI file (presumably split with -T), and that these three groups are exclusively to be routed to TYPE "BEEP" clients only (the broadcaster will drop the stream if no more are available), as opposed to the preference of the bass and treble groups, which may be routed onto other stream clients if they are available. Finally, the last route says that all "noise" UID clients should not proceed any further (receiving "null" streams) instead. Order is important; if a "noise" client already received a stream (such as "+beeps"), then it would receive that route with priority.'''
  54. exit()
  55. GUIS = {}
  56. def gui_pygame():
  57. print 'Starting pygame GUI...'
  58. import pygame, colorsys
  59. pygame.init()
  60. print 'Pygame init'
  61. dispinfo = pygame.display.Info()
  62. DISP_WIDTH = 640
  63. DISP_HEIGHT = 480
  64. if dispinfo.current_h > 0 and dispinfo.current_w > 0:
  65. DISP_WIDTH = dispinfo.current_w
  66. DISP_HEIGHT = dispinfo.current_h
  67. print 'Pygame info'
  68. WIDTH = DISP_WIDTH
  69. if options.pg_width > 0:
  70. WIDTH = options.pg_width
  71. HEIGHT = DISP_HEIGHT
  72. if options.pg_height > 0:
  73. HEIGHT = options.pg_height
  74. flags = 0
  75. if options.fullscreen:
  76. flags |= pygame.FULLSCREEN
  77. disp = pygame.display.set_mode((WIDTH, HEIGHT), flags)
  78. print 'Disp acquire'
  79. PFAC = HEIGHT / 128.0
  80. clock = pygame.time.Clock()
  81. print 'Pygame GUI initialized, running...'
  82. while True:
  83. disp.scroll(-1, 0)
  84. disp.fill((0, 0, 0), (WIDTH - 1, 0, 1, HEIGHT))
  85. idx = 0
  86. for cli, note in sorted(playing_notes.items(), key = lambda pair: pair[0]):
  87. pitch = note[0]
  88. col = colorsys.hls_to_rgb(float(idx) / len(clients), note[1]/2.0, 1.0)
  89. col = [int(i*255) for i in col]
  90. disp.fill(col, (WIDTH - 1, HEIGHT - pitch * PFAC - PFAC, 1, PFAC))
  91. idx += 1
  92. pygame.display.flip()
  93. for ev in pygame.event.get():
  94. if ev.type == pygame.KEYDOWN:
  95. if ev.key == pygame.K_ESCAPE:
  96. thread.interrupt_main()
  97. pygame.quit()
  98. exit()
  99. clock.tick(60)
  100. GUIS['pygame'] = gui_pygame
  101. PORT = 13676
  102. factor = options.factor
  103. print 'Factor:', factor
  104. s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  105. s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
  106. if options.bind_addr:
  107. addr, _, port = options.bind_addr.partition(':')
  108. if not port:
  109. port = '12074'
  110. s.bind((addr, int(port)))
  111. clients = []
  112. uid_groups = {}
  113. type_groups = {}
  114. s.sendto(str(Packet(CMD.PING)), ('255.255.255.255', PORT))
  115. s.settimeout(options.wait_time)
  116. try:
  117. while True:
  118. data, src = s.recvfrom(4096)
  119. clients.append(src)
  120. except socket.timeout:
  121. pass
  122. playing_notes = {}
  123. for cli in clients:
  124. playing_notes[cli] = (0, 0)
  125. print len(clients), 'detected clients'
  126. print 'Clients:'
  127. for cl in clients:
  128. print cl,
  129. s.sendto(str(Packet(CMD.CAPS)), cl)
  130. data, _ = s.recvfrom(4096)
  131. pkt = Packet.FromStr(data)
  132. print 'ports', pkt.data[0],
  133. tp = itos(pkt.data[1])
  134. print 'type', tp,
  135. uid = ''.join([itos(i) for i in pkt.data[2:]]).rstrip('\x00')
  136. print 'uid', uid
  137. if uid == '':
  138. uid = None
  139. uid_groups.setdefault(uid, []).append(cl)
  140. type_groups.setdefault(tp, []).append(cl)
  141. if options.test:
  142. ts, tms = int(options.test_delay), int(options.test_delay * 1000000) % 1000000
  143. s.sendto(str(Packet(CMD.PLAY, ts, tms, 440, options.volume)), cl)
  144. if not options.sync_test:
  145. time.sleep(options.test_delay)
  146. s.sendto(str(Packet(CMD.PLAY, ts, tms, 880, options.volume)), cl)
  147. if options.quit:
  148. s.sendto(str(Packet(CMD.QUIT)), cl)
  149. if options.silence:
  150. s.sendto(str(Packet(CMD.PLAY, 0, 1, 1, 0.0)), cl)
  151. if options.gui:
  152. gui_thr = threading.Thread(target=GUIS[options.gui], args=())
  153. gui_thr.setDaemon(True)
  154. gui_thr.start()
  155. if options.play:
  156. for i, val in enumerate(options.play):
  157. if val.startswith('@'):
  158. options.play[i] = int(val[1:])
  159. else:
  160. options.play[i] = int(440.0 * 2**((int(val) - 69)/12.0))
  161. for i, cl in enumerate(clients):
  162. s.sendto(str(Packet(CMD.PLAY, int(options.duration), int(1000000*(options.duration-int(options.duration))), options.play[i%len(options.play)], options.volume)), cl)
  163. if not options.play_async:
  164. time.sleep(options.duration)
  165. exit()
  166. if options.test and options.sync_test:
  167. time.sleep(0.25)
  168. for cl in clients:
  169. s.sendto(str(Packet(CMD.PLAY, 0, 250000, 880, 1.0)), cl)
  170. if options.test or options.quit or options.silence:
  171. print uid_groups
  172. print type_groups
  173. exit()
  174. if options.random > 0:
  175. while True:
  176. for cl in clients:
  177. s.sendto(str(Packet(CMD.PLAY, int(options.random), int(1000000*(options.random-int(options.random))), random.randint(options.rand_low, options.rand_high), options.volume)), cl)
  178. time.sleep(options.random)
  179. if options.live or options.list_live:
  180. if options.gui:
  181. print 'Waiting a second for GUI init...'
  182. time.sleep(3.0)
  183. import midi
  184. from midi import sequencer
  185. S = sequencer.S
  186. if options.list_live:
  187. print sequencer.SequencerHardware()
  188. exit()
  189. seq = sequencer.SequencerRead(sequencer_resolution=120)
  190. client_set = set(clients)
  191. active_set = {} # note (pitch) -> [client]
  192. deferred_set = set() # pitches held due to sustain
  193. sustain_status = False
  194. client, _, port = options.live.partition(',')
  195. if client or port:
  196. seq.subscribe_port(client, port)
  197. seq.start_sequencer()
  198. if not options.gui: # FIXME
  199. seq.set_nonblock(False)
  200. while True:
  201. ev = S.event_input(seq.client)
  202. if ev is None:
  203. time.sleep(0)
  204. event = None
  205. if ev:
  206. if options.verbose:
  207. print 'SEQ:', ev
  208. if ev < 0:
  209. seq._error(ev)
  210. if ev.type == S.SND_SEQ_EVENT_NOTEON:
  211. event = midi.NoteOnEvent(channel = ev.data.note.channel, pitch = ev.data.note.note, velocity = ev.data.note.velocity)
  212. elif ev.type == S.SND_SEQ_EVENT_NOTEOFF:
  213. event = midi.NoteOffEvent(channel = ev.data.note.channel, pitch = ev.data.note.note, velocity = ev.data.note.velocity)
  214. elif ev.type == S.SND_SEQ_EVENT_CONTROLLER:
  215. event = midi.ControlChangeEvent(channel = ev.data.control.channel, control = ev.data.control.param, value = ev.data.control.value)
  216. elif ev.type == S.SND_SEQ_EVENT_PGMCHANGE:
  217. event = midi.ProgramChangeEvent(channel = ev.data.control.channel, value = ev.data.control.value)
  218. elif ev.type == S.SND_SEQ_EVENT_PITCHBEND:
  219. event = midi.PitchWheelEvent(channel = ev.data.control.channel, pitch = ev.data.control.value)
  220. elif options.verbose:
  221. print 'WARNING: Unparsed event, type %r'%(ev.type,)
  222. continue
  223. if event is not None:
  224. if isinstance(event, midi.NoteOnEvent) and event.velocity == 0:
  225. event.__class__ = midi.NoteOffEvent
  226. if options.verbose:
  227. print 'EVENT:', event
  228. if isinstance(event, midi.NoteOnEvent):
  229. if event.pitch in active_set:
  230. if sustain_status:
  231. deferred_set.discard(event.pitch)
  232. inactive_set = client_set - set(sum(active_set.values(), []))
  233. if not inactive_set:
  234. print 'WARNING: Out of clients to do note %r; dropped'%(event.pitch,)
  235. continue
  236. cli = sorted(inactive_set)[0]
  237. s.sendto(str(Packet(CMD.PLAY, 65535, 0, int(440.0 * 2**((event.pitch-69)/12.0)), event.velocity / 127.0)), cli)
  238. active_set.setdefault(event.pitch, []).append(cli)
  239. playing_notes[cli] = (event.pitch, event.velocity / 127.0)
  240. if options.verbose:
  241. print 'LIVE:', event.pitch, '+ =>', active_set[event.pitch]
  242. elif isinstance(event, midi.NoteOffEvent):
  243. if event.pitch not in active_set or not active_set[event.pitch]:
  244. print 'WARNING: Deactivating inactive note %r'%(event.pitch,)
  245. continue
  246. if sustain_status:
  247. deferred_set.add(event.pitch)
  248. continue
  249. cli = active_set[event.pitch].pop()
  250. s.sendto(str(Packet(CMD.PLAY, 0, 1, 1, 0)), cli)
  251. playing_notes[cli] = (0, 0)
  252. if options.verbose:
  253. print 'LIVE:', event.pitch, '- =>', active_set[event.pitch]
  254. if sustain_status:
  255. print '...ignored (sustain on)'
  256. elif isinstance(event, midi.ControlChangeEvent):
  257. if event.control == 64 and not options.no_sustain:
  258. sustain_status = (event.value >= 64)
  259. if options.verbose:
  260. print 'LIVE: SUSTAIN', ('+' if sustain_status else '-')
  261. if not sustain_status:
  262. for pitch in deferred_set:
  263. if pitch not in active_set or not active_set[pitch]:
  264. print 'WARNING: Attempted deferred removal of inactive note %r'%(pitch,)
  265. continue
  266. for cli in active_set[pitch]:
  267. s.sendto(str(Packet(CMD.PLAY, 0, 1, 1, 0)), cli)
  268. playing_notes[cli] = (0, 0)
  269. del active_set[pitch]
  270. deferred_set.clear()
  271. if options.repeat:
  272. args = itertools.cycle(args)
  273. for fname in args:
  274. try:
  275. iv = ET.parse(fname).getroot()
  276. except IOError:
  277. import traceback
  278. traceback.print_exc()
  279. print fname, ': Bad file'
  280. continue
  281. notestreams = iv.findall("./streams/stream[@type='ns']")
  282. groups = set([ns.get('group') for ns in notestreams if 'group' in ns.keys()])
  283. number = (len(notestreams) * abs(options.number) if options.number < 0 else options.number)
  284. print len(notestreams), 'notestreams'
  285. print len(clients), 'clients'
  286. print len(groups), 'groups'
  287. print number, 'clients used (number)'
  288. class Route(object):
  289. def __init__(self, fattr, fvalue, group, excl=False):
  290. if fattr == 'U':
  291. self.map = uid_groups
  292. elif fattr == 'T':
  293. self.map = type_groups
  294. elif fattr == '0':
  295. self.map = {}
  296. else:
  297. raise ValueError('Not a valid attribute specifier: %r'%(fattr,))
  298. self.value = fvalue
  299. if group is not None and group not in groups:
  300. raise ValueError('Not a present group: %r'%(group,))
  301. self.group = group
  302. self.excl = excl
  303. @classmethod
  304. def Parse(cls, s):
  305. fspecs, _, grpspecs = map(lambda x: x.strip(), s.partition('='))
  306. fpairs = []
  307. ret = []
  308. for fspec in [i.strip() for i in fspecs.split(',')]:
  309. fattr, _, fvalue = map(lambda x: x.strip(), fspec.partition(':'))
  310. fpairs.append((fattr, fvalue))
  311. for part in [i.strip() for i in grpspecs.split(',')]:
  312. for fattr, fvalue in fpairs:
  313. if part[0] == '+':
  314. ret.append(Route(fattr, fvalue, part[1:], False))
  315. elif part[0] == '-':
  316. ret.append(Route(fattr, fvalue, part[1:], True))
  317. elif part[0] == '0':
  318. ret.append(Route(fattr, fvalue, None, True))
  319. else:
  320. raise ValueError('Not an exclusivity: %r'%(part[0],))
  321. return ret
  322. def Apply(self, cli):
  323. return cli in self.map.get(self.value, [])
  324. def __repr__(self):
  325. return '<Route of %r to %s:%s>'%(self.group, ('U' if self.map is uid_groups else 'T'), self.value)
  326. class RouteSet(object):
  327. def __init__(self, clis=None):
  328. if clis is None:
  329. clis = clients[:]
  330. self.clients = clis
  331. self.routes = []
  332. def Route(self, stream):
  333. testset = self.clients[:]
  334. grp = stream.get('group', 'ALL')
  335. if options.verbose:
  336. print 'Routing', grp, '...'
  337. excl = False
  338. for route in self.routes:
  339. if route.group == grp:
  340. if options.verbose:
  341. print '\tMatches route', route
  342. excl = excl or route.excl
  343. matches = filter(lambda x, route=route: route.Apply(x), testset)
  344. if matches:
  345. if options.verbose:
  346. print '\tUsing client', matches[0]
  347. self.clients.remove(matches[0])
  348. return matches[0]
  349. if options.verbose:
  350. print '\tNo matches, moving on...'
  351. if route.group is None:
  352. if options.verbose:
  353. print 'Encountered NULL route, removing from search space...'
  354. toremove = []
  355. for cli in testset:
  356. if route.Apply(cli):
  357. toremove.append(cli)
  358. for cli in toremove:
  359. if options.verbose:
  360. print '\tRemoving', cli, '...'
  361. testset.remove(cli)
  362. if excl:
  363. if options.verbose:
  364. print '\tExclusively routed, no route matched.'
  365. return None
  366. if not testset:
  367. if options.verbose:
  368. print '\tOut of clients, no route matched.'
  369. return None
  370. cli = testset[0]
  371. self.clients.remove(cli)
  372. if options.verbose:
  373. print '\tDefault route to', cli
  374. return cli
  375. routeset = RouteSet()
  376. for rspec in options.routes:
  377. try:
  378. routeset.routes.extend(Route.Parse(rspec))
  379. except Exception:
  380. import traceback
  381. traceback.print_exc()
  382. if options.verbose:
  383. print 'All routes:'
  384. for route in routeset.routes:
  385. print route
  386. class NSThread(threading.Thread):
  387. def drop_missed(self):
  388. nsq, cl = self._Thread__args
  389. cnt = 0
  390. while nsq and float(nsq[0].get('time'))*factor < time.time() - BASETIME:
  391. nsq.pop(0)
  392. cnt += 1
  393. if options.verbose:
  394. print self, 'dropped', cnt, 'notes due to miss'
  395. self._Thread__args = (nsq, cl)
  396. def wait_for(self, t):
  397. if t <= 0:
  398. return
  399. time.sleep(t)
  400. def run(self):
  401. nsq, cl = self._Thread__args
  402. for note in nsq:
  403. ttime = float(note.get('time'))
  404. pitch = int(note.get('pitch')) + options.transpose
  405. vel = int(note.get('vel'))
  406. dur = factor*float(note.get('dur'))
  407. while time.time() - BASETIME < factor*ttime:
  408. self.wait_for(factor*ttime - (time.time() - BASETIME))
  409. s.sendto(str(Packet(CMD.PLAY, int(dur), int((dur*1000000)%1000000), int(440.0 * 2**((pitch-69)/12.0)), int(vel*2 * options.volume/255.0))), cl)
  410. if options.verbose:
  411. print (time.time() - BASETIME), cl, ': PLAY', pitch, dur, vel
  412. self.wait_for(dur - ((time.time() - BASETIME) - factor*ttime))
  413. class NSThread(threading.Thread):
  414. def drop_missed(self):
  415. nsq, cl = self._Thread__args
  416. cnt = 0
  417. while nsq and float(nsq[0].get('time'))*factor < time.time() - BASETIME:
  418. nsq.pop(0)
  419. cnt += 1
  420. if options.verbose:
  421. print self, 'dropped', cnt, 'notes due to miss'
  422. self._Thread__args = (nsq, cl)
  423. def wait_for(self, t):
  424. if t <= 0:
  425. return
  426. time.sleep(t)
  427. def run(self):
  428. nsq, cls = self._Thread__args
  429. for note in nsq:
  430. ttime = float(note.get('time'))
  431. pitch = float(note.get('pitch')) + options.transpose
  432. ampl = float(note.get('ampl', note.get('vel', 127.0) / 127.0))
  433. dur = factor*float(note.get('dur'))
  434. while time.time() - BASETIME < factor*ttime:
  435. self.wait_for(factor*ttime - (time.time() - BASETIME))
  436. for cl in cls:
  437. s.sendto(str(Packet(CMD.PLAY, int(dur), int((dur*1000000)%1000000), int(440.0 * 2**((pitch-69)/12.0)), ampl * options.volume)), cl)
  438. if options.verbose:
  439. print (time.time() - BASETIME), cl, ': PLAY', pitch, dur, vel
  440. playing_notes[cl] = (pitch, ampl)
  441. self.wait_for(dur - ((time.time() - BASETIME) - factor*ttime))
  442. playing_notes[cl] = (0, 0)
  443. if options.verbose:
  444. print '% 6.5f'%(time.time() - BASETIME,), cl, ': DONE'
  445. threads = {}
  446. nscycle = itertools.cycle(notestreams)
  447. for idx, ns in zip(xrange(number), nscycle):
  448. cli = routeset.Route(ns)
  449. if cli:
  450. nsq = ns.findall('note')
  451. if ns in threads:
  452. threads[ns]._Thread__args[1].add(cli)
  453. else:
  454. threads[ns] = NSThread(args=(nsq, set([cli])))
  455. if options.verbose:
  456. print 'Playback threads:'
  457. for thr in threads.values():
  458. print thr._Thread__args[1]
  459. BASETIME = time.time() - (options.seek*factor)
  460. if options.seek > 0:
  461. for thr in threads.values():
  462. thr.drop_missed()
  463. for thr in threads.values():
  464. thr.start()
  465. for thr in threads.values():
  466. thr.join()
  467. print fname, ': Done!'