Skip to content

Commit

Permalink
Fix computeNote
Browse files Browse the repository at this point in the history
  • Loading branch information
cyprienruffino committed Sep 1, 2023
1 parent 3d9d042 commit 5654174
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions app/src/main/java/ovh/soup/chordsquares/logic/Chord.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,20 @@ public static Chord fromSeventh(Note seventh, Nature nature){
}

public static Note computeNote(Note base, int degree, int target, Nature nature){
int rootPosition = Utils.mod(Note.notes.indexOf(base.note) - degree + 1 , Note.notes.size());
Note.RawNote targetNote = Note.notes.get(Utils.mod(rootPosition + target - 1, Note.notes.size()));
Note.RawNote targetRawNote = Note.notes.get(Utils.mod(Note.notes.indexOf(base.note) + target - degree, Note.notes.size()));

if (target < degree)
target += nature.intervals.length;

int interval = 0;
int naturalInterval = 0;
for (int i=0; i<(target-1); i++){
interval += nature.intervals[Utils.mod(i, nature.intervals.length)];
naturalInterval += Chord.naturalIntervals.get(Utils.mod(rootPosition + i, Chord.naturalIntervals.size()));
for (int i=0; i<target-degree; i++){
interval += nature.intervals[Utils.mod(i + degree - 1, nature.intervals.length)];
naturalInterval += Chord.naturalIntervals.get(Utils.mod(i + Note.notes.indexOf(base.note), Chord.naturalIntervals.size()));
}

return new Note(
targetNote,
targetRawNote,
Chord.alterations.get(interval - naturalInterval + base.alteration.value())
);
}
Expand Down

0 comments on commit 5654174

Please sign in to comment.