def cue_examples():
    print('--------------  Cue examples  --------------------------')
    source_expression = '{<Bb-Major: I> sBb:4 A G F qEb D sF g iA i@Bb sF <:IVMaj7> ' \
                        'ir Eb sEb F G A iBb sEb:5 F i@Eb C ' \
                        '<:IIIMin7> sR F:5 Eb D C Bb:4 C:5 D i@Eb sC sr G:4 A G <:I> sG:5 F Eb D D C Bb:4 A ir q@G}'

    t_flip = TDiatonicReflection.create(source_expression,
                                        DiatonicPitch.parse('Eb:4'))
    print('Flip examples based on:')
    print_line(t_flip.source_line)
    print_hct(t_flip.source_hct)
    print()

    print('Flip on Eb:4 (Figure 16.12)')
    target_line, target_hct = t_flip.apply()

    print_line(target_line)
    print_hct(target_hct)
    print()

    print('Shift up an octave (Figure 16.13)')
    t_shift = TShift(target_line, target_hct, TonalInterval.parse('P:8'))
    final_line, final_hct = t_shift.apply()
    print_line(final_line)
    print_hct(final_hct)
Example #2
0
def shift_change_modal_index_modality_and_shift():
    print('----- Shift Change Modal Index, modality, shift Example -----')
    source_expression = '{<C-Major: I> iC:4 C qD E <:IV> iF G hA <:V> ig b qf g <:VI> ie e qd ic d <:i> h@c}'

    t_shift = TShift.create(source_expression)
    print('Shift examples based on:')
    print_line(t_shift.source_line)
    print()

    print('Shift to modal index 1 (dorian)')
    target_line, target_hct = t_shift.apply(root_shift_interval=TonalInterval.parse('M:2'), modal_index=1)

    print_line(target_line)
    print_hct(target_hct)
    print()

    t_shift = TShift(target_line, target_hct)

    print('Shift P:4 to modal index 2 (phrygian) of MelodicMinor')
    target_line, target_hct = t_shift.apply(root_shift_interval=TonalInterval.parse('P:4'),
                                            range_modality_type=ModalityType.MelodicMinor, modal_index=2)

    print_line(target_line)
    print_hct(target_hct)
    print()
Example #3
0
    def test_hct_simple_shift(self):
        print('----- test_hct_simple_shift -----')

        line_str = '{<C-Major: I> C:4 E F D <:IV> F A <:V> G D <:VI> a c b a}'
        lge = LineGrammarExecutor()
        target_line, target_hct = lge.parse(line_str)

        root_shift_interval = TonalInterval.create_interval('C:4', 'G:4')

        tshift = TShift(target_line, target_hct, root_shift_interval)

        temporal_extent = Interval(Fraction(1, 1), Fraction(2, 1))
        tshift.apply(temporal_extent, as_copy=False)
        TestTShift.print_notes(target_line)
        TestTShift.print_hct(target_hct)

        notes = target_line.get_all_notes()
        assert 12 == len(notes)
        assert 'C:5' == str(notes[4].diatonic_pitch)
        assert 'E:5' == str(notes[5].diatonic_pitch)
        assert 'D:5' == str(notes[6].diatonic_pitch)
        assert 'A:4' == str(notes[7].diatonic_pitch)

        hc_list = target_hct.hc_list()
        assert len(hc_list) == 4
        assert hc_list[1].chord.chord_template.scale_degree == 4
        assert {t[0].diatonic_symbol
                for t in hc_list[1].chord.tones} == {'C', 'E', 'G'}
        assert hc_list[1].chord.chord_template.inversion == 1
        assert hc_list[1].tonality.modal_index == 0
        assert hc_list[1].tonality.basis_tone.diatonic_symbol == 'G'
        assert hc_list[1].tonality.root_tone.diatonic_symbol == 'G'
        assert hc_list[1].tonality.modality_type == ModalityType.Major
        assert hc_list[1].chord.chord_type.value == TertianChordType.Maj
