コード例 #1
0
 def test_offset(self):
     p = self.part
     p.add_chord(TreeChord((60, 61), quarter_duration=1))
     p.add_chord(TreeChord(62, quarter_duration=1.75))
     p.add_chord(TreeChord(0, quarter_duration=1.25))
     result = [0, 1, 2.75]
     self.assertEqual([chord.offset for chord in p.chords], result)
コード例 #2
0
 def test_3(self):
     chord = TreeChord(quarter_duration=4, midis=[60])
     chord.staff_number = 1
     chord.staff_number = 2
     expected = 2
     actual = chord.staff_number
     self.assertEqual(expected, actual)
コード例 #3
0
 def test_5(self):
     b = q.TreeBeat(max_division=7, forbidden_divisions=[])
     b.add_chord(TreeChord((60, 61), quarter_duration=0.5))
     b.add_chord(TreeChord((60, 61), quarter_duration=0.2))
     b.add_chord(TreeChord((60, 61), quarter_duration=0.3))
     b.quantize()
     self.assertEqual([chord.quarter_duration for chord in b.chords],
                      [Fraction(1, 2), Fraction(1, 6), Fraction(1, 3)])
コード例 #4
0
 def test_1(self):
     self.score.add_measure()
     self.score.add_part()
     self.score.add_chord(1, 1, TreeChord())
     self.score.add_chord(1, 1, TreeChord(quarter_duration=0))
     result_path = path + '_test_1'
     self.score.write(path=result_path)
     TestScore().assert_template(result_path=result_path)
コード例 #5
0
 def test_add_note(self):
     self.score.add_chord(1, 1, TreeChord(0, 1))
     self.score.add_chord(1, 1, TreeChord(0, quarter_duration=1))
     self.score.add_chord(1, 1, TreeChord(61, quarter_duration=2))
     self.score.finish()
     result_path = path + '_test_add_note'
     self.score.write(path=result_path)
     TestScore().assert_template(result_path=result_path)
コード例 #6
0
class Test(XMLTestCase):
    def setUp(self) -> None:
        self.chord = TreeChord()

    def test_1(self):
        self.chord.add_words('1')
        copied = self.chord.__deepcopy__()
        print(copied._current_children[0]._current_children[0].__dict__)
コード例 #7
0
    def test_previous_chord(self):
        p = self.part
        p.add_chord(TreeChord((60, 61), quarter_duration=1))
        p.add_chord(TreeChord(62, quarter_duration=2))
        p.add_chord(TreeChord(0, quarter_duration=1))

        self.assertEqual(p.chords[0].previous_in_part_voice, None)
        self.assertEqual(id(p.chords[1].previous_in_part_voice), id(p.chords[0]))
        self.assertEqual(id(p.chords[2].previous_in_part_voice), id(p.chords[1]))
コード例 #8
0
 def simple_format(self):
     output = super().simple_format
     if self.show_last_note:
         if self.direction == 'up':
             grace_chord = TreeChord(midis=self.falling_field.min_midi)
         else:
             grace_chord = TreeChord(midis=self.rising_field.max_midi)
         output.chords[-1].add_grace_chords(grace_chord, mode='post')
     return output
コード例 #9
0
 def test_split_beats(self):
     p = self.part
     p.add_chord(TreeChord((60, 61), quarter_duration=1))
     p.add_chord(TreeChord(62, quarter_duration=1.75))
     p.add_chord(TreeChord(0, quarter_duration=1.25))
     p.finish()
     # p._add_chords_to_beats()
     # p._split_chords_beatwise()
     result = [0, Fraction(1, 1), Fraction(2, 1), Fraction(11, 4), Fraction(3, 1)]
     self.assertEqual([chord.offset for chord in p.chords], result)
コード例 #10
0
 def test_2(self):
     measure = self.score.add_measure()
     self.score.add_part()
     chord = TreeChord(quarter_duration=4, midis=[60])
     measure.get_part(1).add_chord(chord)
     chord.staff_number = 2
     measure.get_part(1).staves = 2
     xml_path = path + '_test_2.xml'
     self.score.write(xml_path)
     self.assertCompareFiles(xml_path)
