Пример #1
0
    def test_create(self):
        with self.assertRaises(Exception):
            Range(1.2, 5)

        with self.assertRaises(Exception):
            Range(8, 12.25)

        with self.assertRaises(Exception):
            Range(30, 25)
Пример #2
0
def simple_reshape_no_pf():
    print('----- test_simple_reshape_no_pf -----')

    line_str = '{<C-Major: I> iE:4 E E E E E E E <:IV> qE ie e <:V> qe ie e <:VI>  qE E iE E E E}'

    score = create_score(line_str, 'violin', (3, 4, 'sww'))

    all_notes = score.line.get_all_notes()

    pitch_function = GenericUnivariatePitchFunction(sinasoidal, Position(0),
                                                    Position(3))
    time_range = Range(0, 3)

    # The first note should have one of 3 values, C:4, E:4, G:4
    constraints = {
        ChordalPitchConstraint(all_notes[0]),
        ChordalPitchConstraint(all_notes[9]),
        PitchRangeConstraint([all_notes[0]], PitchRange.create('C:4', 'G:4')),
    }

    motif = Motif(score.line, constraints, 'A')
    melodic_form = MelodicForm([motif])
    treshape = TReshape(score, pitch_function, time_range, melodic_form, False)

    results = treshape.apply()

    mc_filter = MinCurveFitFilter(pitch_function, results)
    print('{0} filtered results'.format(len(mc_filter.scored_results)))

    for index in range(0, min(5, len(mc_filter.scored_results))):
        result = mc_filter.scored_results[index]
        print('[{0}] {1} ({2})'.format(index, str_line(result[0].line),
                                       result[1]))
Пример #3
0
 def __init__(self, start_index, end_index):
     """
     Constructor
     
     Args:
       start_index: integer start chromatic pitch index
       end_index: integer end chromatic pitch index
     Exceptions: is start, end out of range of absolute chromatic range, plus those from Range.
     """
     Range.__init__(self, start_index, end_index)
     if start_index < ChromaticScale.chromatic_start_index():
         raise Exception(
             "Start index {0} lower than chromatic start {1}".format(
                 start_index, ChromaticScale.chromatic_start_index()))
     if end_index > ChromaticScale.chromatic_end_index():
         raise Exception(
             "end index {0} higher than chromatic end {1}".format(
                 end_index, ChromaticScale.chromatic_end_index()))
Пример #4
0
    def test_attributes(self):
        ranger = Range(10, 20)
        self.assertTrue(ranger.size() == 11)
        self.assertTrue(ranger.start_index == 10)
        self.assertTrue(ranger.end_index == 20)

        ranger = Range(10, 10)
        self.assertTrue(ranger.size() == 1)
        self.assertTrue(ranger.start_index == 10)
        self.assertTrue(ranger.end_index == 10)
        self.assertTrue(ranger.is_inbounds(10))
Пример #5
0
    def test_simple_reshape(self):
        print('----- test_hct_simple_shift -----')

        s_notes = [
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),

            ('E:4', 'h'),
            ('E:4', 'h'),

            ('E:4', 'q'),
            ('E:4', 'q'),
            ('E:4', 'q'),
            ('E:4', 'q'),
        ]
        chords = [('tI', 1), ('tIV', (1, 2)), ('tV', (1, 2)), ('tVI', 1)]

        score = TestTReshape.create_score(s_notes, ModalityType.Major, 'C', chords, 'violin', (3, 4, 'sww'))

        all_notes = score.line.get_all_notes()

        pitch_function = GenericUnivariatePitchFunction(TestTReshape.sinasoidal, Position(0), Position(3))
        time_range = Range(0, 3)

        # The first note should have one of 3 values, C:4, E:4, G:4
        constraints = {
            ChordalPitchConstraint(all_notes[0]),
            PitchRangeConstraint([all_notes[0]], PitchRange.create('C:4', 'G:4')),
        }

        motif = Motif(score.line, constraints, 'A')
        melodic_form = MelodicForm([motif])
        treshape = TReshape(score, pitch_function, time_range, melodic_form, False)

        results = treshape.apply()
        assert results is not None
        assert len(results) == 3
        for result in results:
            print('-----')
            print(result.line)

        first_pitch_set = {str(result.line.get_all_notes()[0].diatonic_pitch) for result in results}
        assert {'E:4', 'C:4', 'G:4'} == first_pitch_set

        assert abs(TestTReshape.sinasoidal(Fraction(1, 8)) - DiatonicPitch.parse('D:5').chromatic_distance) < 1
