def parse_kern_item(item, note_system="base40", lineno=1, itemno=1): tokens = kern_tokenizer(item, lineno) if (not tokens['dur']) and ((not tokens['acciac']) or (not tokens['app'])): kern_error("Duration can't be NULL.", lineno) if (tokens['note'] and tokens['rest']): kern_error("A note can't have a pitch and a rest.", lineno) dur = int("".join(tokens['dur'])) dots = len(tokens['dot']) duration = music.calculate_duration(dur, dots) if tokens['note']: notename = "".join(tokens['note']) acc = "".join(tokens['acc']) name = parse_kern_note(notename, acc) note = Note(name, duration) note.articulations = tokens['art'] note.beams = tokens['beam'] note.octave = parse_kern_octave(notename, acc, lineno) note.code = music.string_to_code(notename[0], acc, note_system, note.octave) note.system = note_system note.type = "kern" return note elif tokens['rest']: wholeNote = not bool(tokens['rest'] or len(tokens['rest']) >= 1) return Rest(duration, wholeNote) else: kern_error("Kern data must have a note or rest.", lineno)
def test_calculate_duration_maxima_1(): assert music.calculate_duration("maxima", 1) == Fraction(12, 1)
def test_calculate_duration_longa_1(): assert music.calculate_duration("longa", 1) == Fraction(6, 1)
def test_calculate_duration_maxima_0(): assert music.calculate_duration("maxima", 0) == Fraction(8, 1)
def test_calculate_duration_brevis(): assert music.calculate_duration("brevis", 0) == Fraction(2, 1)
def test_calculate_duration_longa_0(): assert music.calculate_duration("longa", 0) == Fraction(4, 1)
def test_calculate_duration_0_1(): assert music.calculate_duration(0, 1) == Fraction(3, 1)
def test_calculate_duration_0_2(): assert music.calculate_duration(0, 2) == Fraction(7, 2)
def test_calculate_duration_0_0(): assert music.calculate_duration(0, 0) == Fraction(2, 1)
def test_calculate_duration_12_1(): assert music.calculate_duration(12, 1) == Fraction(1, 8)
def test_calculate_duration_4_2(): assert music.calculate_duration(4, 2) == Fraction(7, 16)
def test_calculate_duration_4_1(): assert music.calculate_duration(4, 1) == Fraction(3, 8)
def test_calculate_duration_16(): assert music.calculate_duration(16) == Fraction(1, 16)