有没有办法将Music21的和弦检测限制为非斜切和弦?

发布于 2025-01-20 12:53:02 字数 656 浏览 0 评论 0原文

我正在编写一个脚本,该脚本将一系列 MIDI 音符作为输入,并输出一个和弦符号,以便在开源爵士乐即兴创作助手 Impro-Visor 中使用。为了利用 Impro-Visor 的大量和弦词汇,我一直在尝试添加到 music21 的和弦词汇中——music21 本身将处理 MIDI 音高和最常见和弦的解释——使用 Harmony.addNewChordSymbol 方法,但系统在和弦检测中不提供新和弦。例如,如果我尝试 Harmony 模块文档中的这个和弦:

>>>harmony.addNewChordSymbol('BethChord', '1,3,-6,#9', ['MH', 'beth'])
>>>c = chord.Chord(['C3','D#3','E3','A-3'])
>>>print(harmony.chordSymbolFromChord(c))
'A-+/CaddD#'

而在这种情况下我希望得到: 'Cbeth'

Music21 始终建议像上面这样的斜线和弦,而不是我尝试过的任何和弦添加到词汇表中,大概是因为斜线左侧的和弦类型(在本例中为“+”)在 Harmony.py 中的 OrderedDict 中出现得较早。有什么方法可以使和弦检测更喜欢自定义和弦类型而不是这些斜线和弦(我没有任何处理方法)?

I'm working on a script that takes as input a sequence of MIDI notes and outputs a chord symbol for use in Impro-Visor, an open-source jazz improvisation helper. In order to take advantage of Impro-Visor's large vocabulary of chords I've been trying to add to music21's chord vocabulary--music21 itself will handle the MIDI pitches and the interpretation of most common chords--using the harmony.addNewChordSymbol method, but the system doesn't offer the new chords in its chord detection. For example, if I try this chord from the Harmony module's docs:

>>>harmony.addNewChordSymbol('BethChord', '1,3,-6,#9', ['MH', 'beth'])
>>>c = chord.Chord(['C3','D#3','E3','A-3'])
>>>print(harmony.chordSymbolFromChord(c))
'A-+/CaddD#'

Whereas I would hope in this case to get: 'Cbeth'

Music21 consistently suggests slash chords like the above rather than whatever chord I've tried to add to the vocabulary, presumably because the chord type to the left of the slash--'+', in this case--comes earlier in the OrderedDict in harmony.py. Is there any way to make the chord-detection prefer a custom chord type over these slash chords (which I don't have any way of handling)?

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

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

发布评论

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

评论(1

ζ澈沫 2025-01-27 12:53:02

我发现仅告诉music21您的意思是“ c”成为根的问题。 (否则,它将尝试将三分之一堆叠并将“ ab”视为根。)呼叫.root()这样:

>>> harmony.addNewChordSymbol('BethChord', '1,3,-6,#9', ['MH', 'beth'])
>>> c = chord.Chord(['C3','D#3','E3','A-3'])
>>> c.root(c.bass())
>>> harmony.chordSymbolFromChord(c)
<music21.harmony.ChordSymbol CMH>

I found that just telling music21 you meant for "C" to be the root does the trick. (Otherwise, it will try to stack in thirds and treat "Ab" as the root.) Call .root() like this:

>>> harmony.addNewChordSymbol('BethChord', '1,3,-6,#9', ['MH', 'beth'])
>>> c = chord.Chord(['C3','D#3','E3','A-3'])
>>> c.root(c.bass())
>>> harmony.chordSymbolFromChord(c)
<music21.harmony.ChordSymbol CMH>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文