libmid: add merge_tracks function