Spaces:
Sleeping
Sleeping
update ip version, add songs
Browse files- app.py +67 -11
- requirements.txt +1 -1
app.py
CHANGED
@@ -36,23 +36,34 @@ def display_color(context={}):
|
|
36 |
return get_color(note, size=(256, 256))
|
37 |
|
38 |
|
|
|
|
|
|
|
|
|
|
|
39 |
def get_color(note, size=(256, 256)):
|
40 |
colors = {
|
41 |
"red": (1.0, 0.0, 0.0),
|
42 |
"orange": (1.0, 0.65, 0.0),
|
43 |
-
"yellow": (
|
44 |
"green": (0.0, 0.5, 0.0),
|
45 |
-
"
|
46 |
-
"dark blue": (0.0, 0.0, 0.
|
47 |
"purple": (0.5, 0.0, 0.5),
|
48 |
-
"pink": (1.0, 0.75, 0.8)
|
|
|
49 |
}
|
50 |
-
notes_translation = ["DO", "RE", "MI", "FA", "SOL", "LA", "SI", "DO"]
|
51 |
index = list(NOTE_FREQUENCIES.keys()).index(note)
|
52 |
color = colors.get(list(colors.keys())[index], [0., 0., 0.])
|
53 |
img = np.ones((size[1], size[0], 3)) * np.array(color)[None, None, :]
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
thickness = 2
|
57 |
text_size = cv2.getTextSize(
|
58 |
text, cv2.FONT_HERSHEY_SIMPLEX, font_scale, thickness)[0]
|
@@ -62,16 +73,58 @@ def get_color(note, size=(256, 256)):
|
|
62 |
img,
|
63 |
text,
|
64 |
(text_x, text_y),
|
65 |
-
cv2.FONT_HERSHEY_SIMPLEX, font_scale, (
|
66 |
)
|
67 |
return img
|
68 |
|
69 |
|
70 |
def xylo_player():
|
|
|
71 |
select_note()
|
72 |
audio = create_note()
|
73 |
play_note(audio)
|
74 |
out_image = display_color()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
return out_image
|
76 |
|
77 |
|
@@ -86,6 +139,9 @@ if __name__ == '__main__':
|
|
86 |
img = get_color(note, size=(512, 512))
|
87 |
Image.save_image(img, icon)
|
88 |
interactive(note=Control("C4", all_notes, icons=icon_list))(select_note)
|
89 |
-
|
90 |
-
interactive_pipeline(
|
91 |
-
|
|
|
|
|
|
|
|
36 |
return get_color(note, size=(256, 256))
|
37 |
|
38 |
|
39 |
+
NOTES_TRANSLATION = ["do", "re", "mi", "fa", "sol", "la", "si", "do2"]
|
40 |
+
NOTES_CORRESPONDANCE = {
|
41 |
+
NOTES_TRANSLATION[i]: note for i, note in enumerate(list(NOTE_FREQUENCIES.keys()))}
|
42 |
+
|
43 |
+
|
44 |
def get_color(note, size=(256, 256)):
|
45 |
colors = {
|
46 |
"red": (1.0, 0.0, 0.0),
|
47 |
"orange": (1.0, 0.65, 0.0),
|
48 |
+
"yellow": (0.9, 0.9, 0.0),
|
49 |
"green": (0.0, 0.5, 0.0),
|
50 |
+
"cyan": (0.0, 0.7, 1.0),
|
51 |
+
"dark blue": (0.0, 0.0, 0.7),
|
52 |
"purple": (0.5, 0.0, 0.5),
|
53 |
+
"pink": (1.0, 0.75, 0.8),
|
54 |
+
|
55 |
}
|
|
|
56 |
index = list(NOTE_FREQUENCIES.keys()).index(note)
|
57 |
color = colors.get(list(colors.keys())[index], [0., 0., 0.])
|
58 |
img = np.ones((size[1], size[0], 3)) * np.array(color)[None, None, :]
|
59 |
+
border_size = 4
|
60 |
+
border_color = (0.2, 0.2, 0.2)
|
61 |
+
img[:border_size, :] = border_color
|
62 |
+
img[-border_size:, :] = border_color
|
63 |
+
img[:, :border_size] = border_color
|
64 |
+
img[:, -border_size:] = border_color
|
65 |
+
text = NOTES_TRANSLATION[index].upper()
|
66 |
+
font_scale = size[0] // 64
|
67 |
thickness = 2
|
68 |
text_size = cv2.getTextSize(
|
69 |
text, cv2.FONT_HERSHEY_SIMPLEX, font_scale, thickness)[0]
|
|
|
73 |
img,
|
74 |
text,
|
75 |
(text_x, text_y),
|
76 |
+
cv2.FONT_HERSHEY_SIMPLEX, font_scale, (255, 255, 255), thickness
|
77 |
)
|
78 |
return img
|
79 |
|
80 |
|
81 |
def xylo_player():
|
82 |
+
full_song = song_player()
|
83 |
select_note()
|
84 |
audio = create_note()
|
85 |
play_note(audio)
|
86 |
out_image = display_color()
|
87 |
+
return [full_song, out_image]
|
88 |
+
|
89 |
+
|
90 |
+
SONG_1 = "au clair de la lune"
|
91 |
+
SONG_2 = "ainsi font, font, font"
|
92 |
+
|
93 |
+
|
94 |
+
def song_player(song: str=SONG_1, context={}):
|
95 |
+
SONG = {
|
96 |
+
SONG_1: "fa fa fa sol la - sol - la sol sol fa - fa fa fa sol la",
|
97 |
+
SONG_2: "mi mi do - mi - sol - sol - la sol fa mi re mi do mi mi do - mi - sol - sol - la sol fa mi re do"
|
98 |
+
}
|
99 |
+
song_str = SONG.get(song, "")
|
100 |
+
return generate_song(song_str)
|
101 |
+
|
102 |
+
|
103 |
+
def generate_song(song_str):
|
104 |
+
notes = song_str.split(" ")
|
105 |
+
all_notes = []
|
106 |
+
size = (64, 128)
|
107 |
+
for note in notes:
|
108 |
+
if note in ["-", "."]:
|
109 |
+
img_note = np.zeros((size[1], size[0], 3))
|
110 |
+
else:
|
111 |
+
note_classic = NOTES_CORRESPONDANCE.get(note, None)
|
112 |
+
if note_classic is None:
|
113 |
+
print(f"Note {note} not found")
|
114 |
+
continue
|
115 |
+
img_note = get_color(note_classic, size=size)
|
116 |
+
all_notes.append(img_note)
|
117 |
+
|
118 |
+
# out_image = np.hstack(all_notes)
|
119 |
+
max_notes_per_line = 12
|
120 |
+
remainder = max_notes_per_line - len(all_notes) % max_notes_per_line
|
121 |
+
for _ in range(remainder):
|
122 |
+
all_notes.append(np.zeros_like(all_notes[0]))
|
123 |
+
# out_image = np.hstack(all_notes)
|
124 |
+
# print(len(all_notes))
|
125 |
+
note_lines = [all_notes[i:i + max_notes_per_line]
|
126 |
+
for i in range(0, len(all_notes), max_notes_per_line)]
|
127 |
+
out_image = np.vstack([np.hstack(line) for line in note_lines])
|
128 |
return out_image
|
129 |
|
130 |
|
|
|
139 |
img = get_color(note, size=(512, 512))
|
140 |
Image.save_image(img, icon)
|
141 |
interactive(note=Control("C4", all_notes, icons=icon_list))(select_note)
|
142 |
+
interactive(song=(SONG_1, [SONG_1, SONG_2]))(song_player)
|
143 |
+
interactive_pipeline(
|
144 |
+
gui=args.backend,
|
145 |
+
cache=False,
|
146 |
+
audio=True
|
147 |
+
)(xylo_player)()
|
requirements.txt
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
-
interactive-pipe
|
2 |
wavio
|
|
|
1 |
+
interactive-pipe>=0.8.0
|
2 |
wavio
|