Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from midiutil import MIDIFile
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
|
5 |
+
degrees = [60, 62, 64, 65, 67, 69, 71, 72] # MIDI note number
|
6 |
+
track = 0
|
7 |
+
channel = 0
|
8 |
+
time = 0 # In beats
|
9 |
+
duration = 1 # In beats
|
10 |
+
tempo = 60 # In BPM
|
11 |
+
volume = 100 # 0-127, as per the MIDI standard
|
12 |
+
MyMIDI = MIDIFile(1) # One track, defaults to format 1 (tempo track
|
13 |
+
# automatically created)
|
14 |
+
|
15 |
+
def make_mid():
|
16 |
+
MyMIDI.addTempo(track,time, tempo)
|
17 |
+
for pitch in degrees:
|
18 |
+
MyMIDI.addNote(track, channel, pitch, time, duration, volume)
|
19 |
+
time = time + 1
|
20 |
+
with open("major-scale.mid", "wb") as output_file:
|
21 |
+
MyMIDI.writeFile(output_file)
|
22 |
+
return "major-scale.mid"
|
23 |
+
with gr.Blocks() as iface:
|
24 |
+
btn=gr.Button()
|
25 |
+
outp=gr.Files()
|
26 |
+
btn.click(make_mid,None,outp)
|
27 |
+
iface.launch()
|