Example #1
0
 def test_triad_generation(self):
     diatonic_tonality = Tonality.create(ModalityType.Major, DiatonicTone("C"))
     ret_types = [TertianChordType.Maj, TertianChordType.Min, TertianChordType.Min, TertianChordType.Maj,
                  TertianChordType.Maj,
                  TertianChordType.Min, TertianChordType.Dim]
     for i in range(1, 8):
         chord = TertianChordTemplate.get_triad(diatonic_tonality, i)       
         print(chord)
         assert chord.chord_type.value == ret_types[i - 1]
Example #2
0
    def __init__(self,
                 secondary_chord_template,
                 diatonic_tonality,
                 secondary_tonality=None):
        """
        Constructor.
        :param secondary_chord_template: SecondaryChordTemplate
        :param diatonic_tonality: DiatonicTonality (used in scale degree chord formation)
        :param secondary_tonality: Used to represent denominator tonality
        Note: The means for determining the secondary tonality is not necessarily clean. The standard technique
        involves inferring the modality from the triad built on the i-th tone of the base modality. However,
        the actual technique to be used can be a variable. The secondary_tonality argument is meant for cases where
        the standard technique does not hold up - and provides a means for specifying the exact secondary tonality
        when the standard technique does not apply.
        """
        Chord.__init__(self, secondary_chord_template, diatonic_tonality)

        # Build the tonality upon which the primary chord is based
        diatonic_basis = self.diatonic_tonality.get_tone(
            self.chord_template.secondary_scale_degree - 1)

        # if no secondary modality specified?
        #  Use diatonic_tonality + secondary scale degree.  Determine the triad type of the natural triad there, and
        #  if major, use major modality.  If minor, use melodic minor modality.  Otherwise flag an error.
        if not self.chord_template.secondary_modality:
            triad = TertianChordTemplate.get_triad(
                diatonic_tonality, self.chord_template.secondary_scale_degree)
            if triad:
                modality = ModalityType.Major if triad.chord_type.value == TertianChordType.Maj or \
                                                 triad.chord_type.value == TertianChordType.Aug else \
                           ModalityType.MelodicMinor if triad.chord_type.value == TertianChordType.Min or \
                                                 triad.chord_type.value == TertianChordType.Dim else None
                if modality is None:
                    raise Exception(
                        'Illegal secondary modality for secondary chord')
            else:
                raise Exception(
                    'Cannot determine secondary modality for secondary chord')
        else:
            modality = self.chord_template.secondary_modality

        self.__secondary_tonality = Tonality.create(modality, diatonic_basis) \
            if not secondary_tonality else secondary_tonality

        # Create the principal chord
        self.__primary_chord = self.chord_template.principal_chord_template.create_chord(
            self.secondary_tonality)