-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmidi_generator.py
33 lines (26 loc) · 1.01 KB
/
midi_generator.py
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
#!/usr/bin/python3
from midiutil import MIDIFile
from read_tabs import Tabs
class Track():
def __init__(self,tempo):
self.track = 0
self.channel = 0
self.time = 0.125 # In beats
self.duration = 0.1 # In beats
self.tempo = tempo # In BPM
self.volume = 100 # 0-127, as per the MIDI standard
def midiGenerator(self,a):
MyMIDI = MIDIFile(1)
MyMIDI.addProgramChange(self.track, self.channel, self.time,1)
MyMIDI.addTempo(self.track, self.time, self.tempo)
time=0
for i in range(len(a[0])):
for j in range(len(a)):
duration = self.duration
if a[j][i]!='-':
if a[j][i+1]=='-':
duration = self.duration+1
MyMIDI.addNote(self.track,self.channel,int(a[j][i]),time,duration,self.volume)
time+=self.time
with open("output.mid", "wb") as output_file:
MyMIDI.writeFile(output_file)