Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -35,109 +35,88 @@ def read_MIDI(input_midi)
|
|
35 |
#=======================================================
|
36 |
# PRE-PROCESSING
|
37 |
|
38 |
-
# checking number of instruments in a composition
|
39 |
-
instruments_list_without_drums = list(set([y[3] for y in events_matrix1 if y[3] != 9]))
|
40 |
instruments_list = list(set([y[3] for y in events_matrix1]))
|
41 |
|
42 |
-
|
|
|
|
|
43 |
|
44 |
-
|
|
|
45 |
|
46 |
-
|
|
|
47 |
|
48 |
-
|
49 |
-
for e in events_matrix1:
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
58 |
|
59 |
-
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
|
65 |
-
|
66 |
-
# FINAL PROCESSING
|
67 |
|
68 |
-
|
69 |
-
melody_chords2 = []
|
70 |
|
71 |
-
|
72 |
|
73 |
-
|
74 |
-
drums_present = 19331 # Yes
|
75 |
-
else:
|
76 |
-
drums_present = 19330 # No
|
77 |
|
78 |
-
|
79 |
-
pat = events_matrix1[0][6]
|
80 |
-
else:
|
81 |
-
pat = 128
|
82 |
|
83 |
-
|
84 |
|
85 |
#=======================================================
|
86 |
-
#
|
87 |
-
#=======================================================
|
88 |
|
89 |
-
|
|
|
90 |
|
91 |
-
|
92 |
|
93 |
-
|
|
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
for e in events_matrix1:
|
100 |
-
|
101 |
-
#=======================================================
|
102 |
-
# Timings...
|
103 |
-
|
104 |
-
# Cliping all values...
|
105 |
-
delta_time = max(0, min(255, e[1]-pe[1]))
|
106 |
-
|
107 |
-
# Durations and channels
|
108 |
-
|
109 |
-
dur = max(0, min(255, e[2]))
|
110 |
-
cha = max(0, min(15, e[3]))
|
111 |
-
|
112 |
-
# Patches
|
113 |
-
if cha == 9: # Drums patch will be == 128
|
114 |
-
pat = 128
|
115 |
|
116 |
-
|
117 |
-
|
118 |
|
119 |
-
|
120 |
|
121 |
-
|
122 |
|
123 |
-
|
124 |
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
|
129 |
-
|
130 |
-
|
131 |
|
132 |
-
|
133 |
|
134 |
-
|
135 |
-
|
136 |
|
137 |
-
|
138 |
-
|
139 |
|
140 |
-
|
141 |
|
142 |
return melody_chords, melody_chords2
|
143 |
|
|
|
35 |
#=======================================================
|
36 |
# PRE-PROCESSING
|
37 |
|
|
|
|
|
38 |
instruments_list = list(set([y[3] for y in events_matrix1]))
|
39 |
|
40 |
+
#======================================
|
41 |
+
|
42 |
+
events_matrix1 = TMIDIX.augment_enhanced_score_notes(events_matrix1, timings_divider=16)
|
43 |
|
44 |
+
#=======================================================
|
45 |
+
# FINAL PROCESSING
|
46 |
|
47 |
+
melody_chords = []
|
48 |
+
melody_chords2 = []
|
49 |
|
50 |
+
# Break between compositions / Intro seq
|
|
|
51 |
|
52 |
+
if 9 in instruments_list:
|
53 |
+
drums_present = 19331 # Yes
|
54 |
+
else:
|
55 |
+
drums_present = 19330 # No
|
56 |
|
57 |
+
if events_matrix1[0][3] != 9:
|
58 |
+
pat = events_matrix1[0][6]
|
59 |
+
else:
|
60 |
+
pat = 128
|
61 |
|
62 |
+
melody_chords.extend([19461, drums_present, 19332+pat]) # Intro seq
|
63 |
|
64 |
+
#=======================================================
|
65 |
+
# MAIN PROCESSING CYCLE
|
66 |
+
#=======================================================
|
67 |
|
68 |
+
abs_time = 0
|
|
|
69 |
|
70 |
+
pbar_time = 0
|
|
|
71 |
|
72 |
+
pe = events_matrix1[0]
|
73 |
|
74 |
+
chords_counter = 1
|
|
|
|
|
|
|
75 |
|
76 |
+
comp_chords_len = len(list(set([y[1] for y in events_matrix1])))
|
|
|
|
|
|
|
77 |
|
78 |
+
for e in events_matrix1:
|
79 |
|
80 |
#=======================================================
|
81 |
+
# Timings...
|
|
|
82 |
|
83 |
+
# Cliping all values...
|
84 |
+
delta_time = max(0, min(255, e[1]-pe[1]))
|
85 |
|
86 |
+
# Durations and channels
|
87 |
|
88 |
+
dur = max(0, min(255, e[2]))
|
89 |
+
cha = max(0, min(15, e[3]))
|
90 |
|
91 |
+
# Patches
|
92 |
+
if cha == 9: # Drums patch will be == 128
|
93 |
+
pat = 128
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
+
else:
|
96 |
+
pat = e[6]
|
97 |
|
98 |
+
# Pitches
|
99 |
|
100 |
+
ptc = max(1, min(127, e[4]))
|
101 |
|
102 |
+
# Velocities
|
103 |
|
104 |
+
# Calculating octo-velocity
|
105 |
+
vel = max(8, min(127, e[5]))
|
106 |
+
velocity = round(vel / 15)-1
|
107 |
|
108 |
+
#=======================================================
|
109 |
+
# FINAL NOTE SEQ
|
110 |
|
111 |
+
# Writing final note asynchronously
|
112 |
|
113 |
+
dur_vel = (8 * dur) + velocity
|
114 |
+
pat_ptc = (129 * pat) + ptc
|
115 |
|
116 |
+
melody_chords.extend([delta_time, dur_vel+256, pat_ptc+2304])
|
117 |
+
melody_chords2.append([delta_time, dur_vel+256, pat_ptc+2304])
|
118 |
|
119 |
+
pe = e
|
120 |
|
121 |
return melody_chords, melody_chords2
|
122 |
|