add rgb mode to visualizer
This commit is contained in:
parent
434b8fc84e
commit
a12d2e4a70
@ -36,10 +36,18 @@ def helpmenu():
|
|||||||
print("-s <hex-color> set static color")
|
print("-s <hex-color> set static color")
|
||||||
print("-v visualizer")
|
print("-v visualizer")
|
||||||
|
|
||||||
def visualizer():
|
def visualizer(color):
|
||||||
cava = subprocess.Popen(["cava", "-p", "./cava.conf"], stdout=subprocess.PIPE)
|
cava = subprocess.Popen(["cava", "-p", "./cava.conf"], stdout=subprocess.PIPE)
|
||||||
sed = subprocess.Popen(["sed", "-u", "s/;.*;$//"], stdin=cava.stdout, stdout=subprocess.PIPE)
|
sed = subprocess.Popen(["sed", "-u", "s/;.*;$//"], stdin=cava.stdout, stdout=subprocess.PIPE)
|
||||||
subprocess.Popen([sys.argv[0]], stdin=sed.stdout, shell=False)
|
#subprocess.Popen([sys.argv[0]], stdin=sed.stdout, shell=False)
|
||||||
|
for line in sed.stdout:
|
||||||
|
line = int(line)
|
||||||
|
r,g,b = hex_to_rgb(color)
|
||||||
|
r = int(r*(line/1000))
|
||||||
|
g = int(g*(line/1000))
|
||||||
|
b = int(b*(line/1000))
|
||||||
|
hex_color = rgb_to_hex(r,g,b)
|
||||||
|
send(hex_color)
|
||||||
cava.stdout.close()
|
cava.stdout.close()
|
||||||
sed.stdout.close()
|
sed.stdout.close()
|
||||||
|
|
||||||
@ -140,6 +148,11 @@ def ambient_light():
|
|||||||
def rgb_to_hex(r,g,b):
|
def rgb_to_hex(r,g,b):
|
||||||
return "%02x%02x%02x" % (r,g,b)
|
return "%02x%02x%02x" % (r,g,b)
|
||||||
|
|
||||||
|
def hex_to_rgb(hex):
|
||||||
|
r = int(hex[0:2],16)
|
||||||
|
g = int(hex[2:4],16)
|
||||||
|
b = int(hex[4:6],16)
|
||||||
|
return r,g,b
|
||||||
def test():
|
def test():
|
||||||
for i in range(256):
|
for i in range(256):
|
||||||
h = rgb_to_hex(0,i,0)
|
h = rgb_to_hex(0,i,0)
|
||||||
@ -157,7 +170,7 @@ def main(argv):
|
|||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(argv, "s:vaht")
|
opts, args = getopt.getopt(argv, "s:v:aht")
|
||||||
except getopt.GetoptError:
|
except getopt.GetoptError:
|
||||||
print(sys.argv[0], "invalid option")
|
print(sys.argv[0], "invalid option")
|
||||||
print("Try", sys.argv[0], "-h for help")
|
print("Try", sys.argv[0], "-h for help")
|
||||||
@ -178,7 +191,9 @@ def main(argv):
|
|||||||
disconnect()
|
disconnect()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
elif opt == "-v":
|
elif opt == "-v":
|
||||||
visualizer()
|
connect()
|
||||||
|
visualizer(arg)
|
||||||
|
disconnect()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
elif opt == "-t":
|
elif opt == "-t":
|
||||||
connect()
|
connect()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user