asigalov61 commited on
Commit
a317d05
·
verified ·
1 Parent(s): 9705956

Upload TMIDIX.py

Browse files
Files changed (1) hide show
  1. TMIDIX.py +45 -22
TMIDIX.py CHANGED
@@ -51,7 +51,7 @@ r'''############################################################################
51
 
52
  ###################################################################################
53
 
54
- __version__ = "25.5.4"
55
 
56
  print('=' * 70)
57
  print('TMIDIX Python module')
@@ -11193,13 +11193,17 @@ def escore_notes_core(escore_notes, core_len=128):
11193
 
11194
  ###################################################################################
11195
 
11196
- def multiprocessing_wrapper(function, data_list):
11197
 
11198
  with multiprocessing.Pool() as pool:
11199
 
11200
  results = []
11201
 
11202
- for result in tqdm.tqdm(pool.imap_unordered(function, data_list), total=len(data_list)):
 
 
 
 
11203
  results.append(result)
11204
 
11205
  return results
@@ -12973,7 +12977,7 @@ def ordered_groups(data, key_index):
12973
 
12974
  ###################################################################################
12975
 
12976
- def merge_melody_notes(escore_notes, pitches_idx=4, max_dur=255):
12977
 
12978
  groups = ordered_groups_unsorted(escore_notes, pitches_idx)
12979
 
@@ -12994,7 +12998,16 @@ def merge_melody_notes(escore_notes, pitches_idx=4, max_dur=255):
12994
  g[0][4],
12995
  g[0][5],
12996
  g[0][6]
12997
- ])
 
 
 
 
 
 
 
 
 
12998
 
12999
  return merged_melody_notes
13000
 
@@ -13002,10 +13015,13 @@ def merge_melody_notes(escore_notes, pitches_idx=4, max_dur=255):
13002
 
13003
  def add_expressive_melody_to_enhanced_score_notes(escore_notes,
13004
  melody_start_chord=0,
 
 
13005
  melody_channel=3,
13006
  melody_patch=40,
13007
  melody_notes_max_duration=255,
13008
- medley_max_min_durs=[],
 
13009
  melody_max_velocity=120,
13010
  acc_max_velocity=90,
13011
  return_melody=False
@@ -13018,26 +13034,28 @@ def add_expressive_melody_to_enhanced_score_notes(escore_notes,
13018
 
13019
  cscore = chordify_score([1000, score])
13020
 
13021
- melody_pitches = [72]
13022
 
13023
  for i, c in enumerate(cscore[melody_start_chord:]):
13024
 
13025
- pitches = [e[4] for e in c if e[3] != 9]
13026
-
13027
- if pitches:
13028
- cptc = find_closest_value(mult_pitches(pitches), melody_pitches[-1])[0]
13029
- melody_pitches.append(cptc)
 
 
13030
 
13031
  song_f = []
13032
  mel_f = []
13033
 
13034
  idx = 1
13035
 
13036
- for i, c in enumerate(cscore[:-1]):
13037
  pitches = [e[4] for e in c if e[3] != 9]
13038
 
13039
- if pitches and i >= melody_start_chord:
13040
- dur = min(cscore[i+1][0][1] - c[0][1], melody_notes_max_duration)
13041
 
13042
  mel_f.append(['note',
13043
  c[0][1],
@@ -13050,19 +13068,24 @@ def add_expressive_melody_to_enhanced_score_notes(escore_notes,
13050
  idx += 1
13051
 
13052
  song_f.extend(c)
13053
-
13054
- song_f.extend(cscore[-1])
13055
 
13056
- if medley_max_min_durs:
13057
  for e in mel_f:
13058
- if e[2] >= medley_max_min_durs[0]:
13059
- e[2] = medley_max_min_durs[1]
13060
 
13061
  adjust_score_velocities(mel_f, melody_max_velocity)
13062
 
13063
- song_f = sorted(merge_melody_notes(mel_f, max_dur=melody_notes_max_duration) + song_f,
 
 
 
 
 
13064
  key=lambda x: x[1]
13065
- )
13066
 
13067
  if return_melody:
13068
  return mel_f
 
51
 
52
  ###################################################################################
53
 
54
+ __version__ = "25.5.6"
55
 
56
  print('=' * 70)
57
  print('TMIDIX Python module')
 
11193
 
11194
  ###################################################################################
11195
 
11196
+ def multiprocessing_wrapper(function, data_list, verbose=True):
11197
 
11198
  with multiprocessing.Pool() as pool:
11199
 
11200
  results = []
11201
 
11202
+ for result in tqdm.tqdm(pool.imap_unordered(function, data_list),
11203
+ total=len(data_list),
11204
+ disable=not verbose
11205
+ ):
11206
+
11207
  results.append(result)
11208
 
11209
  return results
 
12977
 
12978
  ###################################################################################
12979
 
12980
+ def merge_melody_notes(escore_notes, pitches_idx=4, max_dur=255, last_dur=128):
12981
 
12982
  groups = ordered_groups_unsorted(escore_notes, pitches_idx)
12983
 
 
12998
  g[0][4],
12999
  g[0][5],
13000
  g[0][6]
13001
+ ])
13002
+
13003
+ merged_melody_notes.append(['note',
13004
+ groups[-1][1][0][1],
13005
+ last_dur,
13006
+ groups[-1][1][0][3],
13007
+ groups[-1][1][0][4],
13008
+ groups[-1][1][0][5],
13009
+ groups[-1][1][0][6]
13010
+ ])
13011
 
13012
  return merged_melody_notes
13013
 
 
13015
 
13016
  def add_expressive_melody_to_enhanced_score_notes(escore_notes,
13017
  melody_start_chord=0,
13018
+ melody_prime_pitch=60,
13019
+ melody_step=1,
13020
  melody_channel=3,
13021
  melody_patch=40,
13022
  melody_notes_max_duration=255,
13023
+ melody_last_note_dur=128,
13024
+ melody_clip_max_min_durs=[],
13025
  melody_max_velocity=120,
13026
  acc_max_velocity=90,
13027
  return_melody=False
 
13034
 
13035
  cscore = chordify_score([1000, score])
13036
 
13037
+ melody_pitches = [melody_prime_pitch]
13038
 
13039
  for i, c in enumerate(cscore[melody_start_chord:]):
13040
 
13041
+ if i % melody_step == 0:
13042
+
13043
+ pitches = [e[4] for e in c if e[3] != 9]
13044
+
13045
+ if pitches:
13046
+ cptc = find_closest_value(mult_pitches(pitches), melody_pitches[-1])[0]
13047
+ melody_pitches.append(cptc)
13048
 
13049
  song_f = []
13050
  mel_f = []
13051
 
13052
  idx = 1
13053
 
13054
+ for i, c in enumerate(cscore[:-melody_step]):
13055
  pitches = [e[4] for e in c if e[3] != 9]
13056
 
13057
+ if pitches and i >= melody_start_chord and i % melody_step == 0:
13058
+ dur = min(cscore[i+melody_step][0][1] - c[0][1], melody_notes_max_duration)
13059
 
13060
  mel_f.append(['note',
13061
  c[0][1],
 
13068
  idx += 1
13069
 
13070
  song_f.extend(c)
13071
+
13072
+ song_f.extend(flatten(cscore[-melody_step:]))
13073
 
13074
+ if len(melody_clip_max_min_durs) == 2:
13075
  for e in mel_f:
13076
+ if e[2] >= melody_clip_max_min_durs[0]:
13077
+ e[2] = melody_clip_max_min_durs[1]
13078
 
13079
  adjust_score_velocities(mel_f, melody_max_velocity)
13080
 
13081
+ merged_melody_notes = merge_melody_notes(mel_f,
13082
+ max_dur=melody_notes_max_duration,
13083
+ last_dur=melody_last_note_dur
13084
+ )
13085
+
13086
+ song_f = sorted(merged_melody_notes + song_f,
13087
  key=lambda x: x[1]
13088
+ )
13089
 
13090
  if return_melody:
13091
  return mel_f