用到的Music21函数总结1

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

用到的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 = 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值