Compare commits
9 Commits
18aaa1b625
...
5f7c61f616
Author | SHA1 | Date | |
---|---|---|---|
|
5f7c61f616 | ||
|
31e4e66408 | ||
|
50b3806825 | ||
|
2f54d37856 | ||
|
1e43a5fc43 | ||
|
8e9cd509ab | ||
|
df068b8e30 | ||
|
0b7ad2d75b | ||
|
b2cc1b1ff5 |
@ -47,6 +47,7 @@ try:
|
|||||||
line = sys.stdin.readline()
|
line = sys.stdin.readline()
|
||||||
if line == "":
|
if line == "":
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
continue
|
||||||
line = line.rstrip('\n')
|
line = line.rstrip('\n')
|
||||||
line=line[1:-1]
|
line=line[1:-1]
|
||||||
line = line.replace("[",'(')
|
line = line.replace("[",'(')
|
||||||
|
@ -162,8 +162,7 @@ try:
|
|||||||
pointsList = ast.literal_eval(line)
|
pointsList = ast.literal_eval(line)
|
||||||
# Do the filter
|
# Do the filter
|
||||||
result = kaleidoscope( pointsList )
|
result = kaleidoscope( pointsList )
|
||||||
print( result, flush=True )
|
if len(result) : print( result, flush=True )
|
||||||
|
|
||||||
looptime = time.time() - start
|
looptime = time.time() - start
|
||||||
# debug(name+" looptime:"+str(looptime))
|
# debug(name+" looptime:"+str(looptime))
|
||||||
if( looptime < optimal_looptime ):
|
if( looptime < optimal_looptime ):
|
||||||
|
6
clitools/filters/redilysis_colors.py
Normal file → Executable file
6
clitools/filters/redilysis_colors.py
Normal file → Executable file
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# -*- mode: Python -*-
|
# -*- mode: Python -*-
|
||||||
@ -145,8 +144,11 @@ def default( pl ):
|
|||||||
colorTuple = int2rgb(ocolor)
|
colorTuple = int2rgb(ocolor)
|
||||||
x = point[0]
|
x = point[0]
|
||||||
dist = abs(x - max_width/2)
|
dist = abs(x - max_width/2)
|
||||||
key = int(2* dist / max_width * 8)
|
key = int(2* dist / max_width * 7)
|
||||||
|
try:
|
||||||
power = spect[key] / spect10Correct[key] * chaos
|
power = spect[key] / spect10Correct[key] * chaos
|
||||||
|
except:
|
||||||
|
pass
|
||||||
color = []
|
color = []
|
||||||
for i in colorTuple:
|
for i in colorTuple:
|
||||||
new_color = int(i * power)
|
new_color = int(i * power)
|
||||||
|
53
clitools/generators/blank.py
Executable file
53
clitools/generators/blank.py
Executable file
@ -0,0 +1,53 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# -*- mode: Python -*-
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
Send only black points
|
||||||
|
v0.1.0
|
||||||
|
|
||||||
|
Use it to test your filters and outputs
|
||||||
|
|
||||||
|
LICENCE : CC
|
||||||
|
|
||||||
|
by cocoa
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
import time
|
||||||
|
import argparse
|
||||||
|
import sys
|
||||||
|
name="generator::dummy"
|
||||||
|
|
||||||
|
|
||||||
|
def debug(*args, **kwargs):
|
||||||
|
if( verbose == False ):
|
||||||
|
return
|
||||||
|
print(*args, file=sys.stderr, **kwargs)
|
||||||
|
|
||||||
|
argsparser = argparse.ArgumentParser(description="dummy generator")
|
||||||
|
argsparser.add_argument("-f","--fps",help="Frame Per Second",default=30,type=int)
|
||||||
|
argsparser.add_argument("-v","--verbose",action="store_true",help="Verbose output")
|
||||||
|
args = argsparser.parse_args()
|
||||||
|
|
||||||
|
fps=args.fps
|
||||||
|
verbose=args.verbose
|
||||||
|
optimal_looptime = 1 / fps
|
||||||
|
debug(name+" optimal looptime "+str(optimal_looptime))
|
||||||
|
|
||||||
|
|
||||||
|
shape = [[400,400,0],[400,400,64],[400,400,0]]
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
start = time.time()
|
||||||
|
print(shape, flush=True);
|
||||||
|
looptime = time.time() - start
|
||||||
|
if( looptime < optimal_looptime ):
|
||||||
|
time.sleep( optimal_looptime - looptime)
|
||||||
|
debug(name+" micro sleep:"+str( optimal_looptime - looptime))
|
||||||
|
|
||||||
|
|
@ -28,9 +28,9 @@ def debug(*args, **kwargs):
|
|||||||
return
|
return
|
||||||
print(*args, file=sys.stderr, **kwargs)
|
print(*args, file=sys.stderr, **kwargs)
|
||||||
|
|
||||||
|
argsparser = argparse.ArgumentParser(description="dummy generator")
|
||||||
argsparser = argparse.ArgumentParser(description="Dummy generator")
|
|
||||||
argsparser.add_argument("-f","--fps",help="Frame Per Second",default=30,type=int)
|
argsparser.add_argument("-f","--fps",help="Frame Per Second",default=30,type=int)
|
||||||
|
argsparser.add_argument("-s","--speed",help="point per frame progress",default=3,type=int)
|
||||||
argsparser.add_argument("-v","--verbose",action="store_true",help="Verbose output")
|
argsparser.add_argument("-v","--verbose",action="store_true",help="Verbose output")
|
||||||
args = argsparser.parse_args()
|
args = argsparser.parse_args()
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ fps=args.fps
|
|||||||
verbose=args.verbose
|
verbose=args.verbose
|
||||||
optimal_looptime = 1 / fps
|
optimal_looptime = 1 / fps
|
||||||
debug(name+" optimal looptime "+str(optimal_looptime))
|
debug(name+" optimal looptime "+str(optimal_looptime))
|
||||||
color = 65280
|
color = 16777215
|
||||||
square = [[100.0, 100.0, color], [100.0, 500.0, color], [500.0, 500.0, color], [500.0, 100.0, color], [100.0, 100.0, color]]
|
square = [[100.0, 100.0, color], [100.0, 500.0, color], [500.0, 500.0, color], [500.0, 100.0, color], [100.0, 100.0, color]]
|
||||||
line =[]
|
line =[]
|
||||||
for i in range(00,800,int(800/120)):
|
for i in range(00,800,int(800/120)):
|
||||||
|
72
clitools/generators/fromRedis.py
Executable file
72
clitools/generators/fromRedis.py
Executable file
@ -0,0 +1,72 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# -*- mode: Python -*-
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
This generator reads a frame from redis
|
||||||
|
v0.1.0
|
||||||
|
|
||||||
|
Use it to create feedback loops by writing to the same frame
|
||||||
|
or to copy the frame from someone else
|
||||||
|
|
||||||
|
LICENCE : CC
|
||||||
|
|
||||||
|
by cocoa
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
import ast
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
import redis
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
name="generator::fromRedis"
|
||||||
|
|
||||||
|
|
||||||
|
def debug(*args, **kwargs):
|
||||||
|
if( verbose == False ):
|
||||||
|
return
|
||||||
|
print(*args, file=sys.stderr, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
argsparser = argparse.ArgumentParser(description="Dummy generator")
|
||||||
|
argsparser.add_argument("-k","--key",required=True,help="Redis key to look after",default=30,type=str)
|
||||||
|
argsparser.add_argument("-i","--ip",help="IP address of the Redis server ",default="127.0.0.1",type=str)
|
||||||
|
argsparser.add_argument("-p","--port",help="Port of the Redis server ",default="6379",type=str)
|
||||||
|
argsparser.add_argument("-f","--fps",help="Frame Per Second",default=30,type=int)
|
||||||
|
argsparser.add_argument("-v","--verbose",action="store_true",help="Verbose output")
|
||||||
|
args = argsparser.parse_args()
|
||||||
|
|
||||||
|
fps = args.fps
|
||||||
|
verbose = args.verbose
|
||||||
|
key = args.key
|
||||||
|
ip = args.ip
|
||||||
|
port = args.port
|
||||||
|
optimal_looptime = 1 / fps
|
||||||
|
debug(name+" optimal looptime "+str(optimal_looptime))
|
||||||
|
|
||||||
|
r = redis.Redis(
|
||||||
|
host=ip,
|
||||||
|
port=port)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
start = time.time()
|
||||||
|
# Read from Redis
|
||||||
|
line = r.get(key)
|
||||||
|
# Decode as list of tuples
|
||||||
|
pointsList = ast.literal_eval(line.decode('ascii'))
|
||||||
|
# convert to list of lists
|
||||||
|
pointsList = [list(elem) for elem in pointsList]
|
||||||
|
# Convert to JSON string
|
||||||
|
line = json.dumps( pointsList )
|
||||||
|
debug(name,"Key:{} line:{}".format(key,line))
|
||||||
|
print(line, flush=True);
|
||||||
|
looptime = time.time() - start
|
||||||
|
if( looptime < optimal_looptime ):
|
||||||
|
time.sleep( optimal_looptime - looptime)
|
||||||
|
debug(name+" micro sleep:"+str( optimal_looptime - looptime))
|
||||||
|
|
@ -62,7 +62,25 @@ square = [
|
|||||||
[-1,1]
|
[-1,1]
|
||||||
]
|
]
|
||||||
|
|
||||||
shape = square
|
circle = [[1,0],
|
||||||
|
[0.9238795325112867,0.3826834323650898],
|
||||||
|
[0.7071067811865476,0.7071067811865475],
|
||||||
|
[0.38268343236508984,0.9238795325112867],
|
||||||
|
[0,1.0],
|
||||||
|
[-0.3826834323650897,0.9238795325112867],
|
||||||
|
[-0.7071067811865475,0.7071067811865476],
|
||||||
|
[-0.9238795325112867,0.3826834323650899],
|
||||||
|
[-1.0,0],
|
||||||
|
[-0.9238795325112868,-0.38268343236508967],
|
||||||
|
[-0.7071067811865477,-0.7071067811865475],
|
||||||
|
[-0.38268343236509034,-0.9238795325112865],
|
||||||
|
[0,-1.0],
|
||||||
|
[0.38268343236509,-0.9238795325112866],
|
||||||
|
[0.707106781186548,-0.707106781186547],
|
||||||
|
[0.9238795325112872,-0.3826834323650887],
|
||||||
|
[1,0]]
|
||||||
|
|
||||||
|
shape = circle
|
||||||
currentCenter = [centerX, centerY]
|
currentCenter = [centerX, centerY]
|
||||||
centerVector= [0,0]
|
centerVector= [0,0]
|
||||||
# tweak random basis
|
# tweak random basis
|
||||||
|
@ -10,6 +10,16 @@ import json
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import redis
|
import redis
|
||||||
|
|
||||||
|
|
||||||
|
environ = {
|
||||||
|
# "REDIS_IP" : "127.0.0.1",
|
||||||
|
"REDIS_IP" : "192.168.2.44",
|
||||||
|
"REDIS_PORT" : "6379",
|
||||||
|
"REDIS_KEY" : "/pl/0/0",
|
||||||
|
"REDIS_SCENE" : "0",
|
||||||
|
"REDIS_LASER" : "0"
|
||||||
|
}
|
||||||
|
|
||||||
class bcolors:
|
class bcolors:
|
||||||
HL = '\033[31m'
|
HL = '\033[31m'
|
||||||
OKBLUE = '\033[94m'
|
OKBLUE = '\033[94m'
|
||||||
@ -37,8 +47,8 @@ def intkey():
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
print("Error.")
|
print("Error.")
|
||||||
|
|
||||||
current_id=0
|
current_id = 0
|
||||||
current_cmd=""
|
current_cmd = ""
|
||||||
process = None
|
process = None
|
||||||
current_filename = ""
|
current_filename = ""
|
||||||
currentPlayList = []
|
currentPlayList = []
|
||||||
@ -105,10 +115,12 @@ def action_changeCommand( inc ):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def action_match( k ):
|
def action_match( k ):
|
||||||
|
global current_id, currentPlayList
|
||||||
if int(k) > (len(currentPlayList) - 1):
|
if int(k) > (len(currentPlayList) - 1):
|
||||||
print( bcolors.HL + "This key does not exist" + bcolors.ENDC )
|
print( bcolors.HL + "This key does not exist" + bcolors.ENDC )
|
||||||
return False
|
return False
|
||||||
else :
|
else :
|
||||||
|
_ok("Changed action id to {}.".format(k))
|
||||||
current_id = int(k)
|
current_id = int(k)
|
||||||
|
|
||||||
def action_runCommand():
|
def action_runCommand():
|
||||||
@ -155,7 +167,7 @@ def action_deleteCommand():
|
|||||||
action_listAll()
|
action_listAll()
|
||||||
key = int(input())
|
key = int(input())
|
||||||
# Exit early
|
# Exit early
|
||||||
if "x" == k:
|
if "x" == key:
|
||||||
return(False)
|
return(False)
|
||||||
del currentPlayList[key]
|
del currentPlayList[key]
|
||||||
return True
|
return True
|
||||||
@ -163,7 +175,7 @@ def action_deleteCommand():
|
|||||||
|
|
||||||
|
|
||||||
def action_listAll():
|
def action_listAll():
|
||||||
global currentPlayList, current_cmd
|
global currentPlayList, current_cmd, current_id
|
||||||
print("\n--------------------------------------")
|
print("\n--------------------------------------")
|
||||||
for i,seq in enumerate(currentPlayList):
|
for i,seq in enumerate(currentPlayList):
|
||||||
pre=""
|
pre=""
|
||||||
@ -232,7 +244,7 @@ def action_loadPlaylist():
|
|||||||
print( bcolors.HL + "This key '{}' is not valid".format(k) + bcolors.ENDC )
|
print( bcolors.HL + "This key '{}' is not valid".format(k) + bcolors.ENDC )
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Load file
|
# @todo replace with _loadPlaylist
|
||||||
playlistFile = Path("./playlists/"+file_list[k].name)
|
playlistFile = Path("./playlists/"+file_list[k].name)
|
||||||
currentPlayList = json.loads(playlistFile.read_text())
|
currentPlayList = json.loads(playlistFile.read_text())
|
||||||
current_playlist_name = file_list[k].name
|
current_playlist_name = file_list[k].name
|
||||||
@ -242,7 +254,18 @@ def action_loadPlaylist():
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def _loadPlaylist( filename ):
|
||||||
|
|
||||||
|
global currentPlayList, current_playlist_name, current_id
|
||||||
|
try:
|
||||||
|
playlistFile = Path(filename)
|
||||||
|
currentPlayList = json.loads(playlistFile.read_text())
|
||||||
|
current_playlist_name = filename
|
||||||
|
current_id = 0
|
||||||
|
_ok("Playlist loaded: {}\n".format(current_playlist_name))
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
_err("_loadPlaylist error when loading '{}':{}".format(filename,e))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -354,12 +377,3 @@ def action_quit():
|
|||||||
if quit != "n":
|
if quit != "n":
|
||||||
_kill(process)
|
_kill(process)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
environ = {
|
|
||||||
# "REDIS_IP" : "127.0.0.1",
|
|
||||||
"REDIS_IP" : "192.168.2.44",
|
|
||||||
"REDIS_PORT" : "6379",
|
|
||||||
"REDIS_KEY" : "/pl/0/0",
|
|
||||||
"REDIS_SCENE" : "0",
|
|
||||||
"REDIS_LASER" : "0"
|
|
||||||
}
|
|
||||||
|
91
clitools/runner_midi.py
Normal file → Executable file
91
clitools/runner_midi.py
Normal file → Executable file
@ -1,12 +1,87 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import sys
|
import argparse
|
||||||
import os
|
|
||||||
import signal
|
|
||||||
import subprocess
|
|
||||||
import time
|
|
||||||
import tty,termios
|
|
||||||
import re
|
import re
|
||||||
import json
|
import redis
|
||||||
from pathlib import Path
|
|
||||||
import runner_lib as runner
|
import runner_lib as runner
|
||||||
|
import time
|
||||||
|
|
||||||
|
novationRows = [
|
||||||
|
[ 0, 1, 2, 3, 4, 5, 6, 7 ],
|
||||||
|
[ *range(16,24)],
|
||||||
|
[ *range(32,40)],
|
||||||
|
[ *range(48,56)]
|
||||||
|
]
|
||||||
|
|
||||||
|
argsparser = argparse.ArgumentParser(description="Playlist midi")
|
||||||
|
argsparser.add_argument("playlist",help="JSON playlist file ",type=str)
|
||||||
|
argsparser.add_argument("-i","--ip",help="IP address of the Redis server ",default="127.0.0.1",type=str)
|
||||||
|
argsparser.add_argument("-r","--row",help="Row of Novation pad. Default:1 ",default=1,type=str)
|
||||||
|
argsparser.add_argument("-k","--key",help="Redis key to update",default="0",type=str)
|
||||||
|
argsparser.add_argument("-l","--laser",help="Laser number. Default:0 ",default=0,type=int)
|
||||||
|
argsparser.add_argument("-p","--port",help="Port of the Redis server ",default="6379",type=str)
|
||||||
|
argsparser.add_argument("-s","--scene",help="Laser scene. Default:0 ",default=0,type=int)
|
||||||
|
argsparser.add_argument("-v","--verbose",action="store_true",help="Verbose")
|
||||||
|
args = argsparser.parse_args()
|
||||||
|
|
||||||
|
ip = args.ip
|
||||||
|
port = args.port
|
||||||
|
key = args.key
|
||||||
|
verbose=args.verbose
|
||||||
|
laser = args.laser
|
||||||
|
scene = args.scene
|
||||||
|
playlist = args.playlist
|
||||||
|
row = args.row - 1
|
||||||
|
rowKeys = novationRows[row]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Subscriber
|
||||||
|
|
||||||
|
r = redis.StrictRedis(host=ip, port=port, db=0)
|
||||||
|
p = r.pubsub()
|
||||||
|
p.subscribe('/midi/last_event')
|
||||||
|
runner._killBill()
|
||||||
|
|
||||||
|
# Set Laser and scene
|
||||||
|
runner._setKey( laser = laser, scene = scene)
|
||||||
|
|
||||||
|
# Load playlist
|
||||||
|
runner._loadPlaylist( playlist )
|
||||||
|
|
||||||
|
print("Loaded playlist : {}".format(runner.currentPlayList))
|
||||||
|
|
||||||
|
|
||||||
|
runner.action_info()
|
||||||
|
runner.current_id = -1
|
||||||
|
while True:
|
||||||
|
runner._killBill()
|
||||||
|
|
||||||
|
message = p.get_message()
|
||||||
|
if message:
|
||||||
|
#runner._ok ("Subscriber: %s" % message['data'])
|
||||||
|
|
||||||
|
|
||||||
|
# b'/midi/noteon/0/19/127'
|
||||||
|
match = re.match(".*/([0-9]+)/[0-9]+",str(message['data']))
|
||||||
|
if not match:
|
||||||
|
continue
|
||||||
|
key = int(match.group(1))
|
||||||
|
|
||||||
|
# Check if the event is for us
|
||||||
|
if key not in rowKeys:
|
||||||
|
print("key {} not in {} ".format(key,rowKeys))
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
command_id = rowKeys.index(key)
|
||||||
|
cmd = runner.currentPlayList[command_id]
|
||||||
|
|
||||||
|
if command_id != runner.current_id :
|
||||||
|
runner._ok("Launching command #{}\n Previous was {}\n Cmd:{}".format(command_id,runner.current_id,cmd))
|
||||||
|
runner.action_match(command_id)
|
||||||
|
runner.action_runCommand()
|
||||||
|
else :
|
||||||
|
runner._err("Not running {} : already running.".format(command_id))
|
||||||
|
except Exception as e :
|
||||||
|
print("Woops.",e)
|
||||||
|
Loading…
Reference in New Issue
Block a user