Example #4
0
def example2():
    print('----- Debug meaning of modal index change and hct -----')

    # example tonality with modal index
    # Create a harmonic minor tonality of some basis root which as Mixolydian has F as the root.
    #       The answer is Bb-HarmonicMinor F(4)

    source_expression = '{<C-Major: I> iC:4}'

    t_shift = TShift.create(source_expression)
    print('Shift examples based on:')
    print_line(t_shift.source_line)
    print()

    print('Shift to modal index 4 (Mixolydian)')
    # This makes C the Mixolydian of F-Major
    target_line, target_hct = t_shift.apply(modal_index=4)
    print_line(target_line)
    print_hct(target_hct)
    print()

    # if you wanted G Mixolydian based on C
    print('Shift as if moving to modal index 4 (Mixolydian) in C')
    target_line, target_hct = t_shift.apply(
           root_shift_interval=TonalInterval.parse('P:5'), modal_index=4)

    print_line(target_line)
    print_hct(target_hct)
    print()
Example #5
0
def shift_modulating_sequence_example():
    print('----- Shift sequence standard example (Figure 15.14) -----')

    source_expression = '{<C-Major: IV> sf:4 a b C:5 <:V/ii> sa:4 e:5 tc# b:4 sC#:5 <:ii> sd tc a:4 sb:4 a}'

    lge = LineGrammarExecutor()
    source_instance_line, source_instance_hct = lge.parse(source_expression)
    print_score('\n[0]: ', source_instance_line, source_instance_hct)

    t_shift = TShift.create(source_expression)
    target_line, target_hct = t_shift.apply(root_shift_interval=TonalInterval.parse('M:2'),
                                            range_modality_type=ModalityType.Major)
    print_score('\n[1]: ', target_line, target_hct)

    t_shift = TShift(target_line, target_hct)
    target_line, target_hct = t_shift.apply(root_shift_interval=TonalInterval.parse('M:2'),
                                            range_modality_type=ModalityType.Major)
    print_score('\n[2]: ', target_line, target_hct)
Example #6
0
def shift_details_on_secondary_chord():
    print('----- Book example of shifted secondary tonality (Figure 15.6) -----')
    source_expression = '{<C-Major: V/iii> iD#:4 F# G A qD#:5 B:4}'

    t_shift = TShift.create(source_expression, TonalInterval.parse('M:3'))
    target_line, target_hct = t_shift.apply(range_modality_type=ModalityType.MelodicMinor)
    print(t_shift.source_hct)
    print(target_line)
    print(target_hct)
Example #7
0
def tonality_mode_change():
    print('----- Book example of shifted tonality on modal not 0 (Figure 15.5) -----')
    source_expression = '{<D-Major(1): I> iE:4 F# G A qE B}'

    t_shift = TShift.create(source_expression,
                            TonalInterval.parse('P:4'))
    target_line, target_hct = t_shift.apply(range_modality_type=ModalityType.MelodicMinor, modal_index=2)
    print(t_shift.source_hct)
    print(target_line)
    print(target_hct)
Example #8
0
def shift_sequence_tonal_example():
    print('----- Shift sequence tonal example -----')

    source_expression = '{<C-Major: IV> qf:4 a b C:5 <:V/ii> a:4 e:5 id C# <:ii> qd c b:4 a}'

    lge = LineGrammarExecutor()
    source_instance_line, source_instance_hct = lge.parse(source_expression)
    print_score('\n[0]: ', source_instance_line, source_instance_hct)

    t_shift = TShift.create(source_expression)
    target_line, target_hct = t_shift.apply(root_shift_interval=TonalInterval.parse('M:2'),
                                            range_modality_type=ModalityType.MelodicMinor)
    print(target_line)
    print(target_hct)
    print()

    t_shift = TShift(target_line, target_hct)
    target_line, target_hct = t_shift.apply(root_shift_interval=TonalInterval.parse('M:2'),
                                            range_modality_type=ModalityType.MelodicMinor)
    print(target_line)
    print(target_hct)
    print()