Пример #6
0
    def test_inbounds(self):
        ranger = Range(12, 40)
        for i in range(12, 41):
            self.assertTrue(ranger.is_inbounds(i),
                            '{0} is not in {1}'.format(i, ranger))
        self.assertFalse(ranger.is_inbounds(11))
        self.assertFalse(ranger.is_inbounds(41))

        self.assertTrue(ranger.is_inbounds(20.56))
        self.assertFalse(ranger.is_inbounds(11.999999))
Пример #7
0
def simple_reshape_cpf():
    print('----- test_simple_reshape_cpf (Fgure 17.21) -----')

    line_str = '{<C-Major: I> iE:4 E E E E E E E <:IV> qE ie e <:V> qe ie e <:VI>  qE E iE E E E}'
    score = create_score(line_str, 'violin', (3, 4, 'sww'))

    all_notes = score.line.get_all_notes()

    # 11 scalar notes to C:4 (0) to G:5 (1) with pitch unit 1/19
    interpreter = ChromaticRangeInterpreter(DiatonicPitch.parse('C:4'), 0,
                                            Fraction(1, 19))

    pitch_function = GenericUnivariatePitchFunction(three_sin,
                                                    Position(0),
                                                    Position(3),
                                                    interp=interpreter)

    # The first note should have one of 3 values, C:4, E:4, G:4
    constraints = {
        ChordalPitchConstraint(all_notes[0]),
        ChordalPitchConstraint(all_notes[8]),
        ChordalPitchConstraint(all_notes[11]),
        ChordalPitchConstraint(all_notes[14]),
        PitchRangeConstraint([all_notes[0]], PitchRange.create('C:4', 'E:4')),
    }

    # motif = Motif(score.line, constraints, 'A')
    motif = Motif([all_notes[0], all_notes[8], all_notes[11], all_notes[14]],
                  constraints, 'A')
    melodic_form = MelodicForm([motif])
    t_reshape = TReshape(score, pitch_function, Range(0, 3), melodic_form,
                         True)

    results = t_reshape.apply()

    filters = MinCurveFitFilter(pitch_function, results)
    print('{0} filtered results'.format(len(filters.scored_results)))

    for index in range(0, min(5, len(filters.scored_results))):
        result = filters.scored_results[index]
        print('[{0}] {1} ({2})'.format(index, str_line(result[0].line),
                                       result[1]))

    print('Chords: {0}'.format(','.join([str(c)
                                         for c in score.hct.hc_list()])))
Пример #8
0
def reshape_to_scale():
    print('----- test_reshape_to_scale (Fgure 17.24) -----')

    line_str = '{<C-Major: I> iE:4 E E E E E E E E E E E E E E E E E E E E E E E wE}'

    score = create_score(line_str, 'violin', (4, 4, 'swww'))

    tonality = score.hct.get_hc_by_position(0).tonality
    all_notes = score.line.get_all_notes()

    plf = PiecewiseLinearFunction([(0, 0), (1, 8), (Fraction(3, 2), 4), (2, 8),
                                   (3, 0)])
    for i in range(0, 17):
        x = Fraction(1, 8) * i
        y = plf(x)
        print('({0}, {1})'.format(x, y))
    time_range = Range(0, 3)

    interpreter = ScalarRangeInterpreter(tonality, DiatonicPitch.parse('C:4'),
                                         0, 1)

    pitch_function = GenericUnivariatePitchFunction(plf, Position(0),
                                                    Position(3), False,
                                                    interpreter)

    constraints = {
        ChordalPitchConstraint(all_notes[0]),
        PitchRangeConstraint([all_notes[0]], PitchRange.create('C:4', 'G:4')),
    }

    motif = Motif([all_notes[0]], constraints, 'A')
    melodic_form = MelodicForm([motif])
    t_reshape = TReshape(score, pitch_function, time_range, melodic_form,
                         False)

    results = t_reshape.apply()

    filters = MinCurveFitFilter(pitch_function, results)
    print('{0} filtered results'.format(len(filters.scored_results)))

    for index in range(0, min(5, len(filters.scored_results))):
        result = filters.scored_results[index]
        print('[{0}] {1} ({2})'.format(index, str_line(result[0].line),
                                       result[1]))
Пример #9
0
def motif_example():
    print('----- motif_example (Fgure 17.25) -----')

    line_str = '{<C-Major: I> iC:4 D E D E E E E C D E D E E E E C D E D E E E E wE}'

    score = create_score(line_str, 'piano', (4, 4, 'swww'))
    tonality = score.hct.get_hc_by_position(0).tonality
    all_notes = score.line.get_all_notes()

    constraints = {
        StepSequenceConstraint(
            [all_notes[0], all_notes[1], all_notes[2], all_notes[3]],
            [1, 1, -1])
    }
    motif = Motif([all_notes[0], all_notes[1], all_notes[2], all_notes[3]],
                  constraints)
    motif1 = motif.copy_to(all_notes[8])
    motif2 = motif.copy_to(all_notes[16])
    form = MelodicForm([motif, motif1, motif2])

    # 11 scalar notes to C:4 (0) to G:5 (11) with pitch unit 1/11
    interpreter = ScalarRangeInterpreter(tonality, DiatonicPitch.parse('C:4'),
                                         0, Fraction(1, 11))

    pitch_function = GenericUnivariatePitchFunction(three_sin, Position(0),
                                                    Position(3), False,
                                                    interpreter)
    t_reshape = TReshape(score, pitch_function, Range(0, 3), form, True)

    results = t_reshape.apply()

    filters = MinCurveFitFilter(pitch_function, results)
    print('{0} filtered results'.format(len(filters.scored_results)))

    for index in range(0, min(5, len(filters.scored_results))):
        result = filters.scored_results[index]
        print('[{0}] {1} ({2})'.format(index, str_line(result[0].line),
                                       result[1]))
Пример #10
0
    def test_piecewise_linear_reshape(self):
        """
        This is a very interesting test case. Although it uses a piecewise linear based reshape function, more
        importantly, the line's harmonic context track is in the key Bb-major, but the pitch function interprets
        pitches in E-major!
        The rule is to always use what the pitch function returns over the hct, except when the computed pitch has
        an enharmonic equivalent - in this case, the only case is Eb == D#, and Eb is preferred.
        :return:
        """
        print('----- test_piecewise_linear_reshape -----')

        s_notes = [
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),

            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
        ]
        chords = [('tI', 1), ('tIV', (1, 2)), ('tV', (1, 2)), ('tVI', 1)]

        score = TestTReshape.create_score(s_notes, ModalityType.Major, 'Bb', chords, 'violin', (4, 4, 'swww'))

        e_interp = ScalarRangeInterpreter(Tonality.create(ModalityType.Major, DiatonicToneCache.get_tone('E')), 'E:4',
                                          0)

        array = [(0, 0), (Fraction(1, 2), 4), (Fraction(1), 0), (Fraction(2), 8)]
        f = PiecewiseLinearFunction(array)
        pitch_function = GenericUnivariatePitchFunction(f, Position(0), Position(2), False,
                                                        e_interp)
        all_notes = score.line.get_all_notes()

        # The first note should have one of 2 values, Eb:4, G:4
        constraints = {
            ChordalPitchConstraint(all_notes[0]),
        }

        motif = Motif(score.line, constraints, 'A')

        melodic_form = MelodicForm([motif])

        time_range = Range(0, 3)

        treshape = TReshape(score, pitch_function, time_range, melodic_form, True)
        results = treshape.apply()
        assert results is not None
        for i in range(0, len(results)):
            print('--- result[{0}] ---'.format(i))
            print(results[i].line)

        assert len(results) == 2
        first_pitch_set = {str(result.line.get_all_notes()[0].diatonic_pitch) for result in results}
        assert {'D:4', 'F:4'} == first_pitch_set

        all_notes = results[0].line.get_all_notes()
        assert 'F#:4' == str(all_notes[1].diatonic_pitch)
        assert 'G#:4' == str(all_notes[2].diatonic_pitch)
        assert 'A:4' == str(all_notes[3].diatonic_pitch)
        assert 'B:4' == str(all_notes[4].diatonic_pitch)
        assert 'A:4' == str(all_notes[5].diatonic_pitch)
        assert 'G#:4' == str(all_notes[6].diatonic_pitch)
        assert 'F#:4' == str(all_notes[7].diatonic_pitch)
        assert 'E:4' == str(all_notes[8].diatonic_pitch)
        assert 'F#:4' == str(all_notes[9].diatonic_pitch)
        assert 'G#:4' == str(all_notes[10].diatonic_pitch)
        assert 'A:4' == str(all_notes[11].diatonic_pitch)
        assert 'B:4' == str(all_notes[12].diatonic_pitch)
        assert 'C#:5' == str(all_notes[13].diatonic_pitch)
        assert 'Eb:5' == str(all_notes[14].diatonic_pitch)

        all_notes = results[1].line.get_all_notes()
        assert 'F#:4' == str(all_notes[1].diatonic_pitch)
        assert 'G#:4' == str(all_notes[2].diatonic_pitch)
        assert 'A:4' == str(all_notes[3].diatonic_pitch)
        assert 'B:4' == str(all_notes[4].diatonic_pitch)
        assert 'A:4' == str(all_notes[5].diatonic_pitch)
        assert 'G#:4' == str(all_notes[6].diatonic_pitch)
        assert 'F#:4' == str(all_notes[7].diatonic_pitch)
        assert 'E:4' == str(all_notes[8].diatonic_pitch)
        assert 'F#:4' == str(all_notes[9].diatonic_pitch)
        assert 'G#:4' == str(all_notes[10].diatonic_pitch)
        assert 'A:4' == str(all_notes[11].diatonic_pitch)
        assert 'B:4' == str(all_notes[12].diatonic_pitch)
        assert 'C#:5' == str(all_notes[13].diatonic_pitch)
        assert 'Eb:5' == str(all_notes[14].diatonic_pitch)
Пример #11
0
    def test_pitch_sequence_shape(self):
        print('----- test_pitch_sequence_shape -----')

        s_notes = [
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),

            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
        ]
        chords = [('tI', 1), ('tIV', 1), ('tV', 1), ('tVI', 1)]

        score = TestTReshape.create_score(s_notes, ModalityType.Major, 'Bb', chords, 'violin', (4, 4, 'swww'))
        all_notes = score.line.get_all_notes()

        eflat_interp = ScalarRangeInterpreter(Tonality.create(ModalityType.Major, DiatonicToneCache.get_tone('Bb')),
                                              'Bb:3', 0)
        pitch_function = GenericUnivariatePitchFunction(TestTReshape.e_flat_linear, Position(0), Position(1), False,
                                                        eflat_interp)

        # The first note should have one of 2 values, Eb:4, G:4
        constraints = {
            ChordalPitchConstraint(all_notes[0]),
            # You need this kind of constraint to limit possibilities.
            PitchRangeConstraint([all_notes[0]], PitchRange.create('Bb:3', 'A:4')),
            StepSequenceConstraint([all_notes[3], all_notes[4], all_notes[5], all_notes[6]], [-1, -1, -1]),
        }

        motif = Motif(score.line, constraints, 'A')

        melodic_form = MelodicForm([motif])

        time_range = Range(0, 3)

        treshape = TReshape(score, pitch_function, time_range, melodic_form, True)
        results = treshape.apply()
        assert results is not None
        for i in range(0, len(results)):
            print('--- result[{0}] ---'.format(i))
            print(results[i].line)

        for result in results:
            notes = result.line.get_all_notes()
            if str(notes[3].diatonic_pitch) == 'Eb:4':
                assert 'D:4' == str(notes[4].diatonic_pitch)
                assert 'C:4' == str(notes[5].diatonic_pitch)
                assert 'Bb:3' == str(notes[6].diatonic_pitch)
            else:
                assert 'D:4' == str(notes[3].diatonic_pitch)
                assert 'C:4' == str(notes[4].diatonic_pitch)
                assert 'Bb:3' == str(notes[5].diatonic_pitch)
                assert 'A:3' == str(notes[6].diatonic_pitch)
Пример #12
0
    def test_onbeat_shape(self):
        print('----- test_onbeat_shape -----')

        s_notes = [
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
        ]
        chords = [('tI', 1), ('tIV', (1, 2)), ('tV', (1, 2)), ('tVI', 1)]

        score = TestTReshape.create_score(s_notes, ModalityType.Major, 'Bb', chords, 'violin', (4, 4, 'swww'))
        all_notes = score.line.get_all_notes()

        # The first note should have one of 2 values, Eb:4, G:4
        constraints = {
            ChordalPitchConstraint(all_notes[0]),
            OnBeatConstraint(all_notes[2], BeatType.Strong),
            # You need this kind of constraint to limit possibilities.
            PitchRangeConstraint([all_notes[0]], PitchRange.create('Bb:3', 'A:4')),
        }

        motif = Motif(score.line, constraints, 'A')

        melodic_form = MelodicForm([motif])

        eflat_interp = ScalarRangeInterpreter(Tonality.create(ModalityType.Major, DiatonicToneCache.get_tone('Bb')),
                                              'Bb:3', 0)
        pitch_function = GenericUnivariatePitchFunction(TestTReshape.e_flat_linear, Position(0), Position(1), False,
                                                        eflat_interp)
        time_range = Range(0, 3)

        treshape = TReshape(score, pitch_function, time_range, melodic_form, False)

        results = treshape.apply()
        assert results is not None
        for i in range(0, len(results)):
            print('--- result[{0}] ---'.format(i))
            print(results[i].line)

        first_pitch_set = {str(result.line.get_all_notes()[0].diatonic_pitch) for result in results}
        assert {'Bb:3', 'D:4', 'F:4'} == first_pitch_set

        all_notes = results[0].line.get_all_notes()
        assert 'C:4' == str(all_notes[1].diatonic_pitch)
        assert 'C:5' == str(all_notes[2].diatonic_pitch)
        assert 'D:5' == str(all_notes[3].diatonic_pitch)
        assert 'Eb:5' == str(all_notes[4].diatonic_pitch)
        assert 'F:5' == str(all_notes[5].diatonic_pitch)
        assert 'G:5' == str(all_notes[6].diatonic_pitch)
        assert 'A:5' == str(all_notes[7].diatonic_pitch)
        assert Position(1) == all_notes[2].get_absolute_position()

        all_notes = results[1].line.get_all_notes()
        assert 'C:4' == str(all_notes[1].diatonic_pitch)
        assert 'C:5' == str(all_notes[2].diatonic_pitch)
        assert 'D:5' == str(all_notes[3].diatonic_pitch)
        assert 'Eb:5' == str(all_notes[4].diatonic_pitch)
        assert 'F:5' == str(all_notes[5].diatonic_pitch)
        assert 'G:5' == str(all_notes[6].diatonic_pitch)
        assert 'A:5' == str(all_notes[7].diatonic_pitch)
        assert Position(1) == all_notes[2].get_absolute_position()
Пример #13
0
    def test_linear_scale(self):
        print('----- test_linear_scale -----')

        s_notes = [
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
            ('E:4', 'e'),
        ]
        chords = [('tI', 1), ('tIV', (1, 2)), ('tV', (1, 2)), ('tVI', 1)]

        score = TestTReshape.create_score(s_notes, ModalityType.Major, 'Eb', chords, 'violin', (3, 4, 'sww'))
        all_notes = score.line.get_all_notes()

        eflat_interp = ScalarRangeInterpreter(Tonality.create(ModalityType.Major, DiatonicToneCache.get_tone('Eb')),
                                              'Eb:4', 0)
        pitch_function = GenericUnivariatePitchFunction(TestTReshape.e_flat_linear, Position(0), Position(1), False,
                                                        eflat_interp)
        time_range = Range(0, 3)

        # The first note should have one of 2 values, Eb:4, G:4
        constraints = {
            ChordalPitchConstraint(all_notes[0]),
            PitchRangeConstraint([all_notes[0]], PitchRange.create('C:4', 'G:4')),
        }

        motif = Motif(score.line, constraints, 'A')

        melodic_form = MelodicForm([motif])

        treshape = TReshape(score, pitch_function, time_range, melodic_form)

        results = treshape.apply()
        assert results is not None
        assert len(results) == 2
        for result in results:
            print('-----')
            print(result.line)

        first_pitch_set = {str(result.line.get_all_notes()[0].diatonic_pitch) for result in results}
        assert {'Eb:4', 'G:4'} == first_pitch_set

        all_notes = results[0].line.get_all_notes()
        assert 'F:4' == str(all_notes[1].diatonic_pitch)
        assert 'G:4' == str(all_notes[2].diatonic_pitch)
        assert 'Ab:4' == str(all_notes[3].diatonic_pitch)
        assert 'Bb:4' == str(all_notes[4].diatonic_pitch)
        assert 'C:5' == str(all_notes[5].diatonic_pitch)
        assert 'D:5' == str(all_notes[6].diatonic_pitch)
        assert 'Eb:5' == str(all_notes[7].diatonic_pitch)

        all_notes = results[1].line.get_all_notes()
        assert 'F:4' == str(all_notes[1].diatonic_pitch)
        assert 'G:4' == str(all_notes[2].diatonic_pitch)
        assert 'Ab:4' == str(all_notes[3].diatonic_pitch)
        assert 'Bb:4' == str(all_notes[4].diatonic_pitch)
        assert 'C:5' == str(all_notes[5].diatonic_pitch)
        assert 'D:5' == str(all_notes[6].diatonic_pitch)
        assert 'Eb:5' == str(all_notes[7].diatonic_pitch)
Пример #14
0
    def class_init():
        """
        This method is a class initializer.  It is called outside the class before 
        its first use.  The tables are:
        1) NAME_MAP: map TempoType to string name.
        2) RANGE_MAP: map TempoType to BPM range.
        3) ALL_TYPES: list of all TempoTypes
        """
        if TempoTypeHelper.RANGE_MAP is not None:
            return

        TempoTypeHelper.RANGE_MAP = {
            TempoType.Larghissimo: Range(0, 24),
            TempoType.Grave: Range(25, 45),
            TempoType.Lento: Range(45, 60),
            TempoType.Largo: Range(40, 60),
            TempoType.Larghetto: Range(60, 66),
            TempoType.Adagio: Range(66, 76),
            TempoType.Adagietto: Range(72, 76),
            TempoType.Andantino: Range(80, 108),
            TempoType.Andante: Range(76, 108),
            TempoType.AndanteModerato: Range(92, 112),
            TempoType.MarciaModerato: Range(83, 85),
            TempoType.Moderato: Range(108, 120),
            TempoType.AllegroModerato: Range(116, 120),
            TempoType.Allegretto: Range(112, 120),
            TempoType.Allegro: Range(120, 168),
            TempoType.Vivace: Range(168, 176),
            TempoType.Vivacissimo: Range(172, 176),
            TempoType.Allegrissimo: Range(172, 176),
            TempoType.Presto: Range(168, 200),
            TempoType.Prestissimo: Range(200, 10000)
        }

        TempoTypeHelper.ALL_TYPES = [
            TempoType.Larghissimo,
            TempoType.Grave,
            TempoType.Lento,
            TempoType.Largo,
            TempoType.Larghetto,
            TempoType.Adagio,
            TempoType.Adagietto,
            TempoType.Andantino,
            TempoType.Andante,
            TempoType.AndanteModerato,
            TempoType.MarciaModerato,
            TempoType.Moderato,
            TempoType.AllegroModerato,
            TempoType.Allegretto,
            TempoType.Allegro,
            TempoType.Vivace,
            TempoType.Vivacissimo,
            TempoType.Allegrissimo,
            TempoType.Presto,
            TempoType.Prestissimo,
        ]
Пример #15
0
def reshape_with_spf():
    print('----- test_reshape_with_spf (Fgure 17.22) -----')

    line_str = '{<C-Major: I> iE:4 E E E E q@E <:IV> qE ie e <:V> qe ie e <:VI>  qE E iE E E E}'

    score = create_score(line_str, 'piano', (3, 4, 'sww'))

    tonality = score.hct.get_hc_by_position(0).tonality
    all_notes = score.line.get_all_notes()

    # 11 scalar notes to C:4 (0) to G:5 (11) with pitch unit 1/11
    interpreter = ScalarRangeInterpreter(tonality, DiatonicPitch.parse('C:4'),
                                         0, Fraction(1, 11))

    pitch_function = GenericUnivariatePitchFunction(three_sin, Position(0),
                                                    Position(3), False,
                                                    interpreter)

    # The first note should have one of 3 values, C:4, E:4, G:4
    constraints = {
        ChordalPitchConstraint(all_notes[0]),
        ChordalPitchConstraint(all_notes[6]),
        ChordalPitchConstraint(all_notes[9]),
        ChordalPitchConstraint(all_notes[12]),
        PitchRangeConstraint([all_notes[0]], PitchRange.create('C:4', 'E:4')),
    }

    motif = Motif([all_notes[0], all_notes[6], all_notes[9], all_notes[12]],
                  constraints, 'A')
    melodic_form = MelodicForm([motif])
    t_reshape = TReshape(score, pitch_function, Range(0, 3), melodic_form,
                         True)

    results = t_reshape.apply()

    filters = MinCurveFitFilter(pitch_function, results)
    print('{0} filtered results'.format(len(filters.scored_results)))

    for index in range(0, min(5, len(filters.scored_results))):
        result = filters.scored_results[index]
        print('[{0}] {1} ({2})'.format(index, str_line(result[0].line),
                                       result[1]))

    constraints = {
        ChordalPitchConstraint(all_notes[0]),
        ChordalPitchConstraint(all_notes[4]),
        ChordalPitchConstraint(all_notes[6]),
        ChordalPitchConstraint(all_notes[8]),
        ChordalPitchConstraint(all_notes[12]),
        ChordalPitchConstraint(all_notes[14]),
        PitchRangeConstraint([all_notes[0]], PitchRange.create('C:4', 'G:4')),
    }

    motif = Motif(score.line, constraints, 'A')
    melodic_form = MelodicForm([motif])
    t_reshape = TReshape(score, pitch_function, Range(0, 3), melodic_form,
                         True)

    results = t_reshape.apply()

    filters = MinCurveFitFilter(pitch_function, results)
    print('{0} filtered results'.format(len(filters.scored_results)))

    for index in range(0, min(5, len(filters.scored_results))):
        result = filters.scored_results[index]
        print('[{0}] {1} ({2})'.format(index, str_line(result[0].line),
                                       result[1]))