asigalov61 commited on
Commit
1b639c6
1 Parent(s): c91ebe0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -6
app.py CHANGED
@@ -29,12 +29,12 @@ def pitches_counts(melody_score):
29
  pcounts = []
30
 
31
  count = 0
32
- pp = pitches[0]
33
 
34
  for p in pitches:
35
  if p == pp:
36
- pcounts.append(count)
37
  count += 1
 
38
  else:
39
  count = 0
40
  pcounts.append(count)
@@ -73,7 +73,7 @@ def find_similar_song(songs, src_melody):
73
 
74
  # =================================================================================================
75
 
76
- def mix_chord(chord, tones_chord, mel_patch, mel_pitch):
77
 
78
  cho = []
79
 
@@ -81,10 +81,14 @@ def mix_chord(chord, tones_chord, mel_patch, mel_pitch):
81
 
82
  if k != 128:
83
  if k == mel_patch:
 
84
  cg = list(g)
 
85
  c = copy.deepcopy(cg[0])
 
86
  c[4] = mel_pitch
87
  c[5] = 105 + (mel_pitch % 12)
 
88
  cho.append(c)
89
 
90
  else:
@@ -98,9 +102,15 @@ def mix_chord(chord, tones_chord, mel_patch, mel_pitch):
98
  tchord = tones_chord + [random.choice(tones_chord) for _ in range(len(cg)-tclen)]
99
 
100
  for i, cc in enumerate(cg):
 
101
  c = copy.deepcopy(cc)
 
 
 
 
102
  c[4] = ((c[4] // 12) * 12) + tchord[i]
103
  c[5] += c[4] % 12
 
104
  cho.append(c)
105
 
106
  else:
@@ -187,19 +197,26 @@ def MixMelody(input_midi, input_find_best_match):
187
 
188
  midx = 0
189
 
190
- for c in cscore:
191
  cho = copy.deepcopy(c)
192
 
193
  patches = sorted(set([e[6] for e in c]))
194
 
195
  if trg_patch in patches:
 
 
 
196
 
197
- mixed_song.extend(mix_chord(c, src_harm_tones_chords[midx], trg_patch, src_melody_pitches[midx]))
198
 
199
  midx += 1
200
 
201
  else:
202
- mixed_song.extend(mix_chord(cho, src_harm_tones_chords[midx], trg_patch, src_melody_pitches[midx]))
 
 
 
 
203
 
204
  if midx == len(src_melody):
205
  break
 
29
  pcounts = []
30
 
31
  count = 0
32
+ pp = -1
33
 
34
  for p in pitches:
35
  if p == pp:
 
36
  count += 1
37
+ pcounts.append(count)
38
  else:
39
  count = 0
40
  pcounts.append(count)
 
73
 
74
  # =================================================================================================
75
 
76
+ def mix_chord(chord, tones_chord, mel_patch, mel_pitch, next_note_dtime):
77
 
78
  cho = []
79
 
 
81
 
82
  if k != 128:
83
  if k == mel_patch:
84
+
85
  cg = list(g)
86
+
87
  c = copy.deepcopy(cg[0])
88
+
89
  c[4] = mel_pitch
90
  c[5] = 105 + (mel_pitch % 12)
91
+
92
  cho.append(c)
93
 
94
  else:
 
102
  tchord = tones_chord + [random.choice(tones_chord) for _ in range(len(cg)-tclen)]
103
 
104
  for i, cc in enumerate(cg):
105
+
106
  c = copy.deepcopy(cc)
107
+
108
+ if cc[2] > next_note_dtime:
109
+ cc[2] == next_note_dtime
110
+
111
  c[4] = ((c[4] // 12) * 12) + tchord[i]
112
  c[5] += c[4] % 12
113
+
114
  cho.append(c)
115
 
116
  else:
 
197
 
198
  midx = 0
199
 
200
+ for i, c in enumerate(cscore):
201
  cho = copy.deepcopy(c)
202
 
203
  patches = sorted(set([e[6] for e in c]))
204
 
205
  if trg_patch in patches:
206
+
207
+ if midx < len(src_melody):
208
+ next_note_dtime = src_melody[midx+1][1] - src_melody[midx][1]
209
 
210
+ mixed_song.extend(mix_chord(c, src_harm_tones_chords[midx], trg_patch, src_melody_pitches[midx], next_note_dtime))
211
 
212
  midx += 1
213
 
214
  else:
215
+
216
+ if i < len(cscore)
217
+ next_note_dtime = cscore[i+1][0][1] - cscore[i][0][1]
218
+
219
+ mixed_song.extend(mix_chord(cho, src_harm_tones_chords[midx], trg_patch, src_melody_pitches[midx], next_note_dtime))
220
 
221
  if midx == len(src_melody):
222
  break