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

python音乐编程问题

用代码块功能插入代码,请勿粘贴截图

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

  • Ko-walski 2022-11-06 15:06
    关注

    会不会格式化发出来。这鬼能看清楚

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

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

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分