コード例 #11
0
    def test_split_chord(self):
        b = TreeBeat()
        p = TreePart('one')
        chord = TreeChord((60, 62), quarter_duration=1)
        m = TreeMeasure()
        m.add_child(p)
        p.add_chord(chord)
        b.add_chord(chord)
        split = chord.split([1, 0.5, 3])

        result = [Fraction(2, 9), Fraction(1, 9), Fraction(2, 3)]
        self.assertEqual([chord.quarter_duration for chord in split], result)
コード例 #12
0
    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)
コード例 #13
0
class Test(TestCase):
    def setUp(self) -> None:
        self.chord = TreeChord()

    def test_1(self):
        self.chord.add_midi(60)
        steps = [
            step.value for note in self.chord.notes
            for pitch in note.get_children_by_type(Pitch)
            for step in pitch.get_children_by_type(Step)
        ]
        self.assertEqual(steps, ['B', 'C'])
コード例 #14
0
 def test_5(self):
     self.score.add_measure()
     self.score.add_part()
     self.score.get_measure(1).get_part(1).add_chord(TreeChord(
         quarter_duration=4, midis=60),
                                                     staff_number=1)
     self.score.get_measure(1).get_part(1).add_chord(TreeChord(
         quarter_duration=4, midis=70),
                                                     staff_number=2)
     xml_path = path + '_test_5.xml'
     self.score.write(path=xml_path)
     self.assertCompareFiles(xml_path)
コード例 #15
0
    def test_rest(self):
        with self.assertRaises(ValueError):
            TreeChord((0, 61), quarter_duration=2)

        chord = TreeChord(0, quarter_duration=2)
        tree_note = chord.notes[0]
        tree_note.update_duration(divisions=1)

        result = '''<note>
  <rest/>
  <duration>2</duration>
</note>
'''
        self.assertEqual(tree_note.to_string(), result)
コード例 #16
0
    def test_split_beats_2(self):
        m = TreeMeasure(time=(3, 4))
        p = TreePart(id='one')
        p.max_division = 8
        p.forbidden_divisions = []
        m.add_child(p)
        # p.set_beats()

        p.add_chord(TreeChord(60, quarter_duration=1.4))
        p.add_chord(TreeChord(60, quarter_duration=1.6))
        # p._add_chords_to_beats()
        # p._split_chords_beatwise()
        p.finish()
        result = [Fraction(1, 1), Fraction(2, 5), Fraction(3, 5), Fraction(1, 1)]
        self.assertEqual([chord.quarter_duration for chord in p.chords], result)
コード例 #17
0
    def test_1(self):
        sf = SimpleFormat()
        sf.add_chord(TreeChord())
        sf.add_chord(TreeChord(quarter_duration=0))
        v = sf.to_stream_voice(1)
        v.add_to_score(self.score)
        chord = self.score.get_measure(1).get_part(1).get_staff(1).get_voice(1).chords[1]
        self.score.fill_with_rest()
        self.score.preliminary_adjoin_rests()
        self.score.add_beats()
        chord.remove_from_score()

        xml_path = path + '_test_1.xml'
        self.score.write(path=xml_path)
        self.assertCompareFiles(xml_path)
コード例 #18
0
    def test_quantize(self):
        m = TreeMeasure(time=(4, 4))
        p = TreePart(id='one')
        p.max_division = 8
        p.forbidden_divisions = []
        m.add_child(p)
        p.add_chord(TreeChord(60, quarter_duration=1))
        p.add_chord(TreeChord(60, quarter_duration=1.2))
        p.add_chord(TreeChord(60, quarter_duration=0.3))
        p.add_chord(TreeChord(60, quarter_duration=0.2))
        p.add_chord(TreeChord(60, quarter_duration=1.3))
        p.finish()

        result = [Fraction(1, 1), Fraction(1, 1), Fraction(1, 6), Fraction(1, 3), Fraction(1, 6), Fraction(1, 3),
                  Fraction(1, 1)]
        self.assertEqual([chord.quarter_duration for chord in p.chords], result)