Example #9
0
    def test_modality_setting(self):
        print('----- test_modality_setting -----')

        line_str = '{<C-Major: I> C:4 E G A <:IV> iF A B C:5 <:V> qG:4 D <:VI> a c:5 b:4 a}'
        lge = LineGrammarExecutor()
        target_line, target_hct = lge.parse(line_str)

        root_shift_interval = TonalInterval.create_interval('C:4', 'C#:4')

        tshift = TShift(target_line,
                        target_hct,
                        root_shift_interval,
                        default_modal_index=2)

        temporal_extent = Interval(Fraction(0), Fraction(3, 1))
        score_line, score_hct = tshift.apply(
            temporal_extent, range_modality_type=ModalityType.MelodicMinor)

        TestTShift.print_notes(score_line)
        TestTShift.print_hct(score_hct)

        notes = score_line.get_all_notes()
        assert 14 == len(notes)
        assert 'F##:4' == str(notes[4].diatonic_pitch)
        assert 'A#:4' == str(notes[5].diatonic_pitch)
        assert 'B#:4' == str(notes[6].diatonic_pitch)
        assert 'C#:5' == str(notes[7].diatonic_pitch)

        hc_list = score_hct.hc_list()
        assert len(hc_list) == 4
        assert hc_list[0].chord.chord_template.scale_degree == 1
        assert {t[0].diatonic_symbol
                for t in hc_list[0].chord.tones} == {'C#', 'E#', 'G##'}
        assert hc_list[0].chord.chord_template.inversion == 1
        assert hc_list[0].tonality.modal_index == 2
        assert hc_list[0].tonality.basis_tone.diatonic_symbol == 'A#'
        assert hc_list[0].tonality.root_tone.diatonic_symbol == 'C#'
        assert hc_list[0].tonality.modality_type == ModalityType.MelodicMinor
        assert hc_list[0].chord.chord_type.value == TertianChordType.Aug
Example #10
0
    def test_modal_tonality_modal_index(self):
        print('----- test_modal_tonality_modal_index -----')
        # diatonic_modality is effectively Dorian

        line_str = '{<D-Major(1): I> D:4 F A B <:IV> iG B C:5 D <:V> qA:4 E <:VI> qB D:5 C B}'
        lge = LineGrammarExecutor()
        target_line, target_hct = lge.parse(line_str)

        # shift whole score sot D being Phrygian in some major scale - scale being Bb-Major
        tshift = TShift(target_line,
                        target_hct,
                        default_root_shift_interval=None,
                        default_modal_index=2)

        temporal_extent = Interval(Fraction(0), Fraction(3, 1))
        score_line, score_hct = tshift.apply(temporal_extent)

        TestTShift.print_notes(score_line)
        TestTShift.print_hct(score_hct)

        notes = score_line.get_all_notes()
        assert 14 == len(notes)
        assert 'G:4' == str(notes[4].diatonic_pitch)
        assert 'B:4' == str(notes[5].diatonic_pitch)
        assert 'Cb:5' == str(notes[6].diatonic_pitch)
        assert 'D:5' == str(notes[7].diatonic_pitch)

        hc_list = score_hct.hc_list()
        assert len(hc_list) == 4
        assert hc_list[0].chord.chord_template.scale_degree == 1
        assert {t[0].diatonic_symbol
                for t in hc_list[0].chord.tones} == {'E', 'G', 'B'}
        assert hc_list[0].chord.chord_template.inversion == 1
        assert hc_list[0].tonality.modal_index == 2
        assert hc_list[0].tonality.basis_tone.diatonic_symbol == 'C'
        assert hc_list[0].tonality.root_tone.diatonic_symbol == 'E'
        assert hc_list[0].tonality.modality_type == ModalityType.Major
        assert hc_list[0].chord.chord_type.value == TertianChordType.Min
