示例#1
0
 def create(modality_type, modal_index=0):
     if modality_type not in BluesModality.BLUES_MODALITIES:
         raise Exception('Type parameter is not blues.')
     if modality_type not in BluesModality.MODALITY_DEFINITION_MAP:
         raise Exception(
             'Illegal diatonic modality value: {0} - Check Modality_definition_map'
             .format(str(modality_type)))
     return Modality(BluesModality.MODALITY_DEFINITION_MAP[modality_type],
                     modal_index)
示例#2
0
    def test_user_defined_modality(self):
        modality_type = ModalityType('my_modality')
        incremental_interval_strs = [
            'P:1', 'm:2', 'M:3', 'm:2', 'm:2', 'M:2', 'A:2'
        ]
        modality_spec = ModalitySpec(modality_type, incremental_interval_strs)
        modality = Modality(modality_spec)

        assert modality.modality_type == modality_type
        assert modality.get_number_of_tones() == 6

        intervals = modality.incremental_intervals
        assert len(intervals) == 7
        assert str(intervals[0]) == 'P:1'
        assert str(intervals[1]) == 'm:2'
        assert str(intervals[2]) == 'M:3'
        assert str(intervals[3]) == 'm:2'
        assert str(intervals[4]) == 'm:2'
        assert str(intervals[5]) == 'M:2'
        assert str(intervals[6]) == 'A:2'
示例#3
0
    def test_build_user_defined_tonality(self):
        modality_type = ModalityType('my_modality')
        incremental_interval_strs = [
            'P:1', 'm:2', 'M:3', 'm:2', 'm:2', 'M:2', 'A:2'
        ]
        modality_spec = ModalitySpec(modality_type, incremental_interval_strs)
        modality = Modality(modality_spec)

        tonality = Tonality(modality, 'A')

        assert 0 == tonality.modal_index
        assert 'A' == tonality.diatonic_tone.diatonic_symbol
        assert ['A', 'Bb', 'D', 'Eb', 'Fb', 'Gb',
                'A'] == [t.diatonic_symbol for t in tonality.annotation]
示例#4
0
    def create_modality(modality_type, modal_index=0):
        """
        Create modality by modality type
        
        Args:
        modality_type: type of modality to create.
        
        Returns: The respective modality object.
        Raises: Exception if type is not recognized.
        
        Note: update this method with each new Modality
        """
        if modality_type in ModalityFactory.ModalityInitDict:
            return Modality(ModalityFactory.ModalityInitDict[modality_type],
                            modal_index)

        raise Exception(
            'Unrecognized modality type {0} in create_modality'.format(
                modality_type))
示例#5
0
 def find_tonality(tones):
     modalities = Modality.find_modality(tones)
     answers = list()
     for modality in modalities:
         answers.append(Tonality.create(modality.modality_type, tones[0], modality.modal_index))
     return answers
示例#6
0
 def create(modality_type, modal_index=0):
     if modality_type != ModalityType.WholeTone:
         raise Exception('Type parameter is not WholeTone.')
     return Modality(WholeToneModality.WHOLE_TONE_SPEC, modal_index)