Пример #1
0
    def test_close_polyphonic_context(self):

        context = midi2lily.PolyphonicContext()

        # voice 1
        melody_expression = midi2lily.CompoundExpression()

        melody_expression.add(
            midi2lily.Note(midi2lily.Pitch(72),
                           midi2lily.Duration(Fraction(4, 4))))

        context.add(melody_expression)

        # voice 2 (unbalanced)
        rythm_expression = midi2lily.CompoundExpression()

        rythm_expression.add(
            midi2lily.Note(midi2lily.Pitch(64),
                           midi2lily.Duration(Fraction(2, 4))))

        context.add(rythm_expression)

        # before closing the context is unbalanced
        self.assertTrue(not context.is_balanced())

        context.close()

        # after closing, the context is balanced by adding a rest
        self.assertTrue(context.is_balanced())
        self.assertEqual(str(context), "<<\n{\nc''1 }\n\\\\\n{\ne'2 r2 }\n>>")
Пример #2
0
    def test_polyphonic_context_is_balanced(self):

        context = midi2lily.PolyphonicContext()

        # voice 1
        melody_expression = midi2lily.CompoundExpression()

        melody_expression.add(
            midi2lily.Note(midi2lily.Pitch(72),
                           midi2lily.Duration(Fraction(4, 4))))

        context.add(melody_expression)

        # voice 2
        rythm_expression = midi2lily.CompoundExpression()

        rythm_expression.add(
            midi2lily.Note(midi2lily.Pitch(64),
                           midi2lily.Duration(Fraction(2, 4))))
        rythm_expression.add(
            midi2lily.Note(midi2lily.Pitch(67),
                           midi2lily.Duration(Fraction(2, 4))))

        context.add(rythm_expression)

        self.assertTrue(context.is_balanced())
Пример #3
0
    def test_quantize_input(self):

        # unquantized inputs (quarters note not exactly in time)
        # (ticks per beat = 12)
        midi_notes = [
            midi2lily.MidiNote(0, 11, 60),
            midi2lily.MidiNote(11, 24, 62),
            midi2lily.MidiNote(24, 37, 64),
            midi2lily.MidiNote(37, 48, 65),
            midi2lily.MidiNote(48, 61, 67),
            midi2lily.MidiNote(61, 73, 69),
            midi2lily.MidiNote(73, 85, 71),
            midi2lily.MidiNote(85, 96, 72)
        ]

        context = midi2lily.ParseContext()
        context.time_signature = midi2lily.TimeSignature(4, 4)
        context.ticks_per_beat = 12
        context.staff = midi2lily.Staff('\\new:')

        # Setup quantizing to 16th note (or 3 ticks)
        quantize_duration = midi2lily.Duration(Fraction(1, 16))
        quantize_ticks = quantize_duration.get_ticks(12, 4)

        file = self.build_file(midi_notes, context, quantize_ticks)

        self.assertEqual(str(file),
                         self.get_expected('test-midi-files/scale.txt'))
Пример #4
0
    def test_duration_crossing_measure2(self):
        # 1/2 note rest...
        rest = midi2lily.Rest(midi2lily.Duration(Fraction(1, 2)))

        # ...rendered in 4/4 time at beat 3 of first measure...
        context = midi2lily.RenderContext()
        context.time_signature = midi2lily.TimeSignature(4, 4)
        context.position = Fraction(3, 4)

        # should be rendered as tied 1/4 note durations when crossing the measure
        self.assertEqual(rest.__str__(context), "r4 | r4")
Пример #5
0
    def test_quantize_prevent_notes_without_duration(self):

        # unquantized midi quarter note (should run from 0 to 12)
        # (ticks per beat = 12)
        midi_note = midi2lily.MidiNote(1, 2, 60)

        # Setup quantizing to 1/2 note (or 24 ticks)
        quantize_duration = midi2lily.Duration(Fraction(1, 2))
        quantize_ticks = quantize_duration.get_ticks(12, 4)

        midi_note.quantize(quantize_ticks)

        self.assertEqual(midi_note.start, 0)
        self.assertEqual(midi_note.end, 24)
Пример #6
0
    def test_quantize(self):

        # unquantized midi quarter note (should run from 0 to 12)
        # (ticks per beat = 12)
        midi_note = midi2lily.MidiNote(1, 11, 60)

        # Setup quantizing to 16th note (or 3 ticks)
        quantize_duration = midi2lily.Duration(Fraction(1, 16))
        quantize_ticks = quantize_duration.get_ticks(12, 4)

        midi_note.quantize(quantize_ticks)

        self.assertEqual(midi_note.start, 0)
        self.assertEqual(midi_note.end, 12)
Пример #7
0
 def test_get_ticks(self):
     duration = midi2lily.Duration(Fraction(1, 16))
     self.assertEqual(duration.get_ticks(12, 4), 3)