Spaces:
Running
Running
File size: 4,115 Bytes
07da807 9454d1d 4720292 07da807 4720292 07da807 54b0803 9454d1d 54b0803 7fb76b1 54b0803 4720292 ac2ac4a 4720292 ac2ac4a 4720292 ac2ac4a 4720292 8d02425 ac2ac4a 8d02425 ac2ac4a e6235c2 4720292 9454d1d 07da807 d60ebd2 07da807 97d13f3 ac2ac4a 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
from midiutil import MIDIFile
from musicpy import *
from musicpy.daw import *
import gradio as gr
def write_song():
guitar = (C('CM7', 3, 1/4, 1/8)^2 |
C('G7sus', 2, 1/4, 1/8)^2 |
C('A7sus', 2, 1/4, 1/8)^2 |
C('Em7', 2, 1/4, 1/8)^2 |
C('FM7', 2, 1/4, 1/8)^2 |
C('CM7', 3, 1/4, 1/8)@1 |
C('AbM7', 2, 1/4, 1/8)^2 |
C('G7sus', 2, 1/4, 1/8)^2) * 2
write(guitar, name="tmp.mid", bpm=100, instrument=25)
return "tmp.mid","tmp.mid"
def write_song2():
current_daw = daw(3)
current_daw.load(0, )
current_daw.load(1, 'Arachno.sf2')
bass1 = chord('A1') % (1,) * 4
bass2 = (chord('A1, A2') % (1/16, 1/8) * 4 |
chord('G1, G2') % (1/16, 1/8) * 4 |
chord('F1, F2') % (1/16, 1/8) * 4 |
chord('D1, D2') % (1/16, 1/8) * 4)
guitar1 = (C('Am/A', 3) @ [1,2,3,4,2,3,4,3] % (1, 1/8) |
C('G/A', 3) @ [1,2,3,4,2,3,4,3] % (1, 1/8) |
C('F/A', 3) @ [1,3,1.1,2.1,3,1.1,2.1,1.1] % (1, 1/8) |
C('Dm/A', 3) @ [1,3,1.1,2.1,3,1.1,2.1,1.1] % (1, 1/8))
guitar2 = (C('Am', 4) @ [2,3,1.1,2.1,3,1.1,2.1,1.1] % (1, 1/8) |
C('G', 4) @ [2,3,1.1,2.1,3,1.1,2.1,1.1] % (1, 1/8) |
C('F', 4) @ [2,3,1.1,2.1,3,1.1,2.1,1.1] % (1, 1/8) |
C('Dm', 4) @ [2,3,1.1,2.1,3,1.1,2.1,1.1] % (1, 1/8))
drum1 = drum('S[l:.8; i:.; r:4], S[l:.16; i:.], S[l:.8; i:.], S[l:.16; i:.], S[l:.8; i:.], S[l:.8; i:.]').notes
drum2 = drum('H, a:.16;., r:16').notes
drum1 &= drum2
drum3 = drum('K, H, S, H, K[l:.16; i:.], K[l:.8; i:.], H[l:.16; i:.], S[l:.8; i:.], H[l:.8; i:.]').notes
synth_pad1 = chord('E5, G5, C6') % (1,) | chord('E5, B5, D6') % (1,) | chord('E5, A5, C6') % (1,) | chord('D5, F5, A5') % (1,)
synth_pad1.set_volume(80)
bass_part = (bass1 * 2 | bass2 * 4) + 3
guitar_part = (guitar1 * 2 | guitar2 * 4) + 3
drum_part = (drum1 * 4 | drum3 * 16)
synth_pad_part = (synth_pad1 * 4) + 3
result = P(tracks=[bass_part, guitar_part, drum_part, synth_pad_part],
instruments=[34, 3, 1, 51],
channels=[0, 1, 9, 2],
daw_channels=[1, 0, 1, 1],
start_times=[0, 0, 4, 8],
bpm=165)
#current_daw.play(result)
current_daw.export(result, filename='song.wav') # export the piece type current_song to
# a wav file named "my first song.wav"
'''
export(obj,
mode='wav',
action='export',
filename='song.wav',
channel_num=0,
bpm=None,
length=None,
extra_length=None,
track_lengths=None,
track_extra_lengths=None,
export_args={},
show_msg=False,
soundfont_args=None)
'''
return 'song.wav','song.wav'
def write_song1():
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()
aud=gr.Audio()
btn.click(write_song2,None,[outp,aud])
iface.launch() |