Upload 7 files
Browse files- .gitattributes +1 -0
- Monster_52905_Mono_Melodies_MIDI_Dataset.pickle +3 -0
- SGM-v2.01-YamahaGrand-Guit-Bass-v2.7.sf2 +3 -0
- TMIDIX.py +0 -0
- app.py +185 -0
- midi_to_colab_audio.py +0 -0
- packages.txt +1 -0
- requirements.txt +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
SGM-v2.01-YamahaGrand-Guit-Bass-v2.7.sf2 filter=lfs diff=lfs merge=lfs -text
|
Monster_52905_Mono_Melodies_MIDI_Dataset.pickle
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:04c8fb75aa991f10f173f5eea3506d9b109988c2409cf4674d30a5b38a5bacfc
|
| 3 |
+
size 1150876437
|
SGM-v2.01-YamahaGrand-Guit-Bass-v2.7.sf2
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cd41a4639c9e7a96413b4b22540d48e6741e24bcdabcb2eff22cd65929df3cfa
|
| 3 |
+
size 553961496
|
TMIDIX.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
app.py
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# https://huggingface.co/spaces/asigalov61/MIDI-Melody
|
| 2 |
+
|
| 3 |
+
import os.path
|
| 4 |
+
|
| 5 |
+
import time as reqtime
|
| 6 |
+
import datetime
|
| 7 |
+
from pytz import timezone
|
| 8 |
+
|
| 9 |
+
import gradio as gr
|
| 10 |
+
|
| 11 |
+
import random
|
| 12 |
+
import tqdm
|
| 13 |
+
|
| 14 |
+
from midi_to_colab_audio import midi_to_colab_audio
|
| 15 |
+
import TMIDIX
|
| 16 |
+
|
| 17 |
+
import matplotlib.pyplot as plt
|
| 18 |
+
|
| 19 |
+
in_space = os.getenv("SYSTEM") == "spaces"
|
| 20 |
+
|
| 21 |
+
# =================================================================================================
|
| 22 |
+
|
| 23 |
+
def AddMelody(input_midi, input_channel, input_patch, input_start_chord):
|
| 24 |
+
print('=' * 70)
|
| 25 |
+
print('Req start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
|
| 26 |
+
start_time = reqtime.time()
|
| 27 |
+
|
| 28 |
+
print('=' * 70)
|
| 29 |
+
|
| 30 |
+
fn = os.path.basename(input_midi.name)
|
| 31 |
+
fn1 = fn.split('.')[0]
|
| 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 |
+
#===============================================================================
|
| 41 |
+
raw_score = TMIDIX.midi2single_track_ms_score(input_midi.name)
|
| 42 |
+
|
| 43 |
+
#===============================================================================
|
| 44 |
+
# Enhanced score notes
|
| 45 |
+
|
| 46 |
+
escore_notes = TMIDIX.advanced_score_processor(raw_score, return_enhanced_score_notes=True)[0]
|
| 47 |
+
|
| 48 |
+
if len(escore_notes) > 0:
|
| 49 |
+
|
| 50 |
+
#=======================================================
|
| 51 |
+
# PRE-PROCESSING
|
| 52 |
+
|
| 53 |
+
#===============================================================================
|
| 54 |
+
# Augmented enhanced score notes
|
| 55 |
+
|
| 56 |
+
escore_notes = TMIDIX.augment_enhanced_score_notes(escore_notes)
|
| 57 |
+
|
| 58 |
+
#===============================================================================
|
| 59 |
+
# Recalculate timings
|
| 60 |
+
|
| 61 |
+
escore_notes = TMIDIX.recalculate_score_timings(escore_notes)
|
| 62 |
+
#===============================================================================
|
| 63 |
+
# Add melody
|
| 64 |
+
|
| 65 |
+
output = TMIDIX.add_melody_to_enhanced_score_notes(escore_notes,
|
| 66 |
+
melody_channel=input_channel,
|
| 67 |
+
melody_patch=input_patch,
|
| 68 |
+
melody_start_chord=input_start_chord
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
print('=' * 70)
|
| 72 |
+
print('Done!')
|
| 73 |
+
print('=' * 70)
|
| 74 |
+
|
| 75 |
+
#===============================================================================
|
| 76 |
+
print('Rendering results...')
|
| 77 |
+
|
| 78 |
+
print('=' * 70)
|
| 79 |
+
print('Sample INTs', output[:12])
|
| 80 |
+
print('=' * 70)
|
| 81 |
+
|
| 82 |
+
output_score, patches, overflow_patches = TMIDIX.patch_enhanced_score_notes(output)
|
| 83 |
+
|
| 84 |
+
detailed_stats = TMIDIX.Tegridy_ms_SONG_to_MIDI_Converter(output_score,
|
| 85 |
+
output_signature = 'MIDI Melody',
|
| 86 |
+
output_file_name = fn1,
|
| 87 |
+
track_name='Project Los Angeles',
|
| 88 |
+
list_of_MIDI_patches=patches,
|
| 89 |
+
timings_multiplier=16
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
new_fn = fn1+'.mid'
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
audio = midi_to_colab_audio(new_fn,
|
| 96 |
+
soundfont_path=soundfont,
|
| 97 |
+
sample_rate=16000,
|
| 98 |
+
volume_scale=10,
|
| 99 |
+
output_for_gradio=True
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
print('Done!')
|
| 103 |
+
print('=' * 70)
|
| 104 |
+
|
| 105 |
+
#========================================================
|
| 106 |
+
|
| 107 |
+
output_midi_title = str(fn1)
|
| 108 |
+
output_midi_summary = str(output_score[:3])
|
| 109 |
+
output_midi = str(new_fn)
|
| 110 |
+
output_audio = (16000, audio)
|
| 111 |
+
|
| 112 |
+
for o in output_score:
|
| 113 |
+
o[1] *= 16
|
| 114 |
+
o[2] *= 16
|
| 115 |
+
|
| 116 |
+
output_plot = TMIDIX.plot_ms_SONG(output_score, plot_title=output_midi_title, return_plt=True)
|
| 117 |
+
|
| 118 |
+
print('Output MIDI file name:', output_midi)
|
| 119 |
+
print('Output MIDI title:', output_midi_title)
|
| 120 |
+
print('Output MIDI summary:', '')
|
| 121 |
+
print('=' * 70)
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
#========================================================
|
| 125 |
+
|
| 126 |
+
print('-' * 70)
|
| 127 |
+
print('Req end time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
|
| 128 |
+
print('-' * 70)
|
| 129 |
+
print('Req execution time:', (reqtime.time() - start_time), 'sec')
|
| 130 |
+
|
| 131 |
+
return output_midi_title, output_midi_summary, output_midi, output_audio, output_plot
|
| 132 |
+
|
| 133 |
+
# =================================================================================================
|
| 134 |
+
|
| 135 |
+
if __name__ == "__main__":
|
| 136 |
+
|
| 137 |
+
PDT = timezone('US/Pacific')
|
| 138 |
+
|
| 139 |
+
print('=' * 70)
|
| 140 |
+
print('App start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
|
| 141 |
+
print('=' * 70)
|
| 142 |
+
|
| 143 |
+
soundfont = "SGM-v2.01-YamahaGrand-Guit-Bass-v2.7.sf2"
|
| 144 |
+
|
| 145 |
+
app = gr.Blocks()
|
| 146 |
+
with app:
|
| 147 |
+
gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>MIDI Melody</h1>")
|
| 148 |
+
gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>Add a unique melody to any MIDI</h1>")
|
| 149 |
+
gr.Markdown(
|
| 150 |
+
"\n\n"
|
| 151 |
+
"This is a demo for TMIDIX Python module from tegridy-tools\n\n"
|
| 152 |
+
"Check out [tegridy-tools](https://github.com/asigalov61/tegridy-tools) on GitHub!\n\n"
|
| 153 |
+
)
|
| 154 |
+
gr.Markdown("## Upload your MIDI or select a sample example MIDI")
|
| 155 |
+
|
| 156 |
+
input_midi = gr.File(label="Input MIDI", file_types=[".midi", ".mid", ".kar"])
|
| 157 |
+
input_channel = gr.Slider(0, 15, value=3, step=1, label="Melody MIDI channel")
|
| 158 |
+
input_patch = gr.Slider(0, 127, value=40, step=1, label="Melody MIDI patch")
|
| 159 |
+
input_start_chord = gr.Slider(0, 128, value=0, step=1, label="Melody start chord")
|
| 160 |
+
|
| 161 |
+
run_btn = gr.Button("add melody", variant="primary")
|
| 162 |
+
|
| 163 |
+
gr.Markdown("## Output results")
|
| 164 |
+
|
| 165 |
+
output_midi_title = gr.Textbox(label="Output MIDI title")
|
| 166 |
+
output_midi_summary = gr.Textbox(label="Output MIDI summary")
|
| 167 |
+
output_audio = gr.Audio(label="Output MIDI audio", format="wav", elem_id="midi_audio")
|
| 168 |
+
output_plot = gr.Plot(label="Output MIDI score plot")
|
| 169 |
+
output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
run_event = run_btn.click(AddMelody, [input_midi, input_channel, input_patch, input_start_chord],
|
| 173 |
+
[output_midi_title, output_midi_summary, output_midi, output_audio, output_plot])
|
| 174 |
+
|
| 175 |
+
gr.Examples(
|
| 176 |
+
[["Sharing The Night Together.kar", 3, 40, 0],
|
| 177 |
+
["Deep Relaxation Melody #6.mid", 3, 40, 0],
|
| 178 |
+
],
|
| 179 |
+
[input_midi, input_channel, input_patch, input_start_chord],
|
| 180 |
+
[output_midi_title, output_midi_summary, output_midi, output_audio, output_plot],
|
| 181 |
+
AddMelody,
|
| 182 |
+
cache_examples=True,
|
| 183 |
+
)
|
| 184 |
+
|
| 185 |
+
app.queue().launch()
|
midi_to_colab_audio.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
packages.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
fluidsynth
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
gradio
|
| 3 |
+
einops
|