Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cents to automatic tuner #57

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions app/src/main/java/com/kwasow/musekit/views/TunerView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ import android.content.Context
import android.os.CountDownTimer
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.widget.AppCompatTextView
import com.google.android.material.card.MaterialCardView
import com.google.android.material.color.MaterialColors
import com.kwasow.musekit.data.Note
import com.kwasow.musekit.databinding.ViewTunerBinding
import kotlin.math.roundToInt

class TunerView : LinearLayout {

Expand All @@ -18,6 +22,10 @@ class TunerView : LinearLayout {
this,
true
)
private val checkMark: ImageView = binding.tunerCheckMark
private val currentNote: AppCompatTextView = binding.currentNoteText
private val currentCents: TextView = binding.currentCentsText

private val inactiveColor = MaterialColors.getColor(
this,
com.google.android.material.R.attr.colorSurfaceContainerHighest
Expand All @@ -28,8 +36,8 @@ class TunerView : LinearLayout {
)

private val centBoundaries = listOf(
-50.0, -41.0, -32.0, -23.0, -14.0, -5.0,
5.0, 14.0, 23.0, 32.0, 41.0, 50.0
-50.0, -45.0, -35.0, -25.0, -15.0, -5.0,
5.0, 15.0, 25.0, 35.0, 45.0, 50.0
)

private val bars: Map<Int, MaterialCardView> = mapOf(
Expand Down Expand Up @@ -73,7 +81,7 @@ class TunerView : LinearLayout {
timer.start()

unmarkAll()
setNote(note)
setNote(note, cents)

if (note == null || cents == null) {
return
Expand All @@ -92,17 +100,21 @@ class TunerView : LinearLayout {
}

// ====== Private methods
private fun setNote(note: Note?) {
if (note == null) {
binding.currentNoteText.text = "—"
private fun setNote(note: Note?, cents: Double? = null) {
if (note == null || cents == null) {
currentNote.text = "—"
currentCents.text = ""
} else {
binding.currentNoteText.text = note.getSuperscripted(context)
val roundedCents = (cents * 100).roundToInt() / 100.0

currentNote.text = note.getSuperscripted(context)
currentCents.text = roundedCents.toString()
}
}

private fun markPitchBar(id: Int) {
if (id == 0) {
binding.tunerCheckMark.drawable.setTint(activeColor)
checkMark.drawable.setTint(activeColor)
} else {
val bar = bars[id]
?: throw IllegalArgumentException("Bar IDs can only be in -5..5")
Expand All @@ -116,6 +128,6 @@ class TunerView : LinearLayout {
it.value.background.setTint(inactiveColor)
}

binding.tunerCheckMark.drawable.setTint(inactiveColor)
checkMark.drawable.setTint(inactiveColor)
}
}
130 changes: 116 additions & 14 deletions app/src/main/res/layout/view_tuner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<LinearLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/tunerLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -28,35 +28,80 @@
style="@style/Widget.Material3.CardView.Filled"
android:layout_width="8dp"
android:layout_height="30dp"
android:layout_margin="4dp" />
android:layout_margin="8dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/pitchUnder4"/>

<!-- <TextView-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginTop="8dp"-->
<!-- android:text="-45"-->
<!-- android:rotation="50"-->
<!-- app:layout_constraintStart_toStartOf="@id/pitchUnder5"-->
<!-- app:layout_constraintEnd_toEndOf="@id/pitchUnder5"-->
<!-- app:layout_constraintTop_toBottomOf="@id/pitchUnder5"/>-->

<com.google.android.material.card.MaterialCardView
android:id="@+id/pitchUnder4"
style="@style/Widget.Material3.CardView.Filled"
android:layout_width="8dp"
android:layout_height="45dp"
android:layout_margin="4dp" />
android:layout_margin="8dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/pitchUnder3" />

<com.google.android.material.card.MaterialCardView
android:id="@+id/pitchUnder3"
style="@style/Widget.Material3.CardView.Filled"
android:layout_width="8dp"
android:layout_height="60dp"
android:layout_margin="4dp" />
android:layout_margin="8dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/pitchUnder2" />

<!-- <TextView-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginTop="8dp"-->
<!-- android:text="-25"-->
<!-- android:rotation="50"-->
<!-- app:layout_constraintStart_toStartOf="@id/pitchUnder3"-->
<!-- app:layout_constraintEnd_toEndOf="@id/pitchUnder3"-->
<!-- app:layout_constraintTop_toBottomOf="@id/pitchUnder3"/>-->

<com.google.android.material.card.MaterialCardView
android:id="@+id/pitchUnder2"
style="@style/Widget.Material3.CardView.Filled"
android:layout_width="8dp"
android:layout_height="75dp"
android:layout_margin="4dp" />
android:layout_margin="8dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/pitchUnder1" />

<com.google.android.material.card.MaterialCardView
android:id="@+id/pitchUnder1"
style="@style/Widget.Material3.CardView.Filled"
android:layout_width="8dp"
android:layout_height="90dp"
android:layout_margin="4dp" />
android:layout_margin="8dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/currentNoteText" />

<!-- <TextView-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginTop="8dp"-->
<!-- android:text="-5"-->
<!-- android:rotation="50"-->
<!-- app:layout_constraintStart_toStartOf="@id/pitchUnder1"-->
<!-- app:layout_constraintEnd_toEndOf="@id/pitchUnder1"-->
<!-- app:layout_constraintTop_toBottomOf="@id/pitchUnder1"/>-->

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/currentNoteText"
Expand All @@ -67,44 +112,101 @@
android:gravity="center"
android:layout_margin="12dp"
app:autoSizeTextType="uniform"
tools:ignore="HardcodedText"/>
tools:ignore="HardcodedText"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />

<TextView
android:id="@+id/currentCentsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="@id/currentNoteText"
app:layout_constraintEnd_toEndOf="@id/currentNoteText"
app:layout_constraintTop_toBottomOf="@id/currentNoteText"/>

<com.google.android.material.card.MaterialCardView
android:id="@+id/pitchOver1"
style="@style/Widget.Material3.CardView.Filled"
android:layout_width="8dp"
android:layout_height="90dp"
android:layout_margin="4dp" />
android:layout_margin="8dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/currentNoteText" />

<!-- <TextView-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginTop="8dp"-->
<!-- android:text="+5"-->
<!-- android:rotation="-50"-->
<!-- app:layout_constraintStart_toStartOf="@id/pitchOver1"-->
<!-- app:layout_constraintEnd_toEndOf="@id/pitchOver1"-->
<!-- app:layout_constraintTop_toBottomOf="@id/pitchOver1"/>-->

<com.google.android.material.card.MaterialCardView
android:id="@+id/pitchOver2"
style="@style/Widget.Material3.CardView.Filled"
android:layout_width="8dp"
android:layout_height="75dp"
android:layout_margin="4dp" />
android:layout_margin="8dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/pitchOver1" />

<com.google.android.material.card.MaterialCardView
android:id="@+id/pitchOver3"
style="@style/Widget.Material3.CardView.Filled"
android:layout_width="8dp"
android:layout_height="60dp"
android:layout_margin="4dp" />
android:layout_margin="8dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/pitchOver2" />

<!-- <TextView-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginTop="8dp"-->
<!-- android:text="+25"-->
<!-- android:rotation="-50"-->
<!-- app:layout_constraintStart_toStartOf="@id/pitchOver3"-->
<!-- app:layout_constraintEnd_toEndOf="@id/pitchOver3"-->
<!-- app:layout_constraintTop_toBottomOf="@id/pitchOver3"/>-->

<com.google.android.material.card.MaterialCardView
android:id="@+id/pitchOver4"
style="@style/Widget.Material3.CardView.Filled"
android:layout_width="8dp"
android:layout_height="45dp"
android:layout_margin="4dp" />
android:layout_margin="8dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/pitchOver3" />

<com.google.android.material.card.MaterialCardView
android:id="@+id/pitchOver5"
style="@style/Widget.Material3.CardView.Filled"
android:layout_width="8dp"
android:layout_height="30dp"
android:layout_margin="4dp" />

</LinearLayout>
android:layout_margin="8dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/pitchOver4" />

<!-- <TextView-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginTop="8dp"-->
<!-- android:text="+45"-->
<!-- android:rotation="-50"-->
<!-- app:layout_constraintStart_toStartOf="@id/pitchOver5"-->
<!-- app:layout_constraintEnd_toEndOf="@id/pitchOver5"-->
<!-- app:layout_constraintTop_toBottomOf="@id/pitchOver5"/>-->

</androidx.constraintlayout.widget.ConstraintLayout>

<ImageView
android:id="@+id/tunerCheckMark"
Expand Down
Loading