asigalov61 commited on
Commit
67342fc
1 Parent(s): 86ae8a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +96 -95
app.py CHANGED
@@ -91,117 +91,117 @@ def find_midi(title, artist):
91
 
92
  if len(outy) != 0:
93
 
94
- song = outy
95
- song_f = []
96
-
97
- time = 0
98
- dur = 0
99
- vel = 90
100
- pitch = 0
101
- channel = 0
102
-
103
- patches = [-1] * 16
104
-
105
- channels = [0] * 16
106
- channels[9] = 1
107
-
108
- for ss in song:
109
-
110
- if 0 <= ss < 256:
111
 
 
 
112
  time += ss * 16
113
-
114
- if 256 <= ss < 2304:
115
-
116
- dur = ((ss-256) // 8) * 16
117
- vel = (((ss-256) % 8)+1) * 15
118
-
119
- if 2304 <= ss < 18945:
120
-
121
- patch = (ss-2304) // 129
122
-
123
- if patch < 128:
124
-
125
  if patch not in patches:
126
  if 0 in channels:
127
  cha = channels.index(0)
128
  channels[cha] = 1
129
  else:
130
  cha = 15
131
-
132
  patches[cha] = patch
133
  channel = patches.index(patch)
134
  else:
135
  channel = patches.index(patch)
136
-
137
  if patch == 128:
138
  channel = 9
 
 
 
 
 
 
 
 
 
 
139
 
140
- pitch = (ss-2304) % 129
 
 
141
 
142
- song_f.append(['note', time, dur, channel, pitch, vel, patch ])
 
143
 
144
-
 
 
145
 
146
- x = []
147
- y = []
148
- c = []
149
 
150
- colors = ['red', 'yellow', 'green', 'cyan',
151
- 'blue', 'pink', 'orange', 'purple',
152
- 'gray', 'white', 'gold', 'silver',
153
- 'lightgreen', 'indigo', 'maroon', 'turquoise']
 
 
 
154
 
155
- for s in [m for m in song_f if m[0] == 'note']:
156
- x.append(s[1])
157
- y.append(s[4])
158
- c.append(colors[s[3]])
159
-
160
- plt.close()
161
- plt.figure(figsize=(14,5))
162
- ax=plt.axes(title='MIDI Match Plot')
163
- ax.set_facecolor('black')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
 
165
- plt.scatter(x,y, c=c)
166
- plt.xlabel("Time in MIDI ticks")
167
- plt.ylabel("MIDI Pitch")
168
-
169
- output_signature = AUX_DATA[search_index][0]
170
- track_name = 'Project Los Angeles'
171
- text_encoding = 'ISO-8859-1'
172
-
173
- list_of_MIDI_patches=[0, 24, 32, 40, 42, 46, 56, 71, 73, 0, 53, 19, 0, 0, 0, 0]
174
-
175
- output_header = [1000,
176
- [['set_tempo', 0, 1000000],
177
- ['time_signature', 0, 4, 2, 24, 8],
178
- ['track_name', 0, bytes(output_signature, text_encoding)]]]
179
-
180
- patch_list = [['patch_change', 0, 0, list_of_MIDI_patches[0]],
181
- ['patch_change', 0, 1, list_of_MIDI_patches[1]],
182
- ['patch_change', 0, 2, list_of_MIDI_patches[2]],
183
- ['patch_change', 0, 3, list_of_MIDI_patches[3]],
184
- ['patch_change', 0, 4, list_of_MIDI_patches[4]],
185
- ['patch_change', 0, 5, list_of_MIDI_patches[5]],
186
- ['patch_change', 0, 6, list_of_MIDI_patches[6]],
187
- ['patch_change', 0, 7, list_of_MIDI_patches[7]],
188
- ['patch_change', 0, 8, list_of_MIDI_patches[8]],
189
- ['patch_change', 0, 9, list_of_MIDI_patches[9]],
190
- ['patch_change', 0, 10, list_of_MIDI_patches[10]],
191
- ['patch_change', 0, 11, list_of_MIDI_patches[11]],
192
- ['patch_change', 0, 12, list_of_MIDI_patches[12]],
193
- ['patch_change', 0, 13, list_of_MIDI_patches[13]],
194
- ['patch_change', 0, 14, list_of_MIDI_patches[14]],
195
- ['patch_change', 0, 15, list_of_MIDI_patches[15]],
196
- ['track_name', 0, bytes(track_name, text_encoding)]]
197
-
198
- output = output_header + [patch_list + song_f]
199
-
200
- with open(f"MIDI-Search-Sample.mid", 'wb') as f:
201
- f.write(MIDI.score2midi(output))
202
- audio = synthesis(MIDI.score2opus(output), soundfont_path)
203
- yield AUX_DATA[search_index][0], "MIDI-Search-Sample.mid", (44100, audio), plt
204
-
205
  #==========================================================================================================
206
 
207
  if __name__ == "__main__":
@@ -261,12 +261,13 @@ if __name__ == "__main__":
261
 
262
  gr.Markdown("# Search results")
263
 
264
- output_midi_seq = gr.Textbox(label="Found MIDI search title")
265
- output_audio = gr.Audio(label="Output MIDI search sample audio", format="mp3", elem_id="midi_audio")
266
- output_plot = gr.Plot(label="Output MIDI search sample plot")
267
- output_midi = gr.File(label="Output MIDI search sample MIDI", file_types=[".mid"])
 
268
 
269
  run_event = submit.click(find_midi, [title, artist],
270
- [output_midi_seq, output_midi, output_audio, output_plot])
271
 
272
  app.launch()
 
91
 
92
  if len(outy) != 0:
93
 
94
+ song = outy
95
+ song_f = []
96
+
97
+ time = 0
98
+ dur = 0
99
+ vel = 90
100
+ pitch = 0
101
+ channel = 0
102
+
103
+ patches = [-1] * 16
104
+
105
+ channels = [0] * 16
106
+ channels[9] = 1
107
+
108
+ for ss in song:
 
 
109
 
110
+ if 0 <= ss < 256:
111
+
112
  time += ss * 16
113
+
114
+ if 256 <= ss < 512:
115
+
116
+ dur = (ss-256) * 16
117
+
118
+ if 512 <= ss <= 640:
119
+
120
+ patch = (ss-512)
121
+
122
+ if patch < 128:
123
+
 
124
  if patch not in patches:
125
  if 0 in channels:
126
  cha = channels.index(0)
127
  channels[cha] = 1
128
  else:
129
  cha = 15
130
+
131
  patches[cha] = patch
132
  channel = patches.index(patch)
133
  else:
134
  channel = patches.index(patch)
135
+
136
  if patch == 128:
137
  channel = 9
138
+
139
+ if 640 < ss < 768:
140
+
141
+ ptc = (ss-640)
142
+
143
+ if 768 < ss < 896:
144
+
145
+ vel = (ss - 768)
146
+
147
+ song_f.append(['note', time, dur, channel, ptc, vel, patch ])
148
 
149
+ patches = [0 if x==-1 else x for x in patches]
150
+
151
+ print('=' * 70)
152
 
153
+ #===============================================================================
154
+ print('Rendering results...')
155
 
156
+ print('=' * 70)
157
+ print('Sample INTs', song_f[:3])
158
+ print('=' * 70)
159
 
160
+ output_score, patches, overflow_patches = TMIDIX.patch_enhanced_score_notes(song_f)
 
 
161
 
162
+ detailed_stats = TMIDIX.Tegridy_ms_SONG_to_MIDI_Converter(output_score,
163
+ output_signature = 'Los Angeles MIDI Dataset Search',
164
+ output_file_name = song_artist,
165
+ track_name='Project Los Angeles',
166
+ list_of_MIDI_patches=patches,
167
+ timings_multiplier=16
168
+ )
169
 
170
+ new_fn = song_artist + '.mid'
171
+
172
+ audio = midi_to_colab_audio(new_fn,
173
+ soundfont_path=soundfont,
174
+ sample_rate=16000,
175
+ volume_scale=10,
176
+ output_for_gradio=True
177
+ )
178
+
179
+ print('Done!')
180
+ print('=' * 70)
181
+
182
+ #========================================================
183
+
184
+ output_midi_title = str(song_artist)
185
+ output_midi_summary = str(song_f[:3])
186
+ output_midi = str(new_fn)
187
+ output_audio = (16000, audio)
188
+
189
+ output_plot = TMIDIX.plot_ms_SONG(output_score, plot_title=output_midi_title, return_plt=True)
190
+
191
+ print('Output MIDI file name:', output_midi)
192
+ print('Output MIDI title:', output_midi_title)
193
+ print('Output MIDI summary:', output_midi_summary)
194
+ print('=' * 70)
195
+
196
+ #========================================================
197
+
198
+ print('-' * 70)
199
+ print('Req end time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
200
+ print('-' * 70)
201
+ print('Req execution time:', (reqtime.time() - start_time), 'sec')
202
+
203
+ return output_midi_title, output_midi_summary, output_midi, output_audio, output_plot
204
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
  #==========================================================================================================
206
 
207
  if __name__ == "__main__":
 
261
 
262
  gr.Markdown("# Search results")
263
 
264
+ output_midi_title = gr.Textbox(label="Output MIDI title")
265
+ output_midi_summary = gr.Textbox(label="Output MIDI summary")
266
+ output_audio = gr.Audio(label="Output MIDI audio", format="wav", elem_id="midi_audio")
267
+ output_plot = gr.Plot(label="Output MIDI score plot")
268
+ output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])
269
 
270
  run_event = submit.click(find_midi, [title, artist],
271
+ [output_midi_title, output_midi_summary, output_midi, output_audio, output_plot ])
272
 
273
  app.launch()