def merge_tracks(midi_dataframe):
    """
    Combines multiple tracks into one track (track 1), then sorts the items by the time values.
    Returns the resulting dataframe.
    """
    midi = midi_dataframe.copy()

    # Change the number of tracks indicated by the header
    midi.loc[midi.iloc[:, 2].apply(lambda str: str.strip().lower() == 'header'), midi.columns[4]] = 1

    # Remove extra 'Start_track' and 'End_track'
    start_indices = midi.loc[midi.iloc[:, 2].apply(lambda str: str.strip().lower() == 'start_track')].index
    end_indices = midi.loc[midi.iloc[:, 2].apply(lambda str: str.strip().lower() == 'end_track')].index
    min_start_idx = midi.loc[start_indices, midi.columns[1]].idxmin()
    max_end_idx = midi.loc[end_indices, midi.columns[1]].idxmax()
    midi.drop(index=start_indices[start_indices != min_start_idx], inplace=True)
    midi.drop(index=end_indices[end_indices != max_end_idx], inplace=True)

    # Change all track numbers to 1 (other meta-data have 0 as their track number, so ignore any item with track number 0)
    midi.loc[midi.iloc[:, 0] > 1, midi.columns[0]] = 1

    # Sort items with track number 1 in ascending order by their time value
    midi.loc[midi.iloc[:, 0] == 1] = midi.loc[midi.iloc[:, 0] == 1].sort_values(midi.columns[1], axis=0, ascending=True).values

    midi.reset_index(drop=True, inplace=True)

    return midi