added some comments to the python file

This commit is contained in:
TanguyPcFixe 2021-05-19 10:44:34 +02:00
parent 5552233c19
commit 90253a81f7

View File

@ -3,24 +3,31 @@ import time
import winsound import winsound
import math import math
#plays a Note through windows
def playNote(freq, dur): def playNote(freq, dur):
winsound.Beep(freq, dur) winsound.Beep(freq, dur)
#convert a note to a frequency
def noteToFreq(note): def noteToFreq(note):
return (2**((note-69)/12))*440 return (2**((note-69)/12))*440
#select which midi channel you want to convert. Can be multiple, but it often doesn't work. Not like anything else does.
channelIsole = [0] channelIsole = [0]
file = mido.MidiFile("laputa.mid") # set the midi file here
file = mido.MidiFile("MIDIs/laputa.mid")
# use this to modify the tempo.
tempoMult = 1/1 tempoMult = 1/1
# use this to modify the key. I've found out my routerboards is less tone deaf with a higher key. Mileage will vary.
freqMult = 1.3 freqMult = 1.3
# start of the shitty code
tabNote = [msg for msg in file] tabNote = [msg for msg in file]
print(f"tab lenght is {len(tabNote)}") # print(f"tab lenght is {len(tabNote)}")
note1 = tabNote[0] note1 = tabNote[0]
note2 = tabNote[0] note2 = tabNote[0]
i = 0 i = 0
@ -31,11 +38,8 @@ biMode = False
out = open("out.txt",'w') out = open("out.txt",'w')
while i < len(tabNote): while i < len(tabNote):
# print(tabNote[i])
# while i < 5000:
while((not isFound) and i < len(tabNote)): while((not isFound) and i < len(tabNote)):
print("b1", i, tabNote[i]) # print("b1", i, tabNote[i])
if tabNote[i].type == "note_on": if tabNote[i].type == "note_on":
if(tabNote[i].channel in channelIsole): if(tabNote[i].channel in channelIsole):
note1 = tabNote[i] note1 = tabNote[i]
@ -44,11 +48,11 @@ while i < len(tabNote):
isFound = False isFound = False
print("found note 1", i-1, note1) # print("found note 1", i-1, note1)
while((not isFound) and i < len(tabNote)): while((not isFound) and i < len(tabNote)):
print("b2", i, tabNote[i]) # print("b2", i, tabNote[i])
if tabNote[i].type == "note_off": if tabNote[i].type == "note_off":
if(tabNote[i].channel in channelIsole ): if(tabNote[i].channel in channelIsole ):
note2 = tabNote[i] note2 = tabNote[i]
@ -65,10 +69,10 @@ while i < len(tabNote):
isFound = False isFound = False
if(biMode): if(biMode):
print("######") # print("######")
print("lol",note1) # print("lol",note1)
print("mdr",note2) # print("mdr",note2)
print("######") # print("######")
freq = int(noteToFreq(note1.note)) freq = int(noteToFreq(note1.note))
duration = int((note1.time + note2.time) *1000) # in ms duration = int((note1.time + note2.time) *1000) # in ms
@ -76,7 +80,7 @@ while i < len(tabNote):
if(duration == 0): if(duration == 0):
duration = 150 duration = 150
print(freq, duration) # print(freq, duration)
#if(msg.time>0.1): #if(msg.time>0.1):
# playNote(freq, int(duration*tempoMult)) # playNote(freq, int(duration*tempoMult))