forked from ideoforms/AbletonOSC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-console.py
executable file
·85 lines (72 loc) · 2.81 KB
/
run-console.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python3
#--------------------------------------------------------------------------------
# Console client for AbletonOSC.
# Takes OSC commands and parameters, and prints the return value.
#--------------------------------------------------------------------------------
import re
import sys
import argparse
try:
import readline
except:
if sys.platform == "win32":
print("On Windows, run-console.py requires pyreadline3: pip install pyreadline3")
else:
raise
from client import AbletonOSCClient
class LiveAPICompleter:
def __init__(self, commands):
self.commands = commands
def complete(self, text, state):
results = [x for x in self.commands if x.startswith(text)] + [None]
return results[state]
words = ["horse", "hogan", "horrific"]
completer = LiveAPICompleter(words)
readline.set_completer(completer.complete)
def main(args):
client = AbletonOSCClient(args.hostname, args.port)
if args.verbose:
client.verbose = True
client.send_message("/live/api/reload")
readline.parse_and_bind('tab: complete')
print("AbletonOSC command console")
print("Usage: /live/osc/command [params]")
while True:
try:
command_str = input(">>> ")
except EOFError:
print()
break
if not re.search("\\w", command_str):
#--------------------------------------------------------------------------------
# Command is empty
#--------------------------------------------------------------------------------
continue
if not re.search("^/", command_str):
#--------------------------------------------------------------------------------
# Command is invalid
#--------------------------------------------------------------------------------
print("OSC address must begin with a slash (/)")
continue
command, *params_str = command_str.split(" ")
params = []
for part in params_str:
try:
part = int(part)
except ValueError:
try:
part = float(part)
except ValueError:
pass
params.append(part)
try:
print(client.query(command, params))
except RuntimeError:
pass
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Console client for AbletonOSC. Takes OSC commands and parameters, and prints the return value.")
parser.add_argument("--hostname", type=str, default="127.0.0.1")
parser.add_argument("--port", type=str, default=11000)
parser.add_argument("--verbose", "-v", action="store_true", help="verbose mode: prints all OSC messages")
args = parser.parse_args()
main(args)