Example #11
0
def simple_shift_example():
    print('----- Simple Shift Example -----')
    source_expression = '{<C-Major: I> iC:4 C qD E <:IV> iF G hA <:V> ig b qf g <:VI> ie e qd ic d <:I> h@c}'

    t_shift = TShift.create(source_expression, TonalInterval.parse('M:3'))
    print('Shift examples based on:')
    print_line(t_shift.source_line)
    print()

    print('Shift up M:3 (Figure 15.8)')
    target_line, target_hct = t_shift.apply()

    print_line(target_line)
    print_hct(target_hct)
    print()

    t_shift = TShift.create(source_expression, TonalInterval.parse('-m:2'))

    target_line, target_hct = t_shift.apply()

    print('Shift down m:2 (Figure 15.9)')
    print_line(target_line)
    print_hct(target_hct)
    print()
Example #12
0
def shift_change_modal_index():
    print('----- Shift Change Modal Index Example -----')
    source_expression = '{<C-Major: I> iC:4 C qD E <:IV> iF G hA <:V> ig b qf g <:VI> ie e qd ic d <:i> h@c}'

    t_shift = TShift.create(source_expression)
    print('Shift examples based on:')
    print_line(t_shift.source_line)
    print()

    print('Shift to modal index 4 (Mixolydian) (Figure 15.12)')
    target_line, target_hct = t_shift.apply(modal_index=4)

    print_line(target_line)
    print_hct(target_hct)
    print()

    print('Shift to C as modal index 3 (lydian) on a melodic minor scale (G)')
    target_line, target_hct = t_shift.apply(range_modality_type=ModalityType.MelodicMinor, modal_index=3)
    print_line(target_line)
    print_hct(target_hct)
    print()
Example #13
0
def shift_change_modality():
    print('----- Shift Change Modality Example -----')
    source_expression = '{<C-Major: I> iC:4 C qD E <:IV> iF G hA <:V> ig b qf g <:VI> ie e qd ic d <:i> h@c}'

    t_shift = TShift.create(source_expression, TonalInterval.parse('P:4'))
    print('Shift examples based on:')
    print_line(t_shift.source_line)
    print()

    print('Shift up P:4, modality MelodicMinor (Figure 5.10)')
    target_line, target_hct = t_shift.apply(range_modality_type=ModalityType.MelodicMinor)

    print_line(target_line)
    print_hct(target_hct)
    print()

    print('Shift up P:4, modality NaturalMinor (Figure 15.11)')
    target_line, target_hct = t_shift.apply(range_modality_type=ModalityType.NaturalMinor)

    print_line(target_line)
    print_hct(target_hct)
    print()
Example #14
0
def chromatic_reflection():
    print('Chromatic_Reflection')
    source_expression = '{<Bb-Major: I> sBb:4 A G F iEb D sF g iA i@Bb sF <:IVMaj7> ' \
                        'ir Eb sEb F G A iBb sEb:5 F i@Eb C ' \
                        '<:IIIMin7> sR F:5 Eb D C Bb:4 C:5 D i@Eb sC sr G:4 A G <:I> sG:5 F Eb D D C Bb:4 A ir q@G}'

    t_flip = TChromaticReflection.create(source_expression,
                                         DiatonicPitch.parse('G:4'))
    print('Flip examples based on:')
    print_line(t_flip.source_line)
    print_hct(t_flip.source_hct)
    print()

    print('Flip on G:4  ')
    target_line, target_hct = t_flip.apply()

    print_line(target_line)
    print_hct(target_hct)
    print()

    print('Shift up an octave (Figure 16.16)')
    t_shift = TShift(target_line, target_hct, TonalInterval.parse('P:8'))
    final_line, final_hct = t_shift.apply()
    print_line(final_line)
    print_hct(final_hct)

    # Center-Tone to upper
    t_flip = TChromaticReflection.create(source_expression,
                                         DiatonicPitch.parse('G:4'),
                                         FlipType.UpperNeighborOfPair)
    print('Flip examples based on:')
    print_line(t_flip.source_line)
    print_hct(t_flip.source_hct)
    print()

    print('Upper Flip on G:4 ')
    target_line, target_hct = t_flip.apply()

    print_line(target_line)
    print_hct(target_hct)
    print()

    print('Shift up an octave (Figure 16.17)')
    t_shift = TShift(target_line, target_hct, TonalInterval.parse('P:8'))
    final_line, final_hct = t_shift.apply()
    print_line(final_line)
    print_hct(final_hct)

    # Center-Tone to lower
    t_flip = TChromaticReflection.create(source_expression,
                                         DiatonicPitch.parse('G:4'),
                                         FlipType.LowerNeighborOfPair)
    print('Flip examples based on:')
    print_line(t_flip.source_line)
    print_hct(t_flip.source_hct)
    print()

    print('Lower Flip on G:4 (Figure 16.18)')
    target_line, target_hct = t_flip.apply()

    print_line(target_line)
    print_hct(target_hct)
    print()

    print('Shift up an octave:')
    t_shift = TShift(target_line, target_hct, TonalInterval.parse('P:8'))
    final_line, final_hct = t_shift.apply()
    print_line(final_line)
    print_hct(final_hct)
