Beispiel #1
0
    def __deepcopy__(self, memodict={}):
        new_chord = TreeChord(quarter_duration=self.quarter_duration,
                              zero_mode=self.zero_mode)
        new_chord.midis = [midi.__deepcopy__() for midi in self.midis]
        for child in self.get_children():
            if isinstance(child, Notations):
                copied_notations = Notations()
                for grand_child in child.get_children():
                    copied_notations.add_child(grand_child)
                new_chord.add_child(copied_notations)
            else:
                new_chord.add_child(child)

        new_chord.is_adjoinable = self.is_adjoinable
        if self._flags:
            new_chord._flags = []
            for flag in self._flags:
                new_chord._flags.append(flag.__deepcopy__())

        new_chord._flags = self._flags
        new_chord._manual_type = self._manual_type
        new_chord._manual_staff_number = self._manual_staff_number
        new_chord.tie_orientation = self.tie_orientation

        for grace_chord in self.get_pre_grace_chords():
            new_chord.add_grace_chords(grace_chord.__deepcopy__())

        for grace_chord in self.get_post_grace_chords():
            new_chord.add_grace_chords(grace_chord.__deepcopy__(), 'post')
        return new_chord
Beispiel #2
0
    def test_1(self):
        fermata = Fermata()
        notations = Notations()
        notations.add_child(fermata)
        # print(notations.to_string())
        result = '''<notations>
  <fermata>normal</fermata>
</notations>
'''
        self.assertEqual(notations.to_string(), result)
Beispiel #3
0
    def test_1(self):
        notations = Notations()
        ornaments = notations.add_child(Ornaments())
        ornaments.add_child(Tremolo(4))
        ornaments.add_child(Turn())
        result = '''<notations>
  <ornaments>
    <tremolo type="single">4</tremolo>
    <turn slash="no"/>
  </ornaments>
</notations>
'''
        self.assertEqual(notations.to_string(), result)
Beispiel #4
0
    def _add_notations(self, notation):
        try:
            notations = self.get_children_by_type(Notations)[0]
        except IndexError:
            notations = self.add_child(Notations())

        notations.add_child(notation)
Beispiel #5
0
    def add_slur_object(self, slur):
        try:
            notations = self.get_children_by_type(Notations)[0]
        except IndexError:
            notations = self.add_child(Notations())

        notations.add_child(slur)
        return slur
Beispiel #6
0
    def add_notations_object(self, object):
        try:
            notations = self.get_children_by_type(Notations)[0]
        except IndexError:
            notations = self.add_child(Notations())

        notations.add_child(object)
        return object
Beispiel #7
0
    def add_fermata(self, value='normal', **kwargs):
        fermata = Fermata(value, **kwargs)
        try:
            notations = self.get_children_by_type(Notations)[0]
        except IndexError:
            notations = self.add_child(Notations())

        notations.add_child(fermata)
Beispiel #8
0
    def test_1(self):
        sf = SimpleFormat(quarter_durations=[1], midis=[(60, 64, 67, 70, 72)])
        n = sf.chords[0].add_child(Notations())
        n.add_child(Arpeggiate())

        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)
Beispiel #9
0
    def add_tremolo(self, number=3, **kwargs):

        try:
            notations = self.get_children_by_type(Notations)[0]
        except IndexError:
            notations = self.add_child(Notations())

        try:
            ornaments = notations.get_children_by_type(Ornaments)[0]
        except IndexError:
            ornaments = notations.add_child(Ornaments())

        ornaments.add_child(Tremolo(value=number, **kwargs))
Beispiel #10
0
    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)
Beispiel #11
0
    def add_articulation_object(self, articulation_object):

        try:
            notations = self.get_children_by_type(Notations)[0]
        except IndexError:
            notations = self.add_child(Notations())

        try:
            articulations = notations.get_children_by_type(Articulations)[0]
        except IndexError:
            articulations = notations.add_child(Articulations())

        articulations.add_child(articulation_object)
Beispiel #12
0
    def add_technical_object(self, technical_object):

        try:
            notations = self.get_children_by_type(Notations)[0]
        except IndexError:
            notations = self.add_child(Notations())

        try:
            technical = notations.get_children_by_type(Technical)[0]
        except IndexError:
            technical = notations.add_child(Technical())

        technical.add_child(technical_object)
Beispiel #13
0
    def add_tie(self, value):
        if value not in ('stop', 'start'):
            raise NotImplementedError(
                'value {} cannot be a tie value'.format(value))

        try:
            notations = self.get_children_by_type(Notations)[0]
        except IndexError:
            notations = self.add_child(Notations())

        if value == 'start' and 'start' not in self.tie_types:
            self.add_child(Tie('start'))
            notations.add_child(Tied('start',
                                     orientation=self.tie_orientation))

        elif value == 'stop' and 'stop' not in self.tie_types:
            self.add_child(Tie('stop'))
            notations.add_child(Tied('stop'))
Beispiel #14
0
    def test_1(self):
        notations = self.note.add_child(Notations())
        articulations = notations.add_child(Articulations())
        articulations.add_child(Accent())
        articulations.add_child(Staccato(relative_y=20))

        result = """<note>
  <pitch>
    <step>C</step>
    <octave>4</octave>
  </pitch>
  <duration>1</duration>
  <notations>
    <articulations>
      <accent/>
      <staccato relative-y="20"/>
    </articulations>
  </notations>
</note>
"""
        self.assertEqual(self.note.to_string(), result)
    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)
Beispiel #16
0
    def add_tuplet(self, type, number=1):
        normals = {
            3: 2,
            5: 4,
            6: 4,
            7: 4,
            9: 8,
            10: 8,
            11: 8,
            12: 8,
            13: 8,
            14: 8,
            15: 8
        }
        types = {8: '32nd', 4: '16th', 2: 'eighth'}
        actual_notes = self.parent_beat.best_div
        normal_notes = normals[actual_notes]
        normal_type = types[normal_notes / self.parent_beat.duration]
        if type != 'continue':
            try:
                notations = self.notations
            except AttributeError:
                notations = self.add_child(Notations())

            v = self.get_children_by_type(Voice)[0]
            if int(v.value) % 2 == 0:
                placement = 'below'
            else:
                placement = 'above'

            notations.add_child(
                Tuplet(type=type,
                       number=number,
                       bracket='yes',
                       placement=placement))

        tm = self.add_child(TimeModification())
        tm.add_child(ActualNotes(actual_notes))
        tm.add_child(NormalNotes(normal_notes))
        tm.add_child(NormalType(normal_type))
Beispiel #17
0
    def test_1(self):
        notations = self.note.add_child(Notations())
        technical = notations.add_child(Technical())
        hole = technical.add_child(Hole())
        hole.add_child(HoleClosed(value='no'))
        technical.add_child(SnapPizzicato(relative_y=20))

        result = """<note>
  <pitch>
    <step>C</step>
    <octave>4</octave>
  </pitch>
  <duration>1</duration>
  <notations>
    <technical>
      <hole>
        <hole-closed>no</hole-closed>
      </hole>
      <snap-pizzicato relative-y="20"/>
    </technical>
  </notations>
</note>
"""
        self.assertEqual(self.note.to_string(), result)
Beispiel #18
0
 def get_notations(self):
     try:
         notations = self.get_children_by_type(Notations)[0]
     except IndexError:
         notations = self.add_child(Notations())
     return notations