def __init__(self): super().__init__() # TODO: Figure out this one more in depth self.set_scale_degree('I', function='subdominant') self.triad_quality = "diminished_triad" self.add_interval(interval.IntervalSpelling("m", 3)) self.add_interval(interval.IntervalSpelling("D", 5)) self.add_interval(interval.IntervalSpelling("D", 7))
def __init__(self, augmented_sixth_type): super().__init__() self.set_scale_degree('iv', '#') self.add_interval(interval.IntervalSpelling("D", 3)) self.add_interval(interval.IntervalSpelling("D", 5)) self.augmented_sixth_type = augmented_sixth_type if self.augmented_sixth_type == 'german': self.add_interval(interval.IntervalSpelling("D", 7)) elif self.augmented_sixth_type == 'french': self.add_interval(interval.IntervalSpelling("m", 6))
def __init__(self, scale_degree='vii'): super().__init__() valid_degrees = ['vii', 'ii'] if scale_degree not in valid_degrees: raise ValueError( 'invalid scale degree {} for half diminished seventh chord'. format(scale_degree)) self.set_scale_degree(scale_degree) # TODO: Figure out the alteration (vii or #vii; will be complicated) self.triad_quality = "diminished_triad" self.add_interval(interval.IntervalSpelling("m", 3)) self.add_interval(interval.IntervalSpelling("D", 5)) self.add_interval(interval.IntervalSpelling("m", 7))
def set_triad_quality(self, triad_quality): if triad_quality not in TertianChord.triad_qualities: raise KeyError("the triad quality '{}' is not supported".format( triad_quality)) self.triad_quality = triad_quality if triad_quality == 'major_triad': self.add_interval(interval.IntervalSpelling('M', 3)) self.add_interval(interval.IntervalSpelling('P', 5)) elif triad_quality == 'minor_triad': self.add_interval(interval.IntervalSpelling('m', 3)) self.add_interval(interval.IntervalSpelling('P', 5)) elif triad_quality == 'diminished_triad': self.add_interval(interval.IntervalSpelling('m', 3)) self.add_interval(interval.IntervalSpelling('D', 5)) elif triad_quality == 'augmented_triad': self.add_interval(interval.IntervalSpelling('M', 3)) self.add_interval(interval.IntervalSpelling('A', 5))
class Key(object): _scale_mapping = { "major": scale.MajorScale(), "natural_minor": scale.NaturalMinorScale(), "harmonic_minor": scale.HarmonicMinorScale(), "default_minor": scale.HarmonicMinorScale(), "ascending_melodic_minor": scale.AscendingMelodicMinorScale() } _scale_degree_alterations = { '--': interval.IntervalSpelling('DD', 1), 'bb': interval.IntervalSpelling('DD', 1), '-': interval.IntervalSpelling('D', 1), 'b': interval.IntervalSpelling('D', 1), "#": interval.IntervalSpelling('A', 1), "##": interval.IntervalSpelling('AA', 1), "x": interval.IntervalSpelling('AA', 1) } def __init__(self, note_letter, alteration=None, scale="major"): self.tonic = pitch_class.PitchClassSpelling(note_letter, alteration) self.scale = scale if not scale in self._scale_mapping: raise KeyError("scale '{}' is not supported.".format(scale)) self.mode = Key._scale_mapping[scale] def scale_degree(self, scale_degree, alteration=None): if type(scale_degree) == str: if scale_degree not in common.roman_to_int: raise ValueError( "scale degree {} is not supported.".format(scale_degree)) scale_degree = common.roman_to_int[scale_degree] if 1 > scale_degree or scale_degree > common.DIATONIC_CLASSES: raise ValueError("scale degree should be within 1 and 7.") interval = self.mode.step_to_interval_spelling(scale_degree) pc = self.tonic.to_interval(interval) if alteration: if not alteration in self._scale_degree_alterations: raise KeyError( "alteration '{}' is not supported.".format(alteration)) unison_alteration = self._scale_degree_alterations[alteration] pc = pc.to_interval(unison_alteration) return pc def __str__(self): return str(self.tonic) + " " + self.scale
def step_to_interval_spelling(self, step, mode=1): qualities = self._qualities[(mode - 1) % harmalysis.common.DIATONIC_CLASSES] quality = qualities[(step - 1) % harmalysis.common.DIATONIC_CLASSES] return interval.IntervalSpelling(quality, step)
def set_as_minor(self): self.set_scale_degree('i', function='dominant') self.triad_quality = "minor_triad" self.add_interval(interval.IntervalSpelling("m", 3)) self.add_interval(interval.IntervalSpelling("P", 5))
def __init__(self): super().__init__() self.set_scale_degree('II', 'b') self.triad_quality = "major_triad" self.add_interval(interval.IntervalSpelling('M', 3)) self.add_interval(interval.IntervalSpelling('P', 5))