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日

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)