asigalov61 commited on
Commit
d26b0ba
·
verified ·
1 Parent(s): 6a567c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -102
app.py CHANGED
@@ -37,87 +37,37 @@ def find_midi(search_string, search_options):
37
  search_data = []
38
 
39
  for A in AUX_DATA:
40
- data = []
41
  if 'Titles' in search_options:
42
- data.append(A[1])
43
  if 'Lyrics' in search_options:
44
- data.append(A[2])
45
  if 'Summaries' in search_options:
46
- data.append(A[3])
47
 
48
  search_data.append(data)
49
 
50
  print('Searching titles...Please wait...')
51
 
52
-
53
-
54
- search_match = process.extract(query=search_string, choices=titles_index, limit=1)
55
- search_index = titles_index.index(search_match[0][0])
56
 
57
  print('Done!')
58
  print('=' * 70)
59
- print('Selected title:', AUX_DATA[search_index][0])
60
  print('=' * 70)
61
 
62
- outy = AUX_DATA[search_index][1]
 
 
 
 
63
 
64
- print('Sample INTs', outy[:12])
65
  print('=' * 70)
66
-
67
- if len(outy) != 0:
68
-
69
- song = outy
70
- song_f = []
71
-
72
- time = 0
73
- dur = 0
74
- vel = 90
75
- pitch = 0
76
- channel = 0
77
-
78
- patches = [-1] * 16
79
-
80
- channels = [0] * 16
81
- channels[9] = 1
82
-
83
- for ss in song:
84
-
85
- if 0 <= ss < 256:
86
-
87
- time += ss * 16
88
-
89
- if 256 <= ss < 2304:
90
-
91
- dur = ((ss-256) // 8) * 16
92
- vel = (((ss-256) % 8)+1) * 15
93
-
94
- if 2304 <= ss < 18945:
95
-
96
- patch = (ss-2304) // 129
97
-
98
- if patch < 128:
99
-
100
- if patch not in patches:
101
- if 0 in channels:
102
- cha = channels.index(0)
103
- channels[cha] = 1
104
- else:
105
- cha = 15
106
-
107
- patches[cha] = patch
108
- channel = patches.index(patch)
109
- else:
110
- channel = patches.index(patch)
111
-
112
- if patch == 128:
113
- channel = 9
114
-
115
- pitch = (ss-2304) % 129
116
-
117
- song_f.append(['note', time, dur, channel, pitch, vel, patch ])
118
-
119
-
120
-
121
  x = []
122
  y = []
123
  c = []
@@ -127,7 +77,7 @@ def find_midi(search_string, search_options):
127
  'gray', 'white', 'gold', 'silver',
128
  'lightgreen', 'indigo', 'maroon', 'turquoise']
129
 
130
- for s in [m for m in song_f if m[0] == 'note']:
131
  x.append(s[1])
132
  y.append(s[4])
133
  c.append(colors[s[3]])
@@ -141,41 +91,15 @@ def find_midi(search_string, search_options):
141
  plt.xlabel("Time in MIDI ticks")
142
  plt.ylabel("MIDI Pitch")
143
 
