Skip to content
This repository has been archived by the owner on Jan 28, 2024. It is now read-only.

Commit

Permalink
Calculate octave number for Solfège (issue #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
gstraube committed Jan 8, 2018
1 parent be898e5 commit 2f63a4d
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion app/src/main/java/com/github/cythara/CanvasPainter.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private void drawText() {
float offset = textPaint.measureText(note) / 2F;

String sign = closest.getSign();
String octave = String.valueOf(closest.getOctave());
String octave = String.valueOf(getOctave(closest.getOctave()));

TextPaint paint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
paint.setColor(Color.BLACK);
Expand All @@ -198,6 +198,28 @@ private void drawText() {
canvas.drawText(note, x - offset, y, textPaint);
}

private int getOctave(int octave) {
SharedPreferences preferences = context.getSharedPreferences(PREFS_FILE, MODE_PRIVATE);

boolean useScientificNotation = preferences.getBoolean(USE_SCIENTIFIC_NOTATION, true);

if (useScientificNotation) {
return octave;
}

/*
The octave number in the (the French notation) of Solfège is one less than the
corresponding octave number in the scientific pitch notation.
There is also no octave with the number zero
(see https://fr.wikipedia.org/wiki/Octave_(musique)#Solf%C3%A8ge).
*/
if (octave <= 1) {
return octave - 2;
}

return octave - 1;
}

private String getNote(NoteName name) {
SharedPreferences preferences = context.getSharedPreferences(PREFS_FILE, MODE_PRIVATE);

Expand Down

0 comments on commit 2f63a4d

Please sign in to comment.