plectrum

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

commit a58ea63262dd367ee07d6111c7a7c13d72615174
parent a1b42fb418ff43d7d206b5e8239735b642d51ba9
Author: gstraube <gstraube@mailbox.org>
Date:   Sun, 13 Aug 2017 12:16:36 +0200

Blank the screen if deviation is outside boundaries

Diffstat:
Mapp/src/androidTest/java/com/github/cythara/TunerViewTest.java | 8++++++++
Mapp/src/main/java/com/github/cythara/CanvasPainter.java | 5+++--
Mapp/src/main/java/com/github/cythara/MainActivity.java | 39++++++++++++++++++---------------------
Aapp/src/main/res/drawable/blank.png | 0
4 files changed, 29 insertions(+), 23 deletions(-)

diff --git a/app/src/androidTest/java/com/github/cythara/TunerViewTest.java b/app/src/androidTest/java/com/github/cythara/TunerViewTest.java @@ -82,6 +82,14 @@ public class TunerViewTest { } } + @Test + public void values_outside_of_boundaries_are_not_displayed() throws IOException { + isDisplayedCorrectly(R.drawable.blank, + new PitchDifference(Note.D3, 30.5)); + isDisplayedCorrectly(R.drawable.blank, + new PitchDifference(Note.D3, -30.5)); + } + public void isDisplayedCorrectly(int referenceId, PitchDifference pitchDifference) throws IOException { MainActivity mainActivity = mActivityRule.getActivity(); diff --git a/app/src/main/java/com/github/cythara/CanvasPainter.java b/app/src/main/java/com/github/cythara/CanvasPainter.java @@ -9,6 +9,7 @@ import android.text.TextPaint; class CanvasPainter { private static final double TOLERANCE = 3D; + private static final double MAX_DEVIATION = 30; private final Context context; private Canvas canvas; @@ -52,7 +53,7 @@ class CanvasPainter { drawGauge(); - if (pitchDifference != null) { + if (pitchDifference != null && Math.abs(pitchDifference.deviation) <= MAX_DEVIATION) { setBackground(); drawIndicator(); @@ -74,7 +75,7 @@ class CanvasPainter { float spaceWidth = gaugeWidth / 3F; - for (int i = 0; i <= 30; i = i + 10) { + for (int i = 0; i <= MAX_DEVIATION; i = i + 10) { float factor = i / 10F; drawMark(y, x + factor * spaceWidth, i); drawMark(y, x - factor * spaceWidth, -i); diff --git a/app/src/main/java/com/github/cythara/MainActivity.java b/app/src/main/java/com/github/cythara/MainActivity.java @@ -26,7 +26,6 @@ public class MainActivity extends AppCompatActivity { private static final int SAMPLE_RATE = 44100; private static final int BUFFER_SIZE = FastYin.DEFAULT_BUFFER_SIZE; private static final int OVERLAP = FastYin.DEFAULT_OVERLAP; - private static final double MAX_DEVIATION = 50; private static final int MIN_ITEMS_COUNT = 15; private static List<PitchDifference> pitchDifferences = new ArrayList<>(); @@ -65,34 +64,32 @@ public class MainActivity extends AppCompatActivity { String msg; - if (Math.abs(pitchDifference.deviation) < MAX_DEVIATION) { - msg = String.format(Locale.US, "Closest: %s Diff: %f Freq: %f", - pitchDifference.closest.name(), - pitchDifference.deviation, pitch); + msg = String.format(Locale.US, "Closest: %s Diff: %f Freq: %f", + pitchDifference.closest.name(), + pitchDifference.deviation, pitch); - log(msg); + log(msg); - pitchDifferences.add(pitchDifference); + pitchDifferences.add(pitchDifference); - if (pitchDifferences.size() >= MIN_ITEMS_COUNT) { - PitchDifference average = - Sampler.calculateAverageDifference(pitchDifferences); + if (pitchDifferences.size() >= MIN_ITEMS_COUNT) { + PitchDifference average = + Sampler.calculateAverageDifference(pitchDifferences); - Message message = new Message(); - Bundle bundle = new Bundle(); - bundle.putParcelable("pitchDiff", average); - message.setData(bundle); + Message message = new Message(); + Bundle bundle = new Bundle(); + bundle.putParcelable("pitchDiff", average); + message.setData(bundle); - msg = String.format(Locale.US, "Note: %s Diff: %f", - pitchDifference.closest.name(), - pitchDifference.deviation); + msg = String.format(Locale.US, "Note: %s Diff: %f", + pitchDifference.closest.name(), + pitchDifference.deviation); - log(msg); + log(msg); - activity.updateHandler.sendMessage(message); + activity.updateHandler.sendMessage(message); - pitchDifferences.clear(); - } + pitchDifferences.clear(); } } } diff --git a/app/src/main/res/drawable/blank.png b/app/src/main/res/drawable/blank.png Binary files differ.