コード例 #19
0
 def test_3(self):
     midis = [(61.0, 63), 61.0, 0, 62.0, 61, 61, 61, (62, 61)]
     measure_number = 1
     for midi in midis:
         chord = TreeChord(midi, quarter_duration=0.5)
         chord.add_lyric([m.value for m in chord.midis])
         self.score.add_chord(measure_number, 1, chord)
         remaining_duration = self.score.get_measure(
             measure_number).get_part(1).get_staff(1).get_voice(
                 1).remaining_duration
         if remaining_duration == 0:
             self.score.add_measure()
             measure_number += 1
     self.score.accidental_mode = 'modern'
     result_path = path + '_test_3'
     self.score.write(path=result_path)
     TestScore().assert_template(result_path=result_path)
コード例 #20
0
ファイル: fractalmusic.py プロジェクト: alexgorji/musurgia
 def chord(self):
     if self.chord_field is None and self._simple_format is None:
         if self._chord is None:
             self._chord = TreeChord(quarter_duration=self.quarter_duration,
                                     midis=[self.midi_value])
         else:
             self._chord.quarter_duration = self.quarter_duration
         return self._chord
     else:
         return None
コード例 #21
0
    def test_split_quantize(self):
        s = TreeScoreTimewise()
        m = TreeMeasure(time=(3, 4))
        s.add_measure(m)
        s.add_part()
        # m.add_child(p)

        chord1 = s.add_chord(1, 1, TreeChord((71, 72), quarter_duration=1.3))
        l1 = Lyric()
        l1.add_child(Text('bla'))
        chord1.add_child(l1)
        s.add_chord(1, 1, TreeChord((60, 63, 65), quarter_duration=0.6))
        s.add_chord(1, 1, TreeChord(60, quarter_duration=1.1))
        s.finish()

        # print(s.to_string())
        s.write(path=path)

        result = '''<part id="one">
コード例 #22
0
    def test_1(self):
        midis = [61, 61, 62, 60, 63, 64, 65, 61]
        for midi in midis:
            self.score.add_chord(1, 1, TreeChord(midi, quarter_duration=0.5))

        self.score.get_measure(1).get_part(1)
        self.score.finish()

        result_path = path + '_test_1'
        self.score.write(path=result_path)
        TestScore().assert_template(result_path=result_path)
コード例 #23
0
 def test_2(self):
     midis = [
         60.0, 60.5, 61.0, 62.5, 64.0, 66.0, 68.0, 69.5, 71.0, 71.5, 72.0,
         71.5, 71.0, 69.5, 68.0, 66.0, 64.0, 62.5, 61.0, 60.5
     ]
     measure_number = 1
     for midi in midis:
         chord = TreeChord(midi, quarter_duration=0.5)
         chord.add_lyric(midi)
         self.score.add_chord(measure_number, 1, chord)
         remaining_duration = self.score.get_measure(
             measure_number).get_part(1).get_staff(1).get_voice(
                 1).remaining_duration
         if remaining_duration == 0:
             self.score.add_measure()
             measure_number += 1
     self.score.accidental_mode = 'modern'
     result_path = path + '_test_2'
     self.score.write(path=result_path)
     TestScore().assert_template(result_path=result_path)
コード例 #24
0
    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)
コード例 #25
0
 def test_1(self):
     fm = FractalMusic(tempo=60,
                       quarter_duration=10,
                       proportions=(1, 2, 3),
                       tree_permutation_order=(3, 1, 2))
     fm.add_layer()
     midis = [B(4), A(4, 'b'), C(4, '#'), A(3), F(4)]
     fm.get_children()[0].add_layer()
     for leaf, midi in zip(fm.traverse_leaves(), midis):
         leaf.set_chord(TreeChord(midi))
     score = fm.get_score(show_fractal_orders=True)
     xml_path = path + '_test_.xml'
     score.write(path=xml_path)
コード例 #26
0
    def _generate_chords(self):
        if self._quarter_durations == [] and self._midis == []:
            pass
        else:
            self._chords = []
            for i in range(len(self._quarter_durations) - len(self._midis)):
                self._midis.append(71)

            for i in range(len(self._midis) - len(self._quarter_durations)):
                self._quarter_durations.append(1)

            for d, m in zip(self._quarter_durations, self._midis):
                self._chords.append(TreeChord(m, d))
コード例 #27
0
    def test_chord_midi(self):
        chord = TreeChord(Midi(63, accidental = Accidental(mode='sharp')), quarter_duration=2)
        tree_note = chord.notes[0]
        tree_note.update_duration(divisions=1)

        result = '''<note>
  <pitch>
    <step>D</step>
    <alter>1</alter>
    <octave>4</octave>
  </pitch>
  <duration>2</duration>
