用到的Music21函数总结1
1.把目录中所有的mid乐谱都转成C调
from music21 import*
def load_data(file_path):
## load midi file using music21 library
piece = converter.parse(file_path)
#transpose all streams to C major. this process is to reduce the number of states
# store the key of music before transposition.
k = piece.analyze('key')
# save the interval of C and current key
if k.mode == 'minor':
i = interval.Interval(k.parallel.tonic, pitch.Pitch('C'))
else:
i = interval.Interval(k.tonic, pitch.Pitch('C'))
# transpose the music using stored interval
piece = piece.transpose(i)
# return transposed music
return piece
2.输出每一个mid文件的基本信息
class preprocessing(object):
def __init__(self):
## to collect and count unique chords, notes, octaves
# lists that store unique chords and octaves
self.chords = []
self.chord_octaves = []
# lists for counting the number of times the chords and octaves appear
self.chord_ref=[]
self.octave_ref=[]
self.chords_cnt = [0] * len(self.chord_ref)
self.chord_octaves_cnt = [0] * len(self.octave_ref)
# the same thing about notes
self.notes = []
self.note_octaves =