diff --git a/clients/framy.py b/clients/framy.py index 844ce78..8671be1 100644 --- a/clients/framy.py +++ b/clients/framy.py @@ -105,7 +105,7 @@ def rPolyLineOneColor(xy_list, c, PL , closed, xpos = 0, ypos =0, resize =0.7, r # 0: point list / 1: Grid def LinesPL(PL): - if r.set('/pl/'+str(PL), str(pl[PL])) == True: + if r.set('/pl/0/'+str(PL), str(pl[PL])) == True: return True else: return False diff --git a/clients/nodeclient.js b/clients/nodeclient.js index 7f101b4..6398f68 100644 --- a/clients/nodeclient.js +++ b/clients/nodeclient.js @@ -83,8 +83,8 @@ console.log(pl0); console.log(pl1); // Send points lists to redis server -client.set("/pl/0",pl0); -client.set("/pl/1",pl1); +client.set("/pl/0/0",pl0); +client.set("/pl/0/1",pl1); // Quit client.quit() diff --git a/clients/pyclient.py b/clients/pyclient.py index b43eba6..5eff9ca 100644 --- a/clients/pyclient.py +++ b/clients/pyclient.py @@ -26,12 +26,12 @@ def rgb2int(r,g,b): pl1 = [(100,300,rgb2int(255,255,255)),(200,300,rgb2int(255,255,255)),(200,200,rgb2int(255,255,255)),(100,200,rgb2int(255,255,255))] # Send to laser 0 (see mainy.conf) -r.set('/pl/0', str(pl0)) +r.set('/pl/0/0', str(pl0)) # Send to laser 1 (see mainy.conf) -r.set('/pl/1', str(pl1)) - -r.set('/pl/2', str(pl1)) +r.set('/pl/0/1', str(pl1)) +# Send to laser 2 (see mainy.conf) +r.set('/pl/0/2', str(pl1)) ''' You can also use PolyLineOneColor or rPolylineOneColor to stack n point lists to build a "frame" diff --git a/font1.py b/font1.py new file mode 100755 index 0000000..63403de --- /dev/null +++ b/font1.py @@ -0,0 +1,119 @@ +# coding=UTF-8 +""" + +LJ Font 1 +v0.7.0 + + +LICENCE : CC +by Sam Neurohack +from /team/laser + + +""" +import gstt + +def DigitsDots(number,color): + dots =[] + #print ASCII_GRAPHICS[ord(char) - 48] + for dot in ASCII_GRAPHICS[number]: + #print dot + dots.append((gstt.xy_center[0]+dot[0],gstt.xy_center[1]+dot[1],color)) + #self.point_list.append((xy + (c,))) + return dots + +ASCII_GRAPHICS = [ + +#implementé + + [(-50,30), (-30,-30), (30,-30), (10,30), (-50,30)], #0 + [(-20,30), (0,-30), (-20,30)], #1 + [(-30,-10), (0,-30), (30,-10), (30,0), (-30,30), (30,30)], #2 + [(-30,-30), (0,-30), (30,-10), (0,0), (30,10), (0,30), (-30,30)], #3 + [(30,10), (-30,10), (0,-30), (0,30)], #4 + [(30,-30), (-30,-30), (-30,0), (0,0), (30,10), (0,30), (-30,30)], #5 + [(30,-30), (0,-30), (-30,-10), (-30,30), (0,30), (30,10), (30,0), (-30,0)], #6 + [(-30,-30), (30,-30), (-30,30)], #7 + [(-30,30), (-30,-30), (30,-30), (30,30), (-30,30), (-30,0), (30,0)], #8 + [(30,0), (-30,0), (-30,-10), (0,-30), (30,-30), (30,10), (0,30), (-30,30)], #9 + +# A implementer + [(-30,10), (30,-10), (30,10), (0,30), (-30,10), (-30,-10), (0,-30), (30,-10)], #: + [(-30,-10), (0,-30), (0,30)], [(-30,30), (30,30)], #; + [(-30,-10), (0,-30), (30,-10), (30,0), (-30,30), (30,30)], #< + [(-30,-30), (0,-30), (30,-10), (0,0), (30,10), (0,30), (-30,30)], #= + [(30,10), (-30,10), (0,-30), (0,30)], #> + [(30,-30), (-30,-30), (-30,0), (0,0), (30,10), (0,30), (-30,30)], #? + [(30,-30), (0,-30), (-30,-10), (-30,30), (0,30), (30,10), (30,0), (-30,0)], #@ + +# Implementé + + + [(-30,30), (-30,-30), (30,-30), (30,30), (30,0), (-30,0)], #A + [(-30,30), (-30,-30), (30,-30), (30,30), (30,0), (-30,0)], #A + [(-30,30), (-30,-30), (30,-30), (30,30), (-30,30), (-30,0), (30,0)], #B + [(30,30), (-30,30), (-30,-30), (30,-30)], #C + [(-30,30), (-30,-30), (30,-30), (30,30), (-30,30)], #D + [(30,30), (-30,30), (-30,-0), (30,0), (-30,0), (-30,-30), (30,-30)], #E + [(-30,30), (-30,-0), (30,0), (-30,0), (-30,-30), (30,-30)], #F + [(0,0), (30,0), (30,30), (-30,30), (-30,-30),(30,-30)], #G + [(-30,-30), (-30,30), (-30,0), (30,0), (30,30), (30,-30)], #H + [(0,30), (0,-30)], #I + [(-30,30), (0,-30), (0,-30), (-30,-30), (30,-30)], #J + [(-30,-30), (-30,30), (-30,0), (30,-30), (-30,0), (30,30)], #K + [(30,30), (-30,30), (-30,-30)], #L + [(-30,30), (-30,-30), (0,0), (30,-30), (30,30)], #M + [(-30,30), (-30,-30), (30,30), (30,-30)], #N + [(-30,30), (-30,-30), (30,-30), (30,30), (-30,30)], #O + [(-30,0), (30,0), (30,-30), (-30,-30), (-30,30)], #P + [(30,30), (30,-30), (-30,-30), (-30,30), (30,30),(35,35)], #Q + [(-30,30), (-30,-30), (30,-30), (30,0), (-30,0), (30,30)], #R + [(30,-30), (-30,-30), (-30,0), (30,0), (30,30), (-30,30)], #S + [(0,30), (0,-30), (-30,-30), (30,-30)], #T + [(-30,-30), (-30,30), (30,30), (30,-30)], #U + [(-30,-30), (0,30), (30,-30)], #V + [(-30,-30), (-30,30), (0,0), (30,30), (30,-30)], #W + [(-30,30), (30,-30)], [(-30,-30), (30,30)], #X + [(0,30), (0,0), (30,-30), (0,0), (-30,-30)], #Y + [(30,30), (-30,30), (30,-30), (-30,-30)], #Z + + # A implementer + + [(-30,-10), (0,-30), (0,30)], [(-30,30), (30,30)], #[ + [(-30,-10), (0,-30), (30,-10), (30,0), (-30,30), (30,30)], #\ + [(-30,-30), (0,-30), (30,-10), (0,0), (30,10), (0,30), (-30,30)], #] + [(30,10), (-30,10), (0,-30), (0,30)], #^ + [(30,-30), (-30,-30), (-30,0), (0,0), (30,10), (0,30), (-30,30)], #_ + [(30,-30), (0,-30), (-30,-10), (-30,30), (0,30), (30,10), (30,0), (-30,0)], #` + + # Implementé + + [(-20,20), (-20,-20), (20,-20), (20,20), (20,0), (-20,0)], #a + [(-20,20), (-20,-20), (20,-20), (20,20), (-20,20), (-20,0), (20,0)], #b + [(20,20), (-20,20), (-20,-20), (20,-20)], #c + [(-20,20), (-20,-20), (20,-20), (20,20), (-20,20)], #d + [(20,20), (-20,20), (-20,-0), (20,0), (-20,0), (-20,-20), (20,-20)], #e + [(-20,20), (-20,-0), (20,0), (-20,0), (-20,-20), (20,-20)], #f + [(0,0), (20,0), (20,20), (-20,20), (-20,-20),(20,-20)], #g + [(-20,-20), (-20,20), (-20,0), (20,0), (20,20), (20,-20)], #H + [(0,20), (0,-20)], #I + [(-20,20), (0,-20), (0,-20), (-20,-20), (20,-20)], #J + [(-20,-20), (-20,20), (-20,0), (20,-20), (-20,0), (20,20)], #K + [(20,20), (-20,20), (-20,-20)], #L + [(-20,20), (-20,-20), (0,0), (20,-20), (20,20)], #M + [(-20,20), (-20,-20), (20,20), (20,-20)], #N + [(-20,20), (-20,-20), (20,-20), (20,20), (-20,20)], #O + [(-20,0), (20,0), (20,-20), (-20,-20), (-20,20)], #P + [(20,20), (20,-20), (-20,-20), (-20,20), (20,20),(25,25)], #Q + [(-20,20), (-20,-20), (20,-20), (20,0), (-20,0), (20,20)], #R + [(20,-20), (-20,-20), (-20,0), (20,0), (20,20), (-20,20)], #S + [(0,20), (0,-20), (-20,-20), (20,-20)], #T + [(-20,-20), (-20,20), (20,20), (20,-20)], #U + [(-20,-20), (0,20), (20,-20)], #V + [(-20,-20), (-20,20), (0,0), (20,20), (20,-20)], #W + [(-20,20), (20,-20)], [(-20,-20), (20,20)], #X + [(0,20), (0,0), (20,-20), (0,0), (-20,-20)], #Y + [(20,20), (-20,20), (20,-20), (-20,-20)], #Z + + [(-2,15), (2,15)] # Point a la place de { +] diff --git a/gstt.py b/gstt.py index a48e1be..408c65c 100644 --- a/gstt.py +++ b/gstt.py @@ -1,9 +1,14 @@ # coding=UTF-8 ''' -Etat global (anciennement singleton de la classe GameState + autres VARIABLES nécessaires partout)" -''' -#from globalVars import * +LJ Global state +v0.8.0 + +LICENCE : CC +by Sam Neurohack, Loloster, pclf +from /team/laser + +''' #ConfigName = "setexample.conf" ConfigName = "mainy.conf" @@ -24,15 +29,16 @@ nozoscip = '192.168.1.15' # gstt.Laser select to what laser modifcation will occur. # Can be changed with /noteon 16-23 -Laser = 2 +Laser = 0 -# gstt.simuPL select what point list number to display in pygame simulator +# gstt.simuPL select what point list number to display in webUI simulator # Can be changed with /noteon 24-31 simuPL = 1 # gstt.laserIPS. Will be overridden by the ConfigName (see below) file values lasersIPS = ['192.168.1.5','192.168.1.6','192.168.1.3','192.168.1.4'] +ClientNumber = 1 # gstt.kpps stores kpps for each laser. # ** Will be overridden by the ConfigName (see below) file values ** @@ -57,54 +63,19 @@ lstt_points = [[0], [0], [0], [0]] swapX = [1,1,1,-1] swapY = [1,1,1,-1] -maxCurvesByLaser = 4 - - # For glitch art : change position and decrease number of points added by newdac.py # shortline for lines shorter than 4000 (in etherdream coordinates) # i.e (0.25,3) means add 3 points at 25% on the line. stepshortline = [(1.0, 8)] stepslongline = [(0.25, 3), (0.75, 3), (1.0, 10)] - -#curveColor = [255,0,0] * maxCurvesByLaser -#curveColor = [[0 for _ in range(3)] for _ in range(maxCurvesByLaser)] -curveColor = [[255 for _ in range(3)] for _ in range(maxCurvesByLaser)] -colorX = [[255 for _ in range(3)] for _ in range(maxCurvesByLaser)] -colorY = [[255 for _ in range(3)] for _ in range(maxCurvesByLaser)] -offsetX = [0] * maxCurvesByLaser -offsetY = [0] * maxCurvesByLaser -curveNumber = 0 -Curve = curveNumber -XTimeAxe=30000 -YTimeAxe=30000 - -#curveX = [255,255,255] * maxCurvesByLaser -#curveY = [255,255,255] * maxCurvesByLaser - point = [0,0,0] -# gstt.colormode select what to display. Can be changed with /noteon 57-64 -colormode = 0 -color = [255,255,255] -newcolor = 0 - -surpriseoff = 10 -surpriseon = 50 -surprisey = -10 -surprisex = -10 - - cc = [0] * 256 lfo = [0] * 10 osc = [0] * 255 oscInUse = [0] * 255 knob = [0] * 33 - -stars0=[] -stars1=[] -stars2=[] -#stars3=[] # Viewer distance (cc 21) cc[21]=60 viewer_distance = cc[21] * 8 @@ -116,33 +87,6 @@ fov = 4 * cc[22] JumpFlag =0 -# nice X (cc 5) Y (cc 6) curve at first -cc[5] = cc[6] = 60 - -# Dot mode start at middle screen -cc[1] = cc[2] = 63 - -note = 0 -velocity = 0 - -WingHere = -1 -BhorealHere = -1 -LaunchHere = -1 -BhorLeds = [0] * 64 - -oscx = 0 -oscy = 0 -oscz = 0 - - -# Ai Parameters - -aivelocity = 0.5 -aiexpressivity = 0.5 -aisensibility = 0.5 -aibeauty = 0.5 - - # OSC ports #temporaray fix hack : iport=nozoport iport = 8001 #LJay (bhorosc) input port @@ -152,41 +96,10 @@ nozoport=8001 #nozosc.py sending port to LJay (main.py) nozuport=0 #linux serial usb port connecting nozoid devices ACM0 by default -X = [0] * maxCurvesByLaser -Y = [0] * maxCurvesByLaser - -# No rotation X (cc 29) Y (cc 30) Z (cc 31) at first -cc[29] = cc[30] = cc[31] = prev_cc29 = 0 -prev_cc29 = prev_cc30 = prev_cc31 = -1 - angleX = 0 angleY = 0 angleZ = 0 -tomidi = False # currently tomidi bypass all other directions -todmx = False -toled = False -tolaser = True -tosynth = False - -sernozoid = "" -nozoid = "" -serdmx = "" -newnumber = "" -oldnumber = "" - -''' -# will be overrided but settings.conf values. -# legacy one laser only values -centerx = LASER_CENTER_X -centery = LASER_CENTER_Y -zoomx = LASER_ZOOM_X -zoomy = LASER_ZOOM_Y -sizex = LASER_SIZE_X -sizey = LASER_SIZE_Y -finangle = LASER_ANGLE -''' - # multilasers arrays # will be overrided but settings.conf values. centerX = [0,0,0,0] diff --git a/homographyp.py b/homographyp.py index eff19b3..d2a8f61 100755 --- a/homographyp.py +++ b/homographyp.py @@ -174,17 +174,18 @@ def EDpoint(mylaser,(pygamex,pygamey)): x = (gstt.xy_center[0] + ((XX * CosANGLE) - (YY * SinANGLE)) - gstt.xy_center[0]) * gstt.zoomX[mylaser] + gstt.centerX[mylaser] y = (gstt.xy_center[1] + ((XX * SinANGLE) + (YY * CosANGLE)) - gstt.xy_center[1]) * gstt.zoomY[mylaser] + gstt.centerY[mylaser] - if gstt.debug >0: + if gstt.debug >1: #print "global center :", xy_center - + print "EDpoint computing..." print "Laser :", mylaser, "center at : ", gstt.centerX[mylaser], gstt.centerY[mylaser] + print "Pygame point",pygamex,",",pygamey ''' print "swaps : ", (gstt.swapX[mylaser]), str(gstt.swapY[mylaser]) print "zooms : ", gstt.zoomX[mylaser], gstt.zoomY[mylaser] print "angles : ", gstt.finANGLE[mylaser] ''' - print "result : ", x * gstt.swapX[mylaser] , y * gstt.swapY[mylaser] + print "Result point : ", x * gstt.swapX[mylaser] , y * gstt.swapY[mylaser] return [x * gstt.swapX[mylaser] , y * gstt.swapY[mylaser]] ''' diff --git a/install.sh b/install.sh index c33abcc..ae3f3f8 100644 --- a/install.sh +++ b/install.sh @@ -1,16 +1,10 @@ #!/bin/bash sudo apt install python-pip sudo apt install git -pip uninstall serial -pip uninstall rtmidi -pip install libasound2-dev python-dev libpython-dev libjack-dev -pip install pysimpledmx +sudo apt install redis pip install numpy pip install scipy -pip install mido -pip install python-rtmidi git clone https://github.com/ptone/pyosc --depth 1 /tmp/pyosc && cd /tmp/pyosc && sudo ./setup.py install -pip install pyserial pip install redis diff --git a/las.py b/las.py index 87742d3..b09fdd7 100644 --- a/las.py +++ b/las.py @@ -41,6 +41,9 @@ def NewEDH(laser): print "New EDH requested for laser ", laser settings.Write() + print "Settings saving swapX ", gstt.swapX[laser] + print "Settings saving swapY ", gstt.swapY[laser] + homographyp.newEDH(laser) #r.set('/order/'+str(laser), 1) @@ -79,14 +82,60 @@ def Resampler(laser,lsteps): r.set('/order/'+str(laser), 4) +def LasClientChange(clientnumber): + + # + if r.get("/pl/"+str(clientnumber)+"/0") != None: + + print "Switching to laser client", clientnumber + gstt.ClientNumber = clientnumber + 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: + print "Error : new laser client",clientnumber,"must send points first to","/pl/"+str(clientnumber)+"/0" + + + +def NoteOn(note): + print "NoteOn", note + + # Change laser client + if note < 8: + LasClientChange(note) + + # New PL displayed + if note > 23 and note < 32: + if note - 24 > gstt.LaserNumber -1: + print "Only",gstt.LaserNumber,"asked, you dum ass !" + else: + gstt.Laser = note -24 + print "Current Laser switched to",gstt.Laser + #LasClientChange(gstt.Laser) + + + def handler(oscpath, args): - pathlength = len(oscpath) - if pathlength == 3: - laser = int(oscpath[2]) - else: - laser = int(oscpath[3]) + print "" + print "Handler" + if oscpath[1] == "client" or oscpath[1] =="noteon": + if oscpath[1] == "client": + LasClientChange(int(args[0])) + else: + NoteOn(int(args[0])) + + else: + pathlength = len(oscpath) + if pathlength == 3: + laser = int(oscpath[2]) + else: + laser = int(oscpath[3]) + + print "args[0] :",args[0]," ", type(args[0]) + # /grid/lasernumber value (0 or 1) if oscpath[1] == "grid": @@ -102,13 +151,12 @@ def handler(oscpath, args): if oscpath[1] == "black": if args[0] == "1": - print "Grid requested for laser ", laser + print "Black requested for laser ", laser BlackOn(laser) else: - print "No grid for laser ", laser + print "No black for laser ", laser UserOn(laser) - # /ip/lasernumber value if oscpath[1] == "ip": @@ -120,19 +168,20 @@ def handler(oscpath, args): # /kpps/lasernumber value # Live change of kpps is not implemented in newdac.py. Change will effect next startup. if oscpath[1] == "kpps": - print "New kpps for laser ", laser, " next startup", args[0] + print "New kpps for laser ", laser, " next startup", int(args[0]) gstt.kpps[laser]= int(args[0]) settings.Write() # /angle/lasernumber value if oscpath[1] == "angle": - print "New Angle modification for laser ", oscpath[2], ":", args[0] - gstt.finANGLE[laser] += int(args[0]) + print "New Angle modification for laser ", oscpath[2], ":", float(args[0]) + gstt.finANGLE[laser] += float(args[0]) NewEDH(laser) + "New angle", gstt.finANGLE[laser] # /intens/lasernumber value if oscpath[1] == "intens": - print "New intensity requested for laser ", laser, ":", args[0] + print "New intensity requested for laser ", laser, ":", int(args[0]) print "Change not implemented yet" @@ -156,24 +205,27 @@ def handler(oscpath, args): # /swap/X/lasernumber value (0 or 1) if oscpath[1] == "swap" and oscpath[2] == "X": + print "swapX was", gstt.swapX[laser] if args[0] == "0": - print "swap X : -1 for laser ", laser + print "swap X -1 for laser ", laser gstt.swapX[laser]= -1 NewEDH(laser) else: - print "swap X : 1 for laser ", laser + print "swap X 1 for laser ", laser gstt.swapX[laser]= 1 NewEDH(laser) # /swap/Y/lasernumber value (0 or 1) if oscpath[1] == "swap" and oscpath[2] == "Y": + + print "swapY was", gstt.swapX[laser] if args[0] == "0": - print "swap Y : -1 for laser ", laser + print "swap Y -1 for laser ", laser gstt.swapY[laser]= -1 NewEDH(laser) else: - print "swap Y : 1 for laser ", laser + print "swap Y 1 for laser ", laser gstt.swapY[laser]= 1 NewEDH(laser) diff --git a/mainy.conf b/mainy.conf index 27e1890..ba109d3 100644 --- a/mainy.conf +++ b/mainy.conf @@ -1,8 +1,8 @@ [General] set = 5 curve = 0 -lasernumber = 1 -debug = 1 +lasernumber = 2 +debug = 0 ljayserverip = 127.0.0.1 nozoscip = 127.0.0.1 bhoroscip = 127.0.0.1 @@ -11,15 +11,15 @@ bhoroscip = 127.0.0.1 color = -1 ip = 192.168.1.4 kpps = 25000 -centerx = 0 -centery = -650 -zoomx = 49.2 -zoomy = 65.0 +centerx = -695 +centery = -2156 +zoomx = 32.2 +zoomy = 29.0 sizex = 31450 sizey = 32000 -finangle = 0.0 +finangle = 17.0 swapx = 1 -swapy = 1 +swapy = -1 lsteps = [ (1.0, 8),(0.25, 3), (0.75, 3), (1.0, 10)] warpdest = [[-1500., 1500.], [ 1500., 1500.], @@ -30,20 +30,20 @@ warpdest = [[-1500., 1500.], color = -1 ip = 192.168.1.5 kpps = 25000 -centerx = 0 -centery = 0 -zoomx = 48.5 +centerx = -200 +centery = -357 +zoomx = 81.5 zoomy = 50.1 sizex = 32000 sizey = 32000 finangle = 0.0 -swapx = 1 -swapy = 1 +swapx = -1 +swapy = -1 lsteps = [ (1.0, 8),(0.25, 3), (0.75, 3), (1.0, 10)] warpdest = [[-1500., 1500.], - [ 1500., 1500.], - [ 1500.,-1500.], - [-1500.,-1500.]] + [ 1500., 1500.], + [ 1500.,-1500.], + [-1500.,-1500.]] [laser2] color = -1 diff --git a/mainyservers.py b/mainyservers.py index eacf491..e4f7367 100644 --- a/mainyservers.py +++ b/mainyservers.py @@ -33,6 +33,7 @@ import random, ast import newdacp import homographyp import las +import font1 from OSC import OSCServer, OSCClient, OSCMessage @@ -43,6 +44,7 @@ import types, thread, time r = redis.StrictRedis(host=gstt.LjayServerIP , port=6379, db=0) args =[0,0] + def dac_process(number, pl): while True: try: @@ -68,7 +70,7 @@ def dac_process(number, pl): # webUI server # - +print "Laser client number :",gstt.ClientNumber serverIP = gstt.LjayServerIP print "Redis IP :", serverIP @@ -166,17 +168,20 @@ def sendnozosc(oscaddress,oscargs=''): def handler(path, tags, args, source): oscpath = path.split("/") - print "debug", gstt.debug + print "" + print "OSC said : ", path, oscpath, args + #print "debug", gstt.debug if gstt.debug >0: print "" print "default handler" - print "Bhorosc said : ", path, oscpath, args + print "OSC said : ", path, oscpath, args sendWSall(path + " " + str(args[0])) las.handler(oscpath,args) # RAW OSC Frame available ? def osc_frame(): + #print 'oscframe' # clear timed_out flag oscserver.timed_out = False # handle all pending requests then return @@ -185,17 +190,9 @@ def osc_frame(): -# OSC Thread. Bhorosc handler and Automated status sender to UI. +# OSC Thread. OSC handler and Automated status sender to UI. def osc_thread(): - #print "Will use Redis server IP ", serverIP - - ''' - r = redis.StrictRedis(host=serverIP, port=6379, db=0) - print "Connection to redis server.." - print "Running..." - ''' - while True: try: while True: @@ -234,17 +231,8 @@ def osc_thread(): # last number of points sent to etherdream buffer sendWSall("/points/" + str(laserid) + " " + str(r.get('/cap/'+str(laserid)))) - sendWSall("/plframe/" + str(laserid) + " " + str(r.get('/pl/'+str(laserid)))) - - # WIP Too much packets -> flood webUI : Draw all PL point lists in JS canvas in WebUI - - ''' - for pl in range(0,1): - bhorosc.sendosc("/plframe/" + str(pl),"") - for plpoint in range(0,len(gstt.PL[pl])): - bhorosc.sendosc("/plpoint/" + str(pl),"") - ''' - + print "Sending simu frame from",'/pl/'+str(gstt.ClientNumber)+'/'+str(gstt.Laser) + sendWSall("/plframe" +" "+ r.get('/pl/'+str(gstt.ClientNumber)+'/'+str(gstt.Laser))) except Exception as e: @@ -295,8 +283,9 @@ def message_received(client, server, message): print ("") print("WS Client(%d) said: %s" % (client['id'], message)) + print("WS Client(%d) said: %s" % (client['id'], message)) oscpath = message.split(" ") - args[0] = float(oscpath[1]) + args[0] = str(oscpath[1]) #print oscpath[0].split("/"),oscpath[1] las.handler(oscpath[0].split("/"),args) @@ -306,10 +295,6 @@ def message_received(client, server, message): sendbhorosc("/on") else: sendbhorosc("/off") - else: - - print "sending to bhorosc",oscpath[0],oscpath[1] - sendbhorosc(oscpath[0],oscpath[1]) # if needed a loop back : WS Client -> server -> WS Client #sendWSall("ws"+message) @@ -326,30 +311,23 @@ def sendWSall(message): -# Some random lists for all lasers at launch. +# Some random lists for all lasers at launch for laser client gstt.ClientNumber print "" -print "Creating startup point lists..." +print "Creating startup point lists for client",gstt.ClientNumber,"..." -random_points = [(300.0+random.randint(-100, 100), 200.0+random.randint(-100, 100), 0), (500.0+random.randint(-100, 100), 200.0+random.randint(-100, 100), 65280), (500.0+random.randint(-100, 100), 400.0+random.randint(-100, 100), 65280), (300.0+random.randint(-100, 100), 400.0+random.randint(-100, 100), 65280), (300.0+random.randint(-100, 100), 200.0+random.randint(-100, 100), 65280)] -if r.set('/pl/0', str(random_points)) == True: - print "/pl/0 ", ast.literal_eval(r.get('/pl/0')) -random_points = [(300.0+random.randint(-100, 100), 200.0+random.randint(-100, 100), 0), (500.0+random.randint(-100, 100), 200.0+random.randint(-100, 100), 65280), (500.0+random.randint(-100, 100), 400.0+random.randint(-100, 100), 65280), (300.0+random.randint(-100, 100), 400.0+random.randint(-100, 100), 65280), (300.0+random.randint(-100, 100), 200.0+random.randint(-100, 100), 65280)] -if r.set('/pl/1', str(random_points)) == True: - print "/pl/1 ", ast.literal_eval(r.get('/pl/1')) +digit_points = font1.DigitsDots(gstt.ClientNumber,16711935) -random_points = [(300.0+random.randint(-100, 100), 200.0+random.randint(-100, 100), 0), (500.0+random.randint(-100, 100), 200.0+random.randint(-100, 100), 65280), (500.0+random.randint(-100, 100), 400.0+random.randint(-100, 100), 65280), (300.0+random.randint(-100, 100), 400.0+random.randint(-100, 100), 65280), (300.0+random.randint(-100, 100), 200.0+random.randint(-100, 100), 65280)] -if r.set('/pl/2', str(random_points)) == True: - print "/pl/2 ", ast.literal_eval(r.get('/pl/2')) - -random_points = [(300.0+random.randint(-100, 100), 200.0+random.randint(-100, 100), 0), (500.0+random.randint(-100, 100), 200.0+random.randint(-100, 100), 65280), (500.0+random.randint(-100, 100), 400.0+random.randint(-100, 100), 65280), (300.0+random.randint(-100, 100), 400.0+random.randint(-100, 100), 65280), (300.0+random.randint(-100, 100), 200.0+random.randint(-100, 100), 65280)] -if r.set('/pl/3', str(random_points)) == True: - print "/pl/3 ", ast.literal_eval(r.get('/pl/3')) - -# Order all lasers to show these random shapes at startup -> tell all 4 laser process to USER PLs +# Order all lasers to show the laser client number at startup -> tell all 4 laser process to USER PLs for laserid in range(0,gstt.LaserNumber): + + if r.set('/pl/'+str(gstt.ClientNumber)+'/'+str(laserid), str(digit_points)) == True: + print "/pl/"+str(gstt.ClientNumber)+"/"+str(laserid)+" ", ast.literal_eval(r.get('/pl/'+str(gstt.ClientNumber)+'/'+str(laserid))) + r.set('/order/'+str(laserid), 0) +if r.set("/clientkey","/pl/"+str(gstt.ClientNumber)+"/")==True: + print "sent clientkey : /pl/"+str(gstt.ClientNumber)+"/" print "" print "Etherdream connection check is NOT DISPLAYED" @@ -388,10 +366,12 @@ try: print "Launching OSC server..." print "at", bhoroscIPin, "port",str(bhoroscPORTin) print "Will update webUI dac status every second" - thread.start_new_thread(osc_thread, ()) - + oscserver.addMsgHandler( "/noteon", las.NoteOn ) # Default OSC handler for all OSC incoming message oscserver.addMsgHandler("default", handler) + thread.start_new_thread(osc_thread, ()) + + #print server print "" @@ -430,6 +410,11 @@ finally: print "Fin des haricots" +''' +Some code previously used, for reference : + +random_points = [(300.0+random.randint(-100, 100), 200.0+random.randint(-100, 100), 0), (500.0+random.randint(-100, 100), 200.0+random.randint(-100, 100), 65280), (500.0+random.randint(-100, 100), 400.0+random.randint(-100, 100), 65280), (300.0+random.randint(-100, 100), 400.0+random.randint(-100, 100), 65280), (300.0+random.randint(-100, 100), 200.0+random.randint(-100, 100), 65280)] +''' diff --git a/newdacp.py b/newdacp.py index 68571fd..f2bd1d8 100644 --- a/newdacp.py +++ b/newdacp.py @@ -235,6 +235,8 @@ class DAC(object): #print "init" self.mylaser = mylaser + self.clientkey = r.get("/clientkey") + #print "Laser",self.mylaser,"Got clientkey", self.clientkey #print "DAC", self.mylaser, "Handler process, connecting to", gstt.lasersIPS[mylaser] self.conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.connstatus = self.conn.connect_ex((gstt.lasersIPS[mylaser], port)) @@ -249,17 +251,18 @@ class DAC(object): self.PL = PL # Lower case pl is the actual point list coordinates - self.pl = ast.literal_eval(r.get('/pl/'+str(self.mylaser))) + print "Laser",self.mylaser,"asking for ckey", self.clientkey+str(self.mylaser) + self.pl = ast.literal_eval(r.get(self.clientkey + str(self.mylaser))) #if self.mylaser ==0: #print "DAC Init Laser", self.mylaser #print "pl :", self.pl #print "EDH/"+str(self.mylaser),r.get('/EDH/'+str(self.mylaser)) if r.get('/EDH/'+str(self.mylaser)) == None: - print "Laser",self.mylaser,"NO EDH !! Computing one..." + #print "Laser",self.mylaser,"NO EDH !! Computing one..." homographyp.newEDH(self.mylaser) else: gstt.EDH[self.mylaser] = np.array(ast.literal_eval(r.get('/EDH/'+str(self.mylaser)))) - print "Laser",self.mylaser,"found its EDH in redis" + #print "Laser",self.mylaser,"found its EDH in redis" #print gstt.EDH[self.mylaser] ''' @@ -355,7 +358,8 @@ class DAC(object): if order == 0: # USER point list - self.pl = ast.literal_eval(r.get('/pl/'+str(self.mylaser))) + self.pl = ast.literal_eval(r.get(self.clientkey+str(self.mylaser))) + else: # Get the new EDH @@ -376,7 +380,7 @@ class DAC(object): self.pl = grid_points - # Resampler Modification + # Resampler Change if order == 4: self.resampler = ast.literal_eval(r.get('/resampler/'+str(self.mylaser))) print "newdacp resetting lsteps for", self.mylaser, ":",self.resampler @@ -384,6 +388,16 @@ class DAC(object): gstt.stepslongline[0] = self.resampler[1] gstt.stepslongline[1] = self.resampler[2] gstt.stepslongline[2] = self.resampler[3] + # Back to user point list order + r.set('/order/'+str(self.mylaser), 0) + + # Client Key change + if order == 5: + print "Laser",self.mylaser,"new clientkey", + self.clientkey = r.get('/clientkey') + # Back to user point list order + r.set('/order/'+str(self.mylaser), 0) + ''' diff --git a/settings.py b/settings.py index 479e976..048c6da 100644 --- a/settings.py +++ b/settings.py @@ -40,7 +40,6 @@ def Write(): config.set(laser, 'swapx', str(gstt.swapX[i])) config.set(laser, 'swapy', str(gstt.swapY[i])) config.set(laser, 'warpdest', np.array2string(gstt.warpdest[i], precision=2, separator=',',suppress_small=True)) - config.write(open(gstt.ConfigName,'w')) @@ -76,33 +75,3 @@ print "* Reading", gstt.ConfigName, "setup file.*" config = ConfigParser.ConfigParser() config.read(gstt.ConfigName) - - -# Save all points for a given "shape" (=['Windows','0']) shapecoord is a list -# in any section of the mapping conf file -def MappingWrite(sections, shape, shapecoord): - - shapestr = " ".join(str(x) for x in shapecoord) - config.set(sections[gstt.CurrentSection], shape, shapestr.replace("] [","],[")) - config.write(open(gstt.ConfigName,'w')) - -def MappingWriteSection(sections, shape, shapecoord): - - shapestr = " ".join(str(x) for x in shapecoord) - shapestr = "[" + shapestr.replace("] [","],[") + "]" - config.set(sections, shape, shapestr) - config.write(open(gstt.ConfigName,'w')) - -# Get a list of all points (="Corners") for a given "shape" = [section,option] like ['Windows','0'] -def MappingRead(shape): - archi = ast.literal_eval(config.get(shape[0], shape[1])) - return archi - - -# Get shape numbers (i.e of windows in Windows section) -def Mapping(shape): - return len(config.options(shape)) - -# Get a list of all sections -def MappingSections(): - return config.sections() diff --git a/webui/LJ.js b/webui/LJ.js new file mode 100644 index 0000000..2547c48 --- /dev/null +++ b/webui/LJ.js @@ -0,0 +1,243 @@ +// +// LJ.js v0.7.0 +// + + + +// Web Audio buttons handler + + +// add a listener for each element. + var message=""; + var log=[]; + var knobs = document.getElementsByTagName('webaudio-knob'); + for(var i = 0; i < knobs.length; i++){ + knobs[i].addEventListener("input",Dump,false); + knobs[i].addEventListener("change",Dump,false); + } + var sliders = document.getElementsByTagName('webaudio-slider'); + for(var i = 0; i < sliders.length; i++){ + sliders[i].addEventListener("input",Dump,false); + sliders[i].addEventListener("change",Dump,false); + } + var switches = document.getElementsByTagName('webaudio-switch'); + for(var i = 0; i < switches.length; i++) { + switches[i].addEventListener("change",Dump,false); + } +// Process button events +function Dump(e) { +var str=""; + str=e.type + " : " + e.target.id + " : " + e.target.value + " "; + //console.log(str); + log.unshift(str); + log.length=1; + str=""; + for(var i=19;i>=0;--i) { + if(log[i]) + str+=log[i]+"
"; + } + var evview=document.getElementById("events"); + evview.innerHTML=str; + + if (e.target.id === "noteon" && e.type ==="input") + { + console.log("only noteon change are sent not input"); + } + else + { + console.log(e.target.id) + _WS.send("/" + e.target.id + " " + e.target.value); + } + + // for /scale : after a change (knob is released) reset knob value to 0 + if (e.target.id.substring(0,5) === "scale" && e.type === "change") { + e.target.value = 0; + console.log(e.target.id + "set to 0") + _WS.send("/" + e.target.id + " " + e.target.value); + } + // for /loffset : after a change (knob is released) reset knob value to 0 + if (e.target.id.substring(0,7) === "loffset" && e.type === "change") { + e.target.value = 0; + console.log(e.target.id + "set to 0") + _WS.send("/" + e.target.id + " " + e.target.value); + } + // for /angle : after a change (knob is released) reset knob value to 0 + if (e.target.id.substring(0,5) === "angle" && e.type === "change") { + e.target.value = 0; + console.log(e.target.id + "set to 0") + _WS.send("/" + e.target.id + " " + e.target.value); + } +} + + +// Websocket Handler + +var pl = ""; +var pl2 = new Array(); +var _WS = { + uri: 'ws://127.0.0.1:9001/', + ws: null, + + + init : function (e) { + _WS.s = new WebSocket(_WS.uri); + _WS.s.onopen = function (e) { _WS.onOpen(e); }; + _WS.s.onclose = function (e) { _WS.onClose(e); }; + _WS.s.onmessage = function (e) { _WS.onMessage(e); }; + _WS.s.onerror = function (e) { _WS.onError(e); }; + }, + + onOpen: function () { + _WS.showout(_WS.uri); + _WS.showout('CONNECTED'); + }, + + onClose: function () { + _WS.showout('DISCONNECTED'); + }, + + onMessage: function (e) { + var res = e.data.split(" "); + //console.log(e.data) + switch (res[0].substring(0,6)) { + case "/statu": + _WS.showstatus(e.data.slice(8)); + break; + case "/plfra": + pl = e.data.slice(9); + //console.log(pl); + pl2 = eval(pl.replace(/[()]/g, '')); + //console.log(pl2); + break; + case "/plpoi": + console.log("plpoint"); + break; + case "/clien": + console.log("New Client : "+res[1]) + break + default: + //console.log(res[0] + " " + res[1]) + //console.log(res[1]) + document.getElementById(res[0].slice(1)).value = res[1]; + _WS.showin(e.data); + } + //_WS.showin(e.data); + }, + + onError: function (e) { + _WS.showin('ERROR: ' + e.data); + }, + + showin: function (message) { + var divtext = document.getElementById('showin'); + divtext.innerHTML=""; + divtext.innerHTML= message.toString(); + }, + + showout: function (message) { + var divtext = document.getElementById('showout'); + divtext.innerHTML=""; + divtext.innerHTML= message.toString(); + }, + + showstatus: function (message) { + var divtext = document.getElementById('showstatus'); + divtext.innerHTML=""; + divtext.innerHTML= message.toString(); + }, + + send: function (message) { + if (!message.length) { + alert('Empty message not allowed !'); + } else { + _WS.showout(message); + _WS.s.send(message); + } + }, + + close: function () { + _WS.showout('GOODBYE !'); + _WS.s.close(); + } +}; + +window.addEventListener('load', _WS.init, false); + + +// Menu Handler + +function noMenu() { + // Set all menu button with normal button style + var x = document.getElementById("showalign"); + x.className = "button"; + + var x = document.getElementById("showrun"); + x.className = "button"; + + var x = document.getElementById("showcanvas"); + x.className = "button"; + + var x = document.getElementById("showlive"); + x.className = "button"; + + // Hide all possible main central grids. + var x = document.getElementById("mgalign"); + x.style.display = "none"; + + var x = document.getElementById("mgcanvas"); + x.style.display = "none"; + + var x = document.getElementById("mgrun"); + x.style.display = "none"; + + var x = document.getElementById("mglive"); + x.style.display = "none"; + } + +function showAlign() { + noMenu(); + var x = document.getElementById("mgalign"); + x.style.display = "grid"; + + var x = document.getElementById("showalign"); + x.className = "button:checked"; + } + +function showRun() { + noMenu(); + var x = document.getElementById("mgrun"); + x.style.display = "grid"; + + var x = document.getElementById("showrun"); + x.className = "button:checked"; + } + +function showCanvas() { + noMenu(); + var x = document.getElementById("mgcanvas"); + x.style.display = "block"; + + var x = document.getElementById("showcanvas"); + x.className = "button:checked"; + } + +function showLive() { + noMenu(); + var x = document.getElementById("mglive"); + x.style.display = "grid"; + + var x = document.getElementById("showlive"); + x.className = "button:checked"; + } + +function buttonClicked(clicked_id) { + _WS.send("/" + clicked_id); + } + +function onSubmit(clicked_id) { + var input = document.getElementById(clicked_id); + console.log("/" + clicked_id + " " + input.value); + _WS.send("/" + clicked_id + " " + input.value); + _WS.showout("/" + clicked_id + " " + input.value); + } + \ No newline at end of file diff --git a/webui/index.html b/webui/index.html index 2e4514f..917e669 100644 --- a/webui/index.html +++ b/webui/index.html @@ -3,7 +3,7 @@ - LJay + LJ @@ -22,7 +22,8 @@ + - - -