</note>
'''
        self.assertEqual(tree_note.to_string(), result)
コード例 #28
0
ファイル: test_clefs.py プロジェクト: alexgorji/musicscore
 def test_1(self):
     sf = SimpleFormat()
     for clef in ALL_CLEFS:
         if clef not in [SUPER_HIGH_TREBLE_CLEF, SUPER_LOW_BASS_CLEF]:
             for midi in clef.optimal_range:
                 if not midi:
                     if clef.optimal_range.index(midi) == 0:
                         midi = G(0)
                     else:
                         midi = C(8)
                 sf.add_chord(TreeChord(quarter_duration=2, midis=[midi]))
             sf.chords[-2].add_clef(clef)
     xml = path + '_test_1.xml'
     sf.to_stream_voice().add_to_score(self.score)
     self.score.finish()
     self.score.to_partwise()
     self.score.write(xml)
コード例 #29
0
    def _get_next_chord(self):
        next_chord = None
        next_midi = self._get_next_midi()
        next_duration = self._get_next_duration()

        if self.chord_generator:
            next_chord = self.chord_generator.__next__()

        if next_chord:
            if next_duration is not None:
                next_chord.quarter_duration = next_duration
            if next_midi is not None:
                next_chord.midis = next_midi
        else:
            if next_duration is None:
                raise NoNextChordError('next_duration is None!')
            if next_midi is None:
                raise NoNextChordError('next_midi is None!')
            next_chord = TreeChord(quarter_duration=next_duration, midis=next_midi)
        if self._chords is None:
            self._chords = []
        self._chords.append(next_chord)
        return next_chord
コード例 #30
0
    def _check_quarter_duration(self):
        if self._chords:
            delta = sum([chord.quarter_duration for chord in self._chords]) - self.quarter_duration
            if delta > 0:
                if self.long_ending_mode == 'self_extend':
                    if self.parent:
                        try:
                            next_child = self.parent.children[self.parent.children.index(self) + 1]
                            next_child._position = delta
                        except IndexError:
                            pass
                    try:
                        self.quarter_duration += delta
                    except ParentSetQuarterDurationError:
                        self.children[-1].quarter_duration += delta
                elif self.long_ending_mode == 'cut':
                    self._chords[-1].quarter_duration -= delta
                elif self.long_ending_mode in ['omit', 'omit_and_add_rest', 'omit_and_stretch']:
                    self._chords.pop()
                    new_delta = self.quarter_duration - sum([chord.quarter_duration for chord in self._chords])
                    if self.long_ending_mode == 'omit_and_add_rest':
                        new_chord = TreeChord(midis=0, quarter_duration=new_delta)
                        new_chord.zero_mode = 'remove'
                        self._chords.append(new_chord)
                    elif self.long_ending_mode == 'omit_and_stretch':
                        self._chords[-1].quarter_duration += new_delta
                    else:
                        self.quarter_duration -= new_delta
                else:
                    raise LongEndingError(delta)

            elif delta < 0:
                if self.short_ending_mode == 'self_shrink':
                    self.quarter_duration += delta
                elif self.short_ending_mode == 'add_rest':
                    new_chord = TreeChord(midis=0, quarter_duration=-delta)
                    new_chord.zero_mode = 'remove'
                    self._chords.append(new_chord)
                elif self.short_ending_mode == 'stretch':
                    self._chords[-1].quarter_duration -= delta
                else:
                    raise ShortEndingError(delta)
            else:
                pass