Spaces:
Runtime error
Runtime error
Upload TMIDIX.py
Browse files4674 unmodified lines4675467646774678467946807 unmodified lines468846894690469146924693469446954696469746983 unmodified lines4702470347044705470647074708463 unmodified lines517251735174517551765177517851795180518151825183518451855 unmodified lines5191519251935194519551965197519851996 unmodified lines5206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752382152 unmodified lines739173927393739473957396739773987399740074013 unmodified lines740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774484674 unmodified linesfull_sorting=True,timings_shift=0,pitch_shift=0,legacy_timings=False):7 unmodified linesdtime = (e[1] / timings_divider) - (pe[1] / timings_divider)if 0.5 < dtime < 1:dtime = 1else:dtime = int(dtime)if legacy_timings:abs_time = int(e[1] / timings_divider) + timings_shift3 unmodified linese[1] = max(0, abs_time + timings_shift)e[2] = max(1, int(e[2] / timings_divider)) + timings_shifte[4] = max(1, min(127, e[4] + pitch_shift))463 unmodified linesfor c in chordified_score:if remove_duplicate_pitches:c.sort(key = lambda x: x[pitches_index], reverse=True)seen = set()ddchord = []for cc in c:if cc[channels_index] != 9:if tuple([cc[pitches_index], cc[patches_index]]) not in seen:5 unmodified lineselse:ddchord.append(cc)c = copy.deepcopy(ddchord)tones_chord = sorted(set([t[pitches_index] % 12 for t in c if t[channels_index] != 9]))if tones_chord:6 unmodified linesif tones_counts[0][1] > 1:tones_chord = [tones_counts[0][0]]elif tones_counts[1][1] > 1:tones_chord = [tones_counts[1][0]]else:tones_chord = [pitches_chord[0] % 12]else:tones_chord_combs = [list(comb) for i in range(len(tones_chord)-2, 0, -1) for comb in combinations(tones_chord, i+1)]for co in tones_chord_combs:if co in CHORDS:tones_chord = cobreakbad_chords_counter += 1new_chord = []c.sort(key = lambda x: x[pitches_index], reverse=True)for e in c:if e[channels_index] != 9:if e[pitches_index] % 12 in tones_chord:new_chord.append(e)else:if not skip_drums:new_chord.append(e)fixed_chordified_score.append(new_chord)2152 unmodified lines###################################################################################def check_and_fix_pitches_chord(pitches_chord,use_filtered_chords=False,use_full_chords=True):pitches_chord = sorted(pitches_chord, reverse=True)if use_filtered_chords:CHORDS = ALL_CHORDS_FILTERED3 unmodified linesif use_full_chords:CHORDS = ALL_CHORDS_FULLtones_chord = sorted(set([p % 12 for p in pitches_chord]))if tones_chord not in CHORDS:if len(tones_chord) == 2:tones_counts = Counter([p % 12 for p in pitches_chord]).most_common()if tones_counts[0][1] > 1:tones_chord = [tones_counts[0][0]]elif tones_counts[1][1] > 1:tones_chord = [tones_counts[1][0]]else:tones_chord = [pitches_chord[0] % 12]if len(tones_chord) > 2:tones_chord_combs = [list(comb) for i in range(len(tones_chord)-2, 0, -1) for comb in combinations(tones_chord, i+1)]tchord = []for co in tones_chord_combs:if co in CHORDS:tchord = cobreakif tchord:tones_chord = tchordelse:tones_chord = [pitches_chord[0] % 12]new_pitches_chord = []for p in pitches_chord:if p % 12 in tones_chord:new_pitches_chord.append(p)return sorted(new_pitches_chord, reverse=True)4674 unmodified lines467546764677467846794680468146827 unmodified lines4690469146924693469446954696469746984699470047014702470347043 unmodified lines47084709471047114712471347144715471647174718471947204721463 unmodified lines51855186518751885189519051915192519351945195519651975198519952005 unmodified lines5206520752085209521052115212521352146 unmodified lines52215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153022152 unmodified lines7455745674577458745974607461746274637464746574667467746874693 unmodified lines747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475554674 unmodified linesfull_sorting=True,timings_shift=0,pitch_shift=0,ceil_timings=False,round_timings=False,legacy_timings=False):7 unmodified linesdtime = (e[1] / timings_divider) - (pe[1] / timings_divider)if round_timings:dtime = round(dtime)else:if ceil_timings:dtime = math.ceil(dtime)else:dtime = int(dtime)if legacy_timings:abs_time = int(e[1] / timings_divider) + timings_shift3 unmodified linese[1] = max(0, abs_time + timings_shift)if round_timings:e[2] = max(1, round(e[2] / timings_divider)) + timings_shiftelse:if ceil_timings:e[2] = max(1, math.ceil(e[2] / timings_divider)) + timings_shiftelse:e[2] = max(1, int(e[2] / timings_divider)) + timings_shifte[4] = max(1, min(127, e[4] + pitch_shift))463 unmodified linesfor c in chordified_score:chord = copy.deepcopy(c)if remove_duplicate_pitches:chord.sort(key = lambda x: x[pitches_index], reverse=True)seen = set()ddchord = []for cc in chord:if cc[channels_index] != 9:if tuple([cc[pitches_index], cc[patches_index]]) not in seen:5 unmodified lineselse:ddchord.append(cc)chord = copy.deepcopy(ddchord)tones_chord = sorted(set([t[pitches_index] % 12 for t in chord if t[channels_index] != 9]))if tones_chord:6 unmodified linesif tones_counts[0][1] > 1:tones_chord = [tones_counts[0][0]]elif tones_counts[1][1] > 1:tones_chord = [tones_counts[1][0]]else:tones_chord = [pitches_chord[0] % 12]else:tones_chord_combs = [list(comb) for i in range(len(tones_chord)-1, 0, -1) for comb in combinations(tones_chord, i)]for co in tones_chord_combs:if co in CHORDS:tones_chord = cobreakif len(tones_chord) == 1:tones_chord = [pitches_chord[0] % 12]bad_chords_counter += 1chord.sort(key = lambda x: x[pitches_index], reverse=True)new_chord = set()pipa = []for e in chord:if e[channels_index] != 9:if e[pitches_index] % 12 in tones_chord:new_chord.add(tuple(e))pipa.append([e[pitches_index], e[patches_index]])elif (e[pitches_index]+1) % 12 in tones_chord:e[pitches_index] += 1new_chord.add(tuple(e))pipa.append([e[pitches_index], e[patches_index]])elif (e[pitches_index]-1) % 12 in tones_chord:e[pitches_index] -= 1new_chord.add(tuple(e))pipa.append([e[pitches_index], e[patches_index]])bad_chord = set()for e in chord:if e[channels_index] != 9:if e[pitches_index] % 12 not in tones_chord:bad_chord.add(tuple(e))elif (e[pitches_index]+1) % 12 not in tones_chord:bad_chord.add(tuple(e))elif (e[pitches_index]-1) % 12 not in tones_chord:bad_chord.add(tuple(e))for bc in bad_chord:bc = list(bc)tone = find_closest_tone(tones_chord, bc[pitches_index] % 12)new_pitch = ((bc[pitches_index] // 12) * 12) + toneif [new_pitch, bc[patches_index]] not in pipa:bc[pitches_index] = new_pitchnew_chord.add(tuple(bc))pipa.append([[new_pitch], bc[patches_index]])if not skip_drums:for e in c:if e[channels_index] == 9:new_chord.append(tuple(e))new_chord = [list(e) for e in new_chord]new_chord.sort(key = lambda x: (-x[pitches_index], x[patches_index]))fixed_chordified_score.append(new_chord)2152 unmodified lines###################################################################################def check_and_fix_pitches_chord(pitches_chord,remove_duplicate_pitches=True,use_filtered_chords=False,use_full_chords=True):if remove_duplicate_pitches:pitches_chord = sorted(set(pitches_chord), reverse=True)else:pitches_chord = sorted(pitches_chord, reverse=True)if use_filtered_chords:CHORDS = ALL_CHORDS_FILTERED3 unmodified linesif use_full_chords:CHORDS = ALL_CHORDS_FULLchord = copy.deepcopy(pitches_chord)tones_chord = sorted(set([t % 12 for t in chord]))if tones_chord:if tones_chord not in CHORDS:if len(tones_chord) == 2:tones_counts = Counter([p % 12 for p in pitches_chord]).most_common()if tones_counts[0][1] > 1:tones_chord = [tones_counts[0][0]]elif tones_counts[1][1] > 1:tones_chord = [tones_counts[1][0]]else:tones_chord = [pitches_chord[0] % 12]else:tones_chord_combs = [list(comb) for i in range(len(tones_chord)-1, 0, -1) for comb in combinations(tones_chord, i)]for co in tones_chord_combs:if co in CHORDS:tones_chord = cobreakif len(tones_chord) == 1:tones_chord = [pitches_chord[0] % 12]chord.sort(reverse=True)new_chord = set()pipa = []for e in chord:if e % 12 in tones_chord:new_chord.add(tuple([e]))pipa.append(e)elif (e+1) % 12 in tones_chord:e += 1new_chord.add(tuple([e]))pipa.append(e)elif (e-1) % 12 in tones_chord:e -= 1new_chord.add(tuple([e]))pipa.append(e)bad_chord = set()for e in chord:if e % 12 not in tones_chord:bad_chord.add(tuple([e]))elif (e+1) % 12 not in tones_chord:bad_chord.add(tuple([e]))elif (e-1) % 12 not in tones_chord:bad_chord.add(tuple([e]))for bc in bad_chord:bc = list(bc)tone = find_closest_tone(tones_chord, bc[0] % 12)new_pitch = ((bc[0] // 12) * 12) + toneif new_pitch not in pipa:new_chord.add(tuple([new_pitch]))pipa.append(new_pitch)new_pitches_chord = [e[0] for e in new_chord]return sorted(new_pitches_chord, reverse=True)
TMIDIX.py+151-44