diff --git a/app/src/main/java/com/github/cythara/CanvasPainter.java b/app/src/main/java/com/github/cythara/CanvasPainter.java
index dae50bb..84d2404 100644
--- a/app/src/main/java/com/github/cythara/CanvasPainter.java
+++ b/app/src/main/java/com/github/cythara/CanvasPainter.java
@@ -17,6 +17,7 @@
import androidx.core.content.ContextCompat;
import static android.graphics.Paint.ANTI_ALIAS_FLAG;
+import static com.github.cythara.MainActivity.*;
class CanvasPainter {
@@ -42,7 +43,6 @@ class CanvasPainter {
private float x;
private float y;
private boolean useScientificNotation;
- private boolean showExactDeviation;
private int referencePitch;
private CanvasPainter(Context context) {
@@ -61,22 +61,20 @@ CanvasPainter paint(PitchDifference pitchDifference) {
void on(Canvas canvas) {
SharedPreferences preferences = context.getSharedPreferences(
- MainActivity.PREFS_FILE, Context.MODE_PRIVATE);
+ PREFS_FILE, Context.MODE_PRIVATE);
useScientificNotation = preferences.getBoolean(
- MainActivity.USE_SCIENTIFIC_NOTATION, true);
-
- showExactDeviation = preferences.getBoolean(MainActivity.SHOW_EXACT_DEVIATION, false);
+ USE_SCIENTIFIC_NOTATION, true);
referencePitch = preferences.getInt(
- MainActivity.REFERENCE_PITCH, 440);
+ REFERENCE_PITCH, 440);
this.canvas = canvas;
redBackground = R.color.red_light;
greenBackground = R.color.green_light;
textColor = Color.BLACK;
- if (MainActivity.isDarkModeEnabled()) {
+ if (isDarkModeEnabled()) {
int color = context.getResources().getColor(R.color.colorPrimaryDark);
this.canvas.drawColor(color);
@@ -95,21 +93,34 @@ void on(Canvas canvas) {
drawGauge();
- if (pitchDifference != null && Math.abs(getNearestDeviation()) <= MAX_DEVIATION) {
- setBackground();
+ if (!isAutoModeEnabled()) {
+ Note[] tuningNotes = getCurrentTuning().getNotes();
+ Note note = tuningNotes[getReferencePosition()];
+ drawText(x, y / 4F, note, symbolPaint);
+ }
- drawGauge();
+ if (pitchDifference != null) {
+ int abs = Math.abs(getNearestDeviation());
+ boolean shouldDraw = abs <= MAX_DEVIATION ||
+ (abs <= MAX_DEVIATION * 2 && !isAutoModeEnabled());
+ if (shouldDraw) {
+ setBackground();
- drawIndicator();
+ drawGauge();
- if (showExactDeviation) {
- drawDeviation();
- }
+ drawIndicator();
- float x = canvas.getWidth() / 2F;
- float y = canvas.getHeight() * 0.75f;
+ if (!isAutoModeEnabled()) {
+ drawDeviation();
+ }
- drawText(x, y, pitchDifference.closest, textPaint);
+ float x = canvas.getWidth() / 2F;
+ float y = canvas.getHeight() * 0.75f;
+
+ drawText(x, y, pitchDifference.closest, textPaint);
+ } else {
+ drawListeningIndicator();
+ }
} else {
drawListeningIndicator();
}
diff --git a/app/src/main/java/com/github/cythara/MainActivity.java b/app/src/main/java/com/github/cythara/MainActivity.java
index 479d521..1b90389 100644
--- a/app/src/main/java/com/github/cythara/MainActivity.java
+++ b/app/src/main/java/com/github/cythara/MainActivity.java
@@ -38,13 +38,14 @@ public class MainActivity extends AppCompatActivity implements TaskCallbacks,
public static final String PREFS_FILE = "prefs_file";
public static final String USE_SCIENTIFIC_NOTATION = "use_scientific_notation";
public static final String CURRENT_TUNING = "current_tuning";
- public static final String SHOW_EXACT_DEVIATION = "show_exact_deviation";
protected static final String REFERENCE_PITCH = "reference_pitch";
private static final String TAG_LISTENER_FRAGMENT = "listener_fragment";
private static final String USE_DARK_MODE = "use_dark_mode";
private static int tuningPosition = 0;
private static boolean isDarkModeEnabled;
private static int referencePitch;
+ private static int referencePosition;
+ private static boolean isAutoModeEnabled = true;
public static Tuning getCurrentTuning() {
return TuningMapper.getTuningFromPosition(tuningPosition);
@@ -58,6 +59,14 @@ public static int getReferencePitch() {
return referencePitch;
}
+ public static boolean isAutoModeEnabled() {
+ return isAutoModeEnabled;
+ }
+
+ public static int getReferencePosition() {
+ return referencePosition - 1; //to account for the position of the AUTO option
+ }
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -154,21 +163,23 @@ public boolean onOptionsItemSelected(MenuItem item) {
dialog.setArguments(bundle);
dialog.setValueChangeListener(this);
- dialog.show(getSupportFragmentManager(), "number_picker");
+ dialog.show(getSupportFragmentManager(), "reference_pitch_picker");
break;
}
- case R.id.show_exact_deviation: {
+ case R.id.choose_tuning_mode: {
final SharedPreferences preferences = getSharedPreferences(PREFS_FILE,
MODE_PRIVATE);
- boolean currentlyShowingExactDeviation = preferences.getBoolean(
- SHOW_EXACT_DEVIATION, false);
+ NotePickerDialog dialog = new NotePickerDialog();
- SharedPreferences.Editor editor = preferences.edit();
- editor.putBoolean(SHOW_EXACT_DEVIATION, !currentlyShowingExactDeviation);
- editor.apply();
+ Bundle bundle = new Bundle();
+ bundle.putBoolean("use_scientific_notation", preferences.getBoolean(
+ MainActivity.USE_SCIENTIFIC_NOTATION, true));
+ bundle.putInt("current_value", referencePosition);
+ dialog.setArguments(bundle);
- recreate();
+ dialog.setValueChangeListener(this);
+ dialog.show(getSupportFragmentManager(), "note_picker");
}
}
@@ -224,21 +235,35 @@ public void onItemSelected(MaterialSpinner view, int position, long id, Object i
editor.apply();
tuningPosition = position;
+
+ isAutoModeEnabled = true;
+ referencePosition = 0;
+
+ recreate();
}
@Override
public void onValueChange(NumberPicker picker, int oldValue, int newValue) {
- final SharedPreferences preferences = getSharedPreferences(PREFS_FILE,
- MODE_PRIVATE);
+ String tag = String.valueOf(picker.getTag());
+ if ("reference_pitch_picker".equalsIgnoreCase(tag)) {
+ final SharedPreferences preferences = getSharedPreferences(PREFS_FILE,
+ MODE_PRIVATE);
- SharedPreferences.Editor editor = preferences.edit();
- editor.putInt(REFERENCE_PITCH, newValue);
- editor.apply();
+ SharedPreferences.Editor editor = preferences.edit();
+ editor.putInt(REFERENCE_PITCH, newValue);
+ editor.apply();
- setReferencePitch();
+ setReferencePitch();
- TunerView tunerView = this.findViewById(R.id.pitch);
- tunerView.invalidate();
+ TunerView tunerView = this.findViewById(R.id.pitch);
+ tunerView.invalidate();
+ } else if ("note_picker".equalsIgnoreCase(tag)) {
+ isAutoModeEnabled = newValue == 0;
+
+ referencePosition = newValue;
+
+ recreate();
+ }
}
private void startRecording() {
diff --git a/app/src/main/java/com/github/cythara/NotePickerDialog.java b/app/src/main/java/com/github/cythara/NotePickerDialog.java
new file mode 100644
index 0000000..63683c4
--- /dev/null
+++ b/app/src/main/java/com/github/cythara/NotePickerDialog.java
@@ -0,0 +1,93 @@
+package com.github.cythara;
+
+import android.app.Dialog;
+import android.os.Bundle;
+import android.view.ContextThemeWrapper;
+
+import androidx.appcompat.app.AlertDialog;
+import androidx.fragment.app.DialogFragment;
+
+import com.shawnlin.numberpicker.NumberPicker;
+
+public class NotePickerDialog extends DialogFragment {
+
+ private NumberPicker.OnValueChangeListener valueChangeListener;
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ final NumberPicker numberPicker = new NumberPicker(getActivity());
+ numberPicker.setTag("note_picker");
+
+ Bundle arguments = getArguments();
+ boolean useScientificNotation = arguments.getBoolean("use_scientific_notation", true);
+ int currentValue = arguments.getInt("current_value", 0);
+
+ Note[] notes = MainActivity.getCurrentTuning().getNotes();
+
+ numberPicker.setMinValue(0);
+ numberPicker.setMaxValue(notes.length);
+ if (currentValue < notes.length) {
+ numberPicker.setValue(currentValue);
+ } else {
+ numberPicker.setValue(0);
+ }
+
+ String[] displayedValues = new String[notes.length + 1];
+
+ displayedValues[0] = "Auto";
+ for (int i = 0; i < notes.length; i++) {
+ Note note = notes[i];
+ NoteName name = note.getName();
+ String noteName = name.getScientific();
+ int octave = note.getOctave();
+ if (!useScientificNotation) {
+ noteName = name.getSol();
+
+ //TODO Extract method
+ if (octave <= 1) {
+ octave = octave - 2;
+ }
+
+ octave = octave - 1;
+ }
+ displayedValues[i + 1] = noteName + note.getSign() + octave;
+ }
+
+ numberPicker.setDisplayedValues(displayedValues);
+
+ if (MainActivity.isDarkModeEnabled()) {
+ int color = getResources().getColor(R.color.colorTextDark);
+ numberPicker.setTextColor(color);
+ numberPicker.setDividerColor(color);
+ numberPicker.setSelectedTextColor(color);
+ }
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(),
+ R.style.AppTheme));
+
+ builder.setPositiveButton("OK",
+ (dialog, which) -> valueChangeListener.onValueChange(numberPicker,
+ numberPicker.getValue(), numberPicker.getValue()));
+
+ builder.setNegativeButton("CANCEL", (dialog, which) -> {
+ });
+
+ builder.setNeutralButton("AUTO",
+ (dialog, which) -> valueChangeListener.onValueChange(numberPicker,
+ 0, 0));
+
+ builder.setView(numberPicker);
+ return builder.create();
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+
+ this.dismiss();
+ }
+
+ void setValueChangeListener(NumberPicker.OnValueChangeListener valueChangeListener) {
+ this.valueChangeListener = valueChangeListener;
+ }
+}
diff --git a/app/src/main/java/com/github/cythara/NumberPickerDialog.java b/app/src/main/java/com/github/cythara/NumberPickerDialog.java
index 03d2bc7..1d9f9f0 100644
--- a/app/src/main/java/com/github/cythara/NumberPickerDialog.java
+++ b/app/src/main/java/com/github/cythara/NumberPickerDialog.java
@@ -16,6 +16,7 @@ public class NumberPickerDialog extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final NumberPicker numberPicker = new NumberPicker(getActivity());
+ numberPicker.setTag("reference_pitch_picker");
Bundle arguments = getArguments();
int currentValue = arguments.getInt("current_value", 440);
diff --git a/app/src/main/java/com/github/cythara/PitchComparator.java b/app/src/main/java/com/github/cythara/PitchComparator.java
index d05420a..bc22f1c 100644
--- a/app/src/main/java/com/github/cythara/PitchComparator.java
+++ b/app/src/main/java/com/github/cythara/PitchComparator.java
@@ -10,7 +10,15 @@ static PitchDifference retrieveNote(float pitch) {
Tuning tuning = MainActivity.getCurrentTuning();
int referencePitch = MainActivity.getReferencePitch();
- Note[] notes = tuning.getNotes();
+ Note[] tuningNotes = tuning.getNotes();
+ Note[] notes;
+
+ if (MainActivity.isAutoModeEnabled()) {
+ notes = tuningNotes;
+ } else {
+ notes = new Note[]{tuningNotes[MainActivity.getReferencePosition()]};
+ }
+
NoteFrequencyCalculator noteFrequencyCalculator =
new NoteFrequencyCalculator(referencePitch);
diff --git a/app/src/main/res/menu/toolbar_menu.xml b/app/src/main/res/menu/toolbar_menu.xml
index 0b103dd..20ae43f 100644
--- a/app/src/main/res/menu/toolbar_menu.xml
+++ b/app/src/main/res/menu/toolbar_menu.xml
@@ -23,7 +23,7 @@
app:showAsAction="never" />
\ No newline at end of file
diff --git a/app/src/main/res/values-de-rDE/strings.xml b/app/src/main/res/values-de-rDE/strings.xml
index 9f9656e..2db24d2 100644
--- a/app/src/main/res/values-de-rDE/strings.xml
+++ b/app/src/main/res/values-de-rDE/strings.xml
@@ -12,7 +12,6 @@
Eine Mikrofongenehmigung ist erforderlich. App wird geschlossen.
OK
- Genaue Abweichung ein-/ausblenden
- Chromatisch
diff --git a/app/src/main/res/values-eu/strings.xml b/app/src/main/res/values-eu/strings.xml
index dff79d3..1993dee 100644
--- a/app/src/main/res/values-eu/strings.xml
+++ b/app/src/main/res/values-eu/strings.xml
@@ -9,5 +9,4 @@
Maiztasun bat hautatu:
Mikrofonoaren baimena beharrezkoa da
Ados
- Erakutsi/ezkutatu desbideratze zehatza
diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml
index 25e9d72..824b456 100644
--- a/app/src/main/res/values-pt-rBR/strings.xml
+++ b/app/src/main/res/values-pt-rBR/strings.xml
@@ -12,7 +12,6 @@
A permissão do microfone é necessária. App será fechado.
OK
- Mostrar/esconder o desvio exato
- Cromático
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 0f31c30..0dfa3f8 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,4 +1,4 @@
-
+
Cythara
Show privacy policy
@@ -14,7 +14,7 @@
Permission required
Microphone permission is required. App will close.
OK
- Show/hide exact deviation
+ Choose tuning mode
- Chromatic