2018-12-13 11:05:32 +00:00
|
|
|
# coding=UTF-8
|
|
|
|
"""
|
|
|
|
|
|
|
|
LJ OSC handler
|
|
|
|
v0.7.0
|
|
|
|
|
|
|
|
|
|
|
|
LICENCE : CC
|
|
|
|
by Sam Neurohack, Loloster,
|
|
|
|
from /team/laser
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
import types, time
|
|
|
|
import gstt
|
|
|
|
|
|
|
|
#import colorify
|
|
|
|
import homographyp
|
|
|
|
import settings
|
|
|
|
#import alignp
|
|
|
|
import redis
|
|
|
|
|
|
|
|
|
|
|
|
r = redis.StrictRedis(host=gstt.LjayServerIP , port=6379, db=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def UserOn(laser):
|
|
|
|
|
2018-12-14 11:34:41 +00:00
|
|
|
print "User for laser ", laser
|
|
|
|
r.set('/order/'+str(laser), 0)
|
2018-12-13 11:05:32 +00:00
|
|
|
# Laser bit 0 = 0 and bit 1 = 0 : USER PL
|
2018-12-14 11:34:41 +00:00
|
|
|
#order = r.get('/order')
|
|
|
|
#neworder = order & ~(1<< laser*2)
|
|
|
|
#neworder = neworder & ~(1<< 1+ laser*2)
|
|
|
|
#r.set('/order', str(neworder))
|
|
|
|
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2018-12-14 11:34:41 +00:00
|
|
|
def NewEDH(laser):
|
|
|
|
|
2018-12-15 19:03:32 +00:00
|
|
|
print "New EDH requested for laser ", laser
|
2018-12-14 11:34:41 +00:00
|
|
|
settings.Write()
|
2018-12-18 01:45:23 +00:00
|
|
|
print "Settings saving swapX ", gstt.swapX[laser]
|
|
|
|
print "Settings saving swapY ", gstt.swapY[laser]
|
|
|
|
|
2018-12-15 19:03:32 +00:00
|
|
|
homographyp.newEDH(laser)
|
|
|
|
|
|
|
|
#r.set('/order/'+str(laser), 1)
|
2018-12-14 11:34:41 +00:00
|
|
|
# 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))
|
2018-12-13 11:05:32 +00:00
|
|
|
|
|
|
|
def BlackOn(laser):
|
|
|
|
|
|
|
|
print "Black for laser ", laser
|
2018-12-14 11:34:41 +00:00
|
|
|
r.set('/order/'+str(laser), 2)
|
2018-12-13 11:05:32 +00:00
|
|
|
# Black PL is Laser bit 0 = 1 and bit 1 = 0 :
|
2018-12-14 11:34:41 +00:00
|
|
|
#order = r.get('/order')
|
|
|
|
#neworder = order | (1<<laser*2)
|
|
|
|
#neworder = neworder & ~(1<< 1+laser*2)
|
|
|
|
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2018-12-14 11:34:41 +00:00
|
|
|
def GridOn(laser):
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2018-12-14 11:34:41 +00:00
|
|
|
print "Grid for laser ", laser
|
|
|
|
r.set('/order/'+str(laser), 3)
|
|
|
|
# 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))
|
2018-12-13 11:05:32 +00:00
|
|
|
|
|
|
|
|
2018-12-15 19:03:32 +00:00
|
|
|
def Resampler(laser,lsteps):
|
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)]"
|
2018-12-14 11:34:41 +00:00
|
|
|
print "Resampler change for laser ", laser
|
2018-12-15 19:03:32 +00:00
|
|
|
r.set('/resampler/' + str(laser), lsteps)
|
2018-12-14 11:34:41 +00:00
|
|
|
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:
|
|
|
|
|
|
|
|
print "Switching to laser client", clientnumber
|
2018-12-19 11:39:54 +00:00
|
|
|
gstt.LasClientNumber = clientnumber
|
2018-12-18 01:45:23 +00:00
|
|
|
r.set('/clientkey', "/pl/"+str(clientnumber)+"/")
|
|
|
|
print "clientkey set to", "/pl/"+str(clientnumber)+"/"
|
|
|
|
for laserid in xrange(0,gstt.LaserNumber):
|
|
|
|
r.set('/order/'+str(laserid), 5)
|
|
|
|
else:
|
2018-12-19 11:39:54 +00:00
|
|
|
print "ERROR : MaxLasClient is set to ", gstt.MaxLasClient
|
2018-12-18 01:45:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def NoteOn(note):
|
|
|
|
print "NoteOn", note
|
|
|
|
|
|
|
|
# Change laser client
|
|
|
|
if note < 8:
|
|
|
|
LasClientChange(note)
|
|
|
|
|
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:
|
2018-12-19 11:39:54 +00:00
|
|
|
print "Only",gstt.LaserNumber,"lasers asked, you dum ass !"
|
2018-12-18 01:45:23 +00:00
|
|
|
else:
|
|
|
|
gstt.Laser = note -24
|
|
|
|
print "Current Laser switched to",gstt.Laser
|
2018-12-19 11:39:54 +00:00
|
|
|
|
2018-12-18 01:45:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-14 11:34:41 +00:00
|
|
|
def handler(oscpath, args):
|
|
|
|
|
2018-12-18 01:45:23 +00:00
|
|
|
print ""
|
|
|
|
print "Handler"
|
|
|
|
|
|
|
|
if oscpath[1] == "client" or oscpath[1] =="noteon":
|
|
|
|
if oscpath[1] == "client":
|
|
|
|
LasClientChange(int(args[0]))
|
|
|
|
else:
|
|
|
|
NoteOn(int(args[0]))
|
|
|
|
|
2018-12-13 11:05:32 +00:00
|
|
|
else:
|
2018-12-18 01:45:23 +00:00
|
|
|
pathlength = len(oscpath)
|
|
|
|
if pathlength == 3:
|
|
|
|
laser = int(oscpath[2])
|
|
|
|
else:
|
|
|
|
laser = int(oscpath[3])
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2018-12-18 01:45:23 +00:00
|
|
|
print "args[0] :",args[0]," ", type(args[0])
|
|
|
|
|
2018-12-13 11:05:32 +00:00
|
|
|
# /grid/lasernumber value (0 or 1)
|
|
|
|
if oscpath[1] == "grid":
|
|
|
|
|
|
|
|
if args[0] == "1":
|
|
|
|
print "Grid requested for laser ", laser
|
|
|
|
GridOn(laser)
|
|
|
|
else:
|
|
|
|
print "No grid for laser ", laser
|
|
|
|
UserOn(laser)
|
|
|
|
|
|
|
|
|
|
|
|
# /black/lasernumber value (0 or 1)
|
|
|
|
if oscpath[1] == "black":
|
|
|
|
|
|
|
|
if args[0] == "1":
|
2018-12-18 01:45:23 +00:00
|
|
|
print "Black requested for laser ", laser
|
2018-12-13 11:05:32 +00:00
|
|
|
BlackOn(laser)
|
|
|
|
else:
|
2018-12-18 01:45:23 +00:00
|
|
|
print "No black for laser ", laser
|
2018-12-13 11:05:32 +00:00
|
|
|
UserOn(laser)
|
|
|
|
|
|
|
|
|
|
|
|
# /ip/lasernumber value
|
|
|
|
if oscpath[1] == "ip":
|
|
|
|
print "New IP for laser ", laser
|
|
|
|
gstt.lasersIPS[laser]= args[0]
|
2018-12-15 19:03:32 +00:00
|
|
|
settings.Write()
|
|
|
|
|
2018-12-13 11:05:32 +00:00
|
|
|
|
|
|
|
# /kpps/lasernumber value
|
|
|
|
# Live change of kpps is not implemented in newdac.py. Change will effect next startup.
|
|
|
|
if oscpath[1] == "kpps":
|
2018-12-18 01:45:23 +00:00
|
|
|
print "New kpps for laser ", laser, " next startup", int(args[0])
|
2018-12-13 11:05:32 +00:00
|
|
|
gstt.kpps[laser]= int(args[0])
|
2018-12-15 19:03:32 +00:00
|
|
|
settings.Write()
|
2018-12-13 11:05:32 +00:00
|
|
|
|
|
|
|
# /angle/lasernumber value
|
|
|
|
if oscpath[1] == "angle":
|
2018-12-18 01:45:23 +00:00
|
|
|
print "New Angle modification for laser ", oscpath[2], ":", float(args[0])
|
|
|
|
gstt.finANGLE[laser] += float(args[0])
|
2018-12-13 11:05:32 +00:00
|
|
|
NewEDH(laser)
|
2018-12-18 01:45:23 +00:00
|
|
|
"New angle", gstt.finANGLE[laser]
|
2018-12-13 11:05:32 +00:00
|
|
|
|
|
|
|
# /intens/lasernumber value
|
|
|
|
if oscpath[1] == "intens":
|
2018-12-18 01:45:23 +00:00
|
|
|
print "New intensity requested for laser ", laser, ":", int(args[0])
|
2018-12-13 11:05:32 +00:00
|
|
|
print "Change not implemented yet"
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-15 19:03:32 +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":
|
|
|
|
Resampler(laser,args[0])
|
|
|
|
|
|
|
|
|
2018-12-13 11:05:32 +00:00
|
|
|
# /mouse/lasernumber value (0 or 1)
|
|
|
|
if oscpath[1] == "mouse":
|
|
|
|
|
|
|
|
if args[0] == "1":
|
|
|
|
print "Mouse requested for laser ", oscpath[2]
|
|
|
|
gstt.Laser = oscpath[2]
|
|
|
|
else:
|
|
|
|
print "No mouse for laser ", oscpath[2]
|
|
|
|
|
|
|
|
|
|
|
|
# /swap/X/lasernumber value (0 or 1)
|
|
|
|
if oscpath[1] == "swap" and oscpath[2] == "X":
|
|
|
|
|
2018-12-18 01:45:23 +00:00
|
|
|
print "swapX was", gstt.swapX[laser]
|
2018-12-13 11:05:32 +00:00
|
|
|
if args[0] == "0":
|
2018-12-18 01:45:23 +00:00
|
|
|
print "swap X -1 for laser ", laser
|
2018-12-13 11:05:32 +00:00
|
|
|
gstt.swapX[laser]= -1
|
|
|
|
NewEDH(laser)
|
|
|
|
|
|
|
|
else:
|
2018-12-18 01:45:23 +00:00
|
|
|
print "swap X 1 for laser ", laser
|
2018-12-13 11:05:32 +00:00
|
|
|
gstt.swapX[laser]= 1
|
|
|
|
NewEDH(laser)
|
|
|
|
|
|
|
|
# /swap/Y/lasernumber value (0 or 1)
|
|
|
|
if oscpath[1] == "swap" and oscpath[2] == "Y":
|
2018-12-18 01:45:23 +00:00
|
|
|
|
|
|
|
print "swapY was", gstt.swapX[laser]
|
2018-12-13 11:05:32 +00:00
|
|
|
if args[0] == "0":
|
2018-12-18 01:45:23 +00:00
|
|
|
print "swap Y -1 for laser ", laser
|
2018-12-13 11:05:32 +00:00
|
|
|
gstt.swapY[laser]= -1
|
|
|
|
NewEDH(laser)
|
|
|
|
else:
|
2018-12-18 01:45:23 +00:00
|
|
|
print "swap Y 1 for laser ", laser
|
2018-12-13 11:05:32 +00:00
|
|
|
gstt.swapY[laser]= 1
|
|
|
|
NewEDH(laser)
|
|
|
|
|
|
|
|
# /loffset/X/lasernumber value
|
|
|
|
if oscpath[1] == "loffset" and oscpath[2] == "X":
|
2018-12-15 19:03:32 +00:00
|
|
|
print "offset/X laser", laser, "modified to", args[0]
|
2018-12-13 11:05:32 +00:00
|
|
|
gstt.centerX[laser] -= int(args[0])
|
|
|
|
NewEDH(laser)
|
|
|
|
|
|
|
|
# /loffset/Y/lasernumber value
|
|
|
|
if oscpath[1] == "loffset" and oscpath[2] == "Y":
|
2018-12-15 19:03:32 +00:00
|
|
|
print "offset/Y laser", laser, "modified to", args[0]
|
2018-12-13 11:05:32 +00:00
|
|
|
gstt.centerY[laser] -= int(args[0])
|
|
|
|
NewEDH(laser)
|
|
|
|
|
|
|
|
|
|
|
|
# /scale/X/lasernumber value
|
|
|
|
if oscpath[1] == "scale" and oscpath[2] == "X":
|
2018-12-15 19:03:32 +00:00
|
|
|
print "scale/X laser", laser , "modified to", args[0]
|
2018-12-13 11:05:32 +00:00
|
|
|
gstt.zoomX[laser] += int(args[0])
|
|
|
|
NewEDH(laser)
|
|
|
|
|
|
|
|
# /scale/Y/lasernumber value
|
|
|
|
if oscpath[1] == "scale" and oscpath[2] == "Y":
|
2018-12-15 19:03:32 +00:00
|
|
|
print "scale/Y laser", laser, "modified to", args[0]
|
2018-12-13 11:05:32 +00:00
|
|
|
gstt.zoomY[laser] += int(args[0])
|
|
|
|
NewEDH(laser)
|
|
|
|
|
|
|
|
'''
|
|
|
|
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
|
|
|
|
|
|
|
|
gstt.zoomY[gstt.Laser] += 0.1
|
|
|
|
|
|
|
|
gstt.sizeX[gstt.Laser] -= 50
|
|
|
|
|
|
|
|
gstt.sizeX[gstt.Laser] += 50
|
|
|
|
|
|
|
|
gstt.sizeY[gstt.Laser] -= 50
|
|
|
|
|
|
|
|
gstt.sizeY[gstt.Laser] += 50
|
|
|
|
|
|
|
|
gstt.finANGLE[gstt.Laser] -= 0.001
|
|
|
|
|
|
|
|
gstt.finANGLE[gstt.Laser] += 0.001
|
|
|
|
'''
|