Merge branch 'master' of https://github.com/tmpbci/LJ
This commit is contained in:
commit
4a2d1a5773
4
LJ.conf
4
LJ.conf
@ -1,13 +1,13 @@
|
||||
[General]
|
||||
lasernumber = 4
|
||||
debug = 2
|
||||
debug = 0
|
||||
ljayserverip = 127.0.0.1
|
||||
nozoscip = 127.0.0.1
|
||||
bhoroscip = 127.0.0.1
|
||||
|
||||
[laser0]
|
||||
color = -1
|
||||
ip = 192.168.1.4
|
||||
ip = 127.0.0.1
|
||||
kpps = 25000
|
||||
centerx = -1610
|
||||
centery = 0
|
||||
|
12
commands.py
12
commands.py
@ -87,7 +87,7 @@ import plugins
|
||||
|
||||
r = redis.StrictRedis(host=gstt.LjayServerIP , port=6379, db=0)
|
||||
|
||||
GenericCommands = ["start","ljclient","clientnumber","noteon","ljpong","ljwars","mouse","emergency","simu","status","run","nozoid","planet","live","words","ai","bank0","pose","lj","cycl","glyph"]
|
||||
GenericCommands = ["start","ljclient","clientnumber","noteon","ljpong","ljwars","mouse","emergency","simu","status","run","nozoid","planet","live","words","ai","bank0","pose","lj","cycl","glyph","pong"]
|
||||
|
||||
|
||||
|
||||
@ -180,22 +180,28 @@ def handler(oscpath, args):
|
||||
|
||||
if oscpath[1] in GenericCommands:
|
||||
|
||||
print "GenericCommand :",oscpath[1],"with args",args
|
||||
|
||||
if oscpath[1] == "ljclient":
|
||||
LasClientChange(int(args[0]))
|
||||
|
||||
|
||||
elif oscpath[1] == "noteon":
|
||||
NoteOn(int(args[0]))
|
||||
|
||||
|
||||
elif oscpath[1] == "pong":
|
||||
print "LJ commands got pong from", args
|
||||
plugins.sendWSall("/" + args[0] + "start 1")
|
||||
plugins.sendWSall("/status got pong from "+ args[0] +".")
|
||||
|
||||
|
||||
elif oscpath[1] == "mouse":
|
||||
Mouse(int(args[0]),int(args[1]),int(args[2]),int(args[3]))
|
||||
|
||||
|
||||
# /emergency value (0 or 1)
|
||||
if oscpath[1] == "emergency":
|
||||
elif oscpath[1] == "emergency":
|
||||
|
||||
if args[0] == "1":
|
||||
|
||||
@ -209,6 +215,8 @@ def handler(oscpath, args):
|
||||
print "Back to normal for laser ", laser
|
||||
UserOn(laser)
|
||||
|
||||
|
||||
|
||||
# Commands with a laser number
|
||||
else:
|
||||
pathlength = len(oscpath)
|
||||
|
96
main.py
96
main.py
@ -92,8 +92,8 @@ print "Laser client number :",gstt.LasClientNumber
|
||||
serverIP = gstt.LjayServerIP
|
||||
print "Redis IP :", serverIP
|
||||
|
||||
extoscIP = gstt.oscIPin
|
||||
print "extosc IP :", extoscIP
|
||||
oscserverIP = gstt.oscIPin
|
||||
print "OSCserver IP :", oscserverIP
|
||||
|
||||
nozoscIP = gstt.nozoscip
|
||||
print "Nozosc IP :", nozoscIP
|
||||
@ -108,36 +108,34 @@ print "Lasers requested :", gstt.LaserNumber
|
||||
# Websocket listening port
|
||||
wsPORT = 9001
|
||||
|
||||
# With extosc
|
||||
# oscserver
|
||||
# OSC Server : accept OSC message on port 8002
|
||||
#oscIPin = "192.168.1.10"s
|
||||
extoscIPin = serverIP
|
||||
oscserverIPin = serverIP
|
||||
|
||||
print "extoscIPin", extoscIPin
|
||||
extoscPORTin = 8002
|
||||
print "oscserverIPin", oscserverIPin
|
||||
oscserverPORTin = 8002
|
||||
|
||||
# OSC Client : to send OSC message to an IP port 8001
|
||||
extoscIPout = extoscIP
|
||||
extoscPORTout = 8001
|
||||
oscserverIPout = oscserverIP
|
||||
oscserverPORTout = 8001
|
||||
|
||||
|
||||
# With Nozoid
|
||||
# OSC Client : to send OSC message to Nozoid inport 8003
|
||||
# Nozoid OSC Client : to send OSC message to Nozoid inport 8003
|
||||
NozoscIPout = nozoscIP
|
||||
NozoscPORTout = plugins.Port("nozoid")
|
||||
|
||||
|
||||
# With Planetarium
|
||||
# OSC Client : to send OSC message to planetarium inport 8005
|
||||
# Planetarium OSC Client : to send OSC message to planetarium inport 8005
|
||||
planetIPout = nozoscIP
|
||||
planetPORTout = plugins.Port("planet")
|
||||
|
||||
# With Bank0
|
||||
# OSC Client : to send OSC message to bank0 inport 8010
|
||||
# Bank0 OSC Client : to send OSC message to bank0 inport 8010
|
||||
bank0IPout = nozoscIP
|
||||
bank0PORTout = plugins.Port("bank0")
|
||||
|
||||
oscserver = OSCServer( (extoscIPin, extoscPORTin) )
|
||||
|
||||
oscserver = OSCServer( (oscserverIPin, oscserverPORTin) )
|
||||
oscserver.timeout = 0
|
||||
OSCRunning = True
|
||||
|
||||
@ -150,23 +148,23 @@ oscserver.handle_timeout = types.MethodType(handle_timeout, oscserver)
|
||||
'''
|
||||
osclientext = OSCClient()
|
||||
oscmsg = OSCMessage()
|
||||
osclientext.connect((extoscIPout, extoscPORTout))
|
||||
osclientext.connect((oscserverIPout, oscserverPORTout))
|
||||
|
||||
# send UI string as OSC message to extosc 8001
|
||||
# sendextosc(oscaddress, [arg1, arg2,...])
|
||||
# send UI string as OSC message to oscserver 8001
|
||||
# sendoscserver(oscaddress, [arg1, arg2,...])
|
||||
|
||||
def sendextosc(oscaddress,oscargs=''):
|
||||
def sendoscserver(oscaddress,oscargs=''):
|
||||
|
||||
oscmsg = OSCMessage()
|
||||
oscmsg.setAddress(oscaddress)
|
||||
oscmsg.append(oscargs)
|
||||
|
||||
#print ("sending to extosc : ",oscmsg)
|
||||
#print ("sending to oscserver : ",oscmsg)
|
||||
try:
|
||||
osclientext.sendto(oscmsg, (extoscIPout, extoscPORTout))
|
||||
osclientext.sendto(oscmsg, (oscserverIPout, oscserverPORTout))
|
||||
oscmsg.clearData()
|
||||
except:
|
||||
print ('Connection to extosc IP', extoscIPout, 'port', extoscPORTout,'refused : died ?')
|
||||
print ('Connection to oscserver IP', oscserverIPout, 'port', oscserverPORTout,'refused : died ?')
|
||||
sendWSall("/on 0")
|
||||
sendWSall("/status NoLJay")
|
||||
|
||||
@ -268,6 +266,22 @@ def osc_frame():
|
||||
while not oscserver.timed_out:
|
||||
oscserver.handle_request()
|
||||
|
||||
def PingAll():
|
||||
|
||||
for plugin in gstt.plugins.keys():
|
||||
|
||||
# Plugin Online
|
||||
if plugins.Ping(plugin):
|
||||
|
||||
sendWSall("/"+ plugin + "/start 1")
|
||||
if gstt.debug >0:
|
||||
print "plugin", plugin, "answered."
|
||||
|
||||
# Plugin Offline
|
||||
else:
|
||||
sendWSall("/"+ plugin + "/start 0")
|
||||
if gstt.debug >0:
|
||||
print "plugin", plugin, "didn't answered."
|
||||
|
||||
|
||||
# OSC server Thread : handler, dacs reports and simulator points sender to UI.
|
||||
@ -367,27 +381,23 @@ def message_received(client, wserver, message):
|
||||
print("")
|
||||
|
||||
oscpath = message.split(" ")
|
||||
if gstt.debug > 0:
|
||||
print "WS Client", client['id'], "said :", message, "splitted in an oscpath :", oscpath
|
||||
PingAll()
|
||||
message4plugin = False
|
||||
|
||||
# WS received Message is for a plugin ?
|
||||
|
||||
# Ping all plugins connexion and send message if right plugin is online.
|
||||
for plugin in gstt.plugins.keys():
|
||||
|
||||
# Plugin Online
|
||||
if plugins.Ping(plugin):
|
||||
if oscpath[0].find(plugin) != -1:
|
||||
|
||||
sendWSall("/"+ plugin + "/start 1")
|
||||
if gstt.debug >0:
|
||||
print "plugin", plugin, "answered."
|
||||
|
||||
if oscpath[0].find(plugin) != -1 and plugins.Send(plugin,oscpath):
|
||||
message4plugin = True
|
||||
if plugins.Send(plugin,oscpath):
|
||||
print "message sent correctly to", plugin
|
||||
|
||||
# Plugin Offline
|
||||
else:
|
||||
sendWSall("/"+ plugin + "/start 0")
|
||||
if gstt.debug >0:
|
||||
print "plugin", plugin, "didn't answered."
|
||||
plugins.sendWSall("/status Running...")
|
||||
|
||||
#plugins.sendWSall("/status Running...")
|
||||
|
||||
'''
|
||||
if plugins.Send("planet",oscpath):
|
||||
@ -416,11 +426,15 @@ def message_received(client, wserver, message):
|
||||
|
||||
if oscpath[0] == "/on":
|
||||
if oscpath[1] == "1":
|
||||
sendextosc("/on")
|
||||
sendoscserver("/on")
|
||||
else:
|
||||
sendextosc("/off")
|
||||
sendoscserver("/off")
|
||||
'''
|
||||
|
||||
# WS received message is an LJ command
|
||||
|
||||
if message4plugin == False:
|
||||
|
||||
if len(oscpath) == 1:
|
||||
args[0] = "noargs"
|
||||
#print "noargs command"
|
||||
@ -432,6 +446,8 @@ def message_received(client, wserver, message):
|
||||
|
||||
commands.handler(oscpath[0].split("/"),args)
|
||||
|
||||
print ""
|
||||
|
||||
|
||||
'''
|
||||
# I message included "nozoid" forward the message as OSC to nozoid IP port 8003
|
||||
@ -540,10 +556,10 @@ try:
|
||||
wserver = WebsocketServer(wsPORT,host=serverIP)
|
||||
plugins.Init(wserver)
|
||||
|
||||
# Launch OSC thread listening to extosc
|
||||
# Launch OSC thread listening to oscserver
|
||||
print ""
|
||||
print "Launching OSC server..."
|
||||
print "at", extoscIPin, "port",str(extoscPORTin)
|
||||
print "at", oscserverIPin, "port",str(oscserverPORTin)
|
||||
print "Will update webUI dac status every second"
|
||||
oscserver.addMsgHandler( "/noteon", commands.NoteOn )
|
||||
# Default OSC handler for all OSC incoming message
|
||||
|
34
plugins.py
34
plugins.py
@ -83,13 +83,9 @@ def Start(name):
|
||||
|
||||
def OSCsend(name, oscaddress, oscargs =''):
|
||||
|
||||
#print "OSCsend in plugins got for", name, ": oscaddress", oscaddress, "oscargs :", oscargs
|
||||
PluginPort = Port(name)
|
||||
sendWSall("/status Checking "+ name + "...")
|
||||
if gstt.debug >1:
|
||||
print ""
|
||||
print "OSCSend is checking plugin", name, "..."
|
||||
print "Plugin", name, "is at", gstt.LjayServerIP, ":" + str(PluginPort)
|
||||
print "Sending", oscaddress, oscargs,"to plugin", name
|
||||
#sendWSall("/status Checking "+ name + "...")
|
||||
|
||||
osclientplugin = OSCClient()
|
||||
osclientplugin.connect((gstt.LjayServerIP, PluginPort))
|
||||
@ -98,6 +94,9 @@ def OSCsend(name, oscaddress, oscargs =''):
|
||||
oscmsg.append(oscargs)
|
||||
|
||||
try:
|
||||
if gstt.debug > 0:
|
||||
print "OSCSend : sending", oscmsg,"to plugin", name, "at", gstt.LjayServerIP, ":", PluginPort
|
||||
|
||||
osclientplugin.sendto(oscmsg, (gstt.LjayServerIP, PluginPort))
|
||||
oscmsg.clearData()
|
||||
#if gstt.debug >0:
|
||||
@ -108,15 +107,17 @@ def OSCsend(name, oscaddress, oscargs =''):
|
||||
if gstt.debug > 0:
|
||||
print 'OSCSend : Connection to plugin IP', gstt.LjayServerIP ,':', PluginPort,'refused : died ?'
|
||||
#sendWSall("/status No plugin.")
|
||||
sendWSall("/status " + name + " is offline")
|
||||
sendWSall("/" + name + "/start 0")
|
||||
#sendWSall("/status " + name + " is offline")
|
||||
#sendWSall("/" + name + "/start 0")
|
||||
#PluginStart(name)
|
||||
return False
|
||||
|
||||
|
||||
def Ping(name):
|
||||
|
||||
return OSCsend(name,"/ping")
|
||||
|
||||
sendWSall("/"+ name + "/start 0")
|
||||
return OSCsend(name,"/ping",1)
|
||||
#return True
|
||||
|
||||
|
||||
@ -138,7 +139,7 @@ def Kill(name):
|
||||
|
||||
|
||||
# Send a command to given plugin. Will also start it if command contain /start 1
|
||||
def Send(name,oscpath):
|
||||
def Send(name, oscpath):
|
||||
|
||||
|
||||
if oscpath[0].find(name) != -1:
|
||||
@ -147,11 +148,10 @@ def Send(name,oscpath):
|
||||
if Ping(name):
|
||||
|
||||
# Light up the plugin button
|
||||
sendWSall("/" + name + "/start 1")
|
||||
sendWSall("/status " + name + " online")
|
||||
if gstt.debug >0:
|
||||
print "Plugin " + name + " online."
|
||||
print "Command", oscpath
|
||||
#sendWSall("/" + name + "/start 1")
|
||||
#sendWSall("/status " + name + " online")
|
||||
if gstt.debug > 0:
|
||||
print "Send got", oscpath, "for plugin", name, "currently online."
|
||||
|
||||
|
||||
# If start 0, try to kill plugin
|
||||
@ -163,9 +163,9 @@ def Send(name,oscpath):
|
||||
|
||||
# Send osc command
|
||||
elif len(oscpath) == 1:
|
||||
OSCsend(name,oscpath[0], oscargs='noargs')
|
||||
OSCsend(name, oscpath[0], oscargs='noargs')
|
||||
else:
|
||||
OSCsend(name,oscpath[0], oscargs=oscpath[1])
|
||||
OSCsend(name, oscpath[0], oscargs=oscpath[1])
|
||||
return True
|
||||
|
||||
# Plugin not online..
|
||||
|
@ -719,6 +719,13 @@ def OSCquit():
|
||||
def WebStatus(message):
|
||||
lj3.SendLJ("/status",message)
|
||||
|
||||
# /pose/ping value
|
||||
def OSCping(value):
|
||||
print("bank0 got /pose/ping with value", value)
|
||||
lj3.OSCping("bank0")
|
||||
|
||||
'''
|
||||
|
||||
|
||||
|
||||
print('Loading Bank0...')
|
||||
@ -731,7 +738,7 @@ osc_startup()
|
||||
osc_udp_server("127.0.0.1", OSCinPort, "InPort")
|
||||
|
||||
osc_method("/bank0/run*", OSCrun)
|
||||
osc_method("/bank0/ping*", lj3.OSCping)
|
||||
osc_method("/bank0/ping*", OSCping)
|
||||
osc_method("/bank0/ljclient", OSCljclient)
|
||||
osc_method("/bank0/ljpl", OSCpl)
|
||||
osc_method("/quit", OSCquit)
|
||||
|
@ -25,7 +25,7 @@ from datetime import datetime
|
||||
from random import randrange
|
||||
import redis
|
||||
import lj3
|
||||
import sys,time
|
||||
import sys,time,traceback
|
||||
import os
|
||||
|
||||
from osc4py3.as_eventloop import *
|
||||
@ -34,7 +34,8 @@ from osc4py3 import oscbuildparse
|
||||
from osc4py3.oscmethod import *
|
||||
import argparse
|
||||
|
||||
|
||||
# 0.25 : each frame will be repeated 4 times.
|
||||
animspeed = 0.25
|
||||
|
||||
screen_size = [700,700]
|
||||
xy_center = [screen_size[0]/2,screen_size[1]/2]
|
||||
@ -44,9 +45,12 @@ OSCinPort = 8011
|
||||
|
||||
ljclient = 0
|
||||
|
||||
idiotiaDisplay = [True,True,True,True]
|
||||
idiotiaDisplay = [True,True,False,False]
|
||||
#idiotiaDisplay = [False,False,False,False]
|
||||
liveDisplay = [False,False,False,False]
|
||||
fieldsDisplay = [False,False,False,False]
|
||||
|
||||
fieldsDisplay = [False,False,True,True]
|
||||
#fieldsDisplay = [True,True,True,True]
|
||||
currentIdiotia = 0
|
||||
|
||||
print ("")
|
||||
@ -99,6 +103,7 @@ else:
|
||||
lj3.Config(redisIP,ljclient)
|
||||
|
||||
|
||||
|
||||
def hex2rgb(hexcode):
|
||||
return tuple(map(ord,hexcode[1:].decode('hex')))
|
||||
|
||||
@ -109,7 +114,7 @@ def rgb2hex(rgb):
|
||||
|
||||
# IdiotIA
|
||||
import json
|
||||
CurrentPose = 1
|
||||
#CurrentPose = 1
|
||||
|
||||
# Get frame number for pose path describe in PoseDir
|
||||
def lengthPOSE(pose_dir):
|
||||
@ -125,6 +130,47 @@ def lengthPOSE(pose_dir):
|
||||
return 0
|
||||
|
||||
|
||||
def prepareIdiotIA(currentAnim):
|
||||
|
||||
WebStatus("Checking anims...")
|
||||
print()
|
||||
print("Reading available IdiotIA anims...")
|
||||
# anim format (name, xpos, ypos, resize, currentframe, totalframe, count, speed)
|
||||
# 0 1 2 3 4 5 6 7
|
||||
# total frames is fetched from directory by lengthPOSE()
|
||||
|
||||
anims[0] = ['boredhh' , xy_center[0] - 100, xy_center[1] + 30, 550, 0, 0, 0, animspeed]
|
||||
anims[1] = ['belka4' , xy_center[0] - 70, xy_center[1] + 380, 680, 0, 0, 0, animspeed]
|
||||
anims[2] = ['belka3' , xy_center[0] - 100, xy_center[1] + 360, 700, 0, 0, 0, animspeed]
|
||||
anims[3] = ['hhhead' , xy_center[0] - 100, xy_center[1] + 300, 600, 0, 0, 0, animspeed]
|
||||
anims[4] = ['hhhead2', xy_center[0] - 100, xy_center[1] + 300, 600, 0, 0, 0, animspeed]
|
||||
anims[5] = ['hhhead4', xy_center[0] - 100, xy_center[1] + 280, 600, 0, 0, 0, animspeed]
|
||||
anims[6] = ['hhred' , xy_center[0] - 250, xy_center[1] + 220, 550, 0, 0, 0, animspeed]
|
||||
anims[7] = ['hhred2' , xy_center[0] - 200, xy_center[1] + 200, 550, 0, 0, 0, animspeed]
|
||||
anims[8] = ['lady1' , xy_center[0] - 100, xy_center[1] + 300, 600, 0, 0, 0, animspeed]
|
||||
anims[9] = ['lady1' , xy_center[0] - 100, xy_center[1] + 280, 600, 0, 0, 0, animspeed]
|
||||
anims[10] = ['lady2' , xy_center[0] - 100, xy_center[1] + 280, 600, 0, 0, 0, animspeed]
|
||||
anims[11] = ['lady3' , xy_center[0] - 100, xy_center[1] + 300, 600, 0, 0, 0, animspeed]
|
||||
anims[12] = ['lady4' , xy_center[0] - 100, xy_center[1] + 300, 600, 0, 0, 0, animspeed]
|
||||
anims[13] = ['mila6' , xy_center[0] - 100, xy_center[1] + 280, 600, 0, 0, 0, animspeed]
|
||||
anims[14] = ['mila5' , xy_center[0] - 100, xy_center[1] + 280, 600, 0, 0, 0, animspeed]
|
||||
anims[15] = ['idiotia1', xy_center[0] - 100, xy_center[1] + 300, 600, 0, 0, 0, animspeed]
|
||||
anims[16] = ['idiotia1', xy_center[0] - 100, xy_center[1] + 300, 600, 0, 0, 0, animspeed]
|
||||
anims[17] = ['belka4', xy_center[0] - 100, xy_center[1] + 280, 600, 0, 0, 0, animspeed]
|
||||
anims[18] = ['belka3', xy_center[0] - 100, xy_center[1] + 280, 600, 0, 0, 0, animspeed]
|
||||
|
||||
#for laseranims in anims:
|
||||
|
||||
for anim in anims:
|
||||
#print(anim)
|
||||
anim[5] = lengthPOSE(anim[0])
|
||||
WebStatus("Checking "+ anim[0] +"...")
|
||||
if debug > 0:
|
||||
print('poses/' + anim[0], "length :", anim[5], "frames")
|
||||
|
||||
print("Current IdiotIA anim is",anims[currentIdiotia][0],"("+str(currentIdiotia)+")")
|
||||
|
||||
|
||||
# get absolute face position points
|
||||
def getFACE(pose_json,pose_points, people):
|
||||
|
||||
@ -180,50 +226,6 @@ def mouth(pose_json, people):
|
||||
|
||||
|
||||
|
||||
def prepareIdiotIA(currentAnim):
|
||||
|
||||
|
||||
WebStatus("Checking anims...")
|
||||
|
||||
print()
|
||||
print("Reading available IdiotIA anims...")
|
||||
# anim format (name, xpos, ypos, resize, currentframe, totalframe, count, speed)
|
||||
# 0 1 2 3 4 5 6 7
|
||||
# total frames is fetched from directory by lengthPOSE()
|
||||
|
||||
anims[0] = [['boredhh', xy_center[0], xy_center[1] + 130, 550,0,0,0,5]]
|
||||
anims[1] = [['belka4', xy_center[0], xy_center[1] + 280, 600,0,0,0,5]]
|
||||
anims[2] = [['belka3', xy_center[0], xy_center[1] + 280, 600,0,0,0,5]]
|
||||
anims[3] = [['hhbored2', xy_center[0], xy_center[1]+ 300, 600,0,0,0,5]]
|
||||
anims[4] = [['hhhead', xy_center[0], xy_center[1]+ 300, 600,0,0,0,5]]
|
||||
anims[5] = [['hhhead2', xy_center[0], xy_center[1] + 280, 600,0,0,0,30]]
|
||||
anims[6] = [['hhhead4', xy_center[0], xy_center[1] + 280, 600,0,0,0,30]]
|
||||
anims[7] = [['hhred', xy_center[0], xy_center[1]+ 300, 600,0,0,0,25]]
|
||||
anims[8] = [['hhred2', xy_center[0], xy_center[1]+ 300, 600,0,0,0,5]]
|
||||
anims[9] = [['lady1', xy_center[0], xy_center[1] + 280, 600,0,0,0,30]]
|
||||
anims[10] = [['lady2', xy_center[0], xy_center[1] + 280, 600,0,0,0,30]]
|
||||
anims[11] = [['lady3', xy_center[0], xy_center[1]+ 300, 600,0,0,0,25]]
|
||||
anims[12] = [['lady4', xy_center[0], xy_center[1]+ 300, 600,0,0,0,5]]
|
||||
anims[13] = [['mila6', xy_center[0], xy_center[1] + 280, 600,0,0,0,30]]
|
||||
anims[14] = [['mila5', xy_center[0], xy_center[1] + 280, 600,0,0,0,30]]
|
||||
anims[15] = [['idiotia1', xy_center[0], xy_center[1]+ 300, 600,0,0,0,25]]
|
||||
anims[16] = [['idiotia1', xy_center[0], xy_center[1]+ 300, 600,0,0,0,5]]
|
||||
anims[17] = [['belka4', xy_center[0], xy_center[1] + 280, 600,0,0,0,30]]
|
||||
anims[18] = [['belka3', xy_center[0], xy_center[1] + 280, 600,0,0,0,30]]
|
||||
|
||||
|
||||
for laseranims in anims:
|
||||
|
||||
for anim in laseranims:
|
||||
anim[5] = lengthPOSE(anim[0])
|
||||
WebStatus("Checking "+ anim[0] +"...")
|
||||
if debug > 0:
|
||||
print('poses/' + anim[0], "length :", anim[5], "frames")
|
||||
|
||||
print("Current IdiotIA anim is",anims[currentIdiotia][0],"("+str(currentIdiotia)+")")
|
||||
|
||||
|
||||
|
||||
|
||||
# display the currentIdiotia animation on all lasers according to display flag
|
||||
def IdiotIA():
|
||||
@ -235,7 +237,7 @@ def IdiotIA():
|
||||
# if display flag is True, send the face points.
|
||||
if idiotiaDisplay[laser]:
|
||||
|
||||
anim = anims[currentIdiotia][0]
|
||||
anim = anims[currentIdiotia]
|
||||
#print(anim)
|
||||
|
||||
PL = laser
|
||||
@ -244,16 +246,19 @@ def IdiotIA():
|
||||
dots = []
|
||||
|
||||
# increase current frame [4] of speed [7] frames
|
||||
anim[4] += 1
|
||||
#print(anim[4],anim[7],anim[4]+anim[7])
|
||||
|
||||
anim[4] = anim[4]+anim[7]
|
||||
|
||||
# compare to total frame [5]
|
||||
if anim[4] >= anim[5]:
|
||||
anim[4] = 0
|
||||
|
||||
posename = 'poses/' + anim[0] + '/' + anim[0] +'-'+str("%05d"%anim[4])+'.json'
|
||||
posename = 'poses/' + anim[0] + '/' + anim[0] +'-'+str("%05d"%int(anim[4]))+'.json'
|
||||
posefile = open(posename , 'r')
|
||||
posedatas = posefile.read()
|
||||
pose_json = json.loads(posedatas)
|
||||
#WebStatus("Frame : "+str("%05d"%int(anim[4])))
|
||||
|
||||
# Draw Face
|
||||
|
||||
@ -270,7 +275,6 @@ def IdiotIA():
|
||||
lj3.rPolyLineOneColor(mouth(pose_json, people), c = white, PL = laser, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
|
||||
lj3.DrawPL(PL)
|
||||
time.sleep(0.02)
|
||||
|
||||
|
||||
# Init Starfields
|
||||
@ -313,8 +317,8 @@ def Starfield(hori=0,verti=0):
|
||||
if displayedstars < num_stars and starfieldcount % 15 == 0:
|
||||
displayedstars += 1
|
||||
|
||||
if displayedstars == num_stars and starfieldcount % 10 == 0:
|
||||
starspeed += 0.005
|
||||
#if displayedstars == num_stars and starfieldcount % 10 == 0:
|
||||
# starspeed += 0.005
|
||||
|
||||
#print starspeed
|
||||
|
||||
@ -433,12 +437,11 @@ def LiveFace():
|
||||
# /pose/idiotia/lasernumber 1
|
||||
def OSCidiotia(address, value):
|
||||
|
||||
print("idiotia",address,value)
|
||||
|
||||
print("pose idiotia got ",address,value)
|
||||
laser = int(address[14:])
|
||||
print("laser", laser, value)
|
||||
|
||||
if value == 1:
|
||||
if value == "1" or value == 1:
|
||||
|
||||
idiotiaDisplay[laser] = True
|
||||
liveDisplay[laser] = False
|
||||
@ -450,41 +453,48 @@ def OSCidiotia(address, value):
|
||||
idiotiaDisplay[laser] = False
|
||||
print(idiotiaDisplay,liveDisplay,fieldsDisplay)
|
||||
|
||||
UpdatePoseUI()
|
||||
|
||||
# /pose/anim
|
||||
def OSCanim(address,state):
|
||||
# /pose/anim/animnumber 1
|
||||
def OSCanim(address, value):
|
||||
global currentIdiotia
|
||||
|
||||
print("/pose/anim",address, state)
|
||||
anim = int(address[12:])
|
||||
print(anim, state)
|
||||
print("pose anim got :", address, type(value), value)
|
||||
anim = int(address[11:])
|
||||
print("anim", anim)
|
||||
|
||||
if state == 1:
|
||||
if value == "1" or value == 1:
|
||||
currentIdiotia = anim
|
||||
UpdatePoseUI()
|
||||
WebStatus("Running "+ anims[currentIdiotia][0]+"...")
|
||||
|
||||
|
||||
# /pose/live/lasernumber value
|
||||
def OSClive(address,value):
|
||||
def OSClive(address, value):
|
||||
|
||||
print("live",address,value)
|
||||
laser = int(address[11:])
|
||||
print("laser", laser, value)
|
||||
#print("laser", laser, value)
|
||||
|
||||
if value == "1":
|
||||
idiotiaDisplay[value] = False
|
||||
liveDisplay[value] = True
|
||||
fieldsDisplay[value] = False
|
||||
if value == "1" or value == 1:
|
||||
idiotiaDisplay[laser] = False
|
||||
liveDisplay[laser] = True
|
||||
fieldsDisplay[laser] = False
|
||||
UpdatePoseUI()
|
||||
|
||||
# /pose/field/lasernumber value
|
||||
def OSCfield(address, value):
|
||||
|
||||
print("Pose bank field got", address, "with value", value)
|
||||
print("Pose field got", address, "with value", type(value), value)
|
||||
laser = int(address[12:])
|
||||
print("laser", laser, value)
|
||||
#print("laser", laser, value)
|
||||
|
||||
if value == "1":
|
||||
idiotiaDisplay[value] = False
|
||||
liveDisplay[value] = False
|
||||
fieldsDisplay[value] = True
|
||||
if value == "1" or value == 1:
|
||||
print("field",laser,"true")
|
||||
idiotiaDisplay[laser] = False
|
||||
liveDisplay[laser] = False
|
||||
fieldsDisplay[laser] = True
|
||||
UpdatePoseUI()
|
||||
|
||||
|
||||
# /pose/ljclient
|
||||
@ -494,6 +504,9 @@ def OSCljclient(value):
|
||||
lj3.LjClient(ljclient)
|
||||
|
||||
|
||||
# /pose/ping value
|
||||
def OSCping(value):
|
||||
lj3.OSCping("pose")
|
||||
|
||||
'''
|
||||
# Starfield, idiotia
|
||||
@ -522,26 +535,26 @@ def UpdatePoseUI():
|
||||
for laser in range(LaserNumber):
|
||||
|
||||
if idiotiaDisplay[laser]:
|
||||
lj3.SendLJ("pose/idiotia/" + str(laser) + " 1")
|
||||
lj3.SendLJ("/pose/idiotia/" + str(laser) + " 1")
|
||||
else:
|
||||
lj3.SendLJ("pose/idiotia/" + str(laser) + " 0")
|
||||
lj3.SendLJ("/pose/idiotia/" + str(laser) + " 0")
|
||||
|
||||
if liveDisplay[laser]:
|
||||
lj3.SendLJ("pose/live/" + str(laser) + " 1")
|
||||
lj3.SendLJ("/pose/live/" + str(laser) + " 1")
|
||||
else:
|
||||
lj3.SendLJ("pose/live/" + str(laser) + " 0")
|
||||
lj3.SendLJ("/pose/live/" + str(laser) + " 0")
|
||||
|
||||
if fieldsDisplay[laser]:
|
||||
lj3.SendLJ("pose/field/" + str(laser) + " 1")
|
||||
lj3.SendLJ("/pose/field/" + str(laser) + " 1")
|
||||
else:
|
||||
lj3.SendLJ("pose/field/" + str(laser) + " 0")
|
||||
lj3.SendLJ("/pose/field/" + str(laser) + " 0")
|
||||
|
||||
|
||||
for anim in range(19):
|
||||
if anim == currentIdiotia:
|
||||
lj3.SendLJ("pose/anim/" + str(anim) + " 1")
|
||||
lj3.SendLJ("/pose/anim/" + str(anim) + " 1")
|
||||
else:
|
||||
lj3.SendLJ("pose/anim/" + str(anim) + " 0")
|
||||
lj3.SendLJ("/pose/anim/" + str(anim) + " 0")
|
||||
|
||||
|
||||
|
||||
@ -549,12 +562,12 @@ print('Loading Pose bank...')
|
||||
WebStatus("Loading Pose bank...")
|
||||
|
||||
# OSC Server callbacks
|
||||
print("Starting OSC server at",myIP,":",OSCinPort,"...")
|
||||
print("Starting OSC server at", myIP, ":", OSCinPort, "...")
|
||||
osc_startup()
|
||||
osc_udp_server(myIP, OSCinPort, "InPort")
|
||||
|
||||
#osc_method("/pose/run*", OSCrun)
|
||||
osc_method("/ping*", lj3.OSCping)
|
||||
osc_method("/ping*", OSCping)
|
||||
osc_method("/pose/ljclient", OSCljclient)
|
||||
osc_method("/quit", OSCquit)
|
||||
osc_method("/pose/idiotia/*", OSCidiotia, argscheme=OSCARG_ADDRESS + OSCARG_DATAUNPACK)
|
||||
@ -562,8 +575,9 @@ osc_method("/pose/field/*", OSCfield,argscheme=OSCARG_ADDRESS + OSCARG_DATAUNPAC
|
||||
osc_method("/pose/live/*", OSClive, argscheme=OSCARG_ADDRESS + OSCARG_DATAUNPACK)
|
||||
osc_method("/pose/anim/*", OSCanim, argscheme=OSCARG_ADDRESS + OSCARG_DATAUNPACK)
|
||||
|
||||
anims =[[]]*20
|
||||
#color = lj3.rgb2int(255,255,255)
|
||||
|
||||
anims =[[]]*19
|
||||
|
||||
|
||||
prepareIdiotIA(0)
|
||||
prepareSTARFIELD()
|
||||
@ -579,24 +593,39 @@ green = lj3.rgb2int(0,255,0)
|
||||
print("Updating Pose UI...")
|
||||
UpdatePoseUI()
|
||||
|
||||
WebStatus("Pose bank running.")
|
||||
print("Pose bank running")
|
||||
|
||||
|
||||
|
||||
|
||||
WebStatus("Running "+ anims[currentIdiotia][0]+"...")
|
||||
#WebStatus("Pose bank running.")
|
||||
#print("Pose bank running")
|
||||
print("Running "+ anims[currentIdiotia][0]+" on " + str(LaserNumber) +" lasers.")
|
||||
|
||||
def Run():
|
||||
|
||||
try:
|
||||
while 1:
|
||||
|
||||
lj3.OSCframe()
|
||||
# If you want an idea
|
||||
# t0 = time.time()
|
||||
Starfield(hori=0,verti=0)
|
||||
IdiotIA()
|
||||
LiveFace()
|
||||
#LiveFace()
|
||||
time.sleep(0.002)
|
||||
#t1 = time.time()
|
||||
# looptime = t1 - t0
|
||||
# 25 frames/sec -> 1 frame is 0.04 sec long
|
||||
# if looptime is 0.01 sec
|
||||
# 0.04/0.01 = 4 loops with the same anim
|
||||
# so speedanim is 1 / 4 = 0.25
|
||||
# speedanim = 1 / (0.04 / looptime)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
#print("Took %f" % (t1 - t0, ))
|
||||
|
||||
#except KeyboardInterrupt:
|
||||
# pass
|
||||
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
|
||||
# Gently stop on CTRL C
|
||||
|
||||
|
@ -82,6 +82,7 @@ def SendLJ(oscaddress,oscargs=''):
|
||||
|
||||
try:
|
||||
msg = oscbuildparse.OSCMessage(oscaddress, None, [oscargs])
|
||||
# print(msg)
|
||||
osc_send(msg, "LJ 8002")
|
||||
OSCframe()
|
||||
|
||||
|
@ -133,7 +133,11 @@ def OSCpl(value):
|
||||
lj3.WebStatus("Glyph to pl "+ str(value))
|
||||
lj3.LjPl(value)
|
||||
|
||||
# /pose/ping value
|
||||
def OSCping(value):
|
||||
lj3.OSCping("glyph")
|
||||
|
||||
'''
|
||||
def Proj(x,y,z,angleX,angleY,angleZ):
|
||||
|
||||
rad = angleX * math.pi / 180
|
||||
@ -176,7 +180,7 @@ def Run():
|
||||
print("Starting OSC at",myIP," port",OSCinPort,"...")
|
||||
osc_startup()
|
||||
osc_udp_server(myIP, OSCinPort, "InPort")
|
||||
osc_method("/ping*", lj3.OSCping)
|
||||
osc_method("/ping*", OSCping)
|
||||
osc_method("/glyph/ljclient", OSCljclient)
|
||||
|
||||
try:
|
||||
|
@ -82,6 +82,7 @@ def SendLJ(oscaddress,oscargs=''):
|
||||
|
||||
try:
|
||||
msg = oscbuildparse.OSCMessage(oscaddress, None, [oscargs])
|
||||
# print(msg)
|
||||
osc_send(msg, "LJ 8002")
|
||||
OSCframe()
|
||||
|
||||
@ -93,10 +94,8 @@ def WebStatus(message):
|
||||
SendLJ("/status", message)
|
||||
|
||||
|
||||
# Answer to LJ pings
|
||||
# Answer to LJ pings with /pong pluginame
|
||||
def OSCping(value):
|
||||
# Will receive message address, and message data flattened in s, x, y
|
||||
print("Got /ping with value", value)
|
||||
SendLJ("/pong",value)
|
||||
|
||||
|
||||
|
@ -31,7 +31,7 @@ import pdb
|
||||
import types, ast, argparse
|
||||
from OSC import OSCServer, OSCClient, OSCMessage
|
||||
|
||||
|
||||
screen_size = [750,750]
|
||||
pl = [[],[],[],[]]
|
||||
|
||||
|
||||
@ -206,7 +206,7 @@ def RenderScreen(surface):
|
||||
if c: pygame.draw.line(surface,c,xyc_prev[:2],xyc[:2],3)
|
||||
xyc_prev = xyc
|
||||
|
||||
screen_size = [700,700]
|
||||
|
||||
pygame.init()
|
||||
screen = pygame.display.set_mode(screen_size)
|
||||
pygame.display.set_caption("LJ Simulator")
|
||||
|
Loading…
Reference in New Issue
Block a user