public Staff getStaff(int index) {
    List<Staff> staves = new ArrayList<Staff>();

    for (int i = 0; i < getStaffCount(); i++) staves.add(new Staff());

    for (Event event:this) {
      if (event instanceof VerticalEvent) {
        for (Staff staff:staves) staff.add(event);
      } else if (event instanceof StaffElement) {
        staves.get(((StaffElement)event).getStaffNumber()).add(event);
      } else if (event instanceof Chord) {
        for (StaffElement staffChord:((Chord)event).getStaffChords()) {
          int staffNumber = staffChord.getStaffNumber();
          staves.get(staffNumber).add(staffChord);
          staffChord.setStaff(staves.get(staffNumber));
        }
      } else if (event instanceof GlobalKeyChange) {
        GlobalKeyChange globalKeyChange = (GlobalKeyChange)event;
        for (int i = 0; i < staves.size(); i++) {
          KeyChange keyChange = new KeyChange(globalKeyChange.getMoment(),
                                              globalKeyChange.getKeySignature(), i);
          staves.get(i).add(keyChange);
        }
      }
    }
    return staves.get(index);
  }