xll__is_me 2022-11-06 15:14 采纳率: 100%
浏览 69
已结题

python中musicpy问题

用代码块功能插入代码,请勿粘贴截图
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

我的解答思路和尝试过的方法
  • 写回答

1条回答 默认 最新

  • onnx 2022-11-07 10:54
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 11月15日
  • 已采纳回答 11月7日
  • 创建了问题 11月6日