File size: 1,387 Bytes
07da807
9454d1d
07da807
 
 
9454d1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
07da807
 
d60ebd2
 
 
 
 
 
 
 
 
 
 
 
 
07da807
 
 
 
 
 
 
 
 
 
9454d1d
07da807
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from midiutil import MIDIFile
from musicpy import *
import gradio as gr


def write_song():
    w = (C('Cmadd9,add11',5) @ [1,3,1.1,4,2.1,5,2.1,4] % (1/2,1/8) * 2 |
    C('A#add9,add11',4) @ [1,3,1.1,4,2.1,5,2.1,4] % (1/2,1/8) * 2 |
    C('G#add9',4) @ [1,3,1.1,4,2.1,4,1.1,3] % (1/2,1/8) * 2 |
    C('A#add9',4) @ [1,3,1.1,4,2.1,4,1.1,3] % (1/2,1/8) * 2)
    
    w2 = translate('C2;C3[l:2], i:2, A#1;A#2[l:2], i:2, G#1;G#2[l:2], i:2, A#1;A#2[l:2]')
    
    # Write the song as a MIDI file
    write(w2,
          bpm=100,
          channel=0,
          name='funky_song.mid',
          save_as_file=True)    
    return "funky_song.mid"

def make_mid():

    degrees = [60, 62, 64, 65, 67, 69, 71, 72] # MIDI note number
    track = 0
    channel = 0
    time = 0 # In beats
    duration = 1 # In beats
    tempo = 60 # In BPM
    volume = 100 # 0-127, as per the MIDI standard
    MyMIDI = MIDIFile(1) # One track, defaults to format 1 (tempo track
    # automatically created)


    
    MyMIDI.addTempo(track,time, tempo)
    for pitch in degrees:
        MyMIDI.addNote(track, channel, pitch, time, duration, volume)
        time = time + 1
    with open("major-scale.mid", "wb") as output_file:
        MyMIDI.writeFile(output_file)
    return "major-scale.mid"
with gr.Blocks() as iface:
    btn=gr.Button()
    outp=gr.Files()
    btn.click(write_song,None,outp)
iface.launch()