在Python Music 21中通过其颜色找到笔记21

发布于 2025-01-26 03:31:49 字数 84 浏览 0 评论 0原文

在Python中使用Music21,我需要选择所有红色的注释,以便我可以将它们更改为黑色,但是我似乎找不到一种方法来选择笔记以其颜色选择……有人有想法吗?

Using music21 in python, I need to select all the notes that are red so I can change them to black but I cannot seem to find a way to select notes by their color... Does anyone have an idea ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

女皇必胜 2025-02-02 03:31:49

没有直接的功能可以按颜色搜索笔记。但是,您可以编写a

from music21 import *

def redFilter(n: note.Note):
    if n.style.color == 'red':
        return True
    else:
        return False

# assuming sc is your score:

for n in sc[note.GeneralNote].addFilter(redFilter):
    n.style.color = 'black'

这使用Music21 V7语法来调用recurse()。getElementsByClass(Note.generalNote) - 如果您不使用v7.3,请务必确保升级。 (如果您在Python中更高级,则可以将参数编写为添加filter作为lambda函数)。

there is no direct function to search for notes by color. However, you could write a Custom Filter to do what you want:

from music21 import *

def redFilter(n: note.Note):
    if n.style.color == 'red':
        return True
    else:
        return False

# assuming sc is your score:

for n in sc[note.GeneralNote].addFilter(redFilter):
    n.style.color = 'black'

This uses music21 v7 syntax for calling recurse().getElementsByClass(note.GeneralNote) -- if you're not on v7.3 be sure to upgrade. (if you're more advanced in Python, you could write the parameter to addFilter as a lambda function).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文