def test_normalise_note_durations_keeps_existing_ties(self): position = FretPosition(string=3, fret=1) notes = [ Note(order=0, position=position, duration=Beat(1, 12), elapsed_beats=Beat(1, 12)), Note(order=1, position=position, duration=Beat(1, 12, tie=True), elapsed_beats=Beat(2, 12)), Note(order=2, position=position, duration=Beat(1, 12), elapsed_beats=Beat(3, 12)), ] result = normalise_note_durations(notes) expected = [ Note(order=0, position=position, duration=Beat(1, 12), elapsed_beats=Beat(1, 12)), Note(order=1, position=position, duration=Beat(1, 12, tie=True), elapsed_beats=Beat(2, 12)), Note(order=2, position=position, duration=Beat(1, 12), elapsed_beats=Beat(3, 12)), ] self.assertEqual(expected, result)
def test_hammer_on_tie_is_kept_on_first_note(self): position = FretPosition(string=3, fret=1) notes = [ Note(order=0, position=position, duration=Beat(3), elapsed_beats=Beat(3), slur=constants.HAMMER_ON), Note(order=1, position=position, duration=Beat(1), elapsed_beats=Beat(4)), ] result = normalise_note_durations(notes) expected = [ Note(order=0, position=position, duration=Beat(1, 2), elapsed_beats=Beat(1, 2), slur=constants.HAMMER_ON), Note(order=1, position=position, duration=Beat(1, 4, tie=True), elapsed_beats=Beat(3, 4)), Note(order=2, position=position, duration=Beat(1, 4), elapsed_beats=Beat(1, 1)), ] self.assertEqual(expected, result)
def test_split_beats_are_in_ascending_order_if_not_at_start_of_bar(self): position = FretPosition(string=3, fret=1) notes = [ Note(order=0, position=position, duration=Beat(1), elapsed_beats=Beat(1)), Note(order=1, position=position, duration=Beat(3), elapsed_beats=Beat(4)), ] result = normalise_note_durations(notes) expected = [ Note(order=0, position=position, duration=Beat(1, 4), elapsed_beats=Beat(1, 4)), Note(order=1, position=position, duration=Beat(1, 4), elapsed_beats=Beat(2, 4)), Note(order=2, position=position, duration=Beat(2, 4, tie=True), elapsed_beats=Beat(1, 1)), ] self.assertEqual(expected, result)
def test_ties_are_not_added_to_rests(self): position = FretPosition(string=3, fret=1) notes = [ Note(order=0, position=None, duration=Beat(3, rest=True), elapsed_beats=Beat(3)), Note(order=1, position=position, duration=Beat(1), elapsed_beats=Beat(4)), ] result = normalise_note_durations(notes) expected = [ Note(order=0, position=None, duration=Beat(1, 2, rest=True), elapsed_beats=Beat(1, 2)), Note(order=1, position=None, duration=Beat(1, 4, rest=True), elapsed_beats=Beat(3, 4)), Note(order=2, position=position, duration=Beat(1, 4), elapsed_beats=Beat(1, 1)), ] self.assertEqual(expected, result)
def test_odd_length_quarter_note_is_split(self): position = FretPosition(string=3, fret=1) notes = [ Note(order=0, position=position, duration=Beat(3), elapsed_beats=Beat(3)), Note(order=1, position=position, duration=Beat(1), elapsed_beats=Beat(4)), ] result = normalise_note_durations(notes) expected = [ Note(order=0, position=position, duration=Beat(1, 2), elapsed_beats=Beat(1, 2)), Note(order=1, position=position, duration=Beat(1, 4, tie=True), elapsed_beats=Beat(3, 4)), Note(order=2, position=position, duration=Beat(1, 4), elapsed_beats=Beat(1, 1)), ] self.assertEqual(expected, result)
def to_vextab(exercise: Sequence) -> str: """ http://vexflow.com/vextab/tutorial.html """ split = normalise_note_durations(exercise.notes) elements = make_elements(split) element_groups = split_staves(elements) staves = [] for element_group in element_groups: tab = " ".join(element_group) show_notation = 'false' if '^3^' in tab: show_notation = 'true' tabstave = (f'tabstave notation={show_notation}\n' f'notes {tab}') staves.append(tabstave) return "\n\n".join(staves)