<commit_before>#!/usr/bin/env python

from align import nw_align


# load the score

score = []

for line in open("../examples/scores/hanon_21_rh.txt"):
    note = line.strip()
    note = int(note)
    score.append(note)


# load the performance

performance = []

for line in open("../examples/recordings/hanon_21_rh.txt"):
    offset, note, velocity = line.strip().split()
    offset = int(float(offset) * 1000000)
    note = int(note)
    velocity = int(velocity)
    
    if velocity > 0:
        performance.append((offset, note, velocity))<commit_msg>calculate the duration of each note performed<commit_after>#!/usr/bin/env python

from align import nw_align


# load the score

score = []

for line in open("../examples/scores/hanon_21_rh.txt"):
    note = line.strip()
    note = int(note)
    score.append(note)


# load the performance

performance = []

# dictionary mapping pitch to offset and velocity of event when that pitch was started
note_started = {}

for line in open("../examples/recordings/hanon_21_rh.txt"):
    offset, note, velocity = line.strip().split()
    offset = int(float(offset) * 1000000)
    note = int(note)
    velocity = int(velocity)
    
    if velocity > 0:
        if note in note_started:
            # new note at that pitch started before previous finished
            # not sure it should happen but let's handle it anyway
            (start_offset, start_velocity) = note_started.pop(note)
            duration = offset - start_offset
            performance.append((start_offset, note, start_velocity, duration))
        note_started[note] = (offset, velocity)
    else: # note end
        if note not in note_started:
            # note was never started so ignore
            pass
        else:
            (start_offset, start_velocity) = note_started.pop(note)
            duration = offset - start_offset
            performance.append((start_offset, note, start_velocity, duration))
{'fraction_non_alphanumeric': 0.10428497676819824, 'fraction_numerical': 0.0123902942694889, 'mean_word_length': 2.792563600782779, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1530918', 'n_tokens_mistral': 598, 'n_tokens_neox': 554, 'n_words': 167}