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

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条回答 默认 最新

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

报告相同问题?

问题事件

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

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效