67 lines
1.6 KiB
Python
Executable File
67 lines
1.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""comment.py: Hog 4 comment macro interpreter and OSC bridge."""
|
|
|
|
__author__ = "Kevin Matz"
|
|
__copyright__ = "Copyright 2018, Company 235, LLC"
|
|
__credits__ = ["Kevin Matz"]
|
|
|
|
__license__ = "MIT"
|
|
__version__ = "0.0.1"
|
|
__maintainer__ = "Kevin Matz"
|
|
__email__ = "kevin@company235.com"
|
|
|
|
__status__ = "Prototype"
|
|
|
|
|
|
import antlr4
|
|
import configparser
|
|
import readline
|
|
import signal
|
|
import sys
|
|
|
|
from CommentMacroLexer import CommentMacroLexer
|
|
from CommentMacroParser import CommentMacroParser
|
|
from OscCommentMacroListener import OscCommentMacroListener
|
|
from pythonosc import udp_client
|
|
|
|
|
|
# refactor this to support multiple net#s
|
|
config = configparser.ConfigParser(allow_no_value=True)
|
|
config.read('server.cfg')
|
|
server = config['hog4']
|
|
net = server.getint("net", 1)
|
|
hog4 = {}
|
|
hog4[net] = udp_client.SimpleUDPClient(server.get("ip", "10.0.0.1"),
|
|
server.getint("port", 6600))
|
|
|
|
|
|
def comment(text):
|
|
input_stream = antlr4.InputStream(text)
|
|
lexer = CommentMacroLexer(input_stream)
|
|
stream = antlr4.CommonTokenStream(lexer)
|
|
parser = CommentMacroParser(stream)
|
|
tree = parser.prog()
|
|
|
|
oscMacro = OscCommentMacroListener(parser, hog4)
|
|
walker = antlr4.ParseTreeWalker()
|
|
walker.walk(oscMacro, tree)
|
|
|
|
|
|
def orderly_exit(signal=None, frame=None):
|
|
print('Goodbye.')
|
|
sys.exit(0)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
signal.signal(signal.SIGINT, orderly_exit)
|
|
if len(sys.argv) > 1:
|
|
comment(sys.argv[1])
|
|
else:
|
|
while True:
|
|
text = input("comment# ")
|
|
if text == 'exit':
|
|
orderly_exit()
|
|
comment(text)
|