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
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()
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)
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)
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()
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
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
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)
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