用代码块功能插入代码,请勿粘贴截图
from typing import *
from musicpy import *
a1 = note('C', 5)
a2 = note('D', 5)
a3 = note('E', 5)
a4 = note('F', 5)
a5 = note('G', 5)
a6 = note('A', 5)
a7 = note('B', 5)
a_1 = note('C', 6)
a_2 = note('D', 6)
a_3 = note('E', 6)
a_4 = note('F', 6)
a_5 = note('G', 6)
a_6 = note('A', 6)
a_7 = note('B', 6)
b1 = note('C', 4)
b2 = note('D', 4)
b3 = note('E', 4)
b4 = note('F', 4)
b5 = note('G', 4)
b6 = note('A', 4)
b7 = note('B', 4)
def stringToList(string: str) -> List[note]:
res = []
s: str
for s in string.split():
if len(s) == 1:
res.append(eval(f'a{s}'))
if len(s) == 2:
res.append(eval(f'a_{s[0]}'))
else:
res.append(eval(f'b{s[0]}'))
return res
时值
n = 1 / 4
nd = 1 / 4 + 1 / 8
_ = 1 / 8
_d = 1 / 8 + 1 / 16
d = 1 / 16
notList = "1 1. 7 1. 6 7 7 7 7 1. 2. 5 5 5 3 4 5 6 5 4 3 5 4 3 2 4 3 2 1 2 1 7.. 6.."
durList = [n] + [n * 3, _d, d] * 2 + [n * 2, _, _, _d, d] + [n * 2, _, _, _, _, ] + [d * 16]
melody = chord(stringToList(notList), durList, durList)
play(melody, bpm=120)
运行结果及报错内容
Traceback (most recent call last):
File "D:/python/music/njfu.py", line 52, in
melody = chord(stringToList(notList), durList, durList)
File "C:\Users\34024\AppData\Roaming\Python\Python310\site-packages\musicpy\structures.py", line 213, in init
self.changeInterval(interval)
File "C:\Users\34024\AppData\Roaming\Python\Python310\site-packages\musicpy\structures.py", line 634, in changeInterval
raise ValueError(
ValueError: please ensure the intervals between notes has the same numbers of the notes