-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
69 lines (66 loc) · 1.97 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import time
import audio
import logorrhea
import net
import player
import recorder
if __name__ == '__main__':
import logging
import sys
try:
import readline
except ModuleNotFoundError:
pass
logging.basicConfig(level=20)
print('enter your name/alias: ', end='')
name = '{}-{}'.format(input(), str(time.time())[-3:])
print('enter relay server address: ', end='')
relay_ip = input()
print('connecting to {}...'.format(relay_ip))
cli = net.Client((relay_ip, 5005), name)
try:
cli.rpc({'type': 'enter'})
except Exception as exc:
import traceback
traceback.print_exc(file=sys.stdout)
sys.exit(1)
print("connected to relay at", relay_ip)
units = []
if '--silent' not in sys.argv:
play = player.Player()
play.start()
cli.raw_listeners.append(play.put_payloads)
units.append(play)
broadcast = getattr(cli, 'broadcast_unreliably' if '--unreliable' in sys.argv else 'broadcast')
rec = None
try:
while True:
print('> ', end='')
cmd = input()
if cmd == 'record':
if rec:
print("already recording")
continue
rec = recorder.Recorder()
rec.start()
rec.listeners.append(broadcast)
units.append(rec)
elif cmd == 'mute':
if not rec:
print("no recording to mute")
continue
rec.stop()
units.remove(rec)
rec = None
elif cmd == 'log':
logorrhea.start_thread()
elif cmd.startswith('tempo '):
bpm = int(cmd.split()[1])
cli.propose_tempo(bpm)
elif cmd:
print('eh wot?')
except (EOFError, KeyboardInterrupt):
print()
for unit in units:
unit.stop()
cli.rpc({'type': 'leave'})