Spaces:
Runtime error
Runtime error
add more songs
Browse files
app.py
CHANGED
@@ -7,10 +7,20 @@ from time import sleep
|
|
7 |
import argparse
|
8 |
import cv2
|
9 |
import numpy as np
|
|
|
10 |
|
11 |
|
12 |
-
SONG_1 = "
|
13 |
-
SONG_2 = "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
|
16 |
def select_song(song: str = SONG_1, context={}):
|
@@ -40,11 +50,15 @@ def play_note(audio_signal: np.ndarray, context={}):
|
|
40 |
sleep(0.01)
|
41 |
print("waiting for file")
|
42 |
assert file_name.exists()
|
43 |
-
|
44 |
-
context["
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
48 |
|
49 |
|
50 |
def display_current_color(context={}):
|
@@ -127,10 +141,7 @@ def xylo_player():
|
|
127 |
|
128 |
def song_player(context={}):
|
129 |
song = context["song"]
|
130 |
-
|
131 |
-
SONG_1: "fa fa fa sol la - sol - la sol sol fa - fa fa fa sol la",
|
132 |
-
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"
|
133 |
-
}
|
134 |
song_str = SONG.get(song, "")
|
135 |
image_song, target_note = generate_song(
|
136 |
song_str, current_time=context.get("time_index", 0))
|
@@ -176,7 +187,7 @@ def generate_song(song_str, current_time=None) -> Tuple[np.ndarray, str]:
|
|
176 |
if __name__ == '__main__':
|
177 |
parser = argparse.ArgumentParser(description='Xylophone synthesizer')
|
178 |
parser.add_argument('-b', '--backend', type=str,
|
179 |
-
default='gradio', choices=['gradio', 'qt'])
|
180 |
args = parser.parse_args()
|
181 |
all_notes = list(NOTE_FREQUENCIES.keys())
|
182 |
icon_list = [Path(f"__{note}.jpg") for note in all_notes]
|
@@ -184,7 +195,7 @@ if __name__ == '__main__':
|
|
184 |
img = get_color(note, size=(512, 512))
|
185 |
Image.save_image(img, icon)
|
186 |
interactive(note=Control("C4", all_notes, icons=icon_list))(select_note)
|
187 |
-
interactive(song=(SONG_1,
|
188 |
interactive_pipeline(
|
189 |
gui=args.backend,
|
190 |
cache=False,
|
|
|
7 |
import argparse
|
8 |
import cv2
|
9 |
import numpy as np
|
10 |
+
import logging
|
11 |
|
12 |
|
13 |
+
SONG_1 = "Au clair de la lune"
|
14 |
+
SONG_2 = "Ainsi font, font, font"
|
15 |
+
SONG_3 = "Dodo l'enfant do"
|
16 |
+
SONG_4 = "A la claire fontaine"
|
17 |
+
|
18 |
+
SONG = {
|
19 |
+
SONG_1: "fa fa fa sol la - sol - fa la sol sol fa - fa fa fa sol la - sol - fa la sol sol fa - - sol sol sol sol re - re - sol fa mi re do - fa fa fa sol la - sol - fa la sol sol fa",
|
20 |
+
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",
|
21 |
+
SONG_3: "mi - do - mi mi do - re mi fa mi re sol mi do - mi - do - mi mi do - re mi fa mi re sol do",
|
22 |
+
SONG_4: "fa - fa la la sol la sol - fa - fa la la sol la - la - la sol fa la do la do - do la fa la sol - fa - fa la la sol fa la fa la - la sol fa la sol fa"
|
23 |
+
}
|
24 |
|
25 |
|
26 |
def select_song(song: str = SONG_1, context={}):
|
|
|
50 |
sleep(0.01)
|
51 |
print("waiting for file")
|
52 |
assert file_name.exists()
|
53 |
+
try:
|
54 |
+
if context["time_index"] == 0:
|
55 |
+
context["__stop"]()
|
56 |
+
else:
|
57 |
+
context["__set_audio"](file_name)
|
58 |
+
context["__play"]()
|
59 |
+
except Exception as e:
|
60 |
+
logging.warning(
|
61 |
+
f"Error playing note {note}: {e}, not expected to work with MPL backend for instance")
|
62 |
|
63 |
|
64 |
def display_current_color(context={}):
|
|
|
141 |
|
142 |
def song_player(context={}):
|
143 |
song = context["song"]
|
144 |
+
|
|
|
|
|
|
|
145 |
song_str = SONG.get(song, "")
|
146 |
image_song, target_note = generate_song(
|
147 |
song_str, current_time=context.get("time_index", 0))
|
|
|
187 |
if __name__ == '__main__':
|
188 |
parser = argparse.ArgumentParser(description='Xylophone synthesizer')
|
189 |
parser.add_argument('-b', '--backend', type=str,
|
190 |
+
default='gradio', choices=['gradio', 'qt', 'mpl'])
|
191 |
args = parser.parse_args()
|
192 |
all_notes = list(NOTE_FREQUENCIES.keys())
|
193 |
icon_list = [Path(f"__{note}.jpg") for note in all_notes]
|
|
|
195 |
img = get_color(note, size=(512, 512))
|
196 |
Image.save_image(img, icon)
|
197 |
interactive(note=Control("C4", all_notes, icons=icon_list))(select_note)
|
198 |
+
interactive(song=(SONG_1, list(SONG.keys())))(select_song)
|
199 |
interactive_pipeline(
|
200 |
gui=args.backend,
|
201 |
cache=False,
|