Example #1
0
    def test_chords(self):
        midi_notes = [
            # c e g
            midi2lily.MidiNote(0, 1, 60),
            midi2lily.MidiNote(0, 1, 64),
            midi2lily.MidiNote(0, 1, 67),
            # f a c
            midi2lily.MidiNote(1, 2, 65),
            midi2lily.MidiNote(1, 2, 69),
            midi2lily.MidiNote(1, 2, 72),
            # g b d
            midi2lily.MidiNote(2, 3, 67),
            midi2lily.MidiNote(2, 3, 71),
            midi2lily.MidiNote(2, 3, 74),
            # c e g
            midi2lily.MidiNote(3, 4, 72),
            midi2lily.MidiNote(3, 4, 76),
            midi2lily.MidiNote(3, 4, 79),
        ]

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

        file = self.build_file(midi_notes, context)

        self.assertEqual(str(file),
                         self.get_expected('test-midi-files/chords.txt'))
Example #2
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'))
Example #3
0
    def test_c(self):
        midi_notes = [midi2lily.MidiNote(0, 1, 60)]

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

        file = self.build_file(midi_notes, context)

        self.assertEqual(str(file), self.get_expected('test-midi-files/c.txt'))
Example #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")
Example #5
0
    def test_2_voices(self):
        midi_notes = [
            midi2lily.MidiNote(0, 2, 60),
            midi2lily.MidiNote(0, 1, 64),
            midi2lily.MidiNote(1, 2, 67)
        ]

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

        file = self.build_file(midi_notes, context)

        self.assertEqual(str(file),
                         self.get_expected('test-midi-files/polyphonic.txt'))
Example #6
0
    def test_four_voices_in_polyphonic_contexts_with_rests(self):

        midi_notes = [
            # voice 1
            midi2lily.MidiNote(0, 4, 60),
            # voice 2
            midi2lily.MidiNote(1, 4, 64),
            # voice 3
            midi2lily.MidiNote(2, 4, 67),
            midi2lily.MidiNote(3, 4, 70)
        ]

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

        file = self.build_file(midi_notes, context)
        self.assertEqual(str(file),
                         self.get_expected('test-midi-files/polyphonic5.txt'))
Example #7
0
    def test_polyphonic_context_between_non_polyphonic_contexts(self):

        midi_notes = [
            midi2lily.MidiNote(0, 2, 72),
            midi2lily.MidiNote(0, 2, 64),
            midi2lily.MidiNote(2, 4, 71),
            midi2lily.MidiNote(2, 3, 67),
            midi2lily.MidiNote(3, 4, 65),
            midi2lily.MidiNote(4, 8, 72),
            midi2lily.MidiNote(4, 8, 64)
        ]

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

        file = self.build_file(midi_notes, context)
        self.assertEqual(str(file),
                         self.get_expected('test-midi-files/polyphonic2.txt'))
Example #8
0
    def test_scale(self):
        midi_notes = [
            midi2lily.MidiNote(0, 1, 60),
            midi2lily.MidiNote(1, 2, 62),
            midi2lily.MidiNote(2, 3, 64),
            midi2lily.MidiNote(3, 4, 65),
            midi2lily.MidiNote(4, 5, 67),
            midi2lily.MidiNote(5, 6, 69),
            midi2lily.MidiNote(6, 7, 71),
            midi2lily.MidiNote(7, 8, 72)
        ]

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

        file = self.build_file(midi_notes, context)

        self.assertEqual(str(file),
                         self.get_expected('test-midi-files/scale.txt'))
Example #9
0
    def test_two_voices_with_rests(self):

        midi_notes = [
            # voice 1
            midi2lily.MidiNote(0, 4, 60),
            midi2lily.MidiNote(4, 8, 60),
            # voice 2
            midi2lily.MidiNote(1, 2, 64),
            midi2lily.MidiNote(2, 3, 72),
            midi2lily.MidiNote(3, 4, 64),
            midi2lily.MidiNote(5, 6, 64),
            midi2lily.MidiNote(6, 7, 67),
            midi2lily.MidiNote(7, 8, 64),
        ]

        context = midi2lily.ParseContext()
        context.time_signature = midi2lily.TimeSignature(4, 4)
        context.ticks_per_beat = 2
        context.staff = midi2lily.Staff(':1')

        file = self.build_file(midi_notes, context)
        self.assertEqual(str(file),
                         self.get_expected('test-midi-files/polyphonic6.txt'))
Example #10
0
 def test78(self):
     signature = midi2lily.TimeSignature(7, 8)
     self.assertEqual(str(signature), '\\time 7/8')
Example #11
0
 def test34(self):
     signature = midi2lily.TimeSignature(3, 4)
     self.assertEqual(str(signature), '\\time 3/4')
Example #12
0
 def testC(self):
     signature = midi2lily.TimeSignature(4, 4)
     self.assertEqual(str(signature), '\\time 4/4')