asigalov61 commited on
Commit
09f21d5
·
verified ·
1 Parent(s): 791ed90

Upload TMIDIX.py

Browse files
Files changed (1) hide show
  1. TMIDIX.py +200 -17
TMIDIX.py CHANGED
@@ -14,14 +14,14 @@ r'''############################################################################
14
  #
15
  # Project Los Angeles
16
  #
17
- # Tegridy Code 2024
18
  #
19
  # https://github.com/Tegridy-Code/Project-Los-Angeles
20
  #
21
  #
22
  ###################################################################################
23
  ###################################################################################
24
- # Copyright 2024 Project Los Angeles / Tegridy Code
25
  #
26
  # Licensed under the Apache License, Version 2.0 (the "License");
27
  # you may not use this file except in compliance with the License.
@@ -9632,19 +9632,7 @@ def escore_notes_to_text_description(escore_notes,
9632
 
9633
  if pitches:
9634
 
9635
- cscore = chordify_score([1000, escore_notes])
9636
-
9637
- tones_chords = Counter()
9638
-
9639
- for c in cscore:
9640
- if len([e for e in c if e[3] != 9]) > 0:
9641
- tones_chords[tuple(sorted(set([e[4] % 12 for e in c if e[3] != 9])))] += 1
9642
-
9643
- most_common_tones_chords = [check_and_fix_tones_chord(list(c[0])) for c in tones_chords.most_common(10)]
9644
-
9645
- mood_scale = statistics.mode(tones_chords_to_types(most_common_tones_chords, return_chord_type_index=True)) % 3
9646
-
9647
- mood = MOOD_SCALES[mood_scale]
9648
 
9649
  #==============================================================================
9650
 
@@ -9730,8 +9718,12 @@ def escore_notes_to_text_description(escore_notes,
9730
  description += '\n'
9731
 
9732
  if pitches:
9733
-
9734
- description += 'It has '
 
 
 
 
9735
 
9736
  description += rythm + ' rythm, '
9737
  description += tempo + ' tempo, '
@@ -10319,6 +10311,197 @@ ALL_BASE_CHORDS_SORTED = [[0], [0, 2], [0, 2, 4], [0, 2, 4, 6], [0, 2, 4, 6, 8],
10319
  [0, 6, 9], [0, 6, 10], [0, 7], [0, 7, 9], [0, 7, 10], [0, 8], [0, 8, 10],
10320
  [0, 9], [0, 10]]
10321
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10322
  ###################################################################################
10323
  #
10324
  # This is the end of the TMIDI X Python module
 
14
  #
15
  # Project Los Angeles
16
  #
17
+ # Tegridy Code 2025
18
  #
19
  # https://github.com/Tegridy-Code/Project-Los-Angeles
20
  #
21
  #
22
  ###################################################################################
23
  ###################################################################################
24
+ # Copyright 2025 Project Los Angeles / Tegridy Code
25
  #
26
  # Licensed under the Apache License, Version 2.0 (the "License");
27
  # you may not use this file except in compliance with the License.
 
9632
 
9633
  if pitches:
9634
 
9635
+ mood = escore_notes_scale(escore_notes)
 
 
 
 
 
 
 
 
 
 
 
 
9636
 
9637
  #==============================================================================
9638
 
 
9718
  description += '\n'
9719
 
9720
  if pitches:
9721
+
9722
+ if mood == 'Major':
9723
+ description += 'This ' + random.choice(['uplifting', 'happy']) + ' song has '
9724
+
9725
+ else:
9726
+ description += 'This ' + random.choice(['melancholic', 'sad']) + ' song has '
9727
 
9728
  description += rythm + ' rythm, '
9729
  description += tempo + ' tempo, '
 
10311
  [0, 6, 9], [0, 6, 10], [0, 7], [0, 7, 9], [0, 7, 10], [0, 8], [0, 8, 10],
10312
  [0, 9], [0, 10]]
10313
 
10314
+ ###################################################################################
10315
+
10316
+ MAJOR_SCALE_CHORDS_COUNTS = [[317, 6610], [320, 6468], [267, 6460], [89, 6329], [301, 6228], [178, 6201],
10317
+ [0, 5822], [314, 5805], [309, 5677], [319, 5545], [288, 5494], [233, 5395],
10318
+ [112, 2232], [194, 1956], [127, 1935], [216, 1884], [256, 1871], [283, 1815],
10319
+ [201, 1768], [16, 1756], [105, 1743], [38, 1727], [23, 1718], [249, 1386],
10320
+ [272, 796], [91, 770], [191, 740], [303, 735], [181, 718], [306, 717],
10321
+ [235, 703], [183, 690], [94, 686], [13, 686], [269, 677], [280, 675],
10322
+ [102, 665], [92, 662], [293, 659], [212, 658], [114, 656], [37, 653],
10323
+ [180, 651], [215, 644], [316, 640], [290, 636], [5, 636], [110, 625],
10324
+ [270, 625], [3, 624], [238, 615], [123, 609], [34, 591], [254, 584],
10325
+ [258, 571], [126, 567], [2, 559], [246, 556], [104, 556], [203, 550],
10326
+ [291, 537], [311, 522], [304, 520], [193, 509], [236, 496], [199, 493],
10327
+ [15, 468], [25, 452], [312, 444], [282, 443], [248, 433], [21, 408],
10328
+ [268, 281], [179, 273], [144, 259], [90, 252], [162, 250], [234, 250],
10329
+ [1, 246], [221, 214], [73, 213], [43, 213], [45, 213], [134, 212], [318, 210],
10330
+ [119, 210], [159, 209], [120, 209], [302, 207], [310, 201], [289, 195],
10331
+ [42, 193], [264, 193], [220, 185], [131, 183], [55, 180], [315, 180],
10332
+ [132, 176], [30, 174], [31, 172], [209, 171], [227, 169], [217, 163],
10333
+ [223, 159], [70, 158], [39, 157], [36, 153], [214, 142], [196, 141],
10334
+ [285, 141], [8, 137], [208, 133], [125, 133], [147, 130], [186, 130],
10335
+ [97, 130], [49, 130], [58, 130], [128, 130], [138, 128], [241, 125],
10336
+ [228, 124], [263, 120], [251, 120], [275, 119], [296, 118], [259, 116],
10337
+ [99, 114], [10, 113], [50, 111], [273, 111], [139, 111], [298, 106], [18, 105],
10338
+ [153, 105], [7, 101], [277, 101], [243, 99], [96, 99], [9, 96], [160, 96],
10339
+ [188, 95], [115, 94], [24, 93], [107, 92], [204, 90], [150, 90], [148, 84],
10340
+ [202, 83], [213, 82], [187, 82], [35, 80], [113, 79], [98, 78], [239, 77],
10341
+ [59, 77], [26, 76], [281, 76], [184, 75], [64, 75], [124, 75], [71, 75],
10342
+ [257, 75], [95, 74], [294, 73], [192, 70], [247, 70], [61, 67], [307, 66],
10343
+ [242, 65], [218, 65], [146, 64], [276, 63], [6, 63], [68, 60], [284, 59],
10344
+ [103, 59], [297, 56], [14, 56], [185, 55], [57, 55], [40, 55], [129, 54],
10345
+ [274, 52], [308, 52], [46, 51], [224, 49], [240, 47], [135, 46], [17, 45],
10346
+ [295, 45], [106, 45], [48, 44], [157, 44], [206, 43], [195, 42], [158, 42],
10347
+ [69, 41], [117, 41], [225, 40], [222, 37], [226, 35], [261, 34], [164, 32],
10348
+ [75, 32], [28, 32], [11, 32], [250, 31], [44, 30], [137, 28], [47, 26],
10349
+ [133, 26], [255, 25], [182, 24], [136, 24], [197, 23], [93, 23], [237, 22],
10350
+ [287, 22], [165, 22], [79, 21], [271, 21], [109, 21], [253, 20], [76, 20],
10351
+ [168, 19], [155, 19], [149, 19], [108, 19], [4, 18], [51, 18], [292, 18],
10352
+ [198, 18], [41, 17], [286, 17], [19, 17], [219, 17], [173, 17], [66, 16],
10353
+ [54, 16], [229, 16], [140, 16], [175, 15], [171, 15], [82, 15], [130, 15],
10354
+ [20, 15], [230, 15], [244, 14], [145, 14], [84, 14], [305, 14], [278, 14],
10355
+ [86, 13], [60, 13], [232, 12], [100, 12], [141, 12], [52, 12], [189, 12],
10356
+ [252, 12], [56, 11], [53, 11], [143, 10], [151, 10], [154, 10], [163, 9],
10357
+ [116, 9], [27, 9], [65, 9], [313, 9], [205, 9], [170, 8], [62, 8], [299, 7],
10358
+ [142, 7], [231, 7], [156, 6], [22, 6], [63, 6], [152, 6], [77, 5], [67, 5],
10359
+ [166, 5], [174, 5], [85, 4], [72, 4], [190, 4], [111, 4], [101, 4], [200, 4],
10360
+ [12, 4], [245, 3], [300, 3], [279, 3], [81, 2], [210, 2], [32, 2], [265, 2],
10361
+ [260, 2], [74, 2], [161, 1], [207, 1], [29, 1], [118, 1], [262, 1], [121, 1]]
10362
+
10363
+ ###################################################################################
10364
+
10365
+ MINOR_SCALE_CHORDS_COUNTS = [[267, 10606], [89, 10562], [301, 10522], [320, 10192], [178, 10191],
10366
+ [317, 10153], [233, 10101], [314, 10065], [288, 9914], [0, 9884], [309, 9694],
10367
+ [319, 9648], [114, 1963], [193, 1778], [25, 1705], [104, 1689], [248, 1671],
10368
+ [282, 1614], [283, 1610], [127, 1530], [203, 1525], [37, 1508], [215, 1473],
10369
+ [105, 1465], [38, 1462], [258, 1445], [112, 1419], [94, 1413], [280, 1391],
10370
+ [194, 1388], [126, 1384], [16, 1374], [272, 1370], [23, 1364], [238, 1351],
10371
+ [306, 1342], [303, 1340], [5, 1338], [183, 1334], [102, 1333], [290, 1322],
10372
+ [269, 1312], [191, 1311], [249, 1305], [15, 1291], [246, 1290], [316, 1288],
10373
+ [13, 1279], [216, 1278], [235, 1275], [256, 1268], [311, 1241], [293, 1228],
10374
+ [91, 1219], [180, 1173], [34, 1167], [2, 1138], [212, 1131], [123, 1118],
10375
+ [201, 1103], [270, 1017], [304, 961], [181, 958], [92, 943], [3, 940],
10376
+ [236, 932], [254, 923], [291, 921], [110, 920], [21, 911], [312, 891],
10377
+ [199, 832], [268, 431], [179, 395], [234, 395], [302, 385], [144, 368],
10378
+ [90, 365], [289, 362], [310, 352], [318, 350], [1, 332], [55, 323], [315, 322],
10379
+ [8, 307], [162, 304], [97, 302], [186, 302], [241, 300], [10, 299], [217, 289],
10380
+ [275, 275], [128, 267], [73, 266], [243, 265], [125, 262], [296, 259],
10381
+ [298, 251], [36, 250], [39, 250], [99, 249], [214, 231], [119, 230],
10382
+ [120, 227], [188, 227], [159, 226], [264, 225], [263, 225], [138, 223],
10383
+ [31, 222], [227, 219], [134, 216], [277, 214], [70, 210], [209, 207],
10384
+ [30, 203], [49, 186], [46, 185], [45, 184], [221, 172], [281, 170], [96, 169],
10385
+ [131, 169], [224, 165], [148, 159], [59, 157], [43, 157], [7, 157], [247, 155],
10386
+ [208, 153], [132, 152], [274, 150], [223, 149], [135, 148], [273, 148],
10387
+ [240, 137], [220, 132], [185, 131], [239, 131], [42, 130], [147, 119],
10388
+ [213, 117], [307, 115], [24, 112], [95, 108], [192, 107], [150, 106],
10389
+ [294, 105], [106, 104], [58, 102], [103, 102], [17, 100], [129, 100], [61, 99],
10390
+ [9, 98], [139, 96], [295, 96], [284, 96], [146, 96], [218, 95], [184, 94],
10391
+ [308, 87], [195, 87], [40, 86], [14, 85], [50, 82], [250, 82], [285, 81],
10392
+ [57, 79], [259, 79], [6, 79], [276, 78], [228, 78], [35, 76], [187, 75],
10393
+ [242, 73], [206, 73], [160, 72], [113, 72], [117, 72], [261, 72], [98, 71],
10394
+ [202, 70], [115, 70], [158, 69], [71, 68], [48, 67], [28, 67], [204, 66],
10395
+ [157, 64], [124, 63], [257, 59], [196, 59], [69, 59], [68, 57], [251, 55],
10396
+ [225, 50], [137, 50], [107, 49], [165, 49], [297, 48], [64, 46], [153, 45],
10397
+ [226, 44], [198, 44], [287, 43], [26, 43], [219, 41], [253, 40], [109, 40],
10398
+ [66, 39], [47, 39], [41, 39], [76, 38], [11, 38], [136, 38], [130, 36],
10399
+ [155, 35], [18, 31], [93, 31], [20, 30], [271, 29], [4, 28], [292, 28],
10400
+ [237, 27], [182, 26], [62, 26], [164, 25], [151, 25], [108, 25], [286, 24],
10401
+ [145, 24], [305, 24], [75, 24], [56, 23], [149, 23], [252, 23], [197, 23],
10402
+ [255, 23], [313, 21], [60, 18], [244, 17], [278, 17], [189, 17], [100, 16],
10403
+ [299, 15], [200, 13], [175, 13], [111, 13], [22, 13], [170, 12], [232, 11],
10404
+ [86, 11], [141, 11], [52, 11], [65, 10], [173, 10], [133, 10], [222, 10],
10405
+ [143, 10], [154, 9], [82, 8], [19, 8], [85, 8], [44, 8], [84, 8], [163, 7],
10406
+ [205, 7], [230, 7], [54, 7], [174, 7], [116, 7], [27, 7], [171, 7], [229, 6],
10407
+ [81, 5], [79, 4], [142, 4], [231, 4], [210, 3], [168, 3], [53, 3], [51, 3],
10408
+ [74, 3], [265, 3], [260, 3], [152, 2], [245, 2], [279, 2], [190, 2], [12, 2],
10409
+ [101, 2], [262, 1], [63, 1], [72, 1], [207, 1], [166, 1], [83, 1], [176, 1],
10410
+ [118, 1], [67, 1], [172, 1], [29, 1], [121, 1], [77, 1], [266, 1], [156, 1],
10411
+ [211, 1], [300, 1], [87, 1], [140, 1], [161, 1]]
10412
+
10413
+ ###################################################################################
10414
+
10415
+ def get_weighted_score(src_order, trg_order):
10416
+
10417
+ score = 0
10418
+
10419
+ for i, (item, count) in enumerate(src_order):
10420
+ if item in trg_order:
10421
+ score += count * abs(i - trg_order.index(item))
10422
+
10423
+ else:
10424
+ score += count * len(trg_order)
10425
+
10426
+ return score
10427
+
10428
+ ###################################################################################
10429
+
10430
+ def escore_notes_scale(escore_notes, return_scales_indexes=False):
10431
+
10432
+ trg_chords = []
10433
+
10434
+ for i in range(-3, 3):
10435
+
10436
+ trans_escore_notes = transpose_escore_notes(escore_notes, i)
10437
+
10438
+ cscore = chordify_score([1000, trans_escore_notes])
10439
+
10440
+ tones_chords = []
10441
+
10442
+ for c in cscore:
10443
+
10444
+ seen = []
10445
+ pitches = []
10446
+
10447
+ for e in c:
10448
+
10449
+ if e[4] not in seen:
10450
+ pitches.append(e[4])
10451
+ seen.append(e[4])
10452
+
10453
+ if pitches:
10454
+
10455
+ tones_chord = sorted(set([p % 12 for p in pitches]))
10456
+
10457
+ if tones_chord not in ALL_CHORDS_SORTED:
10458
+ tones_chord = check_and_fix_tones_chord(tones_chord)
10459
+
10460
+ tones_chords.append(ALL_CHORDS_SORTED.index(tones_chord))
10461
+
10462
+ if tones_chords:
10463
+ trg_chords.extend(tones_chords)
10464
+
10465
+ if trg_chords:
10466
+
10467
+ #========================================================================
10468
+
10469
+ src_order = Counter(trg_chords).most_common()
10470
+ trg1_order = MAJOR_SCALE_CHORDS_COUNTS
10471
+ trg2_order = MINOR_SCALE_CHORDS_COUNTS
10472
+
10473
+
10474
+ trg1_items = [item for item, count in trg1_order]
10475
+ trg2_items = [item for item, count in trg2_order]
10476
+
10477
+
10478
+ trg1_score = get_weighted_score(src_order, trg1_items)
10479
+ trg2_score = get_weighted_score(src_order, trg2_items)
10480
+
10481
+ #========================================================================
10482
+
10483
+ if trg1_score <= trg2_score:
10484
+
10485
+ if return_scales_indexes:
10486
+ return 1
10487
+
10488
+ else:
10489
+ return 'Major'
10490
+
10491
+ else:
10492
+ if return_scales_indexes:
10493
+ return 0
10494
+ else:
10495
+ return 'Minor'
10496
+
10497
+ #========================================================================
10498
+
10499
+ else:
10500
+ if return_scales_indexes:
10501
+ return -1
10502
+ else:
10503
+ return 'Unknown'
10504
+
10505
  ###################################################################################
10506
  #
10507
  # This is the end of the TMIDI X Python module