diff options
-rw-r--r-- | README.md | 4 | ||||
-rwxr-xr-x | tlo-midi.py | 23 |
2 files changed, 19 insertions, 8 deletions
@@ -10,12 +10,12 @@ Requirements: * Python3 * Python3-pip -* mido (Can be installed using pip) +* mido and colour (Can be installed using pip) ``` opkg update opkg install python3-pip -pip3 install mido +pip3 install mido colour ``` Now you should be able to run `tlo-midi.py` script. Input must be midi file. If diff --git a/tlo-midi.py b/tlo-midi.py index 77263c0..5f89ba4 100755 --- a/tlo-midi.py +++ b/tlo-midi.py @@ -6,6 +6,8 @@ import os import time import argparse import mido +import copy +from colour import Color # Parse arguments parser = argparse.ArgumentParser(description='Turris leds midi track player') @@ -23,9 +25,9 @@ if args.c is not None: test_run = False if args.t is not None: test_run = args.t -color = '0xF00' # In default use red +color = Color('#FF0000') # In default use red if args.d is not None: - color = args.d[0] + color = Color(args.d[0]) # Load midi file midi = mido.MidiFile(midi_file) @@ -46,6 +48,16 @@ for msg in midi: if cut_bottom is None or cut_top is None: raise Exception("Midi file seems to contain no audio data") + +def calc_color(intens): + # intens is 0..127 + multi = intens/127 + clr = Color(color) + clr.red = clr.red * multi + clr.green = clr.green * multi + clr.blue = clr.blue * multi + return clr.get_hex_l()[1:] + rainbow_led = ( 'pwr', 'lan0', @@ -68,15 +80,14 @@ def output_line(): line = "" for i in range(0, 12): # We divide velocity by 13 to ensure resolution of 0-9 - # (velocity is 1..128) + # (velocity is 1..127) line = line + str(int(data_line[i]/13)) print(line) else: cmd = "rainbow " for i in range(0, 12): - cmd = cmd + rainbow_led[i] + " " + color + " intensity " - # Here range is from 0-100 - cmd = cmd + str(int(data_line[i]/1.28)) + " " + clr = calc_color(data_line[i]) + cmd = cmd + rainbow_led[i] + " " + clr + " " os.system(cmd) |