Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -49,84 +49,91 @@ SOUDFONT_PATH = 'SGM-v2.01-YamahaGrand-Guit-Bass-v2.7.sf2'
|
|
49 |
|
50 |
#==================================================================================
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
#==================================================================================
|
68 |
|
69 |
-
def
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
def find_closest_tuple(tuples_list, src_tuple):
|
79 |
-
|
80 |
-
def euclidean_distance(t1, t2):
|
81 |
-
return sum((a - b) ** 2 for a, b in zip(t1, t2)) ** 0.5
|
82 |
-
|
83 |
-
closest_tuple = None
|
84 |
-
min_distance = float('inf')
|
85 |
-
|
86 |
-
for t in tuples_list:
|
87 |
-
distance = euclidean_distance(t, src_tuple)
|
88 |
-
if distance < min_distance:
|
89 |
-
min_distance = distance
|
90 |
-
closest_tuple = t
|
91 |
-
|
92 |
-
return closest_tuple
|
93 |
|
94 |
#==================================================================================
|
95 |
|
96 |
-
def
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
#==================================================================================
|
124 |
|
125 |
-
def
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
|
131 |
#===============================================================================
|
132 |
|
@@ -456,6 +463,10 @@ with gr.Blocks() as demo:
|
|
456 |
""")
|
457 |
|
458 |
#==================================================================================
|
|
|
|
|
|
|
|
|
459 |
|
460 |
gr.Markdown("## Mixing options")
|
461 |
|
@@ -473,7 +484,7 @@ with gr.Blocks() as demo:
|
|
473 |
output_plot = gr.Plot(label="MIDI score plot")
|
474 |
output_midi = gr.File(label="MIDI file", file_types=[".mid"])
|
475 |
|
476 |
-
mix_btn.click(
|
477 |
[
|
478 |
max_num_loops,
|
479 |
comp_loops_mult,
|
|
|
49 |
|
50 |
#==================================================================================
|
51 |
|
52 |
+
def split_by_sublist(main_list, sublist):
|
53 |
+
|
54 |
+
n = len(sublist)
|
55 |
+
indices = []
|
56 |
+
result = []
|
57 |
+
|
58 |
+
# Find all starting indices where sublist matches main_list
|
59 |
+
for i in range(len(main_list) - n + 1):
|
60 |
+
if main_list[i:i + n] == sublist:
|
61 |
+
indices.append(i)
|
62 |
+
|
63 |
+
if not indices:
|
64 |
+
# If the sublist is not found, return the entire main_list as one segment
|
65 |
+
return [main_list]
|
66 |
+
|
67 |
+
# Use the indices to split the main_list
|
68 |
+
for idx, start_index in enumerate(indices):
|
69 |
+
if idx < len(indices) - 1:
|
70 |
+
# Slice from current sublist start to the next sublist start
|
71 |
+
end_index = indices[idx + 1]
|
72 |
+
segment = main_list[start_index:end_index]
|
73 |
+
else:
|
74 |
+
# For the last sublist occurrence, include the rest of the list
|
75 |
+
segment = main_list[start_index:]
|
76 |
+
result.append(segment)
|
77 |
+
|
78 |
+
return result
|
79 |
|
80 |
#==================================================================================
|
81 |
|
82 |
+
def fuzzy_find(values, threshold=256):
|
83 |
+
result = set()
|
84 |
+
for i in range(len(values)):
|
85 |
+
for j in range(i+1, len(values)):
|
86 |
+
if abs(values[i] - values[j]) <= threshold:
|
87 |
+
result.add(values[j])
|
88 |
+
result.add(values[i])
|
89 |
+
return sorted(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
|
91 |
#==================================================================================
|
92 |
|
93 |
+
def kmp_search(main_list, sublist):
|
94 |
+
if not sublist:
|
95 |
+
return -1, -1 # Sublist is empty
|
96 |
+
|
97 |
+
# Preprocess the sublist to get the longest prefix-suffix array
|
98 |
+
lps = [0] * len(sublist)
|
99 |
+
length = 0 # Length of the previous longest prefix suffix
|
100 |
+
i = 1
|
101 |
+
while i < len(sublist):
|
102 |
+
if sublist[i] == sublist[length]:
|
103 |
+
length += 1
|
104 |
+
lps[i] = length
|
105 |
+
i += 1
|
106 |
+
else:
|
107 |
+
if length != 0:
|
108 |
+
length = lps[length - 1]
|
109 |
+
else:
|
110 |
+
lps[i] = 0
|
111 |
+
i += 1
|
112 |
+
|
113 |
+
# Start the search
|
114 |
+
i = j = 0 # Index for main_list and sublist
|
115 |
+
while i < len(main_list):
|
116 |
+
if main_list[i] == sublist[j]:
|
117 |
+
i += 1
|
118 |
+
j += 1
|
119 |
+
if j == len(sublist):
|
120 |
+
start_index = i - j
|
121 |
+
end_index = i - 1
|
122 |
+
return start_index, end_index
|
123 |
+
elif i < len(main_list) and main_list[i] != sublist[j]:
|
124 |
+
if j != 0:
|
125 |
+
j = lps[j - 1]
|
126 |
+
else:
|
127 |
+
i += 1
|
128 |
+
return -1, -1 # Sublist not found
|
129 |
|
130 |
#==================================================================================
|
131 |
|
132 |
+
def Remix_MIDI(max_num_loops,
|
133 |
+
comp_loops_mult,
|
134 |
+
chords_chunks_len,
|
135 |
+
loops_chords_set_len
|
136 |
+
):
|
137 |
|
138 |
#===============================================================================
|
139 |
|
|
|
463 |
""")
|
464 |
|
465 |
#==================================================================================
|
466 |
+
|
467 |
+
gr.Markdown("## Upload source MIDI or select an example MIDI below")
|
468 |
+
|
469 |
+
input_midi = gr.File(label="Input MIDI", file_types=[".midi", ".mid", ".kar"])
|
470 |
|
471 |
gr.Markdown("## Mixing options")
|
472 |
|
|
|
484 |
output_plot = gr.Plot(label="MIDI score plot")
|
485 |
output_midi = gr.File(label="MIDI file", file_types=[".mid"])
|
486 |
|
487 |
+
mix_btn.click(Remix_MIDI,
|
488 |
[
|
489 |
max_num_loops,
|
490 |
comp_loops_mult,
|