2018-10-21 09:31:25 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""OscMacroDefinitions.py: Hog 4 comment macros in OSC for Python3."""
|
|
|
|
|
|
|
|
__author__ = "Kevin Matz"
|
|
|
|
__copyright__ = "Copyright 2018, Company 235, LLC"
|
|
|
|
__credits__ = ["Kevin Matz"]
|
|
|
|
|
|
|
|
__license__ = "MIT"
|
2018-10-21 14:22:02 -04:00
|
|
|
__version__ = "3.9"
|
2018-10-21 09:31:25 -04:00
|
|
|
__maintainer__ = "Kevin Matz"
|
|
|
|
__email__ = "kevin@company235.com"
|
|
|
|
|
|
|
|
__status__ = "Prototype"
|
|
|
|
|
2018-10-21 14:14:56 -04:00
|
|
|
import logging
|
2018-10-21 13:39:33 -04:00
|
|
|
from pythonosc import udp_client
|
2018-10-22 15:49:40 -04:00
|
|
|
from pythonosc import osc_message_builder
|
|
|
|
from pythonosc import osc_bundle_builder
|
2018-10-21 13:30:39 -04:00
|
|
|
from time import sleep
|
|
|
|
|
2018-10-21 14:14:56 -04:00
|
|
|
logger = logging.getLogger("CommentMacro")
|
|
|
|
|
2018-10-21 13:30:39 -04:00
|
|
|
|
|
|
|
class HogDevice():
|
|
|
|
def __init__(self, servers):
|
|
|
|
self.servers = servers
|
|
|
|
|
|
|
|
def button_press(self, device, path, delay=0.05):
|
|
|
|
self.send_message(device, path, 1) # button down
|
|
|
|
sleep(delay)
|
|
|
|
self.send_message(device, path, 0) # button up
|
|
|
|
|
2018-10-22 15:04:25 -04:00
|
|
|
# utility function to send simple messages with one argument
|
2018-10-21 13:30:39 -04:00
|
|
|
def send_message(self, device, path, arg):
|
2018-10-22 15:04:25 -04:00
|
|
|
msg = osc_message_builder.OscMessageBuilder(address=path)
|
|
|
|
msg.add_arg(arg)
|
|
|
|
self.send(device, msg.build())
|
|
|
|
|
|
|
|
# send python-osc messages
|
|
|
|
def send(self, device, msg):
|
2018-10-21 13:30:39 -04:00
|
|
|
if device is None:
|
|
|
|
osc = list(self.servers.values())[0]
|
|
|
|
else:
|
|
|
|
if (device.type.getText() != 'h'):
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.warn("Only Hog type devices are curently supported.")
|
|
|
|
logger.error("ERROR: macro discarded!")
|
2018-10-21 14:20:11 -04:00
|
|
|
return
|
2018-10-21 13:30:39 -04:00
|
|
|
else:
|
|
|
|
try:
|
|
|
|
osc = self.servers[device.number.value]
|
|
|
|
except KeyError:
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.warn("Net# "+str(device.number.value)+" not found.")
|
|
|
|
logger.error("ERROR: macro discarded!")
|
2018-10-21 14:20:11 -04:00
|
|
|
return
|
2018-10-22 15:04:25 -04:00
|
|
|
osc.send(msg)
|
2018-10-21 13:30:39 -04:00
|
|
|
|
|
|
|
def _master_go(self, ctx):
|
2018-10-21 09:31:25 -04:00
|
|
|
if ctx.number is not None:
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.warn("GO MASTER doesn't support goto. " +
|
|
|
|
"Cue number "+str(ctx.number.value)+" is ignored.")
|
2018-10-21 13:30:39 -04:00
|
|
|
if (len(ctx.master.targets) == 0):
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.info("Main GO")
|
2018-10-21 13:30:39 -04:00
|
|
|
self.osc.button_press(ctx.device, "/hog/hardware/maingo")
|
2018-10-21 14:20:11 -04:00
|
|
|
return
|
2018-10-21 13:30:39 -04:00
|
|
|
else:
|
|
|
|
for i in ctx.master.targets:
|
|
|
|
if isinstance(i, int) is not True:
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.error("GO MASTER macro targets must be intigers. "
|
|
|
|
+ str(i) + " is not an intigers.")
|
2018-10-21 13:30:39 -04:00
|
|
|
continue
|
|
|
|
if (i < 0):
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.error("Master "+str(i)+" is not greater than 0.")
|
2018-10-21 13:30:39 -04:00
|
|
|
continue
|
|
|
|
master = str(i)
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.info("GO on master " + master)
|
2018-10-21 13:30:39 -04:00
|
|
|
self.osc.button_press(ctx.device, "/hog/hardware/go/" + master)
|
|
|
|
|
|
|
|
def _master_halt(self, ctx):
|
|
|
|
if (len(ctx.master.targets) == 0):
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.info("Main HALT")
|
2018-10-21 13:30:39 -04:00
|
|
|
self.osc.button_press(ctx.device, "/hog/hardware/mainhalt")
|
2018-10-21 14:20:11 -04:00
|
|
|
return
|
2018-10-21 13:30:39 -04:00
|
|
|
else:
|
|
|
|
for i in ctx.master.targets:
|
|
|
|
if isinstance(i, int) is not True:
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.error("GO MASTER macro targets must be intigers. "
|
|
|
|
+ str(i) + " is not an intigers.")
|
2018-10-21 13:30:39 -04:00
|
|
|
continue
|
|
|
|
if (i < 0):
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.error("Master "+str(i)+" is not greater than 0.")
|
2018-10-21 13:30:39 -04:00
|
|
|
continue
|
|
|
|
master = str(i)
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.info("HALT on master " + master)
|
2018-10-21 13:30:39 -04:00
|
|
|
self.osc.button_press(ctx.device,
|
|
|
|
"/hog/hardware/pause/" + master)
|
|
|
|
|
|
|
|
def _master_fade(self, ctx):
|
|
|
|
if (ctx.number) is None:
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.error("ERROR: Missing required argument for LEVEL")
|
2018-10-21 14:20:11 -04:00
|
|
|
return
|
2018-10-21 13:30:39 -04:00
|
|
|
else:
|
|
|
|
level = ctx.number.value
|
|
|
|
if (level < 0 or level > 100):
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.error("Level must be between 0 and 100.")
|
2018-10-21 14:20:11 -04:00
|
|
|
return
|
2018-10-21 13:30:39 -04:00
|
|
|
if (len(ctx.master.targets) == 0):
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.error("MASTER FADE doesn't support * current master.")
|
2018-10-21 14:20:11 -04:00
|
|
|
return
|
2018-10-21 13:30:39 -04:00
|
|
|
else:
|
|
|
|
for i in ctx.master.targets:
|
|
|
|
if isinstance(i, int) is not True:
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.error("FADE MASTER macro targets must be intigers. "
|
|
|
|
+ str(i) + " is not an intigers.")
|
2018-10-21 13:30:39 -04:00
|
|
|
continue
|
|
|
|
if (i < 0):
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.error("Master "+str(i)+" is not greater than 0.")
|
2018-10-21 13:30:39 -04:00
|
|
|
continue
|
|
|
|
master = str(i)
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.info("Fade Master "+master+" to "+str(level)+"%")
|
2018-10-21 13:30:39 -04:00
|
|
|
level *= 255 / 100 # percent in Macro, 0>255 in OSC
|
|
|
|
self.osc.send_message(ctx.device,
|
|
|
|
"/hog/hardware/fader/" + master,
|
|
|
|
level)
|
|
|
|
|
|
|
|
def _master_fade_grand(self, ctx):
|
|
|
|
level = ctx.number.value
|
|
|
|
if (level < 0 or level > 100):
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.error("Level must be between 0 and 100.")
|
2018-10-21 14:20:11 -04:00
|
|
|
return
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.info("Fading Grand Master to " + str(level) + "%")
|
2018-10-21 13:30:39 -04:00
|
|
|
level *= 255 / 100 # percent in Macro, 0>255 in OSC
|
|
|
|
self.osc.send_message(ctx.device, "/hog/hardware/fader/0", level)
|
|
|
|
|
|
|
|
def _master_choose(self, ctx):
|
|
|
|
if (ctx.number.value < 0):
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.error("Master must be greater than 0.")
|
2018-10-21 14:20:11 -04:00
|
|
|
return
|
2018-10-21 13:30:39 -04:00
|
|
|
master = str(ctx.number.value)
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.info("Choose Master " + master)
|
2018-10-21 13:30:39 -04:00
|
|
|
self.osc.button_press(ctx.device, "/hog/hardware/choose/" + master)
|
|
|
|
|
|
|
|
def _list_go(self, ctx):
|
|
|
|
for i in ctx.targets:
|
|
|
|
list = str(i)
|
|
|
|
if ctx.number is not None:
|
|
|
|
list += "." + str(ctx.number.value)
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.info("Go on List " + list)
|
2018-10-21 13:30:39 -04:00
|
|
|
self.osc.send_message(ctx.device, "/hog/playback/go/0", list)
|
|
|
|
|
|
|
|
def _list_halt(self, ctx):
|
|
|
|
for i in ctx.targets:
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.info("Halting List " + str(i))
|
2018-10-21 13:30:39 -04:00
|
|
|
self.osc.send_message(ctx.device, "/hog/playback/halt/0", i)
|
|
|
|
|
|
|
|
def _list_release(self, ctx):
|
|
|
|
for i in ctx.targets:
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.info("Releasing List " + str(i))
|
2018-10-21 13:30:39 -04:00
|
|
|
self.osc.send_message(ctx.device, "/hog/playback/release/0", i)
|
|
|
|
|
|
|
|
def _scene_go(self, ctx):
|
|
|
|
for i in ctx.targets:
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.info("Go on Scene " + str(i))
|
2018-10-21 13:30:39 -04:00
|
|
|
self.osc.send_message(ctx.device, "/hog/playback/go/1", i)
|
|
|
|
|
|
|
|
def _scene_halt(self, ctx):
|
|
|
|
for i in ctx.targets:
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.info("Halt Scene " + str(i))
|
2018-10-21 13:30:39 -04:00
|
|
|
self.osc.send_message(ctx.device, "/hog/playback/halt/1", i)
|
|
|
|
|
|
|
|
def _scene_release(self, ctx):
|
|
|
|
for i in ctx.targets:
|
2018-10-21 14:14:56 -04:00
|
|
|
logger.info("Release Scene " + str(i))
|
2018-10-21 13:30:39 -04:00
|
|
|
self.osc.send_message(ctx.device, "/hog/playback/release/1", i)
|
|
|
|
|
|
|
|
command = {"GM": _master_go,
|
|
|
|
"HM": _master_halt,
|
|
|
|
"FM": _master_fade,
|
|
|
|
"FGM": _master_fade_grand,
|
|
|
|
"CM": _master_choose,
|
|
|
|
"GL": _list_go,
|
|
|
|
"HL": _list_halt,
|
|
|
|
"RL": _list_release,
|
|
|
|
"GS": _scene_go,
|
|
|
|
"HS": _scene_halt,
|
|
|
|
"RS": _scene_release
|
|
|
|
}
|