plectrum

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 2f63a4d84ef6e87902c28c3ce77457c7fe3502a2
parent be898e54e3008cbf7312ce569a978d861fa3e830
Author: gstraube <gstraube@mailbox.org>
Date:   Mon,  8 Jan 2018 17:29:19 +0100

Calculate octave number for Solfège (issue #9)

Diffstat:
Mapp/src/main/java/com/github/cythara/CanvasPainter.java | 24+++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/app/src/main/java/com/github/cythara/CanvasPainter.java b/app/src/main/java/com/github/cythara/CanvasPainter.java @@ -185,7 +185,7 @@ class CanvasPainter { 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); @@ -198,6 +198,28 @@ class CanvasPainter { 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);