1 public class Chord { 2 3 private String rootNote; 4 private String[] keyChordNotes; 5 private String[] extraChordNotes; 6 private boolean arpeggiate; 7 private int chordRootNoteCBIndex; 8 9 public Chord(String rootNote, boolean key){ 10 setKeyChordNotes(new String[7]); 11 setExtraChordNotes(new String[5]); 12 setRootNote(rootNote, key); 13 setChordRootNoteCBIndex(-1); 14 } 15 16 17 // Getters & Setters 18 19 public String getRootNote(){ 20 return this.rootNote; 21 } 22 23 public void setRootNote(String rootNote, boolean key){ 24 this.rootNote = rootNote; 25 if(key){ // rootNote == keyNote 26 getKeyChordNotes()[0] = Melody.extractActualNoteName(getRootNote()); 27 } else { // rootNote == extraNote 28 getExtraChordNotes()[0] = Melody.extractActualNoteName(getRootNote()); 29 } 30 } 31 32 public String[] getKeyChordNotes() { 33 return this.keyChordNotes; 34 } 35 36 public void setKeyChordNotes(String[] keyChordNotes) { 37 this.keyChordNotes = keyChordNotes; 38 } 39 40 public String[] getExtraChordNotes() { 41 return this.extraChordNotes; 42 } 43 44 public void setExtraChordNotes(String[] extraChordNotes) { 45 this.extraChordNotes = extraChordNotes; 46 } 47 48 public boolean getArpeggiate(){ 49 return this.arpeggiate; 50 } 51 52 public void setArpeggiate(boolean arpeggiate){ 53 this.arpeggiate = arpeggiate; 54 } 55 56 public int getChordRootNoteCBIndex(){ 57 return this.chordRootNoteCBIndex; 58 } 59 60 public void setChordRootNoteCBIndex(int chordRootNoteCBIndex){ 61 this.chordRootNoteCBIndex = chordRootNoteCBIndex; 62 } 63 64 65 // Actual methods 66 67 public static boolean chordsEqual(Chord chord1, Chord chord2){ 68 // check whether both are not null 69 if((chord1 == null && chord2 != null) || (chord1 != null && chord2 == null)){ 70 return false; 71 } else if(chord1 == null && chord2 == null){ 72 return true; 73 } else { 74 // compare root notes 75 if(!chord1.getRootNote().equals(chord2.getRootNote())){ 76 return false; 77 } 78 // compare keyNoteArrays 79 for(int i = 0; i < chord1.getKeyChordNotes().length; i++){ 80 if(chord1.getKeyChordNotes()[i] != null && chord2.getKeyChordNotes()[i] != null){ 81 if(!chord1.getKeyChordNotes()[i].equals(chord2.getKeyChordNotes()[i])){ 82 return false; 83 } 84 } else if(!(chord1.getKeyChordNotes()[i] == null && chord2.getKeyChordNotes()[i] == null)){ 85 return false; 86 } 87 } 88 // compare extraNoteArrays 89 for(int i = 0; i < chord1.getExtraChordNotes().length; i++){ 90 if(chord1.getExtraChordNotes()[i] != null && chord2.getExtraChordNotes()[i] != null){ 91 if(!chord1.getExtraChordNotes()[i].equals(chord2.getExtraChordNotes()[i])){ 92 return false; 93 } 94 } else if(!(chord1.getExtraChordNotes()[i] == null && chord2.getExtraChordNotes()[i] == null)){ 95 return false; 96 } 97 } 98 // compare arpeggiate 99 if(chord1.getArpeggiate() != chord2.getArpeggiate()){ 100 return false; 101 } 102 return true; 103 } 104 } 105 } 106