Spaces:
Running
Running
asigalov61
commited on
Commit
•
fec90c5
1
Parent(s):
47bb3a8
Update app.py
Browse files
app.py
CHANGED
@@ -19,7 +19,42 @@ import matplotlib.pyplot as plt
|
|
19 |
in_space = os.getenv("SYSTEM") == "spaces"
|
20 |
|
21 |
# =================================================================================================
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
def MixMelody(input_midi):
|
24 |
print('=' * 70)
|
25 |
print('Req start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
|
@@ -32,9 +67,6 @@ def MixMelody(input_midi):
|
|
32 |
|
33 |
print('-' * 70)
|
34 |
print('Input file name:', fn)
|
35 |
-
print('Req channel:', input_channel)
|
36 |
-
print('Req patch:', input_patch)
|
37 |
-
print('Req start chord:', input_start_chord)
|
38 |
print('-' * 70)
|
39 |
|
40 |
#===============================================================================
|
@@ -43,35 +75,44 @@ def MixMelody(input_midi):
|
|
43 |
#===============================================================================
|
44 |
# Enhanced score notes
|
45 |
|
46 |
-
|
47 |
|
48 |
-
if len(
|
49 |
|
50 |
-
#=======================================================
|
51 |
-
# PRE-PROCESSING
|
52 |
-
|
53 |
#===============================================================================
|
54 |
# Augmented enhanced score notes
|
55 |
|
56 |
-
|
57 |
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
-
escore_notes = TMIDIX.recalculate_score_timings(escore_notes)
|
62 |
#===============================================================================
|
63 |
-
# Add melody
|
64 |
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
print('=' * 70)
|
72 |
-
print('Done
|
73 |
print('=' * 70)
|
74 |
-
|
75 |
#===============================================================================
|
76 |
print('Rendering results...')
|
77 |
|
|
|
19 |
in_space = os.getenv("SYSTEM") == "spaces"
|
20 |
|
21 |
# =================================================================================================
|
22 |
+
|
23 |
+
def mix_chord(chord, tones_chord, mel_patch, mel_pitch):
|
24 |
+
|
25 |
+
cho = []
|
26 |
+
|
27 |
+
for k, g in groupby(sorted(chord, key=lambda x: x[6]), lambda x: x[6]):
|
28 |
+
|
29 |
+
if k != 128:
|
30 |
+
if k == mel_patch:
|
31 |
+
cg = list(g)
|
32 |
+
c = copy.deepcopy(cg[0])
|
33 |
+
c[4] = mel_pitch
|
34 |
+
c[5] = 105 + (mel_pitch % 12)
|
35 |
+
cho.append(c)
|
36 |
+
|
37 |
+
else:
|
38 |
+
cg = list(g)
|
39 |
+
|
40 |
+
tclen = len(tones_chord)
|
41 |
+
|
42 |
+
if len(cg) > tclen:
|
43 |
+
tones_chord = tones_chord + [random.choice(tones_chord) for _ in range(len(cg)-tclen)]
|
44 |
+
|
45 |
+
for i, cc in enumerate(cg):
|
46 |
+
c = copy.deepcopy(cc)
|
47 |
+
c[4] = ((c[4] // 12) * 12) +tones_chord[i]
|
48 |
+
c[5] += c[4] % 12
|
49 |
+
cho.append(c)
|
50 |
+
|
51 |
+
else:
|
52 |
+
cho.extend(list(g))
|
53 |
+
|
54 |
+
return cho
|
55 |
+
|
56 |
+
# =================================================================================================
|
57 |
+
|
58 |
def MixMelody(input_midi):
|
59 |
print('=' * 70)
|
60 |
print('Req start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
|
|
|
67 |
|
68 |
print('-' * 70)
|
69 |
print('Input file name:', fn)
|
|
|
|
|
|
|
70 |
print('-' * 70)
|
71 |
|
72 |
#===============================================================================
|
|
|
75 |
#===============================================================================
|
76 |
# Enhanced score notes
|
77 |
|
78 |
+
raw_escore = TMIDIX.advanced_score_processor(raw_score, return_enhanced_score_notes=True)[0]
|
79 |
|
80 |
+
if len(raw_escore) > 0:
|
81 |
|
|
|
|
|
|
|
82 |
#===============================================================================
|
83 |
# Augmented enhanced score notes
|
84 |
|
85 |
+
src_escore = TMIDIX.recalculate_score_timings(TMIDIX.augment_enhanced_score_notes([e for e in raw_escore if e[6] < 80]))
|
86 |
|
87 |
+
src_cscore = TMIDIX.chordify_score([1000, src_escore])
|
88 |
+
|
89 |
+
src_melody = [c[0] for c in src_cscore][:256]
|
90 |
+
|
91 |
+
src_melody_pitches = [p[4] for p in src_melody]
|
92 |
+
|
93 |
+
src_harm_tones_chords = TMIDIX.harmonize_enhanced_melody_score_notes(src_melody)
|
94 |
|
|
|
95 |
#===============================================================================
|
|
|
96 |
|
97 |
+
matched_songs = [a for a in all_songs if a[2] == max(32, len(src_melody))]
|
98 |
+
|
99 |
+
|
100 |
+
new_song = random.choice(matched_songs)
|
101 |
+
|
102 |
+
if new_song:
|
103 |
+
print(new_song[0], TMIDIX.Number2patch[new_song[1]], new_song[2])
|
104 |
+
|
105 |
+
trg_patch = new_song[1]
|
106 |
+
|
107 |
+
trg_song = copy.deepcopy(new_song[3])
|
108 |
+
TMIDIX.adjust_score_velocities(trg_song, 95)
|
109 |
+
|
110 |
+
cscore = TMIDIX.chordify_score([1000, trg_song])
|
111 |
|
112 |
print('=' * 70)
|
113 |
+
print('Done loading source and target MIDIs...!')
|
114 |
print('=' * 70)
|
115 |
+
|
116 |
#===============================================================================
|
117 |
print('Rendering results...')
|
118 |
|