Merge branch 'main' of github.com:Chroma-Case/Chromacase

This commit is contained in:
Clément Le Bihan
2022-04-16 00:17:27 +02:00
10 changed files with 41 additions and 16 deletions
+41 -16
View File
@@ -1,3 +1,4 @@
from xmlrpc.client import TRANSPORT_ERROR
from chroma_case.Partition import Partition
from chroma_case.Note import Note
import asyncio
@@ -6,6 +7,12 @@ from mido import MidiFile
import board, neopixel
# on octave is 12
RATIO = float(sys.argv[2] if len(sys.argv) > 2 else 1)
OCTAVE = 5
OCTAVE_AMOUNT_KEYS = 12
TRANSPOSE_AMOUNT = OCTAVE_AMOUNT_KEYS * OCTAVE
pixels = neopixel.NeoPixel(board.D18, 20, brightness=0.01)
notePixels = { 'si': [19],
@@ -14,8 +21,8 @@ notePixels = { 'si': [19],
'sol#':[15],
'sol':[13],
'fa#':[10],
'fa':[8],
'mi':[7],
'fa':[9],
'mi':[6],
're#':[5],
're':[3],
'do#':[1],
@@ -50,7 +57,6 @@ async def to_chroma_case(data):
colored_pixels = notePixels[data["key"].lower()]
#if "announce" in data:
tmp = 1.0
c = data["color"]
"""for i in range(5):
for pixelId in colored_pixels:
@@ -70,7 +76,7 @@ async def to_chroma_case(data):
async def printing(data):
print(f"key: {data['key']}, c:{data['color']} for {data['duration'] / 1000}s")
print(f"key: {data['key']}, c:{data['color']} for {data['duration'] / 1000}s, time: {data['time']}")
await asyncio.sleep(data['duration'] / 1000)
print(f"end of {data['key']}")
@@ -80,7 +86,12 @@ def midi_key_my_key(midi_key):
keys.reverse()
return keys[midi_key - 60]
key_index = midi_key - TRANSPOSE_AMOUNT
if key_index >= len(keys):
print("key out of leb barre", key_index)
return "no_key"
return keys[key_index]
@@ -88,27 +99,34 @@ def midi_key_my_key(midi_key):
async def main():
default_duration = 900
default_color = (255, 255, 0)
default_color = (255, 0, 0)
notes = []
# notes will start to play at 3500 ms (colors at the start takes this amount of time)
s = 3500
notes_on = {}
prev_note_on = {}
note_color = {}
for msg in MidiFile(sys.argv[1]):
d = msg.dict()
print(msg, d)
s += d['time'] * 1000
print(msg, s)
s += d['time'] * 1000 * RATIO
if d["type"] == "note_on":
print(s)
prev_note_on[d["note"]] = 0
if d["note"] in notes_on:
prev_note_on[d["note"]] = notes_on[d["note"]] # 500
notes_on[d["note"]] = s # 0
if d["note"] not in note_color.keys():
note_color[d["note"]] = 1
note_color[d["note"]] = not note_color[d["note"]]
if d["type"] == "note_off":
duration = s - notes_on[d["note"]] - 100
notes_on[d["note"]] = s # 500
#duration = s - notes_on[d["note"]]
duration = s - notes_on[d["note"]]
"""notes.append(Note(
s - min(s - prev_note_on[d["note"]], 500),
{
@@ -118,17 +136,24 @@ async def main():
"announce": True
}
))"""
notes.append(Note(s, {"duration": duration, "color": default_color, "key": midi_key_my_key(d["note"])}))
note_start = notes_on[d["note"]]
# time value is only used during debug
notes.append(Note(note_start, {"time": note_start, "duration": duration - 10, "color": default_color if note_color[d["note"]] else (255, 100, 0), "key": midi_key_my_key(d["note"])}))
notes_on[d["note"]] = s # 500
starting = []
for i in notePixels.keys():
starting += [
Note(000, {"duration": default_duration, "color": default_color, "key": i}),
Note(1000, {"duration": default_duration, "color": (255, 255, 0), "key": i}),
Note(2000, {"duration": default_duration, "color": (0, 255, 0), "key": i}),
Note(000, {"duration": default_duration, "color": (255, 0, 0), "key": i, "time": 0}),
Note(1000, {"duration": default_duration, "color": (255, 255, 0), "key": i, "time": 0}),
Note(2000, {"duration": default_duration, "color": (0, 255, 0), "key": i, "time": 0}),
]
p = Partition("test",
p = Partition("my_partition",
starting + notes
)
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 MiB

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.