projectlosangeles commited on
Commit
f9084e6
·
verified ·
1 Parent(s): 31d04df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -24
app.py CHANGED
@@ -220,16 +220,35 @@ def Generate_Drums(input_midi,
220
  if score is not None and chords is not None:
221
 
222
  print('Sample score tokens', score[:10])
 
223
 
224
  #==================================================================
225
 
226
- def gen_drums(seq):
227
 
228
- y = 16641
229
 
230
- while y > 16640:
231
-
232
- x = torch.LongTensor(seq).to(device_type)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
 
234
  with ctx:
235
  out = model.generate(x,
@@ -243,26 +262,18 @@ def Generate_Drums(input_midi,
243
 
244
  y = out.tolist()[0]
245
 
246
- if y > 16640:
247
- seq.append(y)
248
-
249
- return seq
250
-
251
- #==================================================================
252
-
253
- print('=' * 70)
254
- print('Generating...')
255
-
256
- final_song = [18816]
257
-
258
- for i in range(len(chords)):
259
-
260
- final_song.extend(chords[i])
261
-
262
- if i == 0 or (final_song[-2] < 16640 and i % 8 == 0):
263
- final_song.append((128*128)+38+256) # Drum pitch
264
 
265
- final_song = gen_drums(final_song)
 
 
 
 
 
266
 
267
  #==================================================================
268
 
 
220
  if score is not None and chords is not None:
221
 
222
  print('Sample score tokens', score[:10])
223
+ print('=' * 70)
224
 
225
  #==================================================================
226
 
227
+ dur_vel_toks_num = len([t for t in score if 16767 < t < 18816])
228
 
229
+ print('Number of tokens to inapint:', dur_vel_toks_num)
230
 
231
+ #==================================================================
232
+
233
+ print('=' * 70)
234
+ print('Generating...')
235
+
236
+ inpaint_durations = True
237
+ inpaint_velocities = True
238
+
239
+ final_song = []
240
+
241
+ for t in tqdm.tqdm(score):
242
+
243
+ if t < 16767 or t > 18815:
244
+ final_song.append(t)
245
+
246
+ else:
247
+
248
+ fdur = ((t-16768) // 8) * 16
249
+ fvel = (((t-16768) % 8)+1) * 15
250
+
251
+ x = torch.LongTensor(final_song).to(device_type)
252
 
253
  with ctx:
254
  out = model.generate(x,
 
262
 
263
  y = out.tolist()[0]
264
 
265
+ gdur = ((y-16768) // 8) * 16
266
+ gvel = (((y-16768) % 8)+1) * 15
267
+
268
+ if inpaint_durations:
269
+ fdur = gdur
 
 
 
 
 
 
 
 
 
 
 
 
 
270
 
271
+ if inpaint_velocities:
272
+ fvel = gvel
273
+
274
+ dur_vel_tok = ((8 * fdur) + fvel) + 16768
275
+
276
+ final_song.append(dur_vel_tok)
277
 
278
  #==================================================================
279