LJ/libs3/commands.py

836 lines
25 KiB
Python
Raw Permalink Normal View History

2018-12-13 11:05:32 +00:00
# coding=UTF-8
"""
2018-12-21 16:23:43 +00:00
LJ OSC and Websockets laser commands
2018-12-13 11:05:32 +00:00
v0.7.0
LICENCE : CC
2020-09-19 12:28:56 +00:00
by Sam Neurohack, Loloster
2018-12-13 11:05:32 +00:00
from /team/laser
2018-12-30 15:12:30 +00:00
Commands reference. Use commands from websocket (webUI) or OSC, do not set values in redis directly except for /pl.
2020-09-19 12:28:56 +00:00
DAChecks()
UpdateAllwww()
2024-08-19 19:22:38 +00:00
/forwardui "htmlid args"
2020-09-19 12:28:56 +00:00
2020-10-02 22:15:12 +00:00
/scale/X/lasernumber value (0-200)
/scale/Y/lasernumber value (0-200)
2018-12-30 15:12:30 +00:00
/client or note on < 8 : change client displayed for Current Laser
2024-08-19 19:22:38 +00:00
23 < /noteon < 32 : PL number displayed on webUI simulator
2018-12-30 15:12:30 +00:00
/grid/lasernumber value (0 or 1) : switch given laser with grid display on or off
/black/lasernumber value (0 or 1) : set given laser to black on or off
2023-06-03 12:43:53 +00:00
/emergency value (0 or 1) : set all lasers to black on or off
2018-12-30 15:12:30 +00:00
/ip/lasernumber value : change given laser IP i.e '192.168.1.1'
/kpps/lasernumber value
Live change of kpps is not implemented in newdac.py. Change will effect next startup.
2020-10-02 22:15:12 +00:00
/angle/lasernumber value : angle correction for given laser by value (0-360)
2018-12-30 15:12:30 +00:00
2024-08-19 19:22:38 +00:00
/intens/lasernumber value : increase/decrease intensity for given laser by value
2018-12-30 15:12:30 +00:00
/resampler/lasernumber lsteps : change resampling strategy (glitch art) for given laser
lsteps is a string like "[ (1.0, 8),(0.25, 3), (0.75, 3), (1.0, 10)]"
2024-08-19 19:22:38 +00:00
/mouse/lasernumber value (0 or 1)
/swap/X/lasernumber value (0 or 1)
/swap/Y/lasernumber value (0 or 1)
2018-12-30 15:12:30 +00:00
2020-10-02 22:15:12 +00:00
/loffset/X/lasernumber value : change X offset of given laser to value (-32000/32000)
/loffset/Y/lasernumber value : change Y offset of given laser to value (-32000/32000)
2018-12-30 15:12:30 +00:00
/order value : instruct tracer what to do.
0 : display user pointlist with current client key. See below for client key.
2024-08-19 19:22:38 +00:00
1 : pull in redis a new correction matrix (EDH)
2 : display black
2018-12-30 15:12:30 +00:00
3 : display grid
2024-08-19 19:22:38 +00:00
4 : resampler
2018-12-30 15:12:30 +00:00
5 : pull in redis a new client key
2020-09-19 12:28:56 +00:00
6 : Max Intensity Change = reread redis key /intensity
7 : kpps change = reread redis key /kpps
8 : color balance change = reread redis keys /red /green /blue
2024-08-15 16:52:07 +00:00
9 : shutdown
2020-09-19 12:28:56 +00:00
/planet will be forwarded to planetarium client.
/nozoid will be forwarded to nozoid client.
/scene/scenenumber/start 0 or 1
/regen : regen webui index html page.
2018-12-30 15:12:30 +00:00
2020-10-04 17:46:45 +00:00
/plugins/start pluginame
/plugins/stop pluginame
2018-12-30 15:12:30 +00:00
/pl/clientnumber/lasernumber value : value is the pointlist to draw as string type. For string format see code in clients directory.
Example : client 0 send 2 point lists one for laser 0 and one for laser 1 by sending in redis :
/pl/0/0 and /pl/0/1
2024-08-19 19:22:38 +00:00
The "client key" when client 0 is selected to be displayed by lasers is "/pl/0/".
Each tracer pull its pointlist by using the current client key "/pl/0/"
2018-12-30 15:12:30 +00:00
and add its laser number at startup : /pl0/0 ant /pl/0/1
2024-08-19 19:22:38 +00:00
"Client" is a concept. Imagine in a demoparty there is 4 lasers.
John and Paul want to draw on all lasers.
2018-12-30 15:12:30 +00:00
Let's give John client 0, he will send points to /pl/0/0, /pl/0/1, /pl/0/2 and /pl/0/3.
Paul is client 1, so he will use /pl/1/0, /pl/1/1, /pl/1/2 and /pl/1/3.
Both can send their pointlists to redis server.
When John get the lasers switch to client 0, when it's Paul turn switch to client 1.
2024-08-19 19:22:38 +00:00
But say Bob and Lisa needs only 2 lasers each. Give them client 2.
2018-12-30 15:12:30 +00:00
Bob could use /pl/2/0 and /pl/2/1 and Lisa could use /pl/2/2 and /pl/2/3.
2018-12-13 11:05:32 +00:00
"""
2019-08-06 01:08:54 +00:00
2020-10-02 22:15:12 +00:00
import types, time, socket, math
2020-09-19 12:28:56 +00:00
from libs3 import gstt
import redis
2024-08-19 19:22:38 +00:00
from libs3 import OSC3
2020-09-29 22:15:40 +00:00
from libs3 import settings, plugins, homographyp,log
2018-12-13 11:05:32 +00:00
2023-06-03 12:43:53 +00:00
r = redis.StrictRedis(host=gstt.RediServerIP , port=6379, db=0)
#r = redis.StrictRedis(host=gstt.RediServerIP , port=6379, db=0, password='-+F816Y+-')
2018-12-13 11:05:32 +00:00
2024-08-19 19:22:38 +00:00
workers = []
2019-03-10 22:06:04 +00:00
2023-06-03 12:43:53 +00:00
GenericCommands = ["start", "align", "ljclient", "scene", "addest", "deldest", "dest", "clientnumber", "vcvrack", "fft", "mitraille", "faceosc", "midigen", "viewgen", "audiogen", "noteon", "cc", "ljpong", "ljwars", "mouse", "emergency", "simu", "status", "run", "nozoid", "planet", "live", "words", "ai", "bank0", "pose", "lj", "cycl", "glyph", "pong", "maxw", "custom1", "square", "regen", "trckr", "aurora", "line1", "ForwardUI", "settings", "debug", "pl", "plugins"]
2018-12-13 11:05:32 +00:00
2024-08-19 19:22:38 +00:00
2018-12-13 11:05:32 +00:00
def UserOn(laser):
2020-09-19 12:28:56 +00:00
print("User for laser ", laser)
2019-03-17 03:19:57 +00:00
plugins.sendWSall("/status User on laser " + str(laser))
r.set('/order/'+str(laser), 0)
2018-12-13 11:05:32 +00:00
def NewEDH(laser):
2020-09-19 12:28:56 +00:00
print("New EDH requested for laser ", laser)
2019-03-17 03:19:57 +00:00
plugins.sendWSall("/status New EDH on laser " + str(laser))
settings.Write()
2020-09-19 12:28:56 +00:00
print("Settings saving swapX ", gstt.swapX[laser])
print("Settings saving swapY ", gstt.swapY[laser])
2018-12-18 01:45:23 +00:00
2018-12-15 19:03:32 +00:00
homographyp.newEDH(laser)
2018-12-13 11:05:32 +00:00
def BlackOn(laser):
2020-09-19 12:28:56 +00:00
print("Black for laser ", laser)
2019-03-17 03:19:57 +00:00
plugins.sendWSall("/status Black on laser " + str(laser))
2023-06-03 12:43:53 +00:00
sendOSCUI('/black/'+str(laser),1)
r.set('/order/'+str(laser), 2)
2024-08-19 19:22:38 +00:00
2018-12-13 11:05:32 +00:00
def GridOn(laser):
2018-12-13 11:05:32 +00:00
2020-09-19 12:28:56 +00:00
print("Grid for laser ", laser)
2019-03-17 03:19:57 +00:00
plugins.sendWSall("/status Grid on laser " + str(laser))
2023-06-03 12:43:53 +00:00
sendOSCUI('/grid/'+str(laser),1)
r.set('/order/'+str(laser), 3)
2018-12-13 11:05:32 +00:00
2023-06-03 12:43:53 +00:00
2020-09-19 12:28:56 +00:00
def Resampler(laser,args):
2018-12-13 11:05:32 +00:00
2018-12-15 19:03:32 +00:00
# lsteps is a string like : "[ (1.0, 8),(0.25, 3), (0.75, 3), (1.0, 10)]"
2020-09-19 12:28:56 +00:00
print("Resampler change for laser", laser, "[("+str(args[0])+","+str(args[1])+"),("+str(args[2])+","+str(args[3])+"),("+str(args[4])+","+str(args[5])+"),("+str(args[6])+","+str(args[7])+")]")
#r.set('/resampler/' + str(laser), lsteps)
r.set('/resampler/' + str(laser), "[("+str(args[0])+","+str(args[1])+"),("+str(args[2])+","+str(args[3])+"),("+str(args[4])+","+str(args[5])+"),("+str(args[6])+","+str(args[7])+")]")
r.set('/order/'+str(laser), 4)
2018-12-13 11:05:32 +00:00
2018-12-18 01:45:23 +00:00
def LasClientChange(clientnumber):
if r.get("/pl/"+str(clientnumber)+"/0") != None:
2020-09-19 12:28:56 +00:00
print("Switching to laser client", clientnumber)
2019-08-06 01:08:54 +00:00
gstt.SceneNumber = clientnumber
plugins.sendWSall("/status Client " + str(gstt.SceneNumber) + " laser " + str(gstt.Laser))
2019-03-17 03:19:57 +00:00
2018-12-18 01:45:23 +00:00
r.set('/clientkey', "/pl/"+str(clientnumber)+"/")
2020-09-19 12:28:56 +00:00
print("clientkey set to", "/pl/"+str(clientnumber)+"/")
for laserid in range(0,gstt.LaserNumber):
2018-12-18 01:45:23 +00:00
r.set('/order/'+str(laserid), 5)
else:
2020-09-19 12:28:56 +00:00
print("ERROR : Maximum number of scenes is set to ", gstt.MaxScenes)
2024-08-19 19:22:38 +00:00
2018-12-18 01:45:23 +00:00
2019-08-06 01:08:54 +00:00
def SceneChange(newscene):
2020-09-19 12:28:56 +00:00
print("Switching to scene", newscene)
2019-08-06 01:08:54 +00:00
gstt.SceneNumber = int(newscene)
plugins.sendWSall("/status Scene " + newscene)
r.set('/clientkey', "/pl/"+ newscene +"/")
2020-09-19 12:28:56 +00:00
print("clientkey set to", "/pl/" + newscene + "/")
2019-08-06 01:08:54 +00:00
2020-09-19 12:28:56 +00:00
for laserid in range(0,gstt.LaserNumber):
2019-08-06 01:08:54 +00:00
r.set('/order/'+str(laserid), 5)
plugins.sendWSall("/scene/" + str(laserid) + "/start 0")
plugins.sendWSall("/scene/" + newscene + "/start 1")
2020-09-19 12:28:56 +00:00
# Change current laser and send "/scim lasernumber to each plugin"
2018-12-18 01:45:23 +00:00
def NoteOn(note):
2023-07-09 14:09:18 +00:00
print()
2023-06-03 12:43:53 +00:00
print("NoteOn", note)
2018-12-18 01:45:23 +00:00
# Change laser client
if note < 8:
LasClientChange(note)
2024-08-19 19:22:38 +00:00
2018-12-19 11:39:54 +00:00
# Change PL displayed on webui
2018-12-18 01:45:23 +00:00
if note > 23 and note < 32:
if note - 24 > gstt.LaserNumber -1:
2020-09-19 12:28:56 +00:00
print("Only",gstt.LaserNumber,"lasers asked, you dum ass !")
plugins.sendWSall("/redstatus No Laser"+str(note-24))
plugins.sendWSall("/laser "+str(gstt.LaserNumber-1))
2020-09-27 23:04:05 +00:00
plugins.SendAll("/laser "+str(gstt.LaserNumber-1))
2024-08-19 19:22:38 +00:00
else:
2018-12-18 01:45:23 +00:00
gstt.Laser = note -24
2020-09-19 12:28:56 +00:00
print("Current Laser switched to", gstt.Laser)
2020-10-06 01:11:02 +00:00
plugins.sendWSall("/status Laser " + str(gstt.Laser))
2023-07-09 14:09:18 +00:00
plugins.SendAll("/scim "+str(gstt.Laser))
2023-06-03 12:43:53 +00:00
print("sending cropper data..")
plugins.sendWSall("/loffset/X/" + str(gstt.Laser) +" " +str(gstt.centerX[gstt.Laser]))
plugins.sendWSall("/loffset/Y/" + str(gstt.Laser) +" " +str(gstt.centerY[gstt.Laser]))
plugins.sendWSall("/scale/X/" + str(gstt.Laser) +" " + str(gstt.zoomX[gstt.Laser]))
plugins.sendWSall("/scale/Y/" + str(gstt.Laser) +" " +str(gstt.zoomY[gstt.Laser]))
2024-08-19 19:22:38 +00:00
2020-09-19 12:28:56 +00:00
def Scim(path, tags, args, source):
laser = int(args[0])
print("OSC /scim", laser)
# Change PL displayed on webui
if laser > 23 and laser < 32:
if laser - 24 > gstt.LaserNumber -1:
print("Only",gstt.LaserNumber,"lasers asked, you dum ass !")
plugins.sendWSall("/redstatus No Laser"+str(note-24))
plugins.sendWSall("/laser "+str(gstt.LaserNumber-1))
2024-08-19 19:22:38 +00:00
else:
2020-09-19 12:28:56 +00:00
gstt.Laser = laser -24
plugins.sendWSall("/status Laser " + str(gstt.Laser))
print("Current Laser switched to", gstt.Laser)
def Line1(path, tags, args, source):
line1 = args[0]
2024-08-19 19:22:38 +00:00
print("OSC /line1", line1)
2020-09-19 12:28:56 +00:00
plugins.sendWSall("/line1 " +"Fx "+line1)
2024-08-19 19:22:38 +00:00
# forward
2020-09-19 12:28:56 +00:00
def ForwardUI(path, tags, args, source):
line = args[0]
2024-08-19 19:22:38 +00:00
print("OSC /forwardui to WebUI :", line)
2020-09-19 12:28:56 +00:00
print('from path', path, 'args', args)
plugins.sendWSall(line)
2023-06-03 12:43:53 +00:00
sendOSCUI('/status',line)
2020-09-19 12:28:56 +00:00
2018-12-19 11:39:54 +00:00
2019-08-06 01:08:54 +00:00
def CC(number, value):
2020-09-19 12:28:56 +00:00
print("CC", note, value)
2019-08-06 01:08:54 +00:00
2019-01-28 13:18:19 +00:00
def Mouse(x1,y1,x2,y2):
2020-09-19 12:28:56 +00:00
print("Mouse", x1,y1,x2,y2)
2019-01-28 13:18:19 +00:00
2018-12-18 01:45:23 +00:00
def handler(oscpath, args):
2023-06-03 12:43:53 +00:00
#print("OSC handler in commands.py got /"+ str(oscpath)+ " with args :",args)
2020-09-19 12:28:56 +00:00
2019-08-06 01:08:54 +00:00
if gstt.debug > 0:
2020-09-19 12:28:56 +00:00
print("OSC handler in commands.py got /"+ str(oscpath)+ " with args :",args)
2018-12-18 01:45:23 +00:00
2023-06-03 12:43:53 +00:00
2019-03-10 22:06:04 +00:00
# 2 incoming cases : generic or specific for a given lasernumber :
2024-08-19 19:22:38 +00:00
2020-09-19 12:28:56 +00:00
#
# Generic : Commands without a laser number
#
2024-08-19 19:22:38 +00:00
if oscpath[1] in GenericCommands:
2019-03-10 22:06:04 +00:00
2019-08-06 01:08:54 +00:00
if gstt.debug > 0:
2020-09-19 12:28:56 +00:00
print("GenericCommand :", oscpath[1], "with args", args)
2019-08-06 01:08:54 +00:00
2019-03-10 22:06:04 +00:00
if oscpath[1] == "ljclient":
2019-08-06 01:08:54 +00:00
#LasClientChange(int(args[0]))
SceneChange(args[0])
2020-09-19 12:28:56 +00:00
if oscpath[1] == "pl":
2020-10-06 18:07:12 +00:00
print("new pl for", "/"+oscpath[1]+"/"+oscpath[2]+"/"+oscpath[3], ":", args[0])
# was r.set(oscpath, args[0])
r.set("/"+oscpath[1]+"/"+oscpath[2]+"/"+oscpath[3], args[0])
2024-08-19 19:22:38 +00:00
if oscpath[0] == "pl" :
2020-09-19 12:28:56 +00:00
r.set(oscpath, args[0])
2019-08-06 01:08:54 +00:00
#/scene/scenenumber/start 0 or 1
if oscpath[1] == "scene":
2020-09-19 12:28:56 +00:00
print(oscpath[1], oscpath[2], args[0])
2019-08-06 01:08:54 +00:00
if args[0] == '1' and r.get("/pl/" + oscpath[2] + "/0") != None:
SceneChange(oscpath[2])
else:
2020-09-19 12:28:56 +00:00
print("ERROR : Maximum number of scenes is set to ", gstt.MaxScenes)
2019-02-26 10:10:57 +00:00
2019-01-28 13:18:19 +00:00
elif oscpath[1] == "noteon":
2023-07-09 14:09:18 +00:00
2018-12-18 01:45:23 +00:00
NoteOn(int(args[0]))
2019-02-26 10:10:57 +00:00
2019-08-06 01:08:54 +00:00
elif oscpath[1] == "CC":
CC(int(args[0]), int(args[1]))
2019-03-10 22:06:04 +00:00
elif oscpath[1] == "pong":
2019-08-06 01:08:54 +00:00
#print "LJ commands got pong from", args
2020-09-19 12:28:56 +00:00
if gstt.debug >0:
print(("/" + args[0] + "/start 1"))
print(("/status got pong from "+ args[0] +"."))
2024-08-19 19:22:38 +00:00
2019-08-06 01:08:54 +00:00
plugins.sendWSall("/" + args[0] + "/start 1")
2020-09-19 12:28:56 +00:00
#plugins.sendWSall("/status got pong from "+ args[0] +".")
2019-08-06 01:08:54 +00:00
elif oscpath[1] == "vcvrack":
pass
'''
#print "LJ commands got /vcvrack from", args
if oscpath[2] == "1" :
r.set('/vcvrack/1', args[0])
#print('/vcvrack/1', args[0])
if oscpath[2] == "2" :
r.set('/vcvrack/2', args[0])
#print('/vcvrack/2', args[0])
'''
2019-01-28 13:18:19 +00:00
elif oscpath[1] == "mouse":
Mouse(int(args[0]),int(args[1]),int(args[2]),int(args[3]))
2024-08-19 19:22:38 +00:00
# /emergency value (0 or 1)
elif oscpath[1] == "emergency":
2024-08-19 19:22:38 +00:00
2019-02-26 10:10:57 +00:00
if args[0] == "1":
2024-08-19 19:22:38 +00:00
2019-02-26 10:10:57 +00:00
for laser in range(gstt.lasernumber):
2020-09-19 12:28:56 +00:00
print("Black requested for laser ", laser)
2019-03-17 03:19:57 +00:00
BlackOn(laser)
2020-09-19 12:28:56 +00:00
print("EMERGENCY MODE")
2024-08-19 19:22:38 +00:00
plugins.sendWSall("/status EMERGENCY MODE")
2023-06-03 12:43:53 +00:00
2019-02-26 10:10:57 +00:00
else:
for laser in range(gstt.lasernumber):
2020-09-19 12:28:56 +00:00
print("Back to normal for laser ", laser)
2019-02-26 10:10:57 +00:00
UserOn(laser)
2020-10-04 17:46:45 +00:00
2024-08-19 19:22:38 +00:00
# Plugins commands :
2020-10-04 17:46:45 +00:00
elif oscpath[1] == "plugins":
# /plugins/start pluginame
if oscpath[2] == "start":
print()
print("Starting plugin :",args[0])
print()
plugins.Start(args[0])
# /plugins/stop pluginame
if oscpath[2] == "stop":
print()
print("Stopping plugin :",args[0])
print()
plugins.Kill(args[0])
# /plugins/restart pluginame
if oscpath[2] == "restart":
print()
print("Restarting plugin :",args[0])
print()
plugins.Restart(args[0])
2024-08-19 19:22:38 +00:00
# Settings commands :
2020-09-19 12:28:56 +00:00
elif oscpath[1] == "settings":
if oscpath[2] == "lasers":
print()
print("new laser number",args[0])
print()
2020-09-30 10:05:04 +00:00
gstt.LaserNumber = int(args[0])
2020-09-29 22:15:40 +00:00
settings.Write()
2020-09-19 12:28:56 +00:00
if oscpath[2] == "regen":
print()
2020-09-27 23:04:05 +00:00
print("Regen www pages with",gstt.wwwIP,"...")
2020-09-19 12:28:56 +00:00
UpdateAllwww()
if oscpath[2] == "IP":
print()
print("new server IP for www regen",args[0])
gstt.wwwIP = args[0]
2020-09-27 23:04:05 +00:00
settings.Write()
2020-09-19 12:28:56 +00:00
if oscpath[2] == "debug":
print()
print("Debug level",args[0])
print()
gstt.debug = int(args[0])
plugins.SendAll("/debug "+str(gstt.debug))
2020-09-29 22:15:40 +00:00
settings.Write()
2020-09-19 12:28:56 +00:00
if oscpath[2] == "rescan":
print()
DAChecks()
print("Done.")
2020-10-10 17:29:07 +00:00
if oscpath[2] == "reset":
import shutil
print()
shutil.copyfile(gstt.ljpath+'/templates/LJ_template.conf', gstt.ljpath+'/LJ.conf')
print("templates/LJ_template.conf copied to LJ.conf.")
print("** RESTART LJ **")
#LJautokill()
2024-08-19 19:22:38 +00:00
2020-09-29 22:15:40 +00:00
if oscpath[2] == "restart":
2020-09-19 12:28:56 +00:00
print()
print("Restarting", args[0], "...")
if args[0] == "lj":
2020-09-29 22:15:40 +00:00
LJautokill()
import os
os.execv(sys.executable, ['python3'] + sys.argv)
2020-09-19 12:28:56 +00:00
else:
plugins.Restart(args[0])
print()
2020-09-27 23:04:05 +00:00
''' regen index.html (python build.py)
elif oscpath[1] == "regen":
print("new ui IP", args[0])
#subprocess.Popen(["python3", plugins.ljpath + "/webui/build.py"])
'''
2020-09-19 12:28:56 +00:00
#
2019-03-10 22:06:04 +00:00
# Commands with a laser number
2020-09-19 12:28:56 +00:00
#
2018-12-13 11:05:32 +00:00
else:
2019-08-06 01:08:54 +00:00
2020-09-19 12:28:56 +00:00
pathlength = len(oscpath)
if gstt.debug > 0:
print("Non Generic Command :", oscpath[1], "with args", args)
#print "oscpath", oscpath
#print "pathlength", pathlength
#print "args", args
2019-02-26 10:10:57 +00:00
2018-12-18 01:45:23 +00:00
if pathlength == 3:
laser = int(oscpath[2])
2019-08-06 01:08:54 +00:00
2018-12-18 01:45:23 +00:00
else:
laser = int(oscpath[3])
2024-08-19 19:22:38 +00:00
2020-09-19 12:28:56 +00:00
#print "args[0] :",args[0]," ", type(args[0])
2023-06-03 15:44:15 +00:00
2024-08-19 19:22:38 +00:00
# /black/lasernumber value (0 or 1)
2023-06-03 15:44:15 +00:00
if oscpath[1] == "black":
2024-08-19 19:22:38 +00:00
2023-06-03 15:44:15 +00:00
if args[0] == "1":
print("Black requested for laser ", laser)
2024-08-19 19:22:38 +00:00
BlackOn(laser)
2023-06-03 15:44:15 +00:00
else:
print("User mode for laser ", laser)
UserOn(laser)
2024-08-19 19:22:38 +00:00
# /grid/lasernumber value (0 or 1)
2019-02-26 10:10:57 +00:00
if oscpath[1] == "grid":
2024-08-19 19:22:38 +00:00
2019-02-26 10:10:57 +00:00
if args[0] == "1":
2020-09-19 12:28:56 +00:00
print("Grid requested for laser ", laser)
2024-08-19 19:22:38 +00:00
GridOn(laser)
2019-02-26 10:10:57 +00:00
else:
2020-09-19 12:28:56 +00:00
print("No grid for laser ", laser)
2019-02-26 10:10:57 +00:00
UserOn(laser)
2019-03-10 22:06:04 +00:00
2019-02-26 10:10:57 +00:00
# /ip/lasernumber value
if oscpath[1] == "ip":
2020-09-19 12:28:56 +00:00
print("New IP for laser ", laser)
2019-02-26 10:10:57 +00:00
gstt.lasersIPS[laser]= args[0]
settings.Write()
2024-08-19 19:22:38 +00:00
2019-02-26 10:10:57 +00:00
# /kpps/lasernumber value
# Live change of kpps is not implemented in newdac.py. Change will effect next startup.
if oscpath[1] == "kpps":
2020-09-19 12:28:56 +00:00
print("New kpps for laser ", laser, " next startup", int(args[0]))
2019-02-26 10:10:57 +00:00
gstt.kpps[laser]= int(args[0])
settings.Write()
2023-06-03 12:43:53 +00:00
sendOSCUI('/kpps/' + str(laser), args[0])
2020-09-19 12:28:56 +00:00
r.set('/kpps/' + str(laser), str(args[0]))
r.set('/order/'+str(laser), 7)
2024-08-19 19:22:38 +00:00
# /angle/lasernumber value
2019-02-26 10:10:57 +00:00
if oscpath[1] == "angle":
2020-09-19 12:28:56 +00:00
print("New Angle modification for laser ", oscpath[2], ":", float(args[0]))
2020-10-02 22:15:12 +00:00
gstt.finANGLE[laser] = math.radians(float(args[0]))
2023-06-03 12:43:53 +00:00
sendOSCUI('/angle/' + str(laser), gstt.finANGLE[laser])
2019-02-26 10:10:57 +00:00
NewEDH(laser)
2020-09-19 12:28:56 +00:00
print("New angle", gstt.finANGLE[laser])
2024-08-19 19:22:38 +00:00
# /intens/lasernumber value
2019-02-26 10:10:57 +00:00
if oscpath[1] == "intens":
2020-09-19 12:28:56 +00:00
print("LJ2 : New intensity requested for laser ", laser, ":", int(args[0]))
plugins.sendWSall("/status Intensity " + str(args[0]))
2023-06-03 12:43:53 +00:00
sendOSCUI('/intens/' + str(laser), args[0])
2020-09-19 12:28:56 +00:00
r.set('/intensity/' + str(laser), str(args[0]))
r.set('/order/'+str(laser), 6)
2023-06-03 12:43:53 +00:00
2024-08-19 19:22:38 +00:00
2019-02-26 10:10:57 +00:00
# /resampler/lasernumber lsteps
# lsteps is a string like "[ (1.0, 8),(0.25, 3), (0.75, 3), (1.0, 10)]"
if oscpath[1] == "resampler":
2020-09-19 12:28:56 +00:00
#print"resampler with args", args
Resampler(laser,args)
2024-08-19 19:22:38 +00:00
# /mouse/lasernumber value (0 or 1)
2019-02-26 10:10:57 +00:00
if oscpath[1] == "mouse":
2024-08-19 19:22:38 +00:00
2019-02-26 10:10:57 +00:00
if args[0] == "1":
2020-09-19 12:28:56 +00:00
print("Mouse requested for laser ", oscpath[2])
2019-02-26 10:10:57 +00:00
gstt.Laser = oscpath[2]
else:
2020-09-19 12:28:56 +00:00
print("No mouse for laser ", oscpath[2])
2024-08-19 19:22:38 +00:00
# /swap/X/lasernumber value (0 or 1)
2019-02-26 10:10:57 +00:00
if oscpath[1] == "swap" and oscpath[2] == "X":
2024-08-19 19:22:38 +00:00
2020-09-19 12:28:56 +00:00
print("swapX was", gstt.swapX[laser])
2019-02-26 10:10:57 +00:00
if args[0] == "0":
2020-09-19 12:28:56 +00:00
print("swap X -1 for laser ", laser)
2019-02-26 10:10:57 +00:00
gstt.swapX[laser]= -1
NewEDH(laser)
2024-08-19 19:22:38 +00:00
2019-02-26 10:10:57 +00:00
else:
2020-09-19 12:28:56 +00:00
print("swap X 1 for laser ", laser)
2019-02-26 10:10:57 +00:00
gstt.swapX[laser]= 1
NewEDH(laser)
2024-08-19 19:22:38 +00:00
# /swap/Y/lasernumber value (0 or 1)
2019-02-26 10:10:57 +00:00
if oscpath[1] == "swap" and oscpath[2] == "Y":
2024-08-19 19:22:38 +00:00
2020-09-19 12:28:56 +00:00
print("swapY was", gstt.swapX[laser])
2019-02-26 10:10:57 +00:00
if args[0] == "0":
2020-09-19 12:28:56 +00:00
print("swap Y -1 for laser ", laser)
2019-02-26 10:10:57 +00:00
gstt.swapY[laser]= -1
NewEDH(laser)
else:
2020-09-19 12:28:56 +00:00
print("swap Y 1 for laser ", laser)
2019-02-26 10:10:57 +00:00
gstt.swapY[laser]= 1
NewEDH(laser)
2024-08-19 19:22:38 +00:00
2023-06-03 12:43:53 +00:00
2019-02-26 10:10:57 +00:00
# /loffset/X/lasernumber value
if oscpath[1] == "loffset" and oscpath[2] == "X":
2023-06-03 12:43:53 +00:00
if -32000 < float(args[0]) < 32000:
2020-10-02 22:15:12 +00:00
print("offset/X laser", laser, "modified to", args[0])
2023-06-03 12:43:53 +00:00
gstt.centerX[laser] = float(args[0])
2020-10-02 22:15:12 +00:00
NewEDH(laser)
2024-08-19 19:22:38 +00:00
2023-06-03 12:43:53 +00:00
2019-02-26 10:10:57 +00:00
# /loffset/Y/lasernumber value
if oscpath[1] == "loffset" and oscpath[2] == "Y":
2023-06-03 12:43:53 +00:00
if -32000 < float(args[0]) < 32000:
2020-10-02 22:15:12 +00:00
print("offset/Y laser", laser, "modified to", args[0])
2023-06-03 12:43:53 +00:00
gstt.centerY[laser] = float(args[0])
2020-10-02 22:15:12 +00:00
NewEDH(laser)
2024-08-19 19:22:38 +00:00
2019-02-26 10:10:57 +00:00
# /scale/X/lasernumber value
if oscpath[1] == "scale" and oscpath[2] == "X":
2024-08-19 19:22:38 +00:00
2023-06-03 12:43:53 +00:00
gstt.zoomX[laser] = float(args[0])
2020-09-19 12:28:56 +00:00
print("scale/X laser", laser , "modified to", gstt.zoomX[laser])
2019-02-26 10:10:57 +00:00
NewEDH(laser)
2024-08-19 19:22:38 +00:00
2019-02-26 10:10:57 +00:00
# /scale/Y/lasernumber value
if oscpath[1] == "scale" and oscpath[2] == "Y":
2024-08-19 19:22:38 +00:00
2023-06-03 12:43:53 +00:00
gstt.zoomY[laser] = float(args[0])
2020-09-19 12:28:56 +00:00
print("scale/Y laser", laser, "modified to", gstt.zoomY[laser])
2019-02-26 10:10:57 +00:00
NewEDH(laser)
2018-12-13 11:05:32 +00:00
2020-09-19 12:28:56 +00:00
2023-06-03 12:43:53 +00:00
# OSC UI feedback
def sendOSCUI(oscaddress,oscargs=''):
2024-08-19 19:22:38 +00:00
2023-06-03 12:43:53 +00:00
if gstt.TouchOSCUI == True:
oscmsg = OSC3.OSCMessage()
oscmsg.setAddress(oscaddress)
oscmsg.append(oscargs)
2024-08-19 19:22:38 +00:00
2023-06-03 12:43:53 +00:00
oscui = OSC3.OSCClient()
2024-08-19 19:22:38 +00:00
oscui.connect((gstt.TouchOSCIP, 8001))
2023-06-03 12:43:53 +00:00
#print("main sending OSC UI message :", oscmsg, "to", gstt.TouchOSCIP, ":8001")
if gstt.debug >0:
print("main sending OSC UI message :", oscmsg, "to", gstt.TouchOSCIP, ":8001")
2024-08-19 19:22:38 +00:00
2023-06-03 12:43:53 +00:00
try:
oscui.sendto(oscmsg, (gstt.TouchOSCIP, 8001))
oscmsg.clearData()
2024-08-19 19:22:38 +00:00
2023-06-03 12:43:53 +00:00
except:
print ('Connection to OSC UI refused : died ?')
pass
def UpdateOSCUI(laserid):
sendOSCUI("/ip/" + str(laserid), str(gstt.lasersIPS[laserid]))
sendOSCUI("/kpps/" + str(laserid), str(gstt.kpps[laserid]))
sendOSCUI("/intens/" + str(laserid), str(gstt.intens[laserid]))
sendOSCUI("/red/" + str(laserid), str(gstt.red[laserid]))
sendOSCUI("/green/" + str(laserid), str(gstt.green[laserid]))
sendOSCUI("/blue/" + str(laserid), str(gstt.blue[laserid]))
sendOSCUI("/loffset/X/" + str(laserid), str(gstt.centerX[laserid]))
sendOSCUI("/loffset/Y/" + str(laserid), str(gstt.centerY[laserid]))
sendOSCUI("/scale/X/" + str(laserid), str(gstt.zoomX[laserid]))
sendOSCUI("/scale/Y/" + str(laserid), str(gstt.zoomY[laserid]))
sendOSCUI("/angle/" + str(laserid), str(gstt.finANGLE[laserid]))
sendOSCUI("/type/" + str(laserid), str(gstt.lasertype[laserid]))
if gstt.swapX[laserid] == 1:
sendOSCUI("/swap/X/" + str(laserid), 1)
else:
sendOSCUI("/swap/X/" + str(laserid), 0)
if gstt.swapY[laserid] == 1:
sendOSCUI("/swap/Y/" + str(laserid), 1)
else:
sendOSCUI("/swap/Y/" + str(laserid), 0)
2020-09-19 12:28:56 +00:00
2024-08-19 19:22:38 +00:00
#
2020-09-19 12:28:56 +00:00
# Different useful codes for some commands
#
2020-09-27 23:04:05 +00:00
def Updatepage(file_name):
2020-09-19 12:28:56 +00:00
print("updating", file_name)
f=open(file_name,"r+")
a=f.readlines()
2020-09-27 23:04:05 +00:00
#print a
2020-09-19 12:28:56 +00:00
for line in a:
2020-09-27 23:04:05 +00:00
# python3
IPline = ("var LJ = " in line)
if IPline == True:
2020-09-19 12:28:56 +00:00
p=a.index(line)
#so now we have the position of the line which to be modified
2020-09-27 23:04:05 +00:00
a[p]=" var LJ = 'ws://"+gstt.wwwIP+":9001/'\n"
2020-09-19 12:28:56 +00:00
#print(p, line, a[p])
2020-09-27 23:04:05 +00:00
2020-09-19 12:28:56 +00:00
f.seek(0)
f.truncate() #ersing all data from the file
f.close()
#so now we have an empty file and we will write the modified content now in the file
o=open(file_name,"w")
for i in a:
o.write(i)
o.close()
#now the modification is done in the file
2020-10-06 01:11:02 +00:00
# Not used anymare see configure.py
2020-09-19 12:28:56 +00:00
def UpdateAllwww():
2020-09-27 23:04:05 +00:00
2020-10-06 01:11:02 +00:00
pass
2020-09-27 23:04:05 +00:00
print("Updating www files to use", gstt.wwwIP)
Updatepage(gstt.ljpath+"/www/LJ.js")
Updatepage(gstt.ljpath+"/www/trckr/trckrcam1.html")
Updatepage(gstt.ljpath+"/www/simu.html")
2020-10-10 17:29:07 +00:00
Updatepage(gstt.ljpath+"/www/settings.html")
2020-09-27 23:04:05 +00:00
Updatepage(gstt.ljpath+"/www/auralls.html")
Updatepage(gstt.ljpath+"/www/index.html")
2020-09-19 12:28:56 +00:00
def isOpen(ip):
2024-08-15 16:52:07 +00:00
2020-09-19 12:28:56 +00:00
dacksock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
dacksock.settimeout(1)
istate = False
2024-08-15 16:52:07 +00:00
2020-09-19 12:28:56 +00:00
try:
dacksock.connect((ip, 7765))
#s.shutdown(2)
istate = True
dacksock.shutdown(socket.SHUT_RDWR)
except:
time.sleep(1)
finally:
2024-08-19 19:22:38 +00:00
2020-09-19 12:28:56 +00:00
dacksock.close()
return istate
'''
def isconnected(IP):
ipup = False
for i in range(retry):
if isOpen(IP, 7765):
ipup = True
break
else:
time.sleep(delay)
return ipup
'''
2020-09-29 22:15:40 +00:00
def LJautokill():
log.warn("LJ stopping...")
print(gstt.LaserNumber,"Tracers launched")
2023-07-09 14:09:18 +00:00
for laser in range(gstt.LaserNumber):
if gstt.debug > 0:
print('Shutdown order for tracer '+str(laser), 9)
r.set('/order/'+str(laser), 9)
2024-08-19 19:22:38 +00:00
for (n,dac_worker) in enumerate(workers):
log.warn(f'Entering tracer{n} ...')
dac_worker.join()
2020-09-29 22:15:40 +00:00
lasernumber= gstt.LaserNumber -1
2024-08-19 19:22:38 +00:00
# log.warn("Ending tracer0...")
# worker0.join()
# if lasernumber >0:
# log.warn("Ending tracer1...")
# worker1.join()
# if lasernumber >1:
# log.warn("Ending tracer2...")
# worker2.join()
# if lasernumber >2:
# log.warn("Ending tracer3...")
# worker3.join()
2020-09-29 22:15:40 +00:00
log.warn("Laser feedbacks resetting...")
for laserid in range(0,lasernumber+1):
2024-08-19 19:22:38 +00:00
2020-09-29 22:15:40 +00:00
r.set('/lack/'+str(laserid),64)
r.set('/lstt/'+str(laserid),64)
r.set('/cap/'+str(laserid),0)
2024-08-15 16:52:07 +00:00
2020-09-29 22:15:40 +00:00
log.infog("LJ stopped.")
2020-09-19 12:28:56 +00:00
2020-09-27 23:04:05 +00:00
# autodetect DACs in LJ.conf.
2020-09-19 12:28:56 +00:00
def DAChecks():
gstt.dacs = [-1, -1, -1, -1]
gstt.dacnumber = 0
print("Searching DACs...")
for dac in range(gstt.maxdacs):
if isOpen(gstt.lasersIPS[dac]):
print("DAC", dac, "at", gstt.lasersIPS[dac], ": UP")
2024-08-19 19:22:38 +00:00
gstt.dacs[gstt.dacnumber] = dac
2020-09-19 12:28:56 +00:00
gstt.dacnumber +=1
2024-08-19 19:22:38 +00:00
2020-09-19 12:28:56 +00:00
else:
print("DAC", dac, "at", gstt.lasersIPS[dac], ": DOWN")
2020-09-27 23:04:05 +00:00
'''
2020-09-19 12:28:56 +00:00
# At least one.
if gstt.dacnumber == 0:
gstt.dacs = [0, -1, -1, -1]
gstt.dacnumber = 1
gstt.LaserNumber = gstt.dacnumber
2020-09-27 23:04:05 +00:00
'''
2020-09-19 12:28:56 +00:00
2018-12-13 11:05:32 +00:00
'''
For reference values of EDH modifier if assign to keyboard keys (was alignp)
gstt.centerY[gstt.Laser] -= 20
gstt.centerY[gstt.Laser] += 20
gstt.zoomX[gstt.Laser]-= 0.1
gstt.zoomX[gstt.Laser] += 0.1
gstt.zoomY[gstt.Laser] -= 0.1
2024-08-19 19:22:38 +00:00
2018-12-13 11:05:32 +00:00
gstt.zoomY[gstt.Laser] += 0.1
2024-08-19 19:22:38 +00:00
2018-12-13 11:05:32 +00:00
gstt.sizeX[gstt.Laser] -= 50
2024-08-19 19:22:38 +00:00
2018-12-13 11:05:32 +00:00
gstt.sizeX[gstt.Laser] += 50
2024-08-19 19:22:38 +00:00
2018-12-13 11:05:32 +00:00
gstt.sizeY[gstt.Laser] -= 50
2024-08-19 19:22:38 +00:00
2018-12-13 11:05:32 +00:00
gstt.sizeY[gstt.Laser] += 50
2024-08-19 19:22:38 +00:00
2018-12-13 11:05:32 +00:00
gstt.finANGLE[gstt.Laser] -= 0.001
2024-08-19 19:22:38 +00:00
2018-12-13 11:05:32 +00:00
gstt.finANGLE[gstt.Laser] += 0.001
Code for bit analysis 2 bits / laser to encode order.
# Grid PL is Laser bit 0 = 1 and bit 1 = 1
#order = r.get('/order')
#neworder = order | (1<<laser*2)
#neworder = neworder | (1<< 1+laser*2)
#r.set('/order', str(neworder))
# Laser bit 0 = 0 and bit 1 = 0 : USER PL
#order = r.get('/order')
#neworder = order & ~(1<< laser*2)
#neworder = neworder & ~(1<< 1+ laser*2)
2024-08-19 19:22:38 +00:00
#r.set('/order', str(neworder))
# Laser bit 0 = 0 and bit 1 = 1 : New EDH
#order = r.get('/order')
#neworder = order & ~(1<< laser*2)
#neworder = neworder | (1<< 1+laser*2)
#r.set('/order', str(neworder))
# Black PL is Laser bit 0 = 1 and bit 1 = 0 :
#order = r.get('/order')
#neworder = order | (1<<laser*2)
#neworder = neworder & ~(1<< 1+laser*2)
2018-12-13 11:05:32 +00:00
'''