Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mido
- import clipboard
- from operator import itemgetter
- mid = mido.MidiFile('soulless4.mid')
- result = []
- notes_on=[]
- instruments = {}
- volumed = {}
- total_time = 0
- current_instrument = 1
- def get_instrument(msg):
- prog = instruments[msg.channel]
- ins = 1
- if prog in [1,2,3,4]: ins = 1 #piano
- elif prog in [5,6]: ins = 2 #electric piano
- elif prog in [15,17,18,19,20,21,22,23,24]: ins = 3 #organ
- elif prog in [25,26,32]: ins = 4 #guitar
- elif prog in [27,28,29,30,31]: ins = 5 #electric guitar
- elif prog in [33,34,35,36,37,38,39,40]: ins = 6 #bass
- elif prog in [7,46,47,48]: ins = 7 #pizzacito
- elif prog in [41,42,43,44,45]: ins = 8 #cello
- elif prog in [57,58,59,60,61,62,63,64]: ins = 9 #trombone
- elif prog in [8,72]: ins = 10 #clarinet
- elif prog in [65,66,67,68,69,70]: ins = 11 #saxophone
- elif prog in [74,75,76,79,80]: ins = 12 #flute
- elif prog in [73,77,78]: ins = 13 #wooden flute
- elif prog in [71]: ins = 14 #bassoon
- elif prog in [49,50,51,52,53,54,55,56]: ins = 15 #choir
- elif prog in [9,10,12,14,16]: ins = 16 #vibraphone
- elif prog in [11]: ins = 17 #music box
- elif prog in [113,114,115,116,117,118,119,120]: ins = 18 #steel drum
- elif prog in [13]: ins = 19 #marimba
- elif prog in [81,82,83,84,85,86,87,88]: ins = 20 #synth lead
- elif prog in [89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104]: ins = 21#synth pad
- else: ins = 1
- return ins
- for msg in mid:
- if msg.type == 'note_on':
- notes_on.append([msg,total_time+msg.time])#[str(total_time+msg.time),str(ins),str(msg.note),"0.5",str(msg.velocity)])
- if msg.type == 'note_off':
- i=0
- for x in range(len(notes_on)):
- note = notes_on[i][0]
- if note.channel == msg.channel and note.note == msg.note:
- result.append([notes_on[i][1],get_instrument(note),note.note,(msg.time+total_time)-notes_on[i][1],(note.velocity*100)/64])
- notes_on.pop(i)
- i-=1
- i+=1
- if msg.type == 'program_change':
- channel = msg.channel
- program = msg.program
- instruments[channel] = program
- total_time += msg.time
- final = sorted(result,key=itemgetter(0))
- clipboard.copy(','.join([','.join([str(y) for y in x]) for x in final]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement