使用music21的音阶类自定义音阶继承“ deriveAll”功能

问题描述

我想知道定义自定义比例的正确方法是侵犯“ scale”类的属性吗?

我应该在“ music21 / scale / init .py'”

中加入我的课程吗?
class myAbastract(AbstractScale):
    '''
    A pseudo my-scale.
    '''
    def __init__(self):
        super().__init__()
        self.type = 'Abstract My Name'
        self.octaveDuplicating = True
        self.dominantDegree: int = -1
        self.buildNetwork()

当我在main.py中定义myScale时,似乎它没有继承“ deriveAll()”方法/函数

pitchListStrs = 'a b` c d e f g a'.split()
pitchList = [pitch.Pitch(p) for p in pitchListStrs]
myScaleA = scale.ConcreteScale(pitches=pitchList)
[str(p) for p in myScaleA.getPitches('E-5','G-7')]

myScale = myScaleA.abstract
mySol =scale.ConcreteScale()
mySol.tonic = pitch.Pitch('D')

但随后,未定义deriveAll:

myScale.deriveAll(['E5','F5','G5','A5','B`5','C6','D6','E6'])
Traceback (most recent call last):
  File "<stdin>",line 1,in <module>
AttributeError: 'AbstractScale' object has no attribute 'deriveAll'

任何帮助将不胜感激。

解决方法

deriveAll 是在 ConcreteScale 实例上定义的例程。您试图在 AbstractScale 的实例上调用它。尝试在具体的变量 myScaleA 上调用它。