def test_1(self):
     sf = SimpleFormat(quarter_durations=[1, 2, 3, 2, 1])
     sf.chords[1].add_child(Notehead('square'))
     sf.chords[2].add_child(Notehead('diamond'))
     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)
 def test_3(self):
     sf = SimpleFormat(midis=[(60, 62, 63)], quarter_durations=[4])
     sf.chords[0].midis[0].notehead = Notehead('diamond')
     sf.chords[0].midis[1].notehead = Notehead('square')
     sf.chords[0].midis[2].notehead = Notehead('normal')
     sf.to_stream_voice().add_to_score(self.score)
     xml_path = path + '_test_3.xml'
     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_2(self):
     sf = SimpleFormat(midis=[(60, 62, 63)], quarter_durations=[4])
     sf.chords[0].add_child(Notehead('diamond'))
     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)
Beispiel #5
0
    def test_3(self):
        fm = FractalMusic(tempo=60, quarter_duration=10, multi=(1, 3))
        fm.midi_generator.midi_range = [60, 72]
        fm.add_layer()
        for child in fm.get_children():
            for midi in child.chord.midis:
                midi.notehead = Notehead('diamond', filled='no')
        for child in fm.get_children():
            child.add_gliss()

        fm.get_children()[-1].chord_field.chords[-1].get_post_grace_chords(
        )[0].midis[0].notehead = Notehead('diamond', filled='no')
        score = fm.get_score(show_fractal_orders=True,
                             layer_number=fm.number_of_layers)
        xml_path = path + '_test_3.xml'
        score.write(path=xml_path)
        self.assertCompareFiles(xml_path)
    def implement(self, chord):
        if chord.is_tied_to_previous:
            chord.remove_previous_tie()
            chord.add_child(Notehead('none'))
            chord.add_child(Stem('none'))
        elif chord.is_tied_to_next:
            chord.add_child(Stem('none'))

        else:
            chord.add_child(Stem('none'))
        beams = chord.get_children_by_type(Beam)
        for beam in beams:
            chord.remove_child(beam)
        return [chord]
Beispiel #7
0
    def implement(self, chord, beat):
        output = super().implement(chord, beat)
        if not self._head:
            if output[0].quarter_duration == 1:
                if self.clef == 'bass':
                    midi = 59
                elif self.clef == 'treble':
                    midi = 79
                else:
                    raise NotImplementedError()
                output[0].midis = [midi]
            output[0].add_child(Notehead('none'))

        else:
            if self.mode != 1:
                output[0].add_slide('stop')
            output[0].add_slide('start')
        return output
Beispiel #8
0
    def add_gliss(self,
                  unit=1,
                  grid=1,
                  min_quarter_duration=Fraction(1, 8),
                  show_heads=False):
        def get_slides(chord):
            return [
                slide for notation in chord.get_children_by_type(Notations)
                for slide in notation.get_children_by_type(Slide)
            ]

        position = self.quarter_position_in_tree
        delta = unit - (position - int(position))
        if delta >= min_quarter_duration:
            duration_generator = ValueGenerator(
                itertools.chain(iter([delta]), itertools.cycle([unit])))
        else:
            duration_generator = ValueGenerator(itertools.cycle([unit]))

        chord_field = ChordField(
            duration_generator=duration_generator,
            midi_generator=ValueGenerator(
                Interpolation(start=self.midi_generator.midi_range[0],
                              end=self.midi_generator.midi_range[1],
                              grid=grid)),
            long_ending_mode='cut',
            short_ending_mode='stretch')

        first_chord = self.chord.__deepcopy__()
        self.chord_field = chord_field
        list(chord_field)
        first_chord.quarter_duration = chord_field.chords[0].quarter_duration
        chord_field.chords[0] = first_chord
        if chord_field.chords[-1].quarter_duration < min_quarter_duration:
            chord_field._chords = chord_field._chords[:-1]

        for chord in chord_field.chords[1:]:
            for midi in chord.midis:
                if show_heads is False:
                    midi.notehead = Notehead('none')
                    alter = midi.get_pitch_rest().alter
                    if alter:
                        midi.transpose(-alter.value)
                    midi.accidental.force_hide = True

        if self.previous_leaf and self.previous_leaf.chord_field:
            list(self.previous_leaf.chord_field)
            previous_slides_types = [
                slide.type for slide in get_slides(
                    self.previous_leaf.chord_field.chords[0])
            ]
            if 'start' in previous_slides_types:
                try:
                    self.chord.add_slide('stop')
                except AttributeError:
                    self.chord_field.chords[0].add_slide('stop')
        if self.next_leaf is None:
            grace = TreeChord(midis=self.midi_generator.midi_range[1])
            grace.add_slide('stop')
            chord_field.chords[-1].add_grace_chords([grace], mode='post')

        chord_field.chords[0].add_slide('start')
Beispiel #9
0
 def implement(self, chord, beat):
     output = super().implement(chord, beat)
     output[0].add_child(Notehead('x'))
     return output
Beispiel #10
0
 def implement(self, chord):
     chord.add_child(Notehead('square'))
     return [chord]
Beispiel #11
0
 def add_notehead(self, val, **kwargs):
     self.add_notehead_object(Notehead(val, **kwargs))
Beispiel #12
0
 def notehead(self, val):
     if val is not None and not isinstance(val, Notehead):
         val = Notehead(val)
     self._note_head = val