def test_1(self): proportions = (1, 3, 1, 5, 1) breakpoints = (1, Fraction(1, 7), 1) quarter_durations = [8, 12] breathe = Breathe(proportions=proportions, breakpoints=breakpoints, quarter_duration=sum(quarter_durations), quantize=1) breathe.midi_generator = ValueGenerator(cycle([71])) test_chord_field = ChordField(duration_generator=breathe.duration_generator.__deepcopy__()) for i in range(len(quarter_durations)): quarter_duration = quarter_durations[i] midi = 60 + i test_chord_field.add_child( ChordField(midi_generator=ValueGenerator(cycle([midi])), long_ending_mode='self_extend', short_ending_mode='self_shrink', quarter_duration=quarter_duration)) test_chord_field_2 = ChordField(duration_generator=breathe.duration_generator.__deepcopy__()) for i in range(len(quarter_durations)): quarter_duration = quarter_durations[i] midi = 72 + i test_chord_field_2.add_child( ChordField(midi_generator=ValueGenerator(cycle([midi])), long_ending_mode='cut', short_ending_mode='add_rest', quarter_duration=quarter_duration)) breathe.simple_format.to_stream_voice().add_to_score(score=self.score, part_number=1) test_chord_field.simple_format.to_stream_voice().add_to_score(score=self.score, part_number=2) simple_format = SimpleFormat() for child in test_chord_field_2.children: simple_format.extend(child.simple_format) simple_format.to_stream_voice().add_to_score(score=self.score, part_number=3) xml_path = path + '_test_1.xml' self.score.write(xml_path) self.assertCompareFiles(xml_path)
def test_4(self): # fields: midi_generators, first one with ending_mode 'post' # group: duration_generator with __next__ (Arithmetic Progression) cfg = ChordField( duration_generator=ValueGenerator(ArithmeticProgression(a1=0.3, an=1.5, correct_s=True)) ) cf_1 = ChordField(quarter_duration=3, midi_generator=ValueGenerator(cycle([60, 61, 64, 66])), long_ending_mode='self_extend' ) cf_2 = ChordField(quarter_duration=6, midi_generator=ValueGenerator(cycle([72, 73, 74, 73, 72])), short_ending_mode='add_rest', ) cfg.add_child(cf_1) cfg.add_child(cf_2) sf = SimpleFormat() sf.extend(cf_1.simple_format) sf.extend(cf_2.simple_format) xml_path = path + 'test_4.xml' sf.to_stream_voice().add_to_score(self.score) self.score.write(xml_path) self.assertCompareFiles(xml_path)
def test_3(self): # fields: both with midi_generators, one duration_generator # group: duration_generator with __next__ (Random) cfg = ChordField( duration_generator=ValueGenerator(Random(pool=[0.2, 0.4, 0.8, 1.6], seed=10)) ) cf_1 = ChordField(quarter_duration=3, midi_generator=ValueGenerator(cycle([60, 61, 64, 66])), duration_generator=ValueGenerator(cycle([1])) ) cf_2 = ChordField(quarter_duration=6, midi_generator=ValueGenerator(cycle([72, 73, 74, 73, 72])), long_ending_mode='cut' ) cfg.add_child(cf_1) cfg.add_child(cf_2) sf_1 = cf_1.simple_format sf_2 = cf_2.simple_format sf = SimpleFormat() sf.extend(sf_1) sf.extend(sf_2) xml_path = path + 'test_3.xml' # cfg.simple_format.to_stream_voice().add_to_score(self.score) sf.to_stream_voice().add_to_score(self.score) self.score.write(xml_path) self.assertCompareFiles(xml_path)
def test_8(self): # fields: midi_generators # group: duration_generator with __call__ RandomInterpolation # output of fields not group cfg = ChordField( duration_generator=ValueGenerator( RandomInterpolation(start=[0.25, 0.25, 0.5], end=[0.5, 0.75, 1], seed=20))) cf_1 = ChordField( quarter_duration=3, midi_generator=ValueGenerator(cycle([60, 61, 64, 66]))) cf_2 = ChordField( quarter_duration=6, midi_generator=ValueGenerator(cycle([72, 73, 74, 73, 72])), long_ending_mode='self_extend') cfg.add_child(cf_1) cfg.add_child(cf_2) xml_path = path + 'test_8.xml' simple_format = SimpleFormat() simple_format.extend(cf_1.simple_format) simple_format.extend(cf_2.simple_format) simple_format.to_stream_voice().add_to_score(self.score) self.score.write(xml_path) self.assertCompareFiles(xml_path)
def test_4(self): cf_1 = ChordField( quarter_duration=10, midi_generator=ValueGenerator(cycle([60, 61, 64, 66])), long_ending_mode='self_extend', short_ending_mode='self_shrink' ) cf_2 = ChordField( quarter_duration=3, midi_generator=ValueGenerator(cycle([72, 73, 74, 73, 72])), long_ending_mode='self_extend', short_ending_mode='self_shrink' ) breathe_unit = Fraction(1, 5) breathe_breakpoints = (5 * breathe_unit, breathe_unit, 5 * breathe_unit) breathe_proportions = [2, 4, 1, 7, 2] breathe = Breathe(proportions=breathe_proportions, quarter_duration=13, breakpoints=breathe_breakpoints) cfg = ChordField(duration_generator=breathe.duration_generator) cfg.add_child(cf_1) cfg.add_child(cf_2) simple_format = SimpleFormat() simple_format.extend(cf_1.simple_format) simple_format.extend(cf_2.simple_format) self.score.set_time_signatures(ceil(simple_format.quarter_duration)) simple_format.to_stream_voice().add_to_score(self.score) xml_path = path + 'test_4.xml' self.score.write(xml_path) self.assertCompareFiles(xml_path)
def test_1(self): sf = SimpleFormat(quarter_durations=[1, 1, 1, 1]) sf_2 = SimpleFormat(quarter_durations=[2, 2, 2]) sf.extend(sf_2) v = sf.to_stream_voice(1) v.add_to_score(self.score) result_path = path + '_test_1' self.score.write(path=result_path)
while True: try: print('pos:{}, pospar:{}, genpos {}'.format( chord_field.position, chord_field.position_in_parent, chord_field.duration_generator.position, )) next = chord_field.__next__() print('next duration:{}'.format(next.quarter_duration)) except StopIteration: break iterate(copy_parent_chord_field.children[0]) print() iterate(copy_parent_chord_field.children[1]) simple_format = SimpleFormat() for child in copy_parent_chord_field.children: simple_format.extend(child.simple_format) simple_format.to_stream_voice().add_to_score(score=score, part_number=3) print( float( sum([ child.quarter_duration for child in copy_parent_chord_field.children ]))) ## xml_path = path + '_test_1.xml' score.write(xml_path)