music21:伍佰 《挪威的森林》MIDI 音乐分析
pip install music21
以下是使用 music21 对伍佰《挪威的森林》MIDI 音乐进行分析的一些方面:
加载 MIDI 文件
使用 music21 加载《挪威的森林》MIDI 文件,代码如下:
from music21 import converter
score = converter.parse('norwegian_forest.mid')
音符和音高分析
- 提取音符:通过
score.flat.notes
可以遍历乐谱中的每个音符,打印出它的音高和音阶。例如:notes = score.flat.notes for note in notes:print(note.nameWithOctave)
- 音高分布:可以统计不同音高的出现频率,了解歌曲中主要使用的音域范围。通过分析这些数据,能发现歌曲是否有频繁使用的特定音高区域,以及音高的跨度情况。一般来说,《挪威的森林》音高跨度适中,主歌部分音高相对平稳,集中在一定范围内,以配合歌词的叙事性;副歌部分音高会有所上升,增强情感的表达。
节奏分析
- 节拍信息5:通过
score.getTimeSignatures()
可以获取 MIDI 文件中标记的节拍信息,《挪威的森林》标记的节拍为 4/4、2/4 等。4/4 节拍使得歌曲具有稳定的节奏感,适合表达这种流行风格的情感。 - 节奏型分析:可以通过观察音符的时长和排列来分析节奏型。例如,主歌部分可能有较多的平稳节奏型,以叙事为主;而副歌部分可能会出现一些切分音或节奏的变化,来增强情感的张力。
和弦分析
使用score.chordify()
方法可以将乐谱中的音符转换为和弦,然后通过遍历和弦元素来分析和弦的构成和进行。例如:
chords = score.chordify()
for element in chords.recurse().getElementsByClass('Chord'):print(element.normalOrder)
通过分析可以发现,《挪威的森林》的和弦进行较为简单和经典,以 Em 和弦为核心,还包括 Bm、Am、D、E、A、G、C 等和弦11。这些和弦的组合和进行为歌曲营造出了独特的氛围,从主歌到副歌的和弦变化,配合着旋律和歌词,推动着歌曲情感的发展。
乐器分析2
《挪威的森林》MIDI 音乐由多种乐器合奏,如弦乐合奏 2、合成主音 6(人声)、电贝斯(指奏)、打击乐器等。可以通过instrument.partitionByInstrument(stream)
方法来获取不同乐器的部分,了解每个乐器在歌曲中的作用和演奏内容。例如,弦乐可能在一些部分起到烘托氛围的作用,电吉他在副歌部分增强力量感,贝斯则负责稳定节奏和提供低音支持。
整体结构分析
可以通过分析歌曲的段落划分,如主歌、副歌、前奏、间奏、尾声等部分,来了解歌曲的整体结构。通常,《挪威的森林》会有重复的主歌和副歌部分,前奏和间奏会有一些乐器的独奏或合奏来引出歌曲和连接不同的段落,尾声则可能会逐渐减弱,给人一种结束感。通过score.getElementsByClass('Part')
可以获取各个部分,然后进一步分析每个部分的音乐特点。
以下是一段使用 music21
库对《挪威的森林》MIDI 音乐进行基础分析的代码,此代码会对 MIDI 文件进行音符、音高、节奏、和弦等方面的分析。
# -*- coding: utf-8 -*-
""" 伍佰 《挪威的森林》 MIDI 音乐分析 """
from music21 import converter, chord, note
import collectionsdef analyze_midi(file_path):# 解析 MIDI 文件score = converter.parse(file_path)# 音符和音高分析note_names = []for element in score.flat.notes:if isinstance(element, note.Note):note_names.append(element.nameWithOctave)elif isinstance(element, chord.Chord):for n in element.notes:note_names.append(n.nameWithOctave)note_counter = collections.Counter(note_names)print("音符和音高分析:")print("每个音高的出现次数:", note_counter)# 节奏分析 - 节拍信息time_signatures = score.getTimeSignatures()print("\n节奏分析 - 节拍信息:")for ts in time_signatures:print(f"节拍: {ts.ratioString} 在第 {ts.measureNumber} 小节")# 过滤掉 Unpitched 对象pitched_elements = score.flat.getElementsByClass(['Note', 'Chord'])pitched_stream = pitched_elements.stream()# 和弦分析chord_sequence = []chordified_score = pitched_stream.chordify()for element in chordified_score.recurse().getElementsByClass('Chord'):chord_sequence.append(element.pitchedCommonName)chord_counter = collections.Counter(chord_sequence)print("\n和弦分析:")print("每个和弦的出现次数:", chord_counter)# 乐器分析instruments = []parts = score.getElementsByClass('Part')for part in parts:instrument = part.getInstrument()if instrument:instruments.append(instrument.instrumentName)instrument_counter = collections.Counter(instruments)print("\n乐器分析:")print("每个乐器的出现次数:", instrument_counter)if __name__ == "__main__":#file_path = 'norwegian_forest.mid'file_path = '伍佰/挪威森林.mid'analyze_midi(file_path)
代码说明:
- 音符和音高分析:通过遍历 MIDI 文件中的所有音符和和弦,提取每个音符的音高名称,然后使用
collections.Counter
统计每个音高的出现次数。 - 节奏分析:使用
getTimeSignatures
方法获取 MIDI 文件中的节拍信息,并打印出每个节拍出现的小节位置。 - 和弦分析:将 MIDI 文件进行和弦化处理,遍历其中的和弦元素,提取每个和弦的名称,同样使用
collections.Counter
统计每个和弦的出现次数。 - 乐器分析:遍历 MIDI 文件中的每个部分,获取其中的乐器信息,统计每个乐器的出现次数。
注意事项:
你需要将代码中的 'norwegian_forest.mid'
替换为实际的《挪威的森林》MIDI 文件的路径。同时,确保已经安装了 music21
库,可以使用 pip install music21
进行安装。
D:\Music> python wubai_music21.py
音符和音高分析:
每个音高的出现次数: Counter({'G4': 177, 'E4': 139, 'D4': 108, 'A4': 107, 'E2': 104, 'C4': 82, 'C5': 76, 'D2': 73, 'E5': 68, 'D5': 56, 'G5': 50, 'B4': 50, 'A2': 42, 'A3': 36, 'G2': 21, 'A5': 19, 'B5': 13, 'C2': 11, 'E3': 11, 'G3': 10, 'A1': 10, 'C3': 10, 'F4': 9, 'D3': 9, 'G1': 4, 'B3': 1})节奏分析 - 节拍信息:
节拍: 4/4 在第 None 小节和弦分析:
每个和弦的出现次数: Counter({'Perfect Fifth with octave doublings above A': 62, 'Minor Third with octave doublings above E': 44, 'E-minor triad': 36, 'A-incomplete dominant-seventh chord': 28, 'Major Second with octave doublings above D': 28, 'Perfect Fifth with octave doublings above E': 27, 'multiple octaves above D': 25, 'E-incomplete minor-seventh chord': 24, 'Minor Third with octave doublings above A': 21, 'A-minor triad': 20, 'Perfect Fourth with octave doublings above D': 19, 'A-quartal trichord': 18, 'multiple octaves above G': 16, 'D-quartal trichord': 16, 'multiple octaves above C': 16, 'D-incomplete dominant-seventh chord': 16, 'Major Sixth with octave doublings above G': 15, 'Minor Seventh with octave doublings above E': 14, 'C-incomplete major-seventh chord': 13, 'Perfect Fifth with octave doublings above G': 13, 'Minor Sixth with octave doublings above E': 13, 'Perfect Fourth with octave doublings above A': 13, 'Minor Seventh with octave doublings above D': 12, 'Major Tenth above G': 12, 'E-incomplete dominant-seventh chord': 11, 'multiple octaves above A': 10, 'C-major triad': 9, 'multiple octaves above E': 9, 'C-quartal trichord': 8, 'A-incomplete minor-seventh chord': 8, 'Perfect Fifth with octave doublings above D': 8, 'Major Third with octave doublings above G': 7, 'G-major triad': 7, 'Perfect Fourth with octave doublings above G': 7, 'Perfect Fifth above E': 6, 'Major Second with octave doublings above G': 6, 'Minor Seventh with octave doublings above A': 5, 'Perfect Triple-octave above G': 5, 'Perfect Fourth with octave doublings above C': 5, 'Perfect Octave above E': 4, 'Major Seventh above C': 4, 'Major Sixth above G': 4, 'Major Sixth with octave doublings above C': 4, 'Minor Sixth above E': 4, 'F-major triad': 4, 'Perfect Nineteenth above E': 3, 'E-quartal tetramirror': 3, 'C-whole-tone trichord': 3, 'Perfect Fifth above A': 3, 'C-major seventh chord': 3, 'G-whole-tone trichord': 3, 'E-perfect-fourth minor tetrachord': 2, 'Minor Seventh above E': 2, 'Major Third above C': 2, 'Major Second with octave doublings above A': 2, 'F-major-second major tetrachord': 2, 'G-whole-tone tetramirror': 2, 'D-lydian tetrachord': 2, 'F-major seventh chord': 2, 'Major Third with octave doublings above C': 2, 'G-quartal trichord': 2, 'A-perfect-fourth minor tetrachord': 2, 'Perfect Nineteenth above A': 2, 'Perfect Octave above G': 1, 'Major Third above G': 1, 'Perfect Fourth above G': 1, 'Minor Thirteenth above E': 1, 'A-quartal tetramirror': 1, 'Major 27th above G': 1, 'E-minor seventh chord': 1, 'Minor Seventeenth above A': 1, 'D-incomplete minor-seventh chord': 1, 'Perfect Fifth above C': 1, 'Major Sixteenth above D': 1, 'Perfect Double-octave above D': 1, 'Perfect Nineteenth above G': 1, 'F-whole-tone trichord': 1, 'Minor Fourteenth above G': 1, 'Major Seventeenth above C': 1, 'A-major-second minor tetrachord': 1, 'Perfect Fourth above B': 1, 'Major Sixth above D': 1, 'Major Second above A': 1, 'Major Sixth with octave doublings above D': 1, 'Major Thirteenth above D': 1})乐器分析:
每个乐器的出现次数: Counter({None: 5})