2017-04-02 37 views
6

Temel olarak, iki midi dosyası eklemeye çalışıyorum ve bununla ilgili internette fazla bilgi yok, bu yüzden kendi başıma çalışıyorum.Bazı koşullarla listeden verileri ayıkla

Şimdiye kadar yaptığım şey, iki midi'nin iletilerini (midi'nin verileri türü) ekledim ve her iki midi iletisinin listesini aldım. Bu, şu anda iki midi birleştirmem gereken tüm verilere sahip olduğum anlamına geliyor. Sorun, belirli bir biçimde veri ekleyemem.

Yani benim kodudur: Artık

note_on channel=0 note=59 velocity=40 time=0 
note_on channel=0 note=60 velocity=40 time=0 
note_on channel=0 note=64 velocity=40 time=0 
note_off channel=0 note=59 velocity=0 time=55 
note_off channel=0 note=64 velocity=0 time=0 
note_on channel=0 note=52 velocity=40 time=0 
note_off channel=0 note=60 velocity=0 time=55 
note_on channel=0 note=64 velocity=40 time=0 
note_on channel=0 note=67 velocity=40 time=0 
note_off channel=0 note=67 velocity=0 time=55 
note_on channel=0 note=57 velocity=40 time=0 
note_off channel=0 note=52 velocity=0 time=55 
note_off channel=0 note=57 velocity=0 time=0 
note_off channel=0 note=64 velocity=0 time=0 
note_on channel=0 note=57 velocity=40 time=55 
note_off channel=0 note=57 velocity=0 time=55 
note_on channel=0 note=64 velocity=40 time=0 
note_on channel=0 note=67 velocity=40 time=0 
note_off channel=0 note=64 velocity=0 time=55 
note_off channel=0 note=67 velocity=0 time=0 
note_on channel=0 note=57 velocity=40 time=110 
note_on channel=0 note=64 velocity=40 time=0 
note_off channel=0 note=57 velocity=0 time=55 
note_off channel=0 note=64 velocity=0 time=0 
note_on channel=0 note=62 velocity=40 time=0 
note_off channel=0 note=62 velocity=0 time=55 
note_on channel=0 note=57 velocity=40 time=110 
note_on channel=0 note=62 velocity=40 time=0 
note_off channel=0 note=57 velocity=0 time=55 
note_off channel=0 note=62 velocity=0 time=0 
note_on channel=0 note=60 velocity=40 time=0 
note_on channel=0 note=62 velocity=40 time=0 
note_on channel=0 note=67 velocity=40 time=0 
note_on channel=0 note=60 velocity=40 time=55 
note_on channel=0 note=64 velocity=40 time=0 
note_off channel=0 note=60 velocity=0 time=55 
note_off channel=0 note=62 velocity=0 time=0 
note_off channel=0 note=64 velocity=0 time=0 
note_off channel=0 note=67 velocity=0 time=55 
note_on channel=0 note=64 velocity=40 time=0 
note_off channel=0 note=64 velocity=0 time=55 
note_on channel=0 note=60 velocity=40 time=0 
note_off channel=0 note=60 velocity=0 time=55 
note_on channel=0 note=62 velocity=40 time=0 
note_off channel=0 note=62 velocity=0 time=55 
note_on channel=0 note=64 velocity=40 time=0 
note_off channel=0 note=64 velocity=0 time=55 
note_on channel=0 note=60 velocity=40 time=110 
note_on channel=0 note=62 velocity=40 time=0 
note_off channel=0 note=60 velocity=0 time=55 
note_off channel=0 note=62 velocity=0 time=0 
note_on channel=0 note=48 velocity=40 time=110 
note_on channel=0 note=62 velocity=40 time=0 
note_off channel=0 note=48 velocity=0 time=55 
note_off channel=0 note=62 velocity=0 time=0 
note_on channel=0 note=57 velocity=40 time=55 
note_on channel=0 note=60 velocity=40 time=0 

bu tamam ama sorun ben this format :

from mido import Message, MidiFile, MidiTrack 

mid = MidiFile() 
track = MidiTrack() 
mid.tracks.append(track) 

track.append(Message('program_change', program=12, time=0)) 
track.append(Message('note_on', note=64, velocity=64, time=32)) 
track.append(Message('note_off', note=64, velocity=127, time=32)) 

mid.save('new_song.mid') 
izlemek mesaj ekleyebilirsiniz geçerli:

from mido import MidiFile, MidiTrack 

mid = MidiFile('har.mid') 
mid2 = MidiFile('har2.mid') 

l = [msg for track in mid.tracks for msg in track] 
l.pop() 
ka = [msg for track in mid2.tracks for msg in track] 
ka.pop() 

result = l + ka 

for messagess in result: 
    print(messagess) 

bu çıktıyı alıyorum

bu yüzden, her satırın bu biçime nasıl ekleneceğini sorun:

peşin

track.append(Message('note_off', note=62, velocity=0, time=0)) 

teşekkür: track.append(Message())

çünkü track.append desteği sadece bu biçim yöntemi bu biçimde

'note_off', note=62, velocity=0, time=0

-e doğru

note_off channel=0 note=62 velocity=0 time=0 

. Onları tekrar inşa etmek gerek should't böylece result yılında

+0

İletilerin türü() nedir? Dizi? –

+0

Onlar dize değil ama biz onları repr() kullanarak düşünebiliriz düşünüyorum –

+0

Bu soru makine öğrenme etiketi ile ne ilgisi var? –

cevap

2
from mido import MidiFile, MidiTrack 

mid = MidiFile('har.mid') 
mid2 = MidiFile('har2.mid') 

l = [msg for track in mid.tracks for msg in track] 
l.pop() 
ka = [msg for track in mid2.tracks for msg in track] 
ka.pop() 

result = l + ka 

mid3 = MidiFile() 
track = MidiTrack() 
mid3.tracks.append(track) 

for m in result: 
    track.append(m) 

mid3.save('new_song.mid') 

nesneler zaten Message nesneler olmalıdır. Bu kodu deneyin, eğer işe yaramazsa, geri aldığınız tüm hata mesajını kopyalayın.

İlgili konular