asigalov61 commited on
Commit
1ab55c1
1 Parent(s): 32c4091

Upload TMIDIX.py

Browse files
Files changed (1) hide show
  1. TMIDIX.py +151 -44
TMIDIX.py CHANGED
@@ -4675,6 +4675,8 @@ def augment_enhanced_score_notes(enhanced_score_notes,
4675
  full_sorting=True,
4676
  timings_shift=0,
4677
  pitch_shift=0,
 
 
4678
  legacy_timings=False
4679
  ):
4680
 
@@ -4688,11 +4690,15 @@ def augment_enhanced_score_notes(enhanced_score_notes,
4688
 
4689
  dtime = (e[1] / timings_divider) - (pe[1] / timings_divider)
4690
 
4691
- if 0.5 < dtime < 1:
4692
- dtime = 1
4693
 
4694
  else:
4695
- dtime = int(dtime)
 
 
 
 
4696
 
4697
  if legacy_timings:
4698
  abs_time = int(e[1] / timings_divider) + timings_shift
@@ -4702,7 +4708,14 @@ def augment_enhanced_score_notes(enhanced_score_notes,
4702
 
4703
  e[1] = max(0, abs_time + timings_shift)
4704
 
4705
- e[2] = max(1, int(e[2] / timings_divider)) + timings_shift
 
 
 
 
 
 
 
4706
 
4707
  e[4] = max(1, min(127, e[4] + pitch_shift))
4708
 
@@ -5172,14 +5185,16 @@ def advanced_check_and_fix_chords_in_chordified_score(chordified_score,
5172
 
5173
  for c in chordified_score:
5174
 
 
 
5175
  if remove_duplicate_pitches:
5176
 
5177
- c.sort(key = lambda x: x[pitches_index], reverse=True)
5178
 
5179
  seen = set()
5180
  ddchord = []
5181
 
5182
- for cc in c:
5183
  if cc[channels_index] != 9:
5184
 
5185
  if tuple([cc[pitches_index], cc[patches_index]]) not in seen:
@@ -5191,9 +5206,9 @@ def advanced_check_and_fix_chords_in_chordified_score(chordified_score,
5191
  else:
5192
  ddchord.append(cc)
5193
 
5194
- c = copy.deepcopy(ddchord)
5195
 
5196
- tones_chord = sorted(set([t[pitches_index] % 12 for t in c if t[channels_index] != 9]))
5197
 
5198
  if tones_chord:
5199
 
@@ -5206,33 +5221,82 @@ def advanced_check_and_fix_chords_in_chordified_score(chordified_score,
5206
 
5207
  if tones_counts[0][1] > 1:
5208
  tones_chord = [tones_counts[0][0]]
 
5209
  elif tones_counts[1][1] > 1:
5210
  tones_chord = [tones_counts[1][0]]
 
5211
  else:
5212
  tones_chord = [pitches_chord[0] % 12]
5213
 
5214
  else:
5215
- tones_chord_combs = [list(comb) for i in range(len(tones_chord)-2, 0, -1) for comb in combinations(tones_chord, i+1)]
5216
 
5217
  for co in tones_chord_combs:
5218
  if co in CHORDS:
5219
  tones_chord = co
5220
  break
5221
 
 
 
 
5222
  bad_chords_counter += 1
5223
 
5224
- new_chord = []
5225
 
5226
- c.sort(key = lambda x: x[pitches_index], reverse=True)
 
5227
 
5228
- for e in c:
5229
  if e[channels_index] != 9:
5230
  if e[pitches_index] % 12 in tones_chord:
5231
- new_chord.append(e)
 
5232
 
5233
- else:
5234
- if not skip_drums:
5235
- new_chord.append(e)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5236
 
5237
  fixed_chordified_score.append(new_chord)
5238
 
@@ -7391,11 +7455,15 @@ def harmonize_enhanced_melody_score_notes_to_ms_SONG(escore_notes,
7391
  ###################################################################################
7392
 
7393
  def check_and_fix_pitches_chord(pitches_chord,
 
7394
  use_filtered_chords=False,
7395
  use_full_chords=True
7396
  ):
7397
 
7398
- pitches_chord = sorted(pitches_chord, reverse=True)
 
 
 
7399
 
7400
  if use_filtered_chords:
7401
  CHORDS = ALL_CHORDS_FILTERED
@@ -7405,44 +7473,83 @@ def check_and_fix_pitches_chord(pitches_chord,
7405
  if use_full_chords:
7406
  CHORDS = ALL_CHORDS_FULL
7407
 
7408
- tones_chord = sorted(set([p % 12 for p in pitches_chord]))
 
 
7409
 
7410
- if tones_chord not in CHORDS:
7411
 
7412
- if len(tones_chord) == 2:
 
 
 
7413
 
7414
- tones_counts = Counter([p % 12 for p in pitches_chord]).most_common()
 
 
 
 
 
 
 
7415
 
7416
- if tones_counts[0][1] > 1:
7417
- tones_chord = [tones_counts[0][0]]
7418
- elif tones_counts[1][1] > 1:
7419
- tones_chord = [tones_counts[1][0]]
7420
- else:
7421
- tones_chord = [pitches_chord[0] % 12]
 
7422
 
7423
- if len(tones_chord) > 2:
 
 
 
7424
 
7425
- tones_chord_combs = [list(comb) for i in range(len(tones_chord)-2, 0, -1) for comb in combinations(tones_chord, i+1)]
7426
-
7427
- tchord = []
7428
 
7429
- for co in tones_chord_combs:
7430
- if co in CHORDS:
7431
- tchord = co
7432
- break
7433
 
7434
- if tchord:
7435
- tones_chord = tchord
7436
-
7437
- else:
7438
- tones_chord = [pitches_chord[0] % 12]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7439
 
7440
- new_pitches_chord = []
7441
 
7442
- for p in pitches_chord:
 
 
7443
 
7444
- if p % 12 in tones_chord:
7445
- new_pitches_chord.append(p)
7446
 
7447
  return sorted(new_pitches_chord, reverse=True)
7448
 
 
4675
  full_sorting=True,
4676
  timings_shift=0,
4677
  pitch_shift=0,
4678
+ ceil_timings=False,
4679
+ round_timings=False,
4680
  legacy_timings=False
4681
  ):
4682
 
 
4690
 
4691
  dtime = (e[1] / timings_divider) - (pe[1] / timings_divider)
4692
 
4693
+ if round_timings:
4694
+ dtime = round(dtime)
4695
 
4696
  else:
4697
+ if ceil_timings:
4698
+ dtime = math.ceil(dtime)
4699
+
4700
+ else:
4701
+ dtime = int(dtime)
4702
 
4703
  if legacy_timings:
4704
  abs_time = int(e[1] / timings_divider) + timings_shift
 
4708
 
4709
  e[1] = max(0, abs_time + timings_shift)
4710
 
4711
+ if round_timings:
4712
+ e[2] = max(1, round(e[2] / timings_divider)) + timings_shift
4713
+
4714
+ else:
4715
+ if ceil_timings:
4716
+ e[2] = max(1, math.ceil(e[2] / timings_divider)) + timings_shift
4717
+ else:
4718
+ e[2] = max(1, int(e[2] / timings_divider)) + timings_shift
4719
 
4720
  e[4] = max(1, min(127, e[4] + pitch_shift))
4721
 
 
5185
 
5186
  for c in chordified_score:
5187
 
5188
+ chord = copy.deepcopy(c)
5189
+
5190
  if remove_duplicate_pitches:
5191
 
5192
+ chord.sort(key = lambda x: x[pitches_index], reverse=True)
5193
 
5194
  seen = set()
5195
  ddchord = []
5196
 
5197
+ for cc in chord:
5198
  if cc[channels_index] != 9:
5199
 
5200
  if tuple([cc[pitches_index], cc[patches_index]]) not in seen:
 
5206
  else:
5207
  ddchord.append(cc)
5208
 
5209
+ chord = copy.deepcopy(ddchord)
5210
 
5211
+ tones_chord = sorted(set([t[pitches_index] % 12 for t in chord if t[channels_index] != 9]))
5212
 
5213
  if tones_chord:
5214
 
 
5221
 
5222
  if tones_counts[0][1] > 1:
5223
  tones_chord = [tones_counts[0][0]]
5224
+
5225
  elif tones_counts[1][1] > 1:
5226
  tones_chord = [tones_counts[1][0]]
5227
+
5228
  else:
5229
  tones_chord = [pitches_chord[0] % 12]
5230
 
5231
  else:
5232
+ tones_chord_combs = [list(comb) for i in range(len(tones_chord)-1, 0, -1) for comb in combinations(tones_chord, i)]
5233
 
5234
  for co in tones_chord_combs:
5235
  if co in CHORDS:
5236
  tones_chord = co
5237
  break
5238
 
5239
+ if len(tones_chord) == 1:
5240
+ tones_chord = [pitches_chord[0] % 12]
5241
+
5242
  bad_chords_counter += 1
5243
 
5244
+ chord.sort(key = lambda x: x[pitches_index], reverse=True)
5245
 
5246
+ new_chord = set()
5247
+ pipa = []
5248
 
5249
+ for e in chord:
5250
  if e[channels_index] != 9:
5251
  if e[pitches_index] % 12 in tones_chord:
5252
+ new_chord.add(tuple(e))
5253
+ pipa.append([e[pitches_index], e[patches_index]])
5254
 
5255
+ elif (e[pitches_index]+1) % 12 in tones_chord:
5256
+ e[pitches_index] += 1
5257
+ new_chord.add(tuple(e))
5258
+ pipa.append([e[pitches_index], e[patches_index]])
5259
+
5260
+ elif (e[pitches_index]-1) % 12 in tones_chord:
5261
+ e[pitches_index] -= 1
5262
+ new_chord.add(tuple(e))
5263
+ pipa.append([e[pitches_index], e[patches_index]])
5264
+
5265
+ bad_chord = set()
5266
+
5267
+ for e in chord:
5268
+ if e[channels_index] != 9:
5269
+
5270
+ if e[pitches_index] % 12 not in tones_chord:
5271
+ bad_chord.add(tuple(e))
5272
+
5273
+ elif (e[pitches_index]+1) % 12 not in tones_chord:
5274
+ bad_chord.add(tuple(e))
5275
+
5276
+ elif (e[pitches_index]-1) % 12 not in tones_chord:
5277
+ bad_chord.add(tuple(e))
5278
+
5279
+ for bc in bad_chord:
5280
+
5281
+ bc = list(bc)
5282
+
5283
+ tone = find_closest_tone(tones_chord, bc[pitches_index] % 12)
5284
+
5285
+ new_pitch = ((bc[pitches_index] // 12) * 12) + tone
5286
+
5287
+ if [new_pitch, bc[patches_index]] not in pipa:
5288
+ bc[pitches_index] = new_pitch
5289
+ new_chord.add(tuple(bc))
5290
+ pipa.append([[new_pitch], bc[patches_index]])
5291
+
5292
+ if not skip_drums:
5293
+ for e in c:
5294
+ if e[channels_index] == 9:
5295
+ new_chord.append(tuple(e))
5296
+
5297
+ new_chord = [list(e) for e in new_chord]
5298
+
5299
+ new_chord.sort(key = lambda x: (-x[pitches_index], x[patches_index]))
5300
 
5301
  fixed_chordified_score.append(new_chord)
5302
 
 
7455
  ###################################################################################
7456
 
7457
  def check_and_fix_pitches_chord(pitches_chord,
7458
+ remove_duplicate_pitches=True,
7459
  use_filtered_chords=False,
7460
  use_full_chords=True
7461
  ):
7462
 
7463
+ if remove_duplicate_pitches:
7464
+ pitches_chord = sorted(set(pitches_chord), reverse=True)
7465
+ else:
7466
+ pitches_chord = sorted(pitches_chord, reverse=True)
7467
 
7468
  if use_filtered_chords:
7469
  CHORDS = ALL_CHORDS_FILTERED
 
7473
  if use_full_chords:
7474
  CHORDS = ALL_CHORDS_FULL
7475
 
7476
+ chord = copy.deepcopy(pitches_chord)
7477
+
7478
+ tones_chord = sorted(set([t % 12 for t in chord]))
7479
 
7480
+ if tones_chord:
7481
 
7482
+ if tones_chord not in CHORDS:
7483
+
7484
+ if len(tones_chord) == 2:
7485
+ tones_counts = Counter([p % 12 for p in pitches_chord]).most_common()
7486
 
7487
+ if tones_counts[0][1] > 1:
7488
+ tones_chord = [tones_counts[0][0]]
7489
+
7490
+ elif tones_counts[1][1] > 1:
7491
+ tones_chord = [tones_counts[1][0]]
7492
+
7493
+ else:
7494
+ tones_chord = [pitches_chord[0] % 12]
7495
 
7496
+ else:
7497
+ tones_chord_combs = [list(comb) for i in range(len(tones_chord)-1, 0, -1) for comb in combinations(tones_chord, i)]
7498
+
7499
+ for co in tones_chord_combs:
7500
+ if co in CHORDS:
7501
+ tones_chord = co
7502
+ break
7503
 
7504
+ if len(tones_chord) == 1:
7505
+ tones_chord = [pitches_chord[0] % 12]
7506
+
7507
+ chord.sort(reverse=True)
7508
 
7509
+ new_chord = set()
7510
+ pipa = []
 
7511
 
7512
+ for e in chord:
7513
+ if e % 12 in tones_chord:
7514
+ new_chord.add(tuple([e]))
7515
+ pipa.append(e)
7516
 
7517
+ elif (e+1) % 12 in tones_chord:
7518
+ e += 1
7519
+ new_chord.add(tuple([e]))
7520
+ pipa.append(e)
7521
+
7522
+ elif (e-1) % 12 in tones_chord:
7523
+ e -= 1
7524
+ new_chord.add(tuple([e]))
7525
+ pipa.append(e)
7526
+
7527
+ bad_chord = set()
7528
+
7529
+ for e in chord:
7530
+
7531
+ if e % 12 not in tones_chord:
7532
+ bad_chord.add(tuple([e]))
7533
+
7534
+ elif (e+1) % 12 not in tones_chord:
7535
+ bad_chord.add(tuple([e]))
7536
+
7537
+ elif (e-1) % 12 not in tones_chord:
7538
+ bad_chord.add(tuple([e]))
7539
+
7540
+ for bc in bad_chord:
7541
+
7542
+ bc = list(bc)
7543
+
7544
+ tone = find_closest_tone(tones_chord, bc[0] % 12)
7545
 
7546
+ new_pitch = ((bc[0] // 12) * 12) + tone
7547
 
7548
+ if new_pitch not in pipa:
7549
+ new_chord.add(tuple([new_pitch]))
7550
+ pipa.append(new_pitch)
7551
 
7552
+ new_pitches_chord = [e[0] for e in new_chord]
 
7553
 
7554
  return sorted(new_pitches_chord, reverse=True)
7555