asigalov61 commited on
Commit
7c0e727
·
verified ·
1 Parent(s): b2482f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -26
app.py CHANGED
@@ -171,44 +171,54 @@ def GenerateBridge(input_midi, input_start_note):
171
  print('=' * 70)
172
  print('Generating...')
173
 
174
- x = (torch.tensor(seed_melody, dtype=torch.long, device='cuda')[None, ...])
175
-
176
  with ctx:
177
  out = model.generate(x,
178
- 1536,
179
  temperature=0.9,
180
  return_prime=False,
181
  verbose=False)
182
 
183
- output = out[0].tolist()
 
 
 
 
 
 
184
 
185
  print('=' * 70)
186
  print('Done!')
187
  print('=' * 70)
 
 
 
 
 
 
188
 
189
  #===============================================================================
190
  print('Rendering results...')
 
 
191
 
192
  print('=' * 70)
193
- print('Sample INTs', output[:15])
194
  print('=' * 70)
195
-
196
- out1 = output
197
 
198
- if len(out1) != 0:
199
 
200
- song = out1
201
  song_f = []
202
 
203
  time = 0
204
  dur = 0
205
  vel = 90
206
  pitch = 0
 
207
  channel = 0
208
 
209
- patches = [0] * 16
210
- patches[3] = 40
211
-
212
  for ss in song:
213
 
214
  if 0 < ss < 128:
@@ -219,26 +229,33 @@ def GenerateBridge(input_midi, input_start_note):
219
 
220
  dur = (ss-128) * 32
221
 
222
- if 256 < ss < 512:
 
 
 
 
 
 
 
 
 
 
223
 
224
- pitch = (ss-256) % 128
225
 
226
- channel = (ss-256) // 128
227
 
228
- if channel == 1:
229
- channel = 3
230
- vel = 110 + (pitch % 12)
231
- song_f.append(['note', time, dur, channel, pitch, vel, 40])
232
-
233
- else:
234
- vel = 80 + (pitch % 12)
235
- channel = 0
236
- song_f.append(['note', time, dur, channel, pitch, vel, 0])
237
 
238
- fn1 = "Melody2Song-Seq2Seq-Music-Transformer-Composition"
239
 
240
  detailed_stats = TMIDIX.Tegridy_ms_SONG_to_MIDI_Converter(song_f,
241
- output_signature = 'Melody2Song Seq2Seq Music Transformer',
242
  output_file_name = fn1,
243
  track_name='Project Los Angeles',
244
  list_of_MIDI_patches=patches
 
171
  print('=' * 70)
172
  print('Generating...')
173
 
174
+ x = (torch.tensor(td, dtype=torch.long, device=DEVICE)[None, ...])
175
+
176
  with ctx:
177
  out = model.generate(x,
178
+ 1032,
179
  temperature=0.9,
180
  return_prime=False,
181
  verbose=False)
182
 
183
+ y = out.tolist()
184
+
185
+ output = []
186
+
187
+ for i in range(0, len(y[0]), 5):
188
+ if len(y[0][i:i+5]) == 5:
189
+ output.append(y[0][i:i+5])
190
 
191
  print('=' * 70)
192
  print('Done!')
193
  print('=' * 70)
194
+
195
+ start_note_idx = output.index(start_note)
196
+ end_note_idx = len(output)-output[::-1].index(end_note)-1
197
+
198
+ print('Start note check:', start_note in output, '---', start_note_idx)
199
+ print('End note check:',end_note in output, '---', end_note_idx)
200
 
201
  #===============================================================================
202
  print('Rendering results...')
203
+
204
+ data = score_chunk[:STEP] + TMIDIX.flatten(output[:end_note_idx]) + score_chunk[-STEP:]
205
 
206
  print('=' * 70)
207
+ print('Sample INTs', data[:15])
208
  print('=' * 70)
 
 
209
 
210
+ if len(data) != 0:
211
 
212
+ song = data
213
  song_f = []
214
 
215
  time = 0
216
  dur = 0
217
  vel = 90
218
  pitch = 0
219
+ pat = 0
220
  channel = 0
221
 
 
 
 
222
  for ss in song:
223
 
224
  if 0 < ss < 128:
 
229
 
230
  dur = (ss-128) * 32
231
 
232
+ if 256 <= ss <= 384:
233
+
234
+ pat = (ss-256)
235
+ channel = pat // 8
236
+
237
+ if channel == 9:
238
+ channel = 15
239
+ if channel == 16:
240
+ channel = 9
241
+
242
+ if 384 < ss < 640:
243
 
244
+ pitch = (ss-384) % 128
245
 
246
+ if 640 <= ss < 648:
247
 
248
+ vel = ((ss-640)+1) * 15
249
+
250
+ song_f.append(['note', time, dur, channel, pitch, vel, pat])
251
+
252
+ song_f, patches, overflow_patches = TMIDIX.patch_enhanced_score_notes(song_f)
253
+
 
 
 
254
 
255
+ fn1 = "Bridge-Music-Transformer-Composition"
256
 
257
  detailed_stats = TMIDIX.Tegridy_ms_SONG_to_MIDI_Converter(song_f,
258
+ output_signature = 'Bridge Music Transformer',
259
  output_file_name = fn1,
260
  track_name='Project Los Angeles',
261
  list_of_MIDI_patches=patches