144
- output_signature = AUX_DATA[search_index][0]
145
- track_name = 'Project Los Angeles'
146
- text_encoding = 'ISO-8859-1'
147
-
148
- list_of_MIDI_patches=[0, 24, 32, 40, 42, 46, 56, 71, 73, 0, 53, 19, 0, 0, 0, 0]
149
-
150
- output_header = [1000,
151
- [['set_tempo', 0, 1000000],
152
- ['time_signature', 0, 4, 2, 24, 8],
153
- ['track_name', 0, bytes(output_signature, text_encoding)]]]
154
-
155
- patch_list = [['patch_change', 0, 0, list_of_MIDI_patches[0]],
156
- ['patch_change', 0, 1, list_of_MIDI_patches[1]],
157
- ['patch_change', 0, 2, list_of_MIDI_patches[2]],
158
- ['patch_change', 0, 3, list_of_MIDI_patches[3]],
159
- ['patch_change', 0, 4, list_of_MIDI_patches[4]],
160
- ['patch_change', 0, 5, list_of_MIDI_patches[5]],
161
- ['patch_change', 0, 6, list_of_MIDI_patches[6]],
162
- ['patch_change', 0, 7, list_of_MIDI_patches[7]],
163
- ['patch_change', 0, 8, list_of_MIDI_patches[8]],
164
- ['patch_change', 0, 9, list_of_MIDI_patches[9]],
165
- ['patch_change', 0, 10, list_of_MIDI_patches[10]],
166
- ['patch_change', 0, 11, list_of_MIDI_patches[11]],
167
- ['patch_change', 0, 12, list_of_MIDI_patches[12]],
168
- ['patch_change', 0, 13, list_of_MIDI_patches[13]],
169
- ['patch_change', 0, 14, list_of_MIDI_patches[14]],
170
- ['patch_change', 0, 15, list_of_MIDI_patches[15]],
171
- ['track_name', 0, bytes(track_name, text_encoding)]]
172
-
173
- output = output_header + [patch_list + song_f]
174
-
175
- with open(f"MIDI-Search-Sample.mid", 'wb') as f:
176
- f.write(MIDI.score2midi(output))
177
- audio = synthesis(MIDI.score2opus(output), soundfont_path)
178
- yield AUX_DATA[search_index][0], "MIDI-Search-Sample.mid", (44100, audio), plt
179
 
180
  #==========================================================================================================
181
 
 
37
  search_data = []
38
 
39
  for A in AUX_DATA:
40
+ data = ''
41
  if 'Titles' in search_options:
42
+ data += A[1] + '\n\n'
43
  if 'Lyrics' in search_options:
44
+ data += A[2] + '\n\n'
45
  if 'Summaries' in search_options:
46
+ data += A[3] + '\n\n'
47
 
48
  search_data.append(data)
49
 
50
  print('Searching titles...Please wait...')
51
 
52
+ search_match_data = TMIDIX.ascii_texts_search(search_data, search_string)
53
+ search_match_text = search_match_data[0]
54
+ search_match_ratio = search_match_data[1]
55
+ search_match_index = search_data.index(search_match_text)
56
 
57
  print('Done!')
58
  print('=' * 70)
59
+ print('Selected file/title:', AUX_DATA[search_match_index][:2])
60
  print('=' * 70)
61
 
62
+ fn = AUX_DATA[search_match_index][0]
63
+ raw_score = AUX_DATA[search_match_index][4]
64
+ single_track_score_notes = TMIDIX.advanced_score_processor(raw_score,
65
+ return_score_analysis=False,
66
+ return_enhanced_score_notes=True)[0]
67
 
68
+ print('Sample INTs', outy[1][:5])
69
  print('=' * 70)
70
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  x = []
72
  y = []
73
  c = []
 
77
  'gray', 'white', 'gold', 'silver',
78
  'lightgreen', 'indigo', 'maroon', 'turquoise']
79
 
80
+ for s in single_track_score_notes:
81
  x.append(s[1])
82
  y.append(s[4])
83
  c.append(colors[s[3]])
 
91
  plt.xlabel("Time in MIDI ticks")
92
  plt.ylabel("MIDI Pitch")
93
 
94
+ with open(fn+'.mid', 'wb') as f:
95
+ f.write(TMIDIX.score2midi(raw_score))
96
+ audio = midi_to_colab_audio(fn+'.mid',
97
+ soundfont_path=soundfont_path,
98
+ sample_rate=16000, # 44100
99
+ volume_scale=10,
100
+ output_for_gradio=True
101
+ )
102
+ yield AUX_DATA[search_match_index][0], fn+'.mid', (16000, audio), plt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
 
104
  #==========================================================================================================
105