newUI, python3,...

This commit is contained in:
sam 2020-09-19 14:28:56 +02:00
parent 0bb0049f02
commit e9d3009ffb
551 changed files with 22992 additions and 787437 deletions

826
plugins/aurora/anim.py Normal file
View file

@ -0,0 +1,826 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# -*- mode: Python -*-
'''
Aurora Animations points generators
LICENCE : CC
Sam Neurohack
"ScanH", "ScanV", "Wave", "Circle", "Dot00", "Zero", "Maxwell", "Starfield", "Trckr", "Word"
'''
import time, math, sys, os
import numpy as np
from scipy import signal
from random import randrange, randint, random
import live
ljpath = r'%s' % os.getcwd().replace('\\','/')
# import from shell
sys.path.append(ljpath +'/../../libs3/')
sys.path.append(ljpath +'/../libs3/')
#import from LJ
sys.path.append(ljpath +'/libs3/')
sys.path.append('../libs3')
sys.path.append(ljpath +'/../../libs3')
import lj23layers as lj
import gstt
screen_size = [700,700]
xy_center = [screen_size[0]/2,screen_size[1]/2]
width = 700
height = 700
centerX = width / 2
centerY = height / 2
# 3D to 2D projection parameters
fov = 256
viewer_distance = 2.2
# Useful variables init.
white = lj.rgb2int(255,255,255)
red = lj.rgb2int(255,0,0)
blue = lj.rgb2int(0,0,255)
green = lj.rgb2int(0,255,0)
cyan = lj.rgb2int(255,0,255)
yellow = lj.rgb2int(255,255,0)
lifenb = 10
'''
# Animation parameters for each layer
X = [{'coord': 0, 'rotspeed': 0, 'transpeed': 0, 'transmax': 0}] *3
Y = [{'coord': 0, 'rotspeed': 0, 'transpeed': 0, 'transmax': 0}] *3
Z = [{'coord': 0, 'rotspeed': 0, 'transpeed': 0, 'transmax': 0}] *3
Layer = [{'scandots': 100, 'radius': 150, 'color': red, "run": True, "step":0, 'steps': 500, 'stepmax': 200, 'stepvals': [], 'lineSize': 300, 'intensity': 255}] * 3
Xacc = 0.01
Yacc = 0.01
Zacc = 0.00
'''
#
# Useful functions
#
def remap(s,min1,max1, min2, max2):
a1, a2 = min1, max1
b1, b2 = min2, max2
return b1 + ((s - a1) * (b2 - b1) / (a2 - a1))
minred = 0
mingreen = 0
minblue = 0
maxz=50
z = 20
col = (255,255,255)
def z2color(z, color):
rgbcolor = int2rgb(color)
#print()
#print("z2color : z =", z, "color =",color,"rgb :", rgbcolor)
newcolor = (z2range(z, rgbcolor[0], minred), z2range(z, rgbcolor[1], mingreen), z2range(z, rgbcolor[2], minblue))
#print("newcolor :", newcolor)
return rgb2int(newcolor)
def rgb2int(rgb):
return int('0x%02x%02x%02x' % tuple(rgb),0)
def int2rgb(intcode):
#hexcode = hex(intcode)[2:]
hexcode = '{0:06X}'.format(intcode)
return tuple(int(hexcode[i:i+2], 16) for i in (0, 2, 4))
#return tuple(map(ord,hexcode[1:].decode('hex')))
def z2range(z,color, mincolor):
#print("z2range : z=", z, "maxz :",maxz,"component =",color, "mincolor =",mincolor)
if color < mincolor:
return mincolor
a1, a2 = maxz,0
b1, b2 = mincolor, color
#print ("color component :", round(b1 + ((z - a1) * (b2 - b1) / (a2 - a1))))
return round(b1 + ((z - a1) * (b2 - b1) / (a2 - a1)))
def cc2range(s,min,max):
a1, a2 = 0,127
b1, b2 = min, max
return b1 + ((s - a1) * (b2 - b1) / (a2 - a1))
def range2cc(s,min,max):
a1, a2 = min, max
b1, b2 = 0,127
return b1 + ((s - a1) * (b2 - b1) / (a2 - a1))
def Proj(x, y, z, angleX, angleY, angleZ):
rad = angleX * math.pi / 180
cosa = math.cos(rad)
sina = math.sin(rad)
y2 = y
y = y2 * cosa - z * sina
z = y2 * sina + z * cosa
rad = angleY * math.pi / 180
cosa = math.cos(rad)
sina = math.sin(rad)
z2 = z
z = z2 * cosa - x * sina
x = z2 * sina + x * cosa
rad = angleZ * math.pi / 180
cosa = math.cos(rad)
sina = math.sin(rad)
x2 = x
x = x2 * cosa - y * sina
y = x2 * sina + y * cosa
""" Transforms this 3D point to 2D using a perspective projection. """
factor = fov / (viewer_distance + z)
x = x * factor + centerX
y = - y * factor + centerY
return (x,y)
def ssawtooth(samples, freq, phase, scale = 1):
samparray = [0] * samples
t = np.linspace(0+phase, 1+phase, samples)
for ww in range(samples):
samparray[ww] = signal.sawtooth(2 * np.pi * freq * t[ww]) * scale
return samparray
def ssquare(samples, freq, phase, scale = 1):
samparray = [0] * samples
t = np.linspace(0+phase, 1+phase, samples)
for ww in range(samples):
samparray[ww] = signal.square(2 * np.pi * freq * t[ww]) * scale
return samparray
def ssine(samples, freq, phase, scale = 1):
samparray = [0] * samples
t = np.linspace(0+phase, 1+phase, samples)
for ww in range(samples):
samparray[ww] = np.sin(2 * np.pi * freq * t[ww]) * scale
return samparray
def scos(samples, freq, phase, scale = 1):
samparray = [0] * samples
t = np.linspace(0+phase, 1+phase, samples)
for ww in range(samples):
samparray[ww] = np.cos(2 * np.pi * freq * t[ww]) * scale
return samparray
def slinear(samples, min, max):
return np.linspace(min, max, samples)
Range =0
def rangelinear(samples, min, max):
global Range
samparray = []
samparray.append(min)
for sample in range(samples-2):
samparray.append(Range+sample)
samparray.append(max)
if Range + samples-2 > max:
Range = min
Range += 1
return sorted(samparray)
def randlinear(samples, min, max):
samparray = []
for sample in range(samples):
samparray.append(randrange(max))
return sorted(samparray)
# as randlinear but first min and last is max
def randlinear2(samples, min, max):
samparray = []
samparray.append(min)
for sample in range(samples-2):
samparray.append(randrange(int(max)))
samparray.append(max)
return sorted(samparray)
'''
def slinear(samples, min, max):
linearray = [0] * samples
linearinc = (max-min)/samples
for ww in range(samples):
if ww == 0:
linearray[ww] = min
else:
linearray[ww] = linearray[ww-1] + linearinc
print ('linear :',linearray)
return linearray
'''
def sbilinear(samples, min, max):
samparray = [0] * samples
half = round(samples/2)
# UP : min -> max
part = np.linspace(min,max, half)
for ww in range(half):
samparray[ww] = part[ww]
# Down : max -> min
part = np.linspace(max,min, half)
for ww in range(half):
samparray[half+ww] = part[ww]
#print('linear min max', min, max)
#print ('linear',samparray)
return samparray
#
# FXs
#
'''
Beatstep memory 2 Aurora simplex
'''
def ScanV(LAY):
dots = []
arr = randlinear2(LAY['scandots'],0, LAY['lineSize'])
#arr = slinear(LAY['scandots'], LAY['lineSize'], 0)
#print(arr)
for y in arr:
#print(y, LAY['lineSize'] )
dots.append((0 + LAY['lineSize']/2, y - LAY['lineSize']/2, 0))
return dots
def ScanH(LAY):
dots = []
#print(slinear(LAY['scandots'], 0, LAY['lineSize']))
for x in sbilinear(LAY['scandots']*2, LAY['lineSize'],0):
dots.append((x , 0, 0))
#print(dots)
return dots
def Wave(LAY):
dots = []
x = slinear(round(LAY['lineSize']), 0, LAY['lineSize'])
y = ssine(round(LAY['lineSize']), LAY['wavefreq'], 0)
for ww in range(round(LAY['lineSize'])):
dots.append((50+x[ww], 50+y[ww] * LAY['radius'], 0))
return dots
def Circle(LAY):
dots = []
for angle in slinear(LAY['scandots'], 0, 360):
rad = angle * math.pi / 180
x = LAY['radius'] * math.cos(rad)
y = LAY['radius'] * math.sin(rad)
dots.append((x+LAY['lineSize']/2, y, 0))
return dots
def Word(LAY):
lj.Text(LAY['word'], c = LAY['color'], layer = LAY['number'], xpos = LAY['Xcoord']+LAY['lineSize']/2, ypos = LAY['Ycoord'], resize = LAY['scale']*10, rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
#lj.rPolyLineOneColor([(x/2,y/2),((x+1)/2,(y+1)/2)], c = LAY['color'], layer = l, xpos = 0, ypos = 0, resize = LAY['scale'], rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
def Dot00(LAY):
dots = []
dots.append((0, 0, 0))
return dots
def Zero(LAY):
dots = []
return dots
#
# Starfields
#
def Onefield(LAY, Field, hori=0,verti=0):
# starpoints = []
#print(Field['displayedstars'], 'stars displayed')
# Increase number of
if Field['displayedstars'] < Field['num_stars'] and Field['starfieldcount'] % 15 == 0:
Field['displayedstars'] += 1
#if displayedstars == num_stars and starfieldcount % 10 == 0:
# starspeed += 0.005
#print starspeed
for starnumber in range(0, Field['displayedstars']):
# The Z component is decreased on each frame.
Field['stars'][starnumber][2] -= Field['starspeed'] * 3
# If the star has past the screen (I mean Z<=0) then we
# reposition it far away from the screen (Z=max_depth)
# with random X and Y coordinates.
if Field['stars'][starnumber][2] <= 0:
Field['stars'][starnumber][0] = randrange(-25,25)
Field['stars'][starnumber][1] = randrange(-25,25)
Field['stars'][starnumber][2] = Field['max_depth']
# Convert the 3D coordinates to 2D using perspective projection.
k = 128.0 / Field['stars'][starnumber][2]
# Move Starfield origin.
# if stars xpos/ypos is same sign (i.e left stars xpos is <0) than (joystick or code) acceleration (hori and verti moves the star field origin)
if np.sign(Field['stars'][starnumber][0]) == np.sign(hori):
x = int(Field['stars'][starnumber][0] * k + xy_center[0] + (hori*600))
else:
x = int(Field['stars'][starnumber][0] * k + xy_center[0] + (hori*500))
if np.sign(Field['stars'][starnumber][1]) == np.sign(verti):
y = int(Field['stars'][starnumber][1] * k + xy_center[1] + (verti*600))
else:
y = int(Field['stars'][starnumber][1] * k + xy_center[1] + (verti*500))
# Add star to pointlist PL 0 if field display flag is true
if 0 <= x < screen_size[0] - 2 and 0 <= y < screen_size[1] - 2:
# print("adding star", str(x0)+","+str(y0), "to fields 0")
#lj.PolyLineOneColor([(x0,y0),((x0+1),(y0+1))], c = Stars0Form.color, layer = Stars0Form.layer, closed = Stars0Form.closed)
# print((x/2,y/2),((x+1)/2,(y+1)/2))
#print( int2rgb(z2color(Field['stars'][starnumber][2], LAY['color'])))
#lj.rPolyLineOneColor([(x/2,y/2),((x+1)/2,(y+1)/2)], c =LAY['color'], layer = LAY['number'], closed = False, xpos = 0, ypos = 0, resize = LAY['scale'], rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
lj.rPolyLineOneColor([(x/2,y/2,0),((x+1)/2,(y+1)/2,0)], c = z2color(Field['stars'][starnumber][2], LAY['color']), layer = LAY['number'], closed = False, xpos = -200, ypos = 0, resize = LAY['scale'], rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
#
# Maxwell
#
'''
Beatstep Encoders 3 :
LX freq amp phasemod transamt RX freq amp phasemod rotdire
LY freq amp phasemod transamt RL freq amp phasemod rotdire
'''
# sin:0/saw:33/squ:95/lin:127
def MaxOneSide(LAY, Cux, Cuy, Cuz):
#sines = ssine(LAY['scandots'], Cu['freq'], Cu['phasemod'], scale = Cu['amp'])
#cosines = scos(LAY['scandots'], Cu['freq'], Cu['phasemod'], scale = Cu['amp'])
#sines = ssine(LAY['scandots'], Cux['freq'], Cux['phaseoffset'], scale = Cux['amp'])
#cosines = ssine(LAY['scandots'], Cux['freq'], Cux['phaseoffset'], scale = Cux['amp'])
'''
cosines = scos(LAY['scandots'], Cu['freq'], Cu['phase'], scale = Cu['amp'])
saws = ssawtooth(LAY['scandots'], Cu['freq'], Cu['phase'], scale = Cu['amp'])
sqrs = ssquare(LAY['scandots'], Cu['freq'], Cu['phase'], scale = Cu['amp'])
'''
dots = []
#print("X", Cux['type'], Cux['phaseoffset'], Cux['inv'], Cux['amp'])
if Cux['type'] ==0:
xsteps = ssine(LAY['scandots'], Cux['freq'], Cux['phaseoffset'] + Cux['inv'], Cux['amp'])
if Cux['type'] ==33:
xsteps = ssawtooth(LAY['scandots'], Cux['freq'], Cux['phaseoffset'] + Cux['inv'], Cux['amp'])
if Cux['type'] == 95:
xsteps = ssquare(LAY['scandots'], Cux['freq'], Cux['phaseoffset'] + Cux['inv'], Cux['amp'])
if Cux['type'] == 127:
xsteps = slinear(LAY['scandots'], 0, Cux['amp'])
#print("Y", Cuy['type'], Cuy['phaseoffset'], Cuy['inv'], Cuy['amp'])
if Cuy['type'] ==0:
ysteps = ssine(LAY['scandots'], Cuy['freq'], Cuy['phaseoffset'] + Cuy['inv'], Cuy['amp'])
if Cuy['type'] ==33:
ysteps = ssawtooth(LAY['scandots'], Cuy['freq'], Cuy['phaseoffset'] + Cuy['inv'], Cuy['amp'])
if Cuy['type'] == 95:
ysteps = ssquare(LAY['scandots'], Cuy['freq'], Cuy['phaseoffset'] + Cuy['inv'], Cuy['amp'])
if Cuy['type'] == 127:
ysteps = slinear(LAY['scandots'], 0, Cuy['amp'])
#print("xsteps", xsteps)
#print("ysteps", ysteps)
for step in range(LAY['scandots']):
# Cu['type'] sin:0/saw:33/squ:95/lin:127
x = xsteps[step]
y = ysteps[step]
#x = sines[step]
#y = cosines[step]
dots.append((x, y, 0))
return dots
CurveLX = [{'type': 0, 'freq': 1, 'amp': 150, 'phasemod': 0, 'phaseoffset': 0, 'inv': 0}] * 3
CurveLY = [{'type': 0, 'freq': 1, 'amp': 150, 'phasemod': 0, 'phaseoffset': 0, 'inv': np.pi/2}] * 3
CurveLZ = [{'type': 0, 'freq': 1, 'amp': 150, 'phasemod': 0, 'phaseoffset': 0, 'inv': 0}] * 3
CurveRX = [{'type': 0, 'freq': 1, 'amp': 150, 'phasemod': 0, 'phaseoffset': 0, 'inv': 0}] * 3
CurveRY = [{'type': 0, 'freq': 1, 'amp': 150, 'phasemod': 0, 'phaseoffset': 0, 'inv': np.pi/2}] * 3
CurveRZ = [{'type': 0, 'freq': 1, 'amp': 150, 'phasemod': 0, 'phaseoffset': 0, 'inv': 0}] * 3
def Maxwell(LAY):
l =0
mixer = 0
dots = []
dotsL = MaxOneSide(LAY, CurveLX[l], CurveLY[l], CurveLZ[l])
dotsR = MaxOneSide(LAY, CurveRX[l], CurveRY[l], CurveRZ[l])
for dot in range(LAY['scandots']):
dotX = (dotsL[dot][0]*(100-mixer)/100) + (dotsR[dot][0]*mixer/100) #+ transX.values[point]
dotY = (dotsL[dot][1]*(100-mixer)/100) + (dotsR[dot][1]*mixer/100) #+ transY.values[point]
dotZ = (dotsL[dot][2]*(100-mixer)/100) + (dotsR[dot][2]*mixer/100) #+ transZ.values[point]
dots.append((dotX, dotY, dotZ))
return dots
'''
for dot in range(LAY['scandots']):
dotX = (dotsL[dot][0]*(100-LAY['mixer'])/100) + (dotsR[dot][0]*LAY['mixer']/100) #+ transX.values[point]
dotY = (dotsL[dot][1]*(100-LAY['mixer'])/100) + (dotsR[dot][1]*LAY['mixer']/100) #+ transY.values[point]
dotZ = (dotsL[dot][2]*(100-LAY['mixer'])/100) + (dotsR[dot][2]*LAY['mixer']/100) #+ transZ.values[point]
dots.append((dotX, dotY, dotZ))
'''
#
# Trckr
#
# get absolute face position points
def getPART(TrckrPts, pose_points):
dots = []
for dot in pose_points:
dots.append((TrckrPts[dot][0], TrckrPts[dot][1],0))
return dots
# Face keypoints
def face(TrckrPts):
pose_points = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]
return getPART(TrckrPts, pose_points)
def browL(TrckrPts):
pose_points = [15,16,17,18]
return getPART(TrckrPts, pose_points)
def browR(TrckrPts):
pose_points = [22,21,20,19]
return getPART(TrckrPts, pose_points)
def eyeR(TrckrPts):
pose_points = [25,64,24,63,23,66,26,65,25]
return getPART(TrckrPts, pose_points)
def eyeL(TrckrPts):
pose_points = [28,67,29,68,30,69,31,28]
return getPART(TrckrPts, pose_points)
def pupR(TrckrPts):
pose_points = [27]
return getPART(TrckrPts, pose_points)
def pupL(TrckrPts):
pose_points = [32]
return getPART(TrckrPts, pose_points)
def nose1(TrckrPts):
pose_points = [62,41,33]
return getPART(TrckrPts, pose_points)
def nose2(TrckrPts):
pose_points = [40,39,38,43,37,42,36,35,34]
return getPART(TrckrPts, pose_points)
def mouth(TrckrPts):
pose_points = [50,49,48,47,46,45,44,55,54,53,52,51,50]
return getPART(TrckrPts, pose_points)
def mouthfull(TrckrPts):
pose_points = [50,49,48,47,46,45,44,55,54,53,52,51,50,59,60,61,44,56,57,58,50]
return getPART(TrckrPts, pose_points)
def Trckr(LAY, TrckrPts):
#lj.rPolyLineOneColor([(x/2,y/2),((x+1)/2,(y+1)/2)], c = LAY['color'], layer = l, closed = False, xpos = 0, ypos = 0, resize = LAY['scale'], rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
#print(LAY['scale'])
#print("browL", browL(), "browR", browR(), "nose1", nose1(), "mouth", mouth())
lj.rPolyLineOneColor(browL(TrckrPts), c = LAY['color'], layer = LAY['number'], closed = False, xpos = -200 +LAY['Xcoord'], ypos = LAY['Ycoord'], resize = LAY['scale']*0.8, rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
lj.rPolyLineOneColor(eyeL(TrckrPts), c = LAY['color'], layer = LAY['number'], closed = False, xpos = -200 +LAY['Xcoord'], ypos = LAY['Ycoord'], resize = LAY['scale']*0.8, rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
lj.rPolyLineOneColor(browR(TrckrPts), c = LAY['color'], layer = LAY['number'], closed = False, xpos = -200 +LAY['Xcoord'], ypos = LAY['Ycoord'], resize = LAY['scale']*0.8, rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
lj.rPolyLineOneColor(eyeR(TrckrPts), c = LAY['color'], layer = LAY['number'], closed = False, xpos = -200 +LAY['Xcoord'], ypos = LAY['Ycoord'], resize = LAY['scale']*0.8, rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
lj.rPolyLineOneColor(pupL(TrckrPts), c = LAY['color'], layer = LAY['number'], closed = False, xpos = -200 +LAY['Xcoord'], ypos = LAY['Ycoord'], resize = LAY['scale']*0.8, rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
lj.rPolyLineOneColor(pupR(TrckrPts), c = LAY['color'], layer = LAY['number'], closed = False, xpos = -200 +LAY['Xcoord'], ypos = LAY['Ycoord'], resize = LAY['scale']*0.8, rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
lj.rPolyLineOneColor(nose1(TrckrPts), c = LAY['color'], layer = LAY['number'], closed = False, xpos = -200 +LAY['Xcoord'], ypos = LAY['Ycoord'], resize = LAY['scale']*0.8, rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
lj.rPolyLineOneColor(nose2(TrckrPts), c = LAY['color'], layer = LAY['number'], closed = False, xpos = -200 +LAY['Xcoord'], ypos = LAY['Ycoord'], resize = LAY['scale']*0.8, rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
lj.rPolyLineOneColor(mouthfull(TrckrPts), c = LAY['color'], layer = LAY['number'], closed = False, xpos = -200 +LAY['Xcoord'], ypos = LAY['Ycoord'], resize = LAY['scale']*0.8, rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
#
# Butterfly
#
entities = []
for lifes in range(0,lifenb,1):
# 0: random posX, 1: random posY, 2: wing position, 3: Color, 4: XDirection
entities.append([randint(100,width-100), randint(100,height-100), random(), randint(45,16700000), randint(-2,2)])
print("entities", entities)
wingpos = random()
# One wing vertices
vertices = [
( 0.0 , 0.3603683 , 0.7174169 ), #1
( 0.0 , -4.39773 , 0.09228338 ), #2
( wingpos , 0.3603683 , 0.3174169 ), #3
( 0.0 , 0.3603683 , 0.7174169 ), #4
( -wingpos , 0.4115218 , 0.1858825 ), #7
( 0.0 , -4.39773 , 0.09228338 ) #2
]
'''
vertices = [
( 0.0 , -4.39773 , 0.7174169 ), # 1
( 0.0 , 4.39773 , 0.09228338 ), # 2
( wingpos , 0.3603683 , 0.3174169 ), # 3
( 0.0 , 0.3603683 , 0.7174169 ), # 4
( wingpos , -4.39773, 0.7174169 ), # 5
( 0.0 , -4.39773 , 0.7174169 ), # 6 = 1
( -wingpos ,-4.39773 , 0.1858825 ), #7
( 0.0 , 0.3603683 , 0.7174169 ), # 8
( -wingpos , 0.3603683 , 0.3174169 ), # 9
( 0.0 , 4.39773 , 0.09228338 ), # 10
]
'''
fov = 256
viewer_distance = 70.2
angleX = 0
angleY = 120
angleZ = 0
color = 0x101010
speed = 0
def Butterfly(LAY):
global angleX, angleY, angleZ
#angleX += 0.0
#angleY += 0.0
#angleZ += 0.0
for entity in entities:
#print(entity)
entity[0] += entity[4] + randint(-1,1) # change X/Y pos (Xdirection and little chaos)
if randint(0,20) > 15:
entity[1] += randint(-2,2)
centerX = entity[0]
centerY = entity[1]
# remember : z position is overall zoom
entity[2] += 1 # wings animation
if entity[2] > 10:
entity[2] = 0.0
wingpos = entity[2]
angleX = angleX # entity rotated in Z to follow Xdirection
angleY = angleY
if entity[4] > 0:
angleZ = (angleZ + entity[4]*18)
else:
angleZ = -(angleZ + entity[4]*18)
color = entity[3]
dots = []
verticecounter = 0
for v in vertices:
x = v[0]
y = v[1]
z = v[2]
if verticecounter == 2:
x = wingpos
if verticecounter == 4:
x = - wingpos
#print(x,y,z)
dots.append(Proj(x+entity[0], y+entity[1], z, angleX, angleY, angleZ))
verticecounter +=1
#print(dots)
lj.rPolyLineOneColor(dots, c = LAY['color'], layer = LAY['number'], closed = False, xpos = -300 +LAY['Xcoord'], ypos = -300+LAY['Ycoord'], resize = LAY['scale']*1.3, rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
'''
OBJECT Style
name, scandots, radius, color, run, step, steps, stepmax, stepvals, lineSize, intensity
L0 = LAYERobject("0", "saw", 100, 150, red, True, 0, 500, 200, [], 300, 255)
L0.name = name
L0.scandots = 100
L0.radius = 150
L0.color = red
L0.run = True
L0.step = 0,
L0.steps = 500,
L0.stepmax = 200
L0.stepvals =[]
L0.lineSize = 300
L0.intensity = 255
class LAYERobject:
def __init__(self, name, scandots, radius, color, run, step, steps, stepmax, stepvals, lineSize, intensity)
self.name = name
self.scandots = scandots
self.radius = radius
self.color = color
self.run = run
self.step = step
self.steps = steps
self.stepmax = stepmax
self.stepvals = stepvals
self.lineSize = lineSize
self.intensity = intensity
name, coord, rotspeed, ranspeed, transmax
X0 = COORDobject("X0",0, 0, 0, 0)
X0.name = "0"
X0.coord = 0
X0.rotspeed = 0
X0.transpeed = 0
X0.transmax = 0
class COORDobject:
def __init__(self, name, coord, rotspeed, ranspeed, transmax)
self.name = name
self.coord = coord,
self.rotspeed = rotspeed
self.transpeed = transpeed
self.transmax = transmax
#
# OLD STUFF not used
#
def AudioLissa():
global Xrot, Yrot, Zrot
levels = lj.fromRedis('/audiogen/levels')
# levels = r.get('/audiogen/levels')
#PL = 0
dots = []
amp = 200
nb_point = 60
Xrot += Xacc * 25
Yrot += Yacc * 25
Zrot += Zacc * 0
# scale = (380-viewgenbands2scrY(levels[0]))/300
#scale = (380 - (levels[0] * 4))/300
LissaObj.scale = float(levels[0]) / 55
print(type(float(levels[0])),levels[0], LissaObj.scale)
#print ("scale",scale)
#print ("scale",scale)
for t in range(0, nb_point+1):
y = 1 - amp*math.sin(2*math.pi*2*(float(t)/float(nb_point)))
x = 1 - amp*math.cos(2*math.pi*3*(float(t)/float(nb_point)))
#y = 1 - amp*math.sin(2*PI*cc2range(gstt.cc[5],0,24)*(float(t)/float(nb_point)))
#x = 1 - amp*math.cos(2*PI*cc2range(gstt.cc[6],0,24)*(float(t)/float(nb_point)))
dots.append((x,y))
# These points are generated in pygame coordinates space (0,0 is top left) defined by screen_size in globalVars.py
#lj23.PolyLineOneColor( dots, c = white, PL = PL, closed = False )
lj.rPolyLineOneColor(dots, c = LissaObj.color, PL = LissaObj.PL, closed = False , xpos = LissaObj.xpos, ypos = LissaObj.ypos, scale = LissaObj.scale, rotx = LissaObj.rotx, roty = LissaObj.roty , rotz = LissaObj.rotz)
# /X/0/coord
# /Layer/0/color
if path.find('/X') == 0:
command = path.split("/")
eval(command[0]+'['+str(command[1])+']['+command[2]+']='+args[0])
# increase/decrease a CC. Value can be positive or negative
def changeCC(value, path):
MaxwellCC = FindCC(path)
print(MaxwellCC, "CC :", FindCC(path),"was", gstt.ccs[gstt.lasernumber][MaxwellCC])
if gstt.ccs[gstt.lasernumber][MaxwellCC] + value > 127:
gstt.ccs[gstt.lasernumber][MaxwellCC] = 127
if gstt.ccs[gstt.lasernumber][MaxwellCC] + value < 0:
gstt.ccs[gstt.lasernumber][MaxwellCC] = 0
if gstt.ccs[gstt.lasernumber][MaxwellCC] + value < 127 and gstt.ccs[gstt.lasernumber][MaxwellCC] + value >0:
gstt.ccs[gstt.lasernumber][MaxwellCC] += value
print("maxwellccs changeCC in maxwellccs : path =", path, "CC :", FindCC(path), "is now ", gstt.ccs[gstt.lasernumber][MaxwellCC], "for laser", gstt.lasernumber)
cc(MaxwellCC, gstt.ccs[gstt.lasernumber][MaxwellCC] , dest ='to Maxwell 1')
def EncoderPlusOne(value, path = current["path"]):
if value < 50:
changeCC(1, path)
def EncoderMinusOne(value, path = current["path"]):
if value > 90:
changeCC(-1, path)
def EncoderPlusTen(value, path = current["path"]):
if value < 50:
changeCC(10, path)
def EncoderMinusTen(value, path = current["path"]):
if value > 90:
changeCC(-10, path)
'''

1277
plugins/aurora/aurora.py Normal file

File diff suppressed because it is too large Load diff

39
plugins/aurora/log.py Normal file
View file

@ -0,0 +1,39 @@
'''
Log in color from
https://stackoverflow.com/questions/287871/how-to-print-colored-text-in-terminal-in-python
usage :
import log
log.info("Hello World")
log.err("System Error")
'''
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = "\033[1m"
def disable():
HEADER = ''
OKBLUE = ''
OKGREEN = ''
WARNING = ''
FAIL = ''
ENDC = ''
def infog( msg):
print(OKGREEN + msg + ENDC)
def info( msg):
print(OKBLUE + msg + ENDC)
def warn( msg):
print(WARNING + msg + ENDC)
def err( msg):
print(FAIL + msg + ENDC)

1098
plugins/aurora/maxwell.py Normal file

File diff suppressed because it is too large Load diff

744
plugins/aurora/midix.py Normal file
View file

@ -0,0 +1,744 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
Midi3 light version for soundt/Jamidi/clapt
v0.7.0
Midi Handler :
- Hook to the MIDI host
- Enumerate connected midi devices and spawn a process/device to handle incoming events
by Sam Neurohack
from /team/laser
Midi conversions from https://github.com/craffel/pretty-midi
"""
import time
from threading import Thread
import rtmidi
from rtmidi.midiutil import open_midiinput
from rtmidi.midiconstants import (CHANNEL_PRESSURE, CONTROLLER_CHANGE, NOTE_ON, NOTE_OFF,
PITCH_BEND, POLY_PRESSURE, PROGRAM_CHANGE, TIMING_CLOCK, SONG_CONTINUE, SONG_START, SONG_STOP)
import mido
from mido import MidiFile
import traceback
import weakref
import sys
from sys import platform
import os
import re
from collections import deque
import log
ljpath = r'%s' % os.getcwd().replace('\\','/')
# import from shell
sys.path.append(ljpath +'/../../libs3/')
sys.path.append(ljpath +'/../libs3/')
#import from LJ
sys.path.append(ljpath +'/libs3/')
sys.path.append('../libs3')
sys.path.append(ljpath +'/../../libs3')
import gstt
is_py2 = sys.version[0] == '2'
if is_py2:
from queue import Queue
from OSC import OSCServer, OSCClient, OSCMessage
else:
from queue import Queue
from OSC3 import OSCServer, OSCClient, OSCMessage
print("")
midiname = ["Name"] * 16
midiport = [rtmidi.MidiOut() for i in range(16) ]
OutDevice = []
InDevice = []
midisync = True
# max 16 midi port array
midinputsname = ["Name"] * 16
midinputsqueue = [Queue() for i in range(16) ]
midinputs = []
# False = server / True = Client
gstt.clientmode = False
#Mser = False
MidInsNumber = 0
clock = mido.Message(type="clock")
start = mido.Message(type ="start")
stop = mido.Message(type ="stop")
ccontinue = mido.Message(type ="continue")
reset = mido.Message(type ="reset")
songpos = mido.Message(type ="songpos")
#mode = "maxwell"
'''
print "clock",clock)
print "start",start)
print "continue", ccontinue)
print "reset",reset)
print "sonpos",songpos)
'''
try:
input = raw_input
except NameError:
# Python 3
Exception = Exception
STATUS_MAP = {
'noteon': NOTE_ON,
'noteoff': NOTE_OFF,
'programchange': PROGRAM_CHANGE,
'controllerchange': CONTROLLER_CHANGE,
'pitchbend': PITCH_BEND,
'polypressure': POLY_PRESSURE,
'channelpressure': CHANNEL_PRESSURE
}
def SendAU(oscaddress,oscargs=''):
oscmsg = OSCMessage()
oscmsg.setAddress(oscaddress)
oscmsg.append(oscargs)
osclientlj = OSCClient()
osclientlj.connect((gstt.myIP, 8090))
# print("MIDI Aurora sending itself OSC :", oscmsg, "to localhost:8090")
try:
osclientlj.sendto(oscmsg, (gstt.myIP, 8090))
oscmsg.clearData()
except:
log.err('Connection to Aurora refused : died ?')
pass
#time.sleep(0.001
def SendUI(oscaddress,oscargs=''):
oscmsg = OSCMessage()
oscmsg.setAddress(oscaddress)
oscmsg.append(oscargs)
osclientlj = OSCClient()
osclientlj.connect((gstt.TouchOSCIP, gstt.TouchOSCPort))
#print("MIDI Aurora sending UI :", oscmsg, "to",gstt.TouchOSCIP,":",gstt.TouchOSCPort)
try:
osclientlj.sendto(oscmsg, (gstt.TouchOSCIP, gstt.TouchOSCPort))
oscmsg.clearData()
except:
log.err('Connection to Aurora UI refused : died ?')
pass
#time.sleep(0.001
def GetTime():
return time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())
notes = ["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"]
def midi2note(midinote):
print("midinote",midinote, "note", notes[midinote%12]+str(round(midinote/12)))
return notes[midinote%12]+str(round(midinote/12))
def note2midi(note_name):
"""Converts a note name in the format
``'(note)(accidental)(octave number)'`` (e.g. ``'C#4'``) to MIDI note
number.
``'(note)'`` is required, and is case-insensitive.
``'(accidental)'`` should be ``''`` for natural, ``'#'`` for sharp and
``'!'`` or ``'b'`` for flat.
If ``'(octave)'`` is ``''``, octave 0 is assumed.
Parameters
----------
note_name : str
A note name, as described above.
Returns
-------
note_number : int
MIDI note number corresponding to the provided note name.
Notes
-----
Thanks to Brian McFee.
"""
# Map note name to the semitone
pitch_map = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
# Relative change in semitone denoted by each accidental
acc_map = {'#': 1, '': 0, 'b': -1, '!': -1}
# Reg exp will raise an error when the note name is not valid
try:
# Extract pitch, octave, and accidental from the supplied note name
match = re.match(r'^(?P<n>[A-Ga-g])(?P<off>[#b!]?)(?P<oct>[+-]?\d+)$',
note_name)
pitch = match.group('n').upper()
offset = acc_map[match.group('off')]
octave = int(match.group('oct'))
except:
raise ValueError('Improper note format: {}'.format(note_name))
# Convert from the extrated ints to a full note number
return 12*(octave + 1) + pitch_map[pitch] + offset
def hz2midi(frequency):
"""Convert a frequency in Hz to a (fractional) note number.
Parameters
----------
frequency : float
Frequency of the note in Hz.
Returns
-------
note_number : float
MIDI note number, can be fractional.
"""
# MIDI note numbers are defined as the number of semitones relative to C0
# in a 440 Hz tuning
return 12*(np.log2(frequency) - np.log2(440.0)) + 69
def midi2hz(note_number):
"""Convert a (fractional) MIDI note number to its frequency in Hz.
Parameters
----------
note_number : float
MIDI note number, can be fractional.
Returns
-------
note_frequency : float
Frequency of the note in Hz.
"""
# MIDI note numbers are defined as the number of semitones relative to C0
# in a 440 Hz tuning
return 440.0*(2.0**((note_number - 69)/12.0))
# /cc cc number value
def cc(midichannel, ccnumber, value, mididest):
if gstt.debug>0:
print("Midix sending Midi channel", midichannel, "cc", ccnumber, "value", value, "to", mididest)
MidiMsg([CONTROLLER_CHANGE+midichannel-1, ccnumber, value], mididest)
#
# MIDI Startup and handling
#
mqueue = Queue()
inqueue = Queue()
bpm = 0
running = True
samples = deque()
last_clock = None
#
# Events from Generic MIDI Handling
#
def MidinProcess(inqueue, portname):
inqueue_get = inqueue.get
bpm = 0
samples = deque()
last_clock = None
while True:
time.sleep(0.001)
msg = inqueue_get()
#print("")
#print("Generic from", portname,"msg : ", msg)
# NOTE ON message on all midi channels
if NOTE_ON -1 < msg[0] < 160 and msg[2] !=0 :
MidiChannel = msg[0]-144
MidiNote = msg[1]
MidiVel = msg[2]
print()
print("NOTE ON :", MidiNote, 'velocity :', MidiVel, "Channel", MidiChannel)
#print("Midi in process send /aurora/noteon "+str(msg[1])+" "+str(msg[2]))
SendAU("/aurora/noteon",[MidiChannel, msg[1], msg[2]])
'''
# Sampler mode : note <63 launch snare.wav / note > 62 kick.wav
if MidiNote < 63 and MidiVel >0:
if platform == 'darwin':
os.system("afplay snare.wav")
else:
os.system("aplay snare.wav")
if MidiNote > 62 and MidiVel >0:
if platform == 'darwin':
os.system("afplay kick.wav")
else:
os.system("aplay kick.wav")
'''
# NOTE OFF or Note with 0 velocity on all midi channels
if NOTE_OFF -1 < msg[0] < 145 or (NOTE_OFF -1 < msg[0] < 160 and msg[2] == 0):
print("NOTE_off :",NOTE_OFF)
if msg[0] > 143:
MidiChannel = msg[0]-144
else:
MidiChannel = msg[0]-128
#print("NOTE OFF :", MidiNote, "Channel", MidiChannel)
#print("Midi in process send /aurora/noteoff "+str(msg[1]))
SendAU("/aurora/noteoff",[MidiChannel, msg[1]])
# # CC on all Midi Channels
if CONTROLLER_CHANGE -1 < msg[0] < 192:
MidiChannel = msg[0]-175
print()
#print("channel", MidiChannel, "CC :", msg[1], msg[2])
print("Midi in process send /aurora/rawcc "+str(msg[0]-175-1)+" "+str(msg[1])+" "+str(msg[2]))
SendAU("/aurora/rawcc",[msg[0]-175-1, msg[1], msg[2]])
'''
# MMO-3 Midi CC message CHANNEL 1
if CONTROLLER_CHANGE -1 < msg[0] < 192:
print("channel 1 (MMO-3) CC :", msg[1], msg[2])
print("Midi in process send /mmo3/cc/"+str(msg[1])+" "+str(msg[2])+" to WS")
WScom.send("/mmo3/cc/"+str(msg[1])+" "+str(msg[2]))
# OCS-2 Midi CC message CHANNEL 2
if msg[0] == CONTROLLER_CHANGE+1:
print("channel 2 (OCS-2) CC :", msg[1], msg[2])
print("Midi in process send /ocs2/cc/"+str(msg[1])+" "+str(msg[2])+" to WS")
WScom.send("/ocs2/cc/"+str(msg[1])+" "+str(msg[2]))
'''
if msg[0] == TIMING_CLOCK:
now = time.time()
if last_clock is not None:
samples.append(now - last_clock)
last_clock = now
if len(samples) > 24:
samples.popleft()
if len(samples) >= 2:
#bpm = 2.5 / (sum(samples) / len(samples))
#print("%.2f bpm" % bpm)
bpm = round(2.5 / (sum(samples) / len(samples))) # Against BPM lot very tiny change :
sync = True
# print("MIDI BPM", bpm)
#print("Midi clock : BPM", bpm)
SendAU("/aurora/clock",[])
# SendAU("/aurora/bpm",[bpm])
if msg[0] in (SONG_CONTINUE, SONG_START):
running = True
#print("START/CONTINUE received.")
#print("Midi in process send /aurora/start")
SendAU("/aurora/start",[])
if msg[0] == SONG_STOP:
running = False
#print("STOP received.")
#print("Midi in process send /aurora/stop")
SendAU("/aurora/stop",[])
'''
# other midi message
if msg[0] != NOTE_OFF and msg[0] != NOTE_ON and msg[0] != CONTROLLER_CHANGE:
pass
print("from", portname,"other midi message")
MidiMsg(msg[0],msg[1],msg[2],mididest)
'''
#def NoteOn(note, color, mididest):
#https://pypi.org/project/python-rtmidi/0.3a/
# NOTE_ON=#90 et NOTE_OFF=#80 on ajoute le channel (0 le premier) pour envoyer effectivement sur le channel
def NoteOn(note, color, mididest, midichannel=0):
global MidInsNumber
if gstt.debug >0:
print("Sending", note, color, "to", mididest, "on channel", midichannel)
for port in range(MidInsNumber):
# To mididest
if midiname[port].find(mididest) == 0:
midiport[port].send_message([NOTE_ON+midichannel, note, color])
# To All
elif mididest == "all" and midiname[port].find(mididest) != 0:
midiport[port].send_message([NOTE_ON+midichannel, note, color])
def NoteOff(note, mididest):
global MidInsNumber
for port in range(MidInsNumber):
# To mididest
if midiname[port].find(mididest) != -1:
midiport[port].send_message([NOTE_OFF, note, 0])
# To All
elif mididest == "all" and midiname[port].find(mididest) == -1:
midiport[port].send_message([NOTE_OFF, note, 0])
# Generic call back : new msg forwarded to queue
class AddQueue(object):
def __init__(self, portname, port):
self.portname = portname
self.port = port
#print "AddQueue", port)
self._wallclock = time.time()
def __call__(self, event, data=None):
message, deltatime = event
self._wallclock += deltatime
#print "inqueue : [%s] @%0.6f %r" % ( self.portname, self._wallclock, message))
message.append(deltatime)
midinputsqueue[self.port].put(message)
#
# MIDI OUT Handling
#
class OutObject():
_instances = set()
counter = 0
def __init__(self, name, kind, port):
self.name = name
self.kind = kind
self.port = port
self._instances.add(weakref.ref(self))
OutObject.counter += 1
print("Adding OutDevice name", self.name, "kind", self.kind, "port", self.port)
@classmethod
def getinstances(cls):
dead = set()
for ref in cls._instances:
obj = ref()
if obj is not None:
yield obj
else:
dead.add(ref)
cls._instances -= dead
def __del__(self):
OutObject.counter -= 1
def OutConfig():
global midiout, MidInsNumber
#
if len(OutDevice) == 0:
print("")
log.info("MIDIout...")
print("List and attach to available devices on host with IN port :")
# Display list of available midi IN devices on the host, create and start an OUT instance to talk to each of these Midi IN devices
midiout = rtmidi.MidiOut()
available_ports = midiout.get_ports()
for port, name in enumerate(available_ports):
midiname[port]=name
midiport[port].open_port(port)
#print )
#print "New OutDevice [%i] %s" % (port, name))
OutDevice.append(OutObject(name, "generic", port))
#print "")
print(len(OutDevice), "Out devices")
#ListOutDevice()
MidInsNumber = len(OutDevice)+1
def ListOutDevice():
for item in OutObject.getinstances():
print(item.name)
def FindOutDevice(name):
port = -1
for item in OutObject.getinstances():
#print "searching", name, "in", item.name)
if name == item.name:
#print 'found port',item.port)
port = item.port
return port
def DelOutDevice(name):
Outnumber = Findest(name)
print('deleting OutDevice', name)
if Outnumber != -1:
print('found OutDevice', Outnumber)
delattr(OutObject, str(name))
print("OutDevice", Outnumber,"was removed")
else:
print("OutDevice was not found")
#
# MIDI IN Handling
# Create processing thread and queue for each device
#
class InObject():
_instances = set()
counter = 0
def __init__(self, name, kind, port, rtmidi):
self.name = name
self.kind = kind
self.port = port
self.rtmidi = rtmidi
self.queue = Queue()
self._instances.add(weakref.ref(self))
InObject.counter += 1
print("Adding InDevice name", self.name, "kind", self.kind, "port", self.port)
@classmethod
def getinstances(cls):
dead = set()
for ref in cls._instances:
obj = ref()
if obj is not None:
yield obj
else:
dead.add(ref)
cls._instances -= dead
def __del__(self):
InObject.counter -= 1
def InConfig():
print("")
log.info("MIDIin...")
# client mode
if gstt.debug > 0:
if gstt.clientmode == True:
print("midi3 in client mode")
else:
print("midi3 in server mode")
print("List and attach to available devices on host with OUT port :")
if platform == 'darwin':
mido.set_backend('mido.backends.rtmidi/MACOSX_CORE')
genericnumber = 0
for port, name in enumerate(mido.get_input_names()):
outport = FindOutDevice(name)
midinputsname[port]=name
#print "name",name, "Port",port, "Outport", outport)
# print "midinames", midiname)
#ListInDevice()
try:
#print name, name.find("RtMidi output"))
if name.find("RtMidi output") > -1:
print("No thread started for device", name)
else:
portin = object
port_name = ""
portin, port_name = open_midiinput(outport)
if midisync == True:
portin.ignore_types(timing=False)
#midinputs.append(portin)
InDevice.append(InObject(name, "generic", outport, portin))
thread = Thread(target=MidinProcess, args=(midinputsqueue[port],port_name))
thread.setDaemon(True)
thread.start()
#print "Thread launched for midi port", port, "portname", port_name, "Inname", midiname.index(port_name)
#print "counter", InObject.counter
#midinputs[port].set_callback(AddQueue(name),midinputsqueue[port])
#midinputs[port].set_callback(AddQueue(name))
#genericnumber += 1
InDevice[InObject.counter-1].rtmidi.set_callback(AddQueue(name,port))
except Exception:
traceback.print_exc()
#print "")
print(InObject.counter, "In devices")
#ListInDevice()
def ListInDevice():
#print "known IN devices :"
for item in InObject.getinstances():
print(item.name)
print("")
def FindInDevice(name):
port = -1
for item in InObject.getinstances():
#print "searching", name, "in", item.name)
if name in item.name:
#print 'found port',item.port)
port = item.port
return port
def DelInDevice(name):
Innumber = Findest(name)
print('deleting InDevice', name)
if Innumber != -1:
print('found InDevice', Innumber)
delattr(InObject, str(name))
print("InDevice", Innumber,"was removed")
else:
print("InDevice was not found")
def End():
global midiout
#midiin.close_port()
midiout.close_port()
#del virtual
if launchpad.Here != -1:
del launchpad.Here
if bhoreal.Here != -1:
del bhoreal.Here
if LPD8.Here != -1:
del LPD8.Here
# mididest : all or specifiname, won't be sent to launchpad or Bhoreal.
def MidiMsg(midimsg, mididest):
desterror = -1
print("jamidi3 got midimsg", midimsg, "for", mididest)
for port in range(len(OutDevice)):
# To mididest
if midiname[port].find(mididest) != -1:
if gstt.debug>0:
print("jamidi3 sending to name", midiname[port], "port", port, ":", midimsg)
midiport[port].send_message(midimsg)
desterror = 0
if desterror == -1:
print("mididest",mididest, ": ** This midi destination doesn't exists **")
# send midi msg over ws.
#if gstt.clientmode == True:
# ws.send("/ocs2/cc/1 2")
'''
def NoteOn(note, velocity, mididest):
global MidInsNumber
for port in range(MidInsNumber):
# To mididest
if midiname[port].find(mididest) == 0:
midiport[port].send_message([NOTE_ON, note, velocity])
'''
def listdevice(number):
return midiname[number]
def check():
OutConfig()
InConfig()

204
plugins/aurora/user.py Normal file
View file

@ -0,0 +1,204 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# -*- mode: Python -*-
'''
Aurora tutorial generator
Square
LICENCE : CC
Sam Neurohack
2 Cases :
1/ You generate one points position (x,y,z) list, like a one color square and send it back to Aurora that will add color, move your points,...
cf code Case 1
2/ You need several points positions lists with different parameters like colors,...
cf code Case 2
You need to use as much as primitive drawing functions you need :
- PolyLineOneColor, rPolyLineOneColor, LineTo, Line
- PolyLineRGB, rPolyLineRGB, LineRGBTo, LineRGB
- Text(word, integercolor, layer , xpos, ypos, resize, rotx, roty, rotz) : Display a word
- TextRGB(word, red, green, blue, ...)
Your function get a LAY argument
Layer properties from current UI. But you can use your numbers
'number': 0
'FX': "anim.Maxwell"
'scandots': 10
'scale': 2
'color': red
"run": True
'Xcoord': 0
'Ycoord': 250
'Zcoord': 0
'Xtransamt': 0
'Ytransamt': 0
'Ztransamt': 0
'Xtranspeed': 0
'Ytranspeed': 0
'Ztranspeed': 0
'Xrotdirec': 0
'Yrotdirec': 0
'Zrotdirec': 0
'Xrotspeed': 0
'Yrotspeed': 0
'Zrotspeed': 0
'rotspeed': 0
'lineSize': 300
'radius': 150
'wavefreq': 3
'step':0
'steps': 500
'stepmax': 200
'stepvals': []
'intensity': 255
'closed': False
'word': "hello"
'''
import numpy as np
#
# Code Case 1
#
def slinear(samples, min, max):
return np.linspace(min, max, samples)
# draw a square
def User1(LAY):
dots = []
size = LAY['lineSize']
number = LAY['scandots']
for x in slinear(number, 0, size):
dots.append((x , 0, 0))
for y in slinear(number, 0, size):
dots.append((size , y, 0))
for x in slinear(number, size, 0):
dots.append((x , size, 0))
for y in slinear(number, size, 0):
dots.append((0 , y, 0))
#print(dots)
return dots
#
# Code Case 2
#
import os, sys
import math
ljpath = r'%s' % os.getcwd().replace('\\','/')
#import from LJ
#sys.path.append(ljpath +'/libs/')
sys.path.append('../libs3')
#sys.path.append(ljpath +'/../../libs')
import lj23layers as lj
width = 800
height = 600
centerX = width / 2
centerY = height / 2
# colors examples
white = lj.rgb2int(255,255,255)
red = lj.rgb2int(255,0,0)
blue = lj.rgb2int(0,0,255)
green = lj.rgb2int(0,255,0)
cyan = lj.rgb2int(255,0,255)
yellow = lj.rgb2int(255,255,0)
def User2(LAY):
for y in range(0, 300):
dots = []
lj.rLine((100 , y, 0), (150 , y, 0), c= red, layer = LAY['number'], xpos = LAY['Xcoord'], ypos = LAY['Ycoord'], resize = LAY['scale'], rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
lj.rLineTo((200, y, 0), c= green, layer = LAY['number'], xpos = -300 +LAY['Xcoord'], ypos = -300+LAY['Ycoord'], resize = LAY['scale'], rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
lj.rLineTo((300, y, 0), c= red, layer = LAY['number'], xpos = -300 +LAY['Xcoord'], ypos = -300+LAY['Ycoord'], resize = LAY['scale'], rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
lj.rLineTo((350, y, 0), c= green, layer = LAY['number'], xpos = -300 +LAY['Xcoord'], ypos = -300+LAY['Ycoord'], resize = LAY['scale'], rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
lj.rLineTo((400,y, 0), c= red, layer = LAY['number'], xpos = -300 +LAY['Xcoord'], ypos = -300+LAY['Ycoord'], resize = LAY['scale'], rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
'''
for x in slinear(number, 0, 300):
dots = []
if 50 < x < 60:
dots.append((x , y, 0))
rLineTo(xy, c, layer , xpos = 0, ypos =0, resize =0.7, rotx =0, roty =0 , rotz=0)
else:
lj.rPolyLineOneColor(dots, c = LAY['color'], layer = LAY['number'], closed = False, xpos = -300 +LAY['Xcoord'], ypos = -300+LAY['Ycoord'], resize = LAY['scale'], rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
for x in slinear(number, size, 0):
dots.append((x , size, 0))
'''
#lj.rPolyLineRGBr(dots, c = white, layer = LAY['number'], closed = False, xpos = -300 +LAY['Xcoord'], ypos = -300+LAY['Ycoord'], resize = LAY['scale'], rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
#lj.rPolyLineOneColor(dots, c = LAY['color'], layer = LAY['number'], closed = False, xpos = -300 +LAY['Xcoord'], ypos = -300+LAY['Ycoord'], resize = LAY['scale'], rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
def User3(LAY, data):
dots = []
for angle in slinear(LAY['scandots'], 0, 360):
rad = angle * math.pi / 180
x = LAY['radius'] * math.cos(rad)
y = LAY['radius'] * math.sin(rad)
dots.append((x+LAY['lineSize']/2, y, 0))
lj.rPolyLineOneColor(dots, c = white, layer = LAY['number'], closed = False, xpos = -300 +LAY['Xcoord'], ypos = -300+LAY['Ycoord'], resize = LAY['scale'], rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
lj.rPolyLineOneColor(dots, c = LAY['color'], layer = LAY['number'], closed = False, xpos = -300 +LAY['Xcoord'], ypos = -300+LAY['Ycoord'], resize = LAY['scale'], rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
# draw an helix
def User4(LAY):
dots = []
for angle in slinear(LAY['scandots'], 0, 360*LAY['wavefreq']):
rad = angle * math.pi / 180
x = LAY['radius'] * math.cos(rad)
y = LAY['radius'] * math.sin(rad)
z = angle * 2
dots.append((x+LAY['lineSize']/2, y, z))
#print(dots)
return dots
# draw a point
def User4(LAY):
dots = []
dots.append((centerX,centerY, 0))
dots.append((centerX +2,centerY+2, 0))
lj.rPolyLineOneColor(dots, c = red, layer = LAY['number'], closed = False, xpos = LAY['Xcoord'], ypos = -300+LAY['Ycoord'], resize = LAY['scale'], rotx = LAY['Xrotdirec'], roty = LAY['Yrotdirec'], rotz = LAY['Zrotdirec'])
#print(dots)
return dots