def test_1(self): fm = FractalMusic(tempo=60, proportions=[1, 2, 3, 4], tree_permutation_order=[3, 1, 4, 2], quarter_duration=100) fm.midi_generator.midi_range = [60, 79] fm.add_layer() partial_fm = fm.get_leaves()[3] partial_fm.add_layer() for leaf in partial_fm.traverse(): leaf.chord.add_lyric(leaf.fractal_order) leaf.chord.add_words(leaf.midi_generator.midi_range) # leaf.chord.add_words(leaf.midi_generator.directions, relative_y=30) # print([leaf.fractal_order for leaf in partial_fm.traverse_leaves()]) score = TreeScoreTimewise() v = partial_fm.get_simple_format(0).to_stream_voice(1) v.add_to_score(score, 1) v = partial_fm.get_simple_format().__deepcopy__().to_stream_voice(1) v.add_to_score(score, 2) partial_fm.reduce_children( condition=lambda child: child.fractal_order > 2) v = partial_fm.get_simple_format().__deepcopy__().to_stream_voice(1) v.add_to_score(score, 3) xml_path = path + '_test_1.xml' score.write(xml_path) self.assertCompareFiles(actual_file_path=xml_path)
class Test(TestCase): def setUp(self) -> None: self.horn = NaturalHorn() self.score = TreeScoreTimewise() def test_1(self): xml_path = path + '_test_1.xml' harmonics = SimpleFormat() for i in range(1, 17): partial_midi = Midi(round(self.horn.get_partial_midi_value(i) * 2) / 2) if i % 7 == 0: partial_midi.accidental.mode = 'flat' if i % 11 == 0: partial_midi.accidental.mode = 'sharp' if i % 13 == 0: partial_midi.accidental.mode = 'flat' chord = TreeChord(midis=partial_midi) chord.add_words(i) harmonics.add_chord(chord) harmonics.to_stream_voice().add_to_score(self.score, part_number=2) harmonics.transpose(self.horn.transposition) harmonics.to_stream_voice().add_to_score(self.score, part_number=1) self.score.accidental_mode = 'modern' self.score.write(xml_path) TestScore().assert_template(xml_path)
def test_1(self): self.fm.split(1, 2) score = TreeScoreTimewise() self.fm.get_score(score) xml_path = path + '_test_1.xml' score.write(xml_path) self.assertCompareFiles(xml_path)
class Test(TestCase): 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_1(self): chord = self.score.get_measure(1).get_part(1).get_staff(1).get_voice( 1).chords[1] self.assertEqual(chord.__name__, '1.1.1.2') chord = self.score.get_measure(1).get_part(1).get_staff(1).get_voice( 2).chords[0] self.assertEqual(chord.__name__, '1.1.2.1') chord = self.score.get_measure(2).get_part(2).get_staff(1).get_voice( 1).chords[1] self.assertEqual(chord.__name__, '2.2.1.2')
class Test(XMLTestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_1(self): simple_format = SimpleFormat(quarter_durations=4) simple_format.to_stream_voice().add_to_score(self.score) self.score.add_measure() m2 = self.score.get_measure(2) self.score.finish() actual = m2.to_string() expected = """<measure number="2"> <part id="p1"> <attributes> <divisions>1</divisions> </attributes> <note> <rest/> <duration>4</duration> <voice>1</voice> <type>whole</type> </note> </part> </measure> """ self.assertEqual(expected, actual)
class Test(TestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_1(self): chord = TreeChord() notations = chord.add_child(Notations()) dynamics = notations.add_child(Dynamics()) dynamics.add_child(FF()) note = chord.notes[0] note.add_child(Duration(1)) result = '''<note> <pitch> <step>B</step> <octave>4</octave> </pitch> <duration>1</duration> <notations> <dynamics placement="below"> <ff/> </dynamics> </notations> </note> ''' self.assertEqual(note.to_string(), result) def test_2(self): sf = SimpleFormat(quarter_durations=[1, 1]) sf.chords[0].add_dynamics('fff') sf.to_stream_voice().add_to_score(self.score) xml_path = path + '_test_2.xml' self.score.write(xml_path) TestScore().assert_template(xml_path)
def test_10(self): fm = FractalMusic(proportions=[1, 2, 3], tree_permutation_order=[3, 1, 2]) fm.tempo = 60 fm.duration = 10 fm.midi_generator.midi_range = (60, 72) fm.permute_directions = True fm.midi_generator.set_directions(-1, 1, -1) fm.add_layer() for node in fm.traverse(): node.chord.add_lyric(node.midi_generator.directions) node.chord.add_words(node.children_generated_midis, relative_y=30) node.chord.add_words(node.midi_generator.midi_range, relative_y=60) fm.add_layer() score = TreeScoreTimewise() score.accidental_mode = 'modern' score = fm.get_score(score) score.page_style.staff_distance = 150 xml_path = path + '_test_10.xml' score.write(xml_path) self.assertCompareFiles(xml_path)
class Test(XMLTestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() self.sf = _generate_simple_format() def test_1(self): xml_path = path + '_test_1.xml' self.sf.to_stream_voice().add_to_score(self.score) def _change_quarter_duration(chord, factor): chord.quarter_duration *= factor self.sf.change_chords(lambda chord: _change_quarter_duration(chord, 2)) self.sf.to_stream_voice().add_to_score(self.score, staff_number=2) self.score.write(xml_path) self.assertCompareFiles(xml_path) def test_2(self): xml_path = path + '_test_2.xml' self.sf.to_stream_voice().add_to_score(self.score) def _change_quarter_duration(chord, factor): chord.quarter_duration *= factor self.sf.change_chords( lambda chord: _change_quarter_duration(chord, 2) if int(chord.quarter_duration) != chord.quarter_duration else None) self.sf.to_stream_voice().add_to_score(self.score, staff_number=2) self.score.write(xml_path) self.assertCompareFiles(xml_path)
def test_2(self): self.fm.split(1, 2)[1].chord.to_rest() score = TreeScoreTimewise() self.fm.get_score(score) xml_path = path + '_test_2.xml' score.write(xml_path) self.assertCompareFiles(xml_path)
def test_7(self): fm = FractalMusic(tempo=60, proportions=[1, 2, 3, 4], tree_permutation_order=[3, 1, 4, 2], quarter_duration=20) fm.midi_generator.midi_range = [60, 79] fm.add_layer() fm.chord.add_words(fm.midi_generator.midi_range) for child in fm.get_children(): child.chord.add_lyric(child.fractal_order) child.chord.add_words(child.midi_generator.midi_range) for index, node in enumerate(fm.get_children()): node.midi_generator.midi_range = [60 - index, 72 - index] fm.add_layer() for leaf in fm.traverse_leaves(): leaf.chord.add_lyric(leaf.fractal_order) score = TreeScoreTimewise() for layer_number in range(0, fm.number_of_layers + 1): simple_format = fm.get_simple_format(layer_number) v = simple_format.to_stream_voice(1) v.add_to_score(score, layer_number + 1) xml_path = path + '_test_7.xml' score.accidental_mode = 'normal' score.write(xml_path) self.assertCompareFiles(actual_file_path=xml_path)
class Test(XMLTestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_1(self): sf = SimpleFormat(quarter_durations=[7]) sf.chords[0].add_tremolo() sf.to_stream_voice().add_to_score(self.score) xml_path = path + '_test_1.xml' self.score.write(xml_path) self.assertCompareFiles(xml_path) # def test_2(self): # sf = SimpleFormat(quarter_durations=[7]) # # sf.chords[0].add_tremolo(number=4) # # sf.to_stream_voice().add_to_score(self.score) # xml_path = path + '_test_2.xml' # self.score.write(xml_path) # self.assertCompareFiles(xml_path) def test_3(self): sf = SimpleFormat(quarter_durations=[7], midis=[(60, 64)]) sf.chords[0].add_tremolo(3) sf.to_stream_voice().add_to_score(self.score) xml_path = path + '_test_3.xml' self.score.write(xml_path) self.assertCompareFiles(xml_path)
def test_1(self): fm = self.fm fm.add_layer() fm.add_layer(lambda n: True if n.fractal_order > 1 else False) fm.add_layer(lambda n: True if n.fractal_order > 1 else False) fm.add_layer(lambda n: True if n.fractal_order > 1 else False) # for node in fm.traverse(): # node.chord.add_words(node.midi_generator.midi_range) fm.add_layer(lambda n: True if n.fractal_order > 1 else False) # for node in fm.traverse(): # node.chord.add_words(node.children_generated_midis) # node.chord.add_words(node.midi_generator.directions, relative_y=30) # node.chord.add_words(node.children_generated_midis) # node.chord.add_words(node.permutation_order, relative_y=60) score = TreeScoreTimewise() score = fm.get_score(score=score, show_fractal_orders=False) text_path = path + '_test_1.txt' fm.write_infos(text_path) self.assertCompareFiles(actual_file_path=text_path) xml_path = path + '_test_1.xml' score.write(path=xml_path) self.assertCompareFiles(actual_file_path=xml_path)
class Test(XMLTestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() 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_2(self): sf_1 = SimpleFormat(quarter_durations=[2, 2], midis=[0, 71]) sf_1.chords[1].add_words('up') sf_1.to_stream_voice(1).add_to_score(self.score, staff_number=1) sf_2 = SimpleFormat(quarter_durations=[2, 2], midis=[60, 0]) sf_2.chords[0].add_words('down', placement='below') sf_2.to_stream_voice(2).add_to_score(self.score, staff_number=1) sf_1 = SimpleFormat(quarter_durations=[2, 2], midis=[0, 71]) sf_1.chords[1].add_words('up') sf_1.to_stream_voice(1).add_to_score(self.score, staff_number=2) sf_2 = SimpleFormat(quarter_durations=[2, 2], midis=[60, 0]) sf_2.chords[0].add_words('down', placement='below') sf_2.to_stream_voice(2).add_to_score(self.score, staff_number=2) xml_path = path + '_test_2.xml' self.score.write(xml_path) self.assertCompareFiles(xml_path)
class Test(TestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_1(self): xml_path = path + '_test_1.xml' durations = [2, 1, 0.5, 0.25, 0.25, 4, 2, 3] sf = SimpleFormat(quarter_durations=durations) for chord in sf.chords: articulation = Accent() chord.add_articulation_object(articulation) sf.to_stream_voice().add_to_score(self.score) self.score.write(xml_path) TestScore().assert_template(xml_path) def test_2(self): xml_path = path + '_test_2.xml' articulations = [ 'accent', 'strong-accent', 'staccato', 'tenuto', 'detached-legato', 'staccatissimo', 'spiccato', 'scoop', 'plop', 'doit', 'falloff', 'breath-mark', 'caesura', 'stress', 'unstress' ] durations = len(articulations) * [1.25] sf = SimpleFormat(quarter_durations=durations) for index, chord in enumerate(sf.chords): chord.add_articulation(articulations[index]) sf.to_stream_voice().add_to_score(self.score) self.score.write(xml_path) TestScore().assert_template(xml_path)
def setUp(self) -> None: self.score = TreeScoreTimewise() fm = FractalMusic(tempo=60, quarter_duration=10, reading_direction='vertical') fm.add_layer() fm.add_layer() self.fm = fm.get_children()[1] self.deep_copied = self.fm.__deepcopy__()
def generate_score(modules): score = TreeScoreTimewise() for index, module in enumerate(modules): module.get_simple_format( layer=module.number_of_layers ).to_stream_voice().add_to_score(score=score, part_number=index + 1) score.finish() partwise = score.to_partwise() return partwise
def setUp(self) -> None: self.fm = FractalMusic(proportions=(1, 2, 3), tree_permutation_order=(3, 1, 2)) self.fm.duration = 10 self.fm.tempo = 60 self.fm.midi_generator.midi_range = [60, 67] self.fm.add_layer() self.score = TreeScoreTimewise() self.score.set_time_signatures( quarter_durations=[self.fm.quarter_duration])
def setUp(self) -> None: self.score = TreeScoreTimewise() sf = SimpleFormat(quarter_durations=[4]) sf.to_stream_voice().add_to_score(self.score, part_number=1) sf.to_stream_voice().add_to_score(self.score, part_number=2) sf.to_stream_voice().add_to_score(self.score, part_number=3) sf.to_stream_voice().add_to_score(self.score, part_number=4) self.score.get_score_parts()[0].instrument = Violin(1) self.score.get_score_parts()[1].instrument = Violin(2) self.score.get_score_parts()[2].instrument = Viola() self.score.get_score_parts()[3].instrument = Cello()
class Test(TestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_1(self): midis = [C(4, 'flat'), C(4), C(4, 'sharp')] sf = SimpleFormat(midis=midis) v = sf.to_stream_voice(1) v.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_2(self): midis = [ D(4), D(4), D(4), D(4), C(4), C(4), C(4), B(3), C(4), C(4), C(4), F(4), E(4), D(4), F(4), F(4), F(4), E(4), D(4), E(4), F(4) ] durations = [ 2, 3, 1, 2, 3, 1, 4, 2, 4, 2, 2, 3, 1, 2, 2, 2, 2, 3, 1, 1, 4 ] durations = [d / 2 for d in durations] sf = SimpleFormat(midis=midis, quarter_durations=durations) v = sf.to_stream_voice(1) v.add_to_score(self.score) result_path = path + '_test_2' self.score.write(path=result_path) def test_3(self): midi = E(6) # print(midi.value) midi.transpose(3)
class TestOffset(XMLTestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() 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) def test_2(self): sf_1 = SimpleFormat(quarter_durations=[1, 0.25, 2.25]) sf_2 = SimpleFormat(quarter_durations=[0.25, 2.25, 1]) sf_3 = SimpleFormat(quarter_durations=[2.25, 1, 0.25]) sf_1.to_stream_voice().add_to_score(self.score, part_number=1, staff_number=1) sf_2.to_stream_voice().add_to_score(self.score, part_number=1, staff_number=2) sf_3.to_stream_voice().add_to_score(self.score, part_number=1, staff_number=3) xml_path = path + '_test_2.xml' self.score.write(xml_path) chord_offsets = {} for measure in self.score.get_children_by_type(TreeMeasure): for part in measure.get_children_by_type(TreePart): for key in part.tree_part_staves.keys(): staff = part.tree_part_staves[key] chord_offsets[key] = [tree_chord.offset for tree_chord in staff.chords] expected = {1: [0, Fraction(1, 1), Fraction(5, 4), Fraction(2, 1), Fraction(7, 2)], 2: [0, Fraction(1, 4), Fraction(1, 1), Fraction(5, 2), Fraction(7, 2)], 3: [0, Fraction(2, 1), Fraction(9, 4), Fraction(3, 1), Fraction(13, 4), Fraction(7, 2)]} actual = chord_offsets self.assertEqual(expected, actual) def test_3(self): sf_1 = SimpleFormat(quarter_durations=[1, 0.25, 2.25]) sf_2 = SimpleFormat(quarter_durations=[0.25, 2.25, 1], midis=[60, 60, 60]) sf_1.to_stream_voice(1).add_to_score(self.score, part_number=1, staff_number=1) sf_2.to_stream_voice(2).add_to_score(self.score, part_number=1, staff_number=1) xml_path = path + '_test_3.xml' self.score.write(xml_path) chord_offsets = {} 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(): for key in staff.tree_part_voices.keys(): voice = staff.tree_part_voices[key] chord_offsets[key] = [tree_chord.offset for tree_chord in voice.chords] expected = {1: [0, Fraction(1, 1), Fraction(5, 4), Fraction(2, 1), Fraction(7, 2)], 2: [Fraction(0, 1), Fraction(1, 4), Fraction(1, 1), Fraction(5, 2), Fraction(7, 2)]} actual = chord_offsets self.assertEqual(actual, expected)
class Test(XMLTestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_1(self): xml_path = path + '_test_1.xml' sf = SimpleFormat(quarter_durations=4, midis=0) sf.to_stream_voice().add_to_score(self.score) self.score.get_measure(1).get_part(1).add_clef(BASS_CLEF) self.score.write(xml_path) self.assertCompareFiles(xml_path)
class Test(XMLTestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_1(self): sf = SimpleFormat(quarter_durations=[1, 5], midis=[60, 60]) for chord in sf.chords: chord.add_child(Stem('down')) sf.to_stream_voice().add_to_score(self.score) xml_path = path + '_test_1.xml' self.score.write(xml_path) self.assertCompareFiles(xml_path)
class TestAddPedal(XMLTestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_imply(self): xml_path = path.parent.joinpath(path.stem + '_imply.xml') sf = SimpleFormat(quarter_durations=[1, 1, 1, 1]) sf.chords[0].add_pedal('start') sf.chords[2].add_pedal('stop') sf.to_stream_voice().add_to_score(self.score) self.score.write(xml_path) self.assertCompareFiles(xml_path)
class Test(TestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_1(self): sf = SimpleFormat(quarter_durations=[1, 3.5]) v = sf.to_stream_voice(1) v.add_to_score(self.score, part_number=2, first_measure=2) result_path = path + '_test_1' self.score.write(path=result_path) TestScore().assert_template(result_path=result_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)
class Test(TestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_1(self): sf = SimpleFormat(quarter_durations=[1, 0, 3, 0, 1]) sf.chords[1].zero_mode = 'remove' sf.to_stream_voice().add_to_score(self.score) xml_path = path + '_test_1.xml' self.score.write(xml_path) TestScore().assert_template(xml_path)
class Test(TestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() sf = SimpleFormat(quarter_durations=[4]) sf.to_stream_voice().add_to_score(self.score) def test_1(self): self.score.get_score_parts()[0].instrument = Violin() self.score.get_score_parts()[0].instrument.part_name.font_size = 9 xml_path = path + '_test_1.xml' self.score.write(path=xml_path)
class Test(TestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_1(self): # sf = SimpleFormat(durations=[4, 4, 2, 1, 1.5, 1.8, 0.2, 0.4, 0.5, 1]) sf = SimpleFormat(quarter_durations=[4, 4]) for chord in sf.chords: # chord.add_flag(PizzFlag()) chord.add_flag(PercussionFlag1()) v = sf.to_stream_voice() self.score.set_time_signatures([4, 3, 1]) v.add_to_score(self.score) result_path = path + '_test_1' # self.score.fill_with_rest() # self.score.add_beats() # self.score.quantize() # for measure in self.score.get_children_by_type(TreeMeasure): # for part in measure.get_children_by_type(TreePart): # for beat in part.get_beats(): # new_chords = [] # for chord in beat.chords: # if chord.is_tied_to_previous: # chord.to_rest() # new_chords.append(chord) # # elif chord.position_in_beat == 0: # split = [chord] # if chord.quarter_duration == 1: # split = chord.split(1, 1) # elif chord.quarter_duration == 2: # split = chord.split(1, 3) # elif chord.quarter_duration == 3: # split = chord.split(1, 5) # elif chord.quarter_duration == 4: # split = chord.split(1, 7) # elif chord.quarter_duration == 6: # split = chord.split(1, 11) # else: # pass # try: # split[1].to_rest() # except IndexError: # pass # new_chords.extend(split) # else: # new_chords.append(chord) # beat._chords = new_chords self.score.write(path=result_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)
class Test(TestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_1(self): sf = SimpleFormat(quarter_durations=[1, 1, 1]) sf.chords[0].add_fermata() sf.chords[1].add_fermata('square') sf.chords[2].add_fermata('angled') sf.to_stream_voice().add_to_score(self.score) xml_path = path + '_test_1.xml' self.score.write(xml_path)