def merge_on_pitch(gt_df, trans_df, offset=True):
    """
    Merge the given ground truth and transcribed dfs on pitch, with
    corresponding suffixes, and possibly offset columns.

    Parameters
    ----------
    gt_df : pd.DataFrame
        The ground truth data frame.

    trans_df : pd.DataFrame
        The transcription data frame.

    offset : boolean
        Calculate offset columns pre-merge.

    Results
    -------
    merge_df : pd.DataFrame
        The gt and trans DataFrames, merged on equal pitches, with index
        columns added for each pre-merge, and _gt and _trans suffixes added
        to the resulting columns. If offset is True, offset columns are
        calculated pre-merge.
    """
    # This both creates a copy and creates an index column which will be
    # retained in the merge
    gt_df = gt_df.reset_index()
    trans_df = trans_df.reset_index()

    # Pre-calculate offset time once
    if offset:
        gt_df["offset"] = gt_df.onset + gt_df.dur
        trans_df["offset"] = trans_df.onset + trans_df.dur

    # Merge notes with equal pitch -- keep all pairs
    return trans_df.reset_index().merge(
        gt_df.reset_index(), on="pitch", suffixes=("_trans", "_gt")
    )