This can be solved by adding a thing like `file.notes.sort(key=lambda note: (note.tick, note.layer))` before writing to file