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'))
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'))
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'))
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'))
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'))
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'))
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'))
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'))