def base40DeltaToInterval(delta): ''' Returns a music21 Interval between two Base40 pitch numbers given the delta (difference) between them. Raises a Base40 Exception if the interval is not handled by Base40. Base40 can only handle major, minor, perfect, augmented, and diminished intervals. Although not for certain, it seems that the engineers that designed this system assumed that other intervals (doubly augmented intervals, for instance) would be of a very rare occurrence, and extreme intervals which would trigger an incorrect answer (C-- to C##, for instance, would return a diminished second, even though it's a quadruple augmented unison) just would not occur. >>> musedata.base40.base40DeltaToInterval(4) <music21.interval.Interval d2> >>> musedata.base40.base40DeltaToInterval(11) <music21.interval.Interval m3> >>> musedata.base40.base40DeltaToInterval(23) <music21.interval.Interval P5> >>> musedata.base40.base40DeltaToInterval(-23) <music21.interval.Interval P-5> >>> musedata.base40.base40DeltaToInterval(52) <music21.interval.Interval M10> >>> musedata.base40.base40DeltaToInterval(-52) <music21.interval.Interval M-10> >>> musedata.base40.base40DeltaToInterval(77) Traceback (most recent call last): music21.musedata.base40.Base40Exception: Interval not handled by Base40 37 ''' direction = 1 if delta < 0: direction = -1 simpleDelta = abs(delta) % 40 try: simpleIntervalName = base40IntervalTable[simpleDelta] simpleInterval = interval.Interval(simpleIntervalName) except KeyError: raise Base40Exception('Interval not handled by Base40 ' + str(simpleDelta)) numOctaves = abs(delta) // 40 sgi = simpleInterval.generic # Simple generic interval # Compound generic interval cgi = interval.GenericInterval(direction * (sgi.value + 7 * numOctaves)) sdi = simpleInterval.diatonic # Simple diatonic interval newInterval = interval.convertSpecifier(sdi.specifier)[1] + str(cgi.value) return interval.Interval(newInterval)
def base40DeltaToInterval(delta): ''' Returns a music21 Interval between two Base40 pitch numbers given the delta (difference) between them. Raises a Base40 Exception if the interval is not handled by Base40. Base40 can only handle major, minor, perfect, augmented, and diminished intervals. Although not for certain, it seems that the engineers that designed this system assumed that asdfasdf other intervals (doubly augmented intervals, for instance) would be of a very rare occurrence, and extreme intervals which would trigger an incorrect answer (C-- to C##, for instance, would return a diminished second, even though it's a quadruple augmented unison) just would not occur. >>> musedata.base40.base40DeltaToInterval(4) <music21.interval.Interval d2> >>> musedata.base40.base40DeltaToInterval(11) <music21.interval.Interval m3> >>> musedata.base40.base40DeltaToInterval(23) <music21.interval.Interval P5> >>> musedata.base40.base40DeltaToInterval(-23) <music21.interval.Interval P-5> >>> musedata.base40.base40DeltaToInterval(52) <music21.interval.Interval M10> >>> musedata.base40.base40DeltaToInterval(-52) <music21.interval.Interval M-10> >>> musedata.base40.base40DeltaToInterval(77) Traceback (most recent call last): music21.musedata.base40.Base40Exception: Interval not handled by Base40 37 ''' direction = 1 if delta < 0: direction = -1 simpleDelta = abs(delta) % 40 try: simpleIntervalName = base40IntervalTable[simpleDelta] simpleInterval = interval.Interval(simpleIntervalName) except KeyError: raise Base40Exception('Interval not handled by Base40 ' + str(simpleDelta)) numOctaves = abs(delta) // 40 sgi = simpleInterval.generic #Simple generic interval #Compound generic interval cgi = interval.GenericInterval(direction * (sgi.value + 7 * numOctaves)) sdi = simpleInterval.diatonic #Simple diatonic interval newInterval = interval.convertSpecifier(sdi.specifier)[1] + str(cgi.value) return interval.Interval(newInterval)