def test_can_handle_multiple_rests_in_sequence(self): rhythm = [ Beat(duration=1), Beat(duration=1, rest=True), Beat(duration=1, rest=True), Beat(duration=1), ] pattern = make_single_position_pattern(length=2) notes = apply_rhythm(pattern, rhythm) self.assertEqual(4, len(notes)) self.assertEqual( Note(position=pattern[0][0], duration=Beat(1), order=0, elapsed_beats=Beat(1)), notes[0]) self.assertEqual( Note(position=None, duration=Beat(1, rest=True), order=1, elapsed_beats=Beat(2)), notes[1]) self.assertEqual( Note(position=None, duration=Beat(1, rest=True), order=2, elapsed_beats=Beat(3)), notes[2]) self.assertEqual( Note(position=pattern[1][0], duration=Beat(1), order=3, elapsed_beats=Beat(4)), notes[3])
def test_can_apply_rhythm_to_chords_and_individual_notes(self): pattern = [ [ FretPosition(string=6, fret=1), FretPosition(string=5, fret=3), ], [FretPosition(string=6, fret=0)], ] rhythm = [ Beat(duration=1), Beat(duration=1), ] notes = apply_rhythm(pattern, rhythm) self.assertEqual(3, len(notes)) self.assertEqual( Note(position=pattern[0][0], duration=Beat(1), order=0, elapsed_beats=Beat(1)), notes[0]) self.assertEqual( Note(position=pattern[0][1], duration=Beat(1), order=0, elapsed_beats=Beat(1)), notes[1]) self.assertEqual( Note(position=pattern[1][0], duration=Beat(1), order=1, elapsed_beats=Beat(2)), notes[2])
def test_rhythm_is_repeated_when_shorter_than_pattern(self): rhythm = [ Beat(duration=1), ] pattern = make_single_position_pattern(length=4) notes = apply_rhythm(pattern, rhythm) self.assertEqual(4, len(notes)) self.assertEqual( Note(position=pattern[0][0], duration=Beat(1), order=0, elapsed_beats=Beat(1)), notes[0]) self.assertEqual( Note(position=pattern[1][0], duration=Beat(1), order=1, elapsed_beats=Beat(2)), notes[1]) self.assertEqual( Note(position=pattern[2][0], duration=Beat(1), order=2, elapsed_beats=Beat(3)), notes[2]) self.assertEqual( Note(position=pattern[3][0], duration=Beat(1), order=3, elapsed_beats=Beat(4)), notes[3])
def test_rest_beats_are_added_to_sequence_and_ignored_by_pick_pattern( self): rhythm = [ Beat(duration=1), Beat(duration=1, rest=True), Beat(duration=1), ] pattern = make_single_position_pattern(length=2) notes = apply_rhythm(pattern, rhythm) self.assertEqual(3, len(notes)) self.assertEqual( Note(position=pattern[0][0], duration=Beat(1), order=0, elapsed_beats=Beat(1)), notes[0]) self.assertEqual( Note(position=None, duration=Beat(1, rest=True), order=1, elapsed_beats=Beat(2)), notes[1]) self.assertEqual( Note(position=pattern[1][0], duration=Beat(1), order=2, elapsed_beats=Beat(3)), notes[2])
def test_can_apply_half_beats(self): rhythm = [ Beat(duration=1, division=2), Beat(duration=1), Beat(duration=1, division=2), Beat(duration=1), ] pattern = make_single_position_pattern(length=4) notes = apply_rhythm(pattern, rhythm) self.assertEqual(4, len(notes)) self.assertEqual( Note(position=pattern[0][0], duration=Beat(1, 2), order=0, elapsed_beats=Beat(1, 2)), notes[0]) self.assertEqual( Note(position=pattern[1][0], duration=Beat(1), order=1, elapsed_beats=Beat(3, 4)), notes[1]) self.assertEqual( Note(position=pattern[2][0], duration=Beat(1, 2), order=2, elapsed_beats=Beat(5, 4)), notes[2]) self.assertEqual( Note(position=pattern[3][0], duration=Beat(1), order=3, elapsed_beats=Beat(6, 4)), notes[3])
def test_can_apply_triplets(self): rhythm = [ Beat(duration=1, division=12), Beat(duration=1, division=12), Beat(duration=1, division=12), Beat(duration=1), Beat(duration=1, division=12), Beat(duration=2, division=12), Beat(duration=1), ] pattern = make_single_position_pattern(length=7) notes = apply_rhythm(pattern, rhythm) self.assertEqual(7, len(notes)) self.assertEqual( Note(position=pattern[0][0], duration=Beat(1, 12), order=0, elapsed_beats=Beat(1, 12)), notes[0]) self.assertEqual( Note(position=pattern[1][0], duration=Beat(1, 12), order=1, elapsed_beats=Beat(2, 12)), notes[1]) self.assertEqual( Note(position=pattern[2][0], duration=Beat(1, 12), order=2, elapsed_beats=Beat(3, 12)), notes[2]) self.assertEqual( Note(position=pattern[3][0], duration=Beat(1), order=3, elapsed_beats=Beat(2, 4)), notes[3]) self.assertEqual( Note(position=pattern[4][0], duration=Beat(1, 12), order=4, elapsed_beats=Beat(7, 12)), notes[4]) self.assertEqual( Note(position=pattern[5][0], duration=Beat(2, 12), order=5, elapsed_beats=Beat(3, 4)), notes[5]) self.assertEqual( Note(position=pattern[6][0], duration=Beat(1), order=6, elapsed_beats=Beat(4)), notes[6])
def test_single_rest_returned_if_all_beats_are_rests(self): rhythm = [ Beat(duration=1, rest=True), Beat(duration=1000, rest=True), Beat(duration=1, rest=True), ] pattern = make_single_position_pattern(length=4) notes = apply_rhythm(pattern, rhythm) self.assertEqual(1, len(notes)) self.assertEqual( Note(position=None, duration=Beat(4, rest=True), order=0, elapsed_beats=Beat(4)), notes[0])
def test_rhythm_is_shortened_when_longer_than_pattern(self): rhythm = [ Beat(duration=1), Beat(duration=1), Beat(duration=1), Beat(duration=1), ] pattern = make_single_position_pattern(length=1) notes = apply_rhythm(pattern, rhythm) self.assertEqual(1, len(notes)) self.assertEqual( Note(position=pattern[0][0], duration=Beat(1), order=0, elapsed_beats=Beat(1)), notes[0])
def test_can_can_apply_two_beats(self): rhythm = [ Beat(duration=2), Beat(duration=1), ] pattern = make_single_position_pattern(length=2) notes = apply_rhythm(pattern, rhythm) self.assertEqual(2, len(notes)) self.assertEqual( Note(position=pattern[0][0], duration=Beat(2), order=0, elapsed_beats=Beat(2)), notes[0]) self.assertEqual( Note(position=pattern[1][0], duration=Beat(1), order=1, elapsed_beats=Beat(3)), notes[1])
def test_can_apply_sixteenth_notes(self): rhythm = [ Beat(duration=1, division=16), Beat(duration=1, division=16), Beat(duration=1, division=16), Beat(duration=1, division=16), Beat(duration=1), ] pattern = make_single_position_pattern(length=5) notes = apply_rhythm(pattern, rhythm) self.assertEqual(5, len(notes)) self.assertEqual( Note(position=pattern[0][0], duration=Beat(1, 16), order=0, elapsed_beats=Beat(1, 16)), notes[0]) self.assertEqual( Note(position=pattern[1][0], duration=Beat(1, 16), order=1, elapsed_beats=Beat(2, 16)), notes[1]) self.assertEqual( Note(position=pattern[2][0], duration=Beat(1, 16), order=2, elapsed_beats=Beat(3, 16)), notes[2]) self.assertEqual( Note(position=pattern[3][0], duration=Beat(1, 16), order=3, elapsed_beats=Beat(4, 16)), notes[3]) self.assertEqual( Note(position=pattern[4][0], duration=Beat(1), order=4, elapsed_beats=Beat(2, 4)), notes[4])