Upload TMIDIX.py
Browse files13 unmodified lines141516171718192021222324242526279604 unmodified lines9632963396349635963696379638963996409641964296439644964596469647963596369637963879 unmodified lines97189719972097339734972197229723972497259726972797289729581 unmodified lines103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050713 unmodified lines## Project Los Angeles## Tegridy Code 2024# Tegridy Code 2025## https://github.com/Tegridy-Code/Project-Los-Angeles######################################################################################################################################################################### Copyright 2024 Project Los Angeles / Tegridy Code# Copyright 2025 Project Los Angeles / Tegridy Code## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.9604 unmodified lines if pitches: cscore = chordify_score([1000, escore_notes])
tones_chords = Counter()
for c in cscore: if len([e for e in c if e[3] != 9]) > 0: tones_chords[tuple(sorted(set([e[4] % 12 for e in c if e[3] != 9])))] += 1 most_common_tones_chords = [check_and_fix_tones_chord(list(c[0])) for c in tones_chords.most_common(10)] mood_scale = statistics.mode(tones_chords_to_types(most_common_tones_chords, return_chord_type_index=True)) % 3
mood = MOOD_SCALES[mood_scale] mood = escore_notes_scale(escore_notes)
#============================================================================== 79 unmodified lines description += '\n' if pitches:
description += 'It has ' if mood == 'Major': description += 'This ' + random.choice(['uplifting', 'happy']) + ' song has ' else: description += 'This ' + random.choice(['melancholic', 'sad']) + ' song has ' description += rythm + ' rythm, ' description += tempo + ' tempo, '581 unmodified lines [0, 6, 9], [0, 6, 10], [0, 7], [0, 7, 9], [0, 7, 10], [0, 8], [0, 8, 10], [0, 9], [0, 10]]
###################################################################################
MAJOR_SCALE_CHORDS_COUNTS = [[317, 6610], [320, 6468], [267, 6460], [89, 6329], [301, 6228], [178, 6201], [0, 5822], [314, 5805], [309, 5677], [319, 5545], [288, 5494], [233, 5395], [112, 2232], [194, 1956], [127, 1935], [216, 1884], [256, 1871], [283, 1815], [201, 1768], [16, 1756], [105, 1743], [38, 1727], [23, 1718], [249, 1386], [272, 796], [91, 770], [191, 740], [303, 735], [181, 718], [306, 717], [235, 703], [183, 690], [94, 686], [13, 686], [269, 677], [280, 675], [102, 665], [92, 662], [293, 659], [212, 658], [114, 656], [37, 653], [180, 651], [215, 644], [316, 640], [290, 636], [5, 636], [110, 625], [270, 625], [3, 624], [238, 615], [123, 609], [34, 591], [254, 584], [258, 571], [126, 567], [2, 559], [246, 556], [104, 556], [203, 550], [291, 537], [311, 522], [304, 520], [193, 509], [236, 496], [199, 493], [15, 468], [25, 452], [312, 444], [282, 443], [248, 433], [21, 408], [268, 281], [179, 273], [144, 259], [90, 252], [162, 250], [234, 250], [1, 246], [221, 214], [73, 213], [43, 213], [45, 213], [134, 212], [318, 210], [119, 210], [159, 209], [120, 209], [302, 207], [310, 201], [289, 195], [42, 193], [264, 193], [220, 185], [131, 183], [55, 180], [315, 180], [132, 176], [30, 174], [31, 172], [209, 171], [227, 169], [217, 163], [223, 159], [70, 158], [39, 157], [36, 153], [214, 142], [196, 141], [285, 141], [8, 137], [208, 133], [125, 133], [147, 130], [186, 130], [97, 130], [49, 130], [58, 130], [128, 130], [138, 128], [241, 125], [228, 124], [263, 120], [251, 120], [275, 119], [296, 118], [259, 116], [99, 114], [10, 113], [50, 111], [273, 111], [139, 111], [298, 106], [18, 105], [153, 105], [7, 101], [277, 101], [243, 99], [96, 99], [9, 96], [160, 96], [188, 95], [115, 94], [24, 93], [107, 92], [204, 90], [150, 90], [148, 84], [202, 83], [213, 82], [187, 82], [35, 80], [113, 79], [98, 78], [239, 77], [59, 77], [26, 76], [281, 76], [184, 75], [64, 75], [124, 75], [71, 75], [257, 75], [95, 74], [294, 73], [192, 70], [247, 70], [61, 67], [307, 66], [242, 65], [218, 65], [146, 64], [276, 63], [6, 63], [68, 60], [284, 59], [103, 59], [297, 56], [14, 56], [185, 55], [57, 55], [40, 55], [129, 54], [274, 52], [308, 52], [46, 51], [224, 49], [240, 47], [135, 46], [17, 45], [295, 45], [106, 45], [48, 44], [157, 44], [206, 43], [195, 42], [158, 42], [69, 41], [117, 41], [225, 40], [222, 37], [226, 35], [261, 34], [164, 32], [75, 32], [28, 32], [11, 32], [250, 31], [44, 30], [137, 28], [47, 26], [133, 26], [255, 25], [182, 24], [136, 24], [197, 23], [93, 23], [237, 22], [287, 22], [165, 22], [79, 21], [271, 21], [109, 21], [253, 20], [76, 20], [168, 19], [155, 19], [149, 19], [108, 19], [4, 18], [51, 18], [292, 18], [198, 18], [41, 17], [286, 17], [19, 17], [219, 17], [173, 17], [66, 16], [54, 16], [229, 16], [140, 16], [175, 15], [171, 15], [82, 15], [130, 15], [20, 15], [230, 15], [244, 14], [145, 14], [84, 14], [305, 14], [278, 14], [86, 13], [60, 13], [232, 12], [100, 12], [141, 12], [52, 12], [189, 12], [252, 12], [56, 11], [53, 11], [143, 10], [151, 10], [154, 10], [163, 9], [116, 9], [27, 9], [65, 9], [313, 9], [205, 9], [170, 8], [62, 8], [299, 7], [142, 7], [231, 7], [156, 6], [22, 6], [63, 6], [152, 6], [77, 5], [67, 5], [166, 5], [174, 5], [85, 4], [72, 4], [190, 4], [111, 4], [101, 4], [200, 4], [12, 4], [245, 3], [300, 3], [279, 3], [81, 2], [210, 2], [32, 2], [265, 2], [260, 2], [74, 2], [161, 1], [207, 1], [29, 1], [118, 1], [262, 1], [121, 1]]
###################################################################################
MINOR_SCALE_CHORDS_COUNTS = [[267, 10606], [89, 10562], [301, 10522], [320, 10192], [178, 10191], [317, 10153], [233, 10101], [314, 10065], [288, 9914], [0, 9884], [309, 9694], [319, 9648], [114, 1963], [193, 1778], [25, 1705], [104, 1689], [248, 1671], [282, 1614], [283, 1610], [127, 1530], [203, 1525], [37, 1508], [215, 1473], [105, 1465], [38, 1462], [258, 1445], [112, 1419], [94, 1413], [280, 1391], [194, 1388], [126, 1384], [16, 1374], [272, 1370], [23, 1364], [238, 1351], [306, 1342], [303, 1340], [5, 1338], [183, 1334], [102, 1333], [290, 1322], [269, 1312], [191, 1311], [249, 1305], [15, 1291], [246, 1290], [316, 1288], [13, 1279], [216, 1278], [235, 1275], [256, 1268], [311, 1241], [293, 1228], [91, 1219], [180, 1173], [34, 1167], [2, 1138], [212, 1131], [123, 1118], [201, 1103], [270, 1017], [304, 961], [181, 958], [92, 943], [3, 940], [236, 932], [254, 923], [291, 921], [110, 920], [21, 911], [312, 891], [199, 832], [268, 431], [179, 395], [234, 395], [302, 385], [144, 368], [90, 365], [289, 362], [310, 352], [318, 350], [1, 332], [55, 323], [315, 322], [8, 307], [162, 304], [97, 302], [186, 302], [241, 300], [10, 299], [217, 289], [275, 275], [128, 267], [73, 266], [243, 265], [125, 262], [296, 259], [298, 251], [36, 250], [39, 250], [99, 249], [214, 231], [119, 230], [120, 227], [188, 227], [159, 226], [264, 225], [263, 225], [138, 223], [31, 222], [227, 219], [134, 216], [277, 214], [70, 210], [209, 207], [30, 203], [49, 186], [46, 185], [45, 184], [221, 172], [281, 170], [96, 169], [131, 169], [224, 165], [148, 159], [59, 157], [43, 157], [7, 157], [247, 155], [208, 153], [132, 152], [274, 150], [223, 149], [135, 148], [273, 148], [240, 137], [220, 132], [185, 131], [239, 131], [42, 130], [147, 119], [213, 117], [307, 115], [24, 112], [95, 108], [192, 107], [150, 106], [294, 105], [106, 104], [58, 102], [103, 102], [17, 100], [129, 100], [61, 99], [9, 98], [139, 96], [295, 96], [284, 96], [146, 96], [218, 95], [184, 94], [308, 87], [195, 87], [40, 86], [14, 85], [50, 82], [250, 82], [285, 81], [57, 79], [259, 79], [6, 79], [276, 78], [228, 78], [35, 76], [187, 75], [242, 73], [206, 73], [160, 72], [113, 72], [117, 72], [261, 72], [98, 71], [202, 70], [115, 70], [158, 69], [71, 68], [48, 67], [28, 67], [204, 66], [157, 64], [124, 63], [257, 59], [196, 59], [69, 59], [68, 57], [251, 55], [225, 50], [137, 50], [107, 49], [165, 49], [297, 48], [64, 46], [153, 45], [226, 44], [198, 44], [287, 43], [26, 43], [219, 41], [253, 40], [109, 40], [66, 39], [47, 39], [41, 39], [76, 38], [11, 38], [136, 38], [130, 36], [155, 35], [18, 31], [93, 31], [20, 30], [271, 29], [4, 28], [292, 28], [237, 27], [182, 26], [62, 26], [164, 25], [151, 25], [108, 25], [286, 24], [145, 24], [305, 24], [75, 24], [56, 23], [149, 23], [252, 23], [197, 23], [255, 23], [313, 21], [60, 18], [244, 17], [278, 17], [189, 17], [100, 16], [299, 15], [200, 13], [175, 13], [111, 13], [22, 13], [170, 12], [232, 11], [86, 11], [141, 11], [52, 11], [65, 10], [173, 10], [133, 10], [222, 10], [143, 10], [154, 9], [82, 8], [19, 8], [85, 8], [44, 8], [84, 8], [163, 7], [205, 7], [230, 7], [54, 7], [174, 7], [116, 7], [27, 7], [171, 7], [229, 6], [81, 5], [79, 4], [142, 4], [231, 4], [210, 3], [168, 3], [53, 3], [51, 3], [74, 3], [265, 3], [260, 3], [152, 2], [245, 2], [279, 2], [190, 2], [12, 2], [101, 2], [262, 1], [63, 1], [72, 1], [207, 1], [166, 1], [83, 1], [176, 1], [118, 1], [67, 1], [172, 1], [29, 1], [121, 1], [77, 1], [266, 1], [156, 1], [211, 1], [300, 1], [87, 1], [140, 1], [161, 1]]
###################################################################################
def get_weighted_score(src_order, trg_order): score = 0 for i, (item, count) in enumerate(src_order): if item in trg_order: score += count * abs(i - trg_order.index(item)) else: score += count * len(trg_order) return score
###################################################################################
def escore_notes_scale(escore_notes, return_scales_indexes=False):
trg_chords = []
for i in range(-3, 3): trans_escore_notes = transpose_escore_notes(escore_notes, i) cscore = chordify_score([1000, trans_escore_notes]) tones_chords = [] for c in cscore: seen = [] pitches = [] for e in c: if e[4] not in seen: pitches.append(e[4]) seen.append(e[4]) if pitches: tones_chord = sorted(set([p % 12 for p in pitches])) if tones_chord not in ALL_CHORDS_SORTED: tones_chord = check_and_fix_tones_chord(tones_chord) tones_chords.append(ALL_CHORDS_SORTED.index(tones_chord)) if tones_chords: trg_chords.extend(tones_chords) if trg_chords: #========================================================================
src_order = Counter(trg_chords).most_common() trg1_order = MAJOR_SCALE_CHORDS_COUNTS trg2_order = MINOR_SCALE_CHORDS_COUNTS trg1_items = [item for item, count in trg1_order] trg2_items = [item for item, count in trg2_order]
trg1_score = get_weighted_score(src_order, trg1_items) trg2_score = get_weighted_score(src_order, trg2_items)
#======================================================================== if trg1_score <= trg2_score: if return_scales_indexes: return 1
else: return 'Major' else: if return_scales_indexes: return 0 else: return 'Minor' #======================================================================== else: if return_scales_indexes: return -1 else: return 'Unknown' #################################################################################### # This is the end of the TMIDI X Python moduleTMIDIX.py+200-17