asigalov61 commited on
Commit
093a03a
·
verified ·
1 Parent(s): 800ddf4

Upload TMIDIX.py

Browse files
Files changed (1) hide show
  1. TMIDIX.py +141 -36
TMIDIX.py CHANGED
@@ -51,7 +51,7 @@ r'''############################################################################
51
 
52
  ###################################################################################
53
 
54
- __version__ = "26.3.24"
55
 
56
  print('=' * 70)
57
  print('TMIDIX Python module')
@@ -9335,37 +9335,46 @@ def find_fuzzy_lrno_pattern_fast(lst, threshold=0, prefix_suffix_len=1):
9335
  ###################################################################################
9336
 
9337
  def find_chunk_indexes(original_list, chunk, ignore_index=-1):
 
 
 
 
9338
 
9339
- chunk_length = len(chunk)
9340
-
9341
- for i in range(len(original_list) - chunk_length + 1):
9342
-
9343
- chunk_index = 0
9344
- start_index = ignore_index
9345
 
9346
- for j in range(i, len(original_list)):
9347
- if original_list[j] == chunk[chunk_index]:
9348
 
9349
- if start_index == ignore_index:
9350
- start_index = j
9351
 
9352
- chunk_index += 1
9353
 
9354
- if chunk_index == chunk_length:
9355
- return [start_index, j]
 
 
9356
 
9357
- elif original_list[j] != ignore_index:
9358
- break
 
 
 
9359
 
9360
- return None
9361
 
9362
  ###################################################################################
9363
 
9364
  def escore_notes_lrno_pattern_fast(escore_notes,
9365
  channels_index=3,
9366
- pitches_index=4,
 
 
9367
  zero_start_time=True,
9368
  use_full_chords=True,
 
9369
  skip_pitches=False,
9370
  fuzzy_matching=False,
9371
  fuzzy_thres=5,
@@ -9378,31 +9387,55 @@ def escore_notes_lrno_pattern_fast(escore_notes,
9378
  else:
9379
  CHORDS = ALL_CHORDS_SORTED
9380
 
 
 
 
9381
  cscore = chordify_score([1000, escore_notes])
9382
 
9383
  score_chords = []
9384
-
9385
  for c in cscore:
9386
-
9387
- pitches = sorted(set([e[pitches_index] for e in c if e[channels_index] != 9]))
9388
-
9389
- chord_tok = -1
9390
- tchord = []
9391
-
9392
- if (skip_pitches and len(pitches) > 1) or not skip_pitches:
9393
-
9394
- tchord = sorted(set([p % 12 for p in pitches]))
9395
 
9396
- if tchord:
 
9397
 
9398
- if tchord not in ALL_CHORDS_SORTED:
9399
- tchord = check_and_fix_tones_chord(tchord,
9400
- use_full_chords=use_full_chords
9401
- )
9402
 
9403
- chord_tok = ALL_CHORDS_SORTED.index(tchord)
 
9404
 
9405
- score_chords.append(chord_tok)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9406
 
9407
  schords = [c for c in score_chords if c != -1]
9408
 
@@ -9416,7 +9449,7 @@ def escore_notes_lrno_pattern_fast(escore_notes,
9416
 
9417
  if lrno:
9418
 
9419
- sidx, eidx = find_chunk_indexes(score_chords, lrno)
9420
 
9421
  escore_notes_lrno_pattern = flatten(cscore[sidx:eidx+1])
9422
 
@@ -17746,6 +17779,78 @@ def rle_tokens_to_escore_notes(rle_tokens_list,
17746
 
17747
  ###################################################################################
17748
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17749
  print('Module loaded!')
17750
  print('=' * 70)
17751
  print('Enjoy! :)')
 
51
 
52
  ###################################################################################
53
 
54
+ __version__ = "26.3.27"
55
 
56
  print('=' * 70)
57
  print('TMIDIX Python module')
 
9335
  ###################################################################################
9336
 
9337
  def find_chunk_indexes(original_list, chunk, ignore_index=-1):
9338
+
9339
+ results = []
9340
+ chunk_length = len(chunk)
9341
+ i = 0
9342
 
9343
+ while i <= len(original_list) - chunk_length:
9344
+ chunk_index = 0
9345
+ start_index = ignore_index
 
 
 
9346
 
9347
+ for j in range(i, len(original_list)):
9348
+ if original_list[j] == chunk[chunk_index]:
9349
 
9350
+ if start_index == ignore_index:
9351
+ start_index = j
9352
 
9353
+ chunk_index += 1
9354
 
9355
+ if chunk_index == chunk_length:
9356
+ results.append([start_index, j])
9357
+ i = j + 1
9358
+ break
9359
 
9360
+ elif original_list[j] != ignore_index:
9361
+ i += 1
9362
+ break
9363
+ else:
9364
+ i += 1
9365
 
9366
+ return results if results else None
9367
 
9368
  ###################################################################################
9369
 
9370
  def escore_notes_lrno_pattern_fast(escore_notes,
9371
  channels_index=3,
9372
+ pitches_index=4,
9373
+ patches_index=6,
9374
+ patches_list=[],
9375
  zero_start_time=True,
9376
  use_full_chords=True,
9377
+ use_dtimes=True,
9378
  skip_pitches=False,
9379
  fuzzy_matching=False,
9380
  fuzzy_thres=5,
 
9387
  else:
9388
  CHORDS = ALL_CHORDS_SORTED
9389
 
9390
+ if not patches_list:
9391
+ patches_list = sorted(range(128))
9392
+
9393
  cscore = chordify_score([1000, escore_notes])
9394
 
9395
  score_chords = []
9396
+ pc = cscore[0]
9397
  for c in cscore:
9398
+ dtime = c[0][1]-pc[0][1]
9399
+ if use_dtimes:
9400
+ pitches = sorted(set([e[pitches_index] for e in c if e[channels_index] != 9 and e[6] in patches_list]))
9401
+ if skip_pitches:
9402
+
9403
+ if len(pitches) > 1:
9404
+ score_chords.append(dtime)
9405
+ pc = c
 
9406
 
9407
+ else:
9408
+ score_chords.append(-1)
9409
 
9410
+ else:
9411
+ if pitches:
9412
+ score_chords.append(dtime)
9413
+ pc = c
9414
 
9415
+ else:
9416
+ score_chords.append(-1)
9417
 
9418
+ else:
9419
+
9420
+ pitches = sorted(set([e[pitches_index] for e in c if e[channels_index] != 9 and e[6] in patches_list]))
9421
+
9422
+ chord_tok = -1
9423
+ tchord = []
9424
+
9425
+ if (skip_pitches and len(pitches) > 1) or not skip_pitches:
9426
+
9427
+ tchord = sorted(set([p % 12 for p in pitches]))
9428
+
9429
+ if tchord:
9430
+
9431
+ if tchord not in CHORDS:
9432
+ tchord = check_and_fix_tones_chord(tchord,
9433
+ use_full_chords=use_full_chords
9434
+ )
9435
+
9436
+ chord_tok = CHORDS.index(tchord)
9437
+
9438
+ score_chords.append(chord_tok)
9439
 
9440
  schords = [c for c in score_chords if c != -1]
9441
 
 
9449
 
9450
  if lrno:
9451
 
9452
+ sidx, eidx = find_chunk_indexes(score_chords, lrno)[0]
9453
 
9454
  escore_notes_lrno_pattern = flatten(cscore[sidx:eidx+1])
9455
 
 
17779
 
17780
  ###################################################################################
17781
 
17782
+ def find_chords_chunk_in_escore_notes(escore_notes,
17783
+ chords_chunk,
17784
+ use_full_chords=False,
17785
+ skip_pitches=False,
17786
+ zero_start_times=False
17787
+ ):
17788
+
17789
+ if use_full_chords:
17790
+ CHORDS = ALL_CHORDS_FULL
17791
+
17792
+ else:
17793
+ CHORDS = ALL_CHORDS_SORTED
17794
+
17795
+ cscore = chordify_score([1000, escore_notes])
17796
+
17797
+ if cscore:
17798
+
17799
+ score_chords = []
17800
+
17801
+ for c in cscore:
17802
+ pitches = sorted(set([e[4] for e in c if e[3] != 9]))
17803
+
17804
+ chord_tok = -1
17805
+ tchord = []
17806
+
17807
+ if (skip_pitches and len(pitches) > 1) or not skip_pitches:
17808
+
17809
+ tchord = sorted(set([p % 12 for p in pitches]))
17810
+
17811
+ if tchord:
17812
+
17813
+ if tchord not in CHORDS:
17814
+ tchord = check_and_fix_tones_chord(tchord,
17815
+ use_full_chords=use_full_chords
17816
+ )
17817
+
17818
+ chord_tok = CHORDS.index(tchord)
17819
+
17820
+ score_chords.append(chord_tok)
17821
+
17822
+ if score_chords:
17823
+
17824
+ chunk_indexes = find_chunk_indexes(score_chords, chords_chunk)
17825
+
17826
+ if chunk_indexes:
17827
+
17828
+ all_scores = []
17829
+
17830
+ for sidx, eidx in chunk_indexes:
17831
+
17832
+ score = flatten(cscore[sidx:eidx+1])
17833
+
17834
+ if zero_start_times:
17835
+ score = recalculate_score_timings(score)
17836
+
17837
+ all_scores.append(score)
17838
+
17839
+ return all_scores
17840
+
17841
+ return None
17842
+
17843
+ ###################################################################################
17844
+
17845
+ def distribute_k_values(k: float, n: int):
17846
+ if n < 2:
17847
+ return [float(k)]
17848
+
17849
+ step = (k - 1) / (n - 1)
17850
+ return [1 + i * step for i in range(n)]
17851
+
17852
+ ###################################################################################
17853
+
17854
  print('Module loaded!')
17855
  print('=' * 70)
17856
  print('Enjoy! :)')