def test_3(self): xml_path = path + '_test_3.xml' durations = [0.25] midis = [60] sf = SimpleFormat(quarter_durations=durations, midis=midis) for chord in sf.chords: chord.add_flag(FingerTremoloFlag2(tremolo_chord=TreeChord(midis=[67]))) sf.to_stream_voice().add_to_score(self.score) self.score.write(xml_path) TestScore().assert_template(xml_path)
def test_3(self): sf = SimpleFormat(quarter_durations=[4]) sf.chords[0].add_grace_chords( [TreeChord(60), TreeChord(63), TreeChord(68)]) sf.chords[0].add_grace_chords( [TreeChord(61), TreeChord(66)], mode='post') sf.to_stream_voice().add_to_score(self.score) xml_path = path + 'test_3.xml' self.score.write(xml_path) TestScore().assert_template(result_path=xml_path)
def test_3(self): xml_path = path + '_test_3.xml' durations = [5] sf = SimpleFormat(quarter_durations=durations) for chord in sf.chords: chord.add_flag(XFlag1()) sf.to_stream_voice().add_to_score(self.score, part_number=1) self.score.write(xml_path) TestScore().assert_template(xml_path)
def test_2(self): sf = SimpleFormat(quarter_durations=[4, 4, 4, 4, 4]) v = sf.to_stream_voice(1) v.add_to_score(self.score, 1) sf = SimpleFormat(quarter_durations=[4, 4, 4, 4, 4]) v = sf.to_stream_voice(1) v.add_to_score(self.score, 2) self.score.get_measure(3).add_page_break() result_path = path + '_test_2' self.score.write(path=result_path) TestScore().assert_template(result_path=result_path)
def test_10(self): # chord clef r_sf = SimpleFormat( quarter_durations=[4, 4], midis=[60, 61]) l_sf = SimpleFormat(quarter_durations=[4, 4], midis=[50, 55]) l_sf.chords[0].add_clef(BASS_CLEF) r_sf.to_stream_voice().add_to_score(self.score, part_number=1, staff_number=1) l_sf.to_stream_voice().add_to_score(self.score, part_number=1, staff_number=2) xml_path = path + '_test_10.xml' self.score.write(xml_path) self.assertCompareFiles(xml_path)
def test_all_possible_16ths(self): self.score.set_time_signatures(times={1: (1, 4)}) keys = list(range(1, 5)) all_durations = flatten(convert_note_groups_to_quarter_durations(get_16_groups(keys), 16)) sf = SimpleFormat(quarter_durations=all_durations) sf.to_stream_voice().add_to_score(self.score) xml_path = path + '_all_possible_16ths.xml' self.score.finish() self.score.to_partwise() self.score.write(xml_path) TestScore().assert_template(xml_path)
def test_1(self): sf = SimpleFormat(midis=[70, 72, 73], quarter_durations=[2, 0.5, 0.5]) voice1 = sf.to_stream_voice(1) voice1.add_to_score(self.score) sf = SimpleFormat(midis=[50, 52, 53], quarter_durations=[0.5, 1, 2]) voice2 = sf.to_stream_voice(2) voice2.add_to_score(self.score) result_path = path + '_test_1' self.score.write(result_path) TestScore().assert_template(result_path=result_path)
def test_2(self): xml_path = path + '_test_2.xml' sf_1 = SimpleFormat(quarter_durations=[1, 2, 3, 2, 1], midis=[60, (60, 62), (64, 66, 71), 72, 73]) sf_1.to_stream_voice().add_to_score(self.score) sf_2 = SimpleFormat(quarter_durations=[0.5, 1, 1.5, 2, 3], midis=[0, 69, (72, 73), (58, 60, 65, 71), 80]) sf_2.to_stream_voice().add_to_score(self.score, staff_number=2) sf_3 = SimpleFormat.sum(sf_1, sf_2, no_doubles=True) sf_3.to_stream_voice().add_to_score(self.score, staff_number=3) self.score.write(xml_path) self.assertCompareFiles(xml_path)
def test_1(self): # sf = SimpleFormat(midis = [52, 51, 70, 100, 110, 107, 90, 80, 70, 60, 50, 40, 30]) sf = SimpleFormat(midis=[ 30, 40, 50, 60, 70, 80, 90, 100, 110, 100, 90, 80, 70, 60, 50, 40, 30 ]) sf.auto_clef() sf.to_stream_voice().add_to_score(self.score) result_path = path + '_test_1' self.score.write(path=result_path) TestScore().assert_template(result_path=result_path)
def test_8(self): midis = [60 + factor * 0.5 for factor in range(0, 25)] simple_format = SimpleFormat(midis=midis + midis[-1::-1][1:]) for index, chord in enumerate(simple_format.chords): if index <= len(midis) - 1: chord.midis[0].accidental.mode = 'sharp' else: chord.midis[0].accidental.mode = 'flat' simple_format.to_stream_voice().add_to_score(self.score) xml_path = path + '_test_8.xml' self.score.write(xml_path) TestScore().assert_template(xml_path)
def test_1(self): score = TreeScoreTimewise() sf = SimpleFormat(midis=[(60, 64, 68, 73)], quarter_durations=[4]) sf.to_stream_voice().add_to_score(score=score) sf.chords[0].inverse() sf.to_stream_voice().add_to_score(score=score, part_number=2) xml_path = path + '.xml' score.write(xml_path) TestScore().assert_template(xml_path)
def test_8(self): r_sf = SimpleFormat( quarter_durations=[0.25, 2.25, 0.5, 1, 2, Fraction(1, 3), Fraction(4, 3), Fraction(1, 3), 1]) l_sf = SimpleFormat(quarter_durations=[4, 5], midis=[50, 55]) r_sf.to_stream_voice().add_to_score(self.score, part_number=1, staff_number=1) l_sf.to_stream_voice().add_to_score(self.score, part_number=1, staff_number=2) clef = BASS_CLEF.__deepcopy__() clef.number = 2 self.score.get_measure(1).get_part(1).add_clef(clef) xml_path = path + '_test_8.xml' self.score.write(xml_path) self.assertCompareFiles(xml_path)
def test_1(self): sf_1 = SimpleFormat(quarter_durations=[2, 2], midis=[0, 71]) sf_1.chords[1].add_words('up') sf_1.to_stream_voice().add_to_score(self.score, staff_number=1) sf_2 = SimpleFormat(quarter_durations=[2, 2], midis=[71, 0]) sf_2.chords[0].add_words('down') sf_2.to_stream_voice().add_to_score(self.score, staff_number=2) xml_path = path + '_test_1.xml' self.score.write(xml_path) self.assertCompareFiles(xml_path)
def test_1(self): simple_format = SimpleFormat(quarter_durations=[1, 2, 3]) simple_format.to_stream_voice().add_to_score(self.score) measure_1_chords = self.score.get_measure(1).get_part(1).get_staff( 1).get_voice(1).chords measure_2_chords = self.score.get_measure(2).get_part(1).get_staff( 1).get_voice(1).chords for chord in measure_1_chords + measure_2_chords: if chord.next_in_score: chord.add_words(chord.next_in_score.quarter_duration) xml_path = path + '_test_1.xml' self.score.write(xml_path)
def test_32_first_group(self): self.score.set_time_signatures(times={1: (1, 4)}) self.score.break_beam_32 = True keys = [1] all_durations = flatten(convert_note_groups_to_quarter_durations(get_32_groups(keys), 32)) sf = SimpleFormat(quarter_durations=all_durations) sf.to_stream_voice().add_to_score(self.score) xml_path = path + '_32_first_group.xml' self.score.finish() self.score.to_partwise() self.score.write(xml_path) TestScore().assert_template(xml_path)
def test_4(self): sf = SimpleFormat() for notehead in TypeNoteheadValue._PERMITTED: sf.add_chord(TreeChord(quarter_duration=1)) sf.chords[-1].midis[0].notehead = Notehead(notehead) sf.chords[-1].add_words(notehead) sf.add_chord(TreeChord(quarter_duration=2)) sf.chords[-1].midis[0].notehead = Notehead(notehead) self.score.set_time_signatures(times={1: (3, 4)}) sf.to_stream_voice().add_to_score(self.score) xml_path = path + '_test_4.xml' self.score.write(xml_path) TestScore().assert_template(xml_path)
def test_4(self): # finger tremolo xml_path = path + '_test_4.xml' durations = [0.2, 0.8, 1] midis = [60, 62, 63] sf = SimpleFormat(quarter_durations=durations, midis=midis) for chord in sf.chords: chord.add_flag( FingerTremoloFlag2(tremolo_chord=TreeChord(midis=[67]))) sf.to_stream_voice().add_to_score(self.score) self.score.write(xml_path) self.assertCompareFiles(xml_path)
def test_1(self): instrument = TreeInstrument(name='banjo', abbreviation='bjo', number=2) instrument.standard_clefs = ALTO_CLEF sf = SimpleFormat(quarter_durations=[1, 2, 3, 1, 2, 3, 1, 2, 3]) score = TreeScoreTimewise() sf.to_stream_voice(2).add_to_score(score) sf.transpose(5) sf.to_stream_voice(1).add_to_score(score) score.get_score_parts()[0].instrument = instrument xml_path = path + '_test_1.xml' score.write(xml_path) self.assertCompareFiles(xml_path)
def test_1(self): sf = SimpleFormat(quarter_durations=[4], midis=[(60, 65)]) chord = sf.chords[0] notations = chord.add_child(Notations()) technical = notations.add_child(Technical()) harmonic = technical.add_child(Harmonic()) harmonic.add_child(Artificial()) harmonic.add_child(TouchingPitch()) sf.to_stream_voice().add_to_score(self.score) xml_path = path + '_test_1.xml' self.score.write(xml_path)
def test_5(self): sf = SimpleFormat(quarter_durations=[2]) chords = sf.chords[0].split(1, 1) sf._chords = [] for ch in chords: sf.add_chord(ch) sf.chords[0].remove_tie('start') sf.chords[0].add_slur(type='start', line_type='dashed') sf.chords[1].remove_tie('stop') sf.chords[1].add_slur(type='stop') sf.to_stream_voice().add_to_score(self.score) xml_path = path + '_test_5.xml' self.score.write(xml_path)
def test_6(self): # noise flag xml_path = path + '_test_6.xml' durations = [ 0.25, 0.75, 0.5, 0.5, 1, 1.25, 1.5, 2, 2.5, 3, 3.5, 4, 4.5 ] sf = SimpleFormat(quarter_durations=durations) for chord in sf.chords: chord.add_flag(NoiseFlag2()) sf.to_stream_voice().add_to_score(self.score) self.score.write(xml_path) self.assertCompareFiles(xml_path)
def test_5(self): # finger tremolo self.score.add_instrument(Piano()) xml_path = path + '_test_5.xml' durations = [5, 3] midis = [63, 0] sf = SimpleFormat(quarter_durations=durations, midis=midis) tremolo_chord = TreeChord(midis=[47]) tremolo_chord.manual_staff_number = 2 sf.chords[0].add_flag(FingerTremoloFlag2(tremolo_chord=tremolo_chord)) sf.to_stream_voice().add_to_score(self.score) self.score.write(xml_path) self.assertCompareFiles(xml_path)
def test_3(self): midis = { 'flat': [Midi(value, accidental=Accidental('flat', force_show=True)) for value in range(60, 72)], 'sharp': [Midi(value, accidental=Accidental('sharp', force_show=True)) for value in range(60, 72)] } sf = SimpleFormat(midis=midis['flat'] + midis['sharp']) for chord in sf.chords: chord.add_harmonic(5) self.score.set_time_signatures(times={1: [12, 4]}) sf.to_stream_voice().add_to_score(self.score) xml_path = path + '_test_3.xml' self.score.write(xml_path)
def setUp(self) -> None: self.score = TreeScoreTimewise() sf = SimpleFormat(quarter_durations=[1, 1]) v = sf.to_stream_voice(1) v.add_to_score(self.score, part_number=1, first_measure=1) sf = SimpleFormat(quarter_durations=[1, 1]) v = sf.to_stream_voice(2) v.add_to_score(self.score, part_number=1, first_measure=1) sf = SimpleFormat(quarter_durations=[1, 1]) v = sf.to_stream_voice(1) v.add_to_score(self.score, part_number=2, first_measure=2)
def test_2(self): sf_1 = SimpleFormat(quarter_durations=[2, 2], midis=[0, 71]) sf_1.to_stream_voice().add_to_score(self.score, staff_number=1) sf_2 = SimpleFormat(quarter_durations=[2, 2], midis=[71, 0]) sf_2.to_stream_voice().add_to_score(self.score, staff_number=2) first_staff = self.score.get_measure(1).get_part(1) staff_details = first_staff.attributes.add_child(StaffDetails()) staff_details.add_child(StaffSize(65)) xml_path = path + '_test_2.xml' self.score.write(xml_path) self.assertCompareFiles(xml_path)
def test_5(self): # todo: see template xml_path = path + '_test_5.xml' durations = [3.5] self.score.set_time_signatures(quarter_durations=[3.5]) sf = SimpleFormat(quarter_durations=durations) sf.to_stream_voice().add_to_score(self.score, part_number=1) for chord in sf.chords: chord.add_flag(XFlag1()) sf.to_stream_voice().add_to_score(self.score, part_number=2) self.score.write(xml_path)
def test_11(self): r_sf = SimpleFormat( quarter_durations=[0.25, 2.25, 0.5, 1, 2, Fraction(1, 3), Fraction(4, 3), Fraction(1, 3), 1], midis=[60, 61, 54, 63]) l_sf = SimpleFormat(quarter_durations=[4, 5], midis=[72, 53]) r_sf.chords[1].manual_staff_number = 2 r_sf.auto_clef() l_sf.auto_clef() r_sf.to_stream_voice().add_to_score(self.score, part_number=1, staff_number=1) l_sf.to_stream_voice().add_to_score(self.score, part_number=1, staff_number=2) xml_path = path + '_test_11.xml' self.score.write(xml_path) self.assertCompareFiles(xml_path)
def test_arrow(self): xml_path = path + '_test_arrow.xml' sf = SimpleFormat(quarter_durations=5 * [2.25]) sf.chords[0].add_bracket(type='start', line_end='none', relative_x=50) sf.chords[1].add_bracket(type='continue', line_end='none') sf.chords[2].add_bracket(type='stop', line_end='arrow', relative_x=-30, relative_y=20) sf.to_stream_voice().add_to_score(self.score) self.score.write(xml_path) self.assertCompareFiles(xml_path)
def test_3(self): sf = SimpleFormat(quarter_durations=[0.25, 2.25, 0.5, 1, 2, Fraction(1, 3), Fraction(4, 3), Fraction(1, 3), 1]) for index, chord in enumerate(sf.chords): if index in [1, 6]: chord.staff_number = 2 sf.to_stream_voice(1).add_to_score(self.score, part_number=1) all_parts = [part for m in self.score.get_children_by_type(TreeMeasure) for part in m.get_children_by_type(TreePart)] for part in all_parts: part.staves = 2 xml_path = path + '_test_3.xml' self.score.write(xml_path) self.assertCompareFiles(xml_path)
def test_1(self): sf = SimpleFormat(quarter_durations=[1, 0.25, 2.25, 0.5, 1, 2]) sf.to_stream_voice(1).add_to_score(self.score) xml_path = path + '_test_1.xml' self.score.write(xml_path) chords = [] for measure in self.score.get_children_by_type(TreeMeasure): for part in measure.get_children_by_type(TreePart): for staff in part.tree_part_staves.values(): chords.extend(staff.chords) expected = [0, Fraction(1, 1), Fraction(5, 4), Fraction(2, 1), Fraction(7, 2), 0, Fraction(1, 1), Fraction(3, 1)] actual = [tree_chord.offset for tree_chord in chords] self.assertEqual(expected, actual)