用到的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 =

本文总结了使用Music21库对MIDI乐谱进行转换为C调及输出基本信息的操作,包括音符、八度、和弦等统计。此外,还介绍了如何利用Music21创作升调练声曲,对于音乐生成和声乐练习有实用价值。
最低0.47元/天 解锁文章
810

被折叠的 条评论
为什么被折叠?



