def transform_midi(midi_file):
    input_path = midi_file
    try:
        input_file = compress_midi_file(input_path, min_variation=min_variation, cutoff=cutoff)
        if (input_file is None):
            return None
    except Exception as e:
        if ('badly form' in str(e)):
            return None
        if ('out of range' in str(e)):
            return None
        print('Error parsing midi', input_path, e)
        return None
    stream = file2stream(input_file)
    try:
        chordarr = stream2chordarr(stream)
    except Exception as e:
        print('Could not encode to chordarr:', input_path, e)
        print(traceback.format_exc())
        return None
    chord_trim = trim_chordarr_rests(chordarr)
    chord_short = shorten_chordarr_rests(chord_trim)
    delta_trim = (chord_trim.shape[0] - chord_short.shape[0])
    chordarr = chord_short
    npenc = chordarr2npenc(chordarr)
    if (not is_valid_npenc(npenc, input_path=input_path)):
        return None
    return npenc
def transform_midi(midi_file):
    input_path = midi_file
    try:
        input_file = compress_midi_file(input_path, min_variation=min_variation, cutoff=cutoff)
        if (input_file is None):
            return None
    except Exception as e:
        if ('badly form' in str(e)):
            return None
        if ('out of range' in str(e)):
            return None
        print('Error parsing midi', input_path, e)
        return None
    stream = file2stream(input_file)
    try:
        chordarr = stream2chordarr(stream)
    except Exception as e:
        print('Could not encode to chordarr:', input_path, e)
        print(traceback.format_exc())
        return None
    chord_trim = trim_chordarr_rests(chordarr)
    chord_short = shorten_chordarr_rests(chord_trim)
    delta_trim = (chord_trim.shape[0] - chord_short.shape[0])
    chordarr = chord_short
    npenc = chordarr2npenc(chordarr)
    if (not is_valid_npenc(npenc, input_path=input_path)):
        return None
    return npenc