Example #15
0
    def test_modal_secondary_tonality(self):
        print('----- test_modal_tonality_modal_index -----')
        # diatonic_modality is effectively Dorian
        diatonic_tonality = Tonality.create(ModalityType.Major,
                                            DiatonicTone('C'))

        chords = [('tI', 1), ('V/iii', (1, 2)), ('tiii', (1, 2)), ('tVI', 1)]
        hc_track = TestTShift.create_track(chords, diatonic_tonality)
        TestTShift.print_hct(hc_track)

        s_notes = [
            ('C:4', 'q'),
            ('E:4', 'q'),
            ('G:4', 'q'),
            ('A:4', 'q'),
            ('B:4', 'e'),
            ('C#5', 'e'),
            ('d#:5', 'e'),
            ('e:5', 'e'),
            ('b:4', 'q'),
            ('g:4', 'q'),
            ('a:4', 'q'),
            ('c:5', (1, 4)),
            ('b:5', (1, 4)),
            ('a:4', (1, 4)),
        ]

        line = TestTShift.create_line(s_notes)
        root_shift_interval = TonalInterval.create_interval('C:4', 'F:4')

        tshift = TShift(line,
                        hc_track,
                        root_shift_interval,
                        default_range_modality_type=ModalityType.MelodicMinor)

        temporal_extent = Interval(Fraction(0), Fraction(3, 1))
        score_line, score_hct = tshift.apply(
            temporal_extent,
            range_modality_type=ModalityType.MelodicMinor,
            as_copy=False)

        TestTShift.print_notes(score_line)
        TestTShift.print_hct(score_hct)

        notes = score_line.get_all_notes()
        assert 14 == len(notes)
        assert 'Eb:5' == str(notes[4].diatonic_pitch)
        assert 'F:5' == str(notes[5].diatonic_pitch)
        assert 'G:5' == str(notes[6].diatonic_pitch)
        assert 'Ab:5' == str(notes[7].diatonic_pitch)

        hc_list = score_hct.hc_list()
        assert len(hc_list) == 4
        assert hc_list[1].chord.chord_template.secondary_scale_degree == 3
        assert {t[0].diatonic_symbol
                for t in hc_list[1].chord.tones} == {'Eb', 'G', 'Bb'}
        assert hc_list[
            1].chord.chord_template.principal_chord_template.inversion == 1
        assert hc_list[1].tonality.modal_index == 0
        assert hc_list[1].tonality.basis_tone.diatonic_symbol == 'F'
        assert hc_list[1].tonality.root_tone.diatonic_symbol == 'F'
        assert hc_list[1].tonality.modality_type == ModalityType.MelodicMinor
        assert hc_list[1].chord.chord_type.value == TertianChordType.Maj