Skip to content

Commit

Permalink
Add support for gracenotes
Browse files Browse the repository at this point in the history
  • Loading branch information
heiligbasil committed Jun 15, 2022
1 parent 5df2446 commit fbc9ed2
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ object Constants {
const val CHAR_BAR_START = "\uD834\uDD03"
const val CHAR_BAR_END = "\uD834\uDD02"
const val CHAR_QUARTER_NOTE = "\uD834\uDD5F"
const val CHAR_GRACENOTE = "\uD834\uDD62"
}
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ class FullscreenActivity : AppCompatActivity() {
}

private fun updateHighlightedNoteOnDeck() {
val notesList = upcomingNotesList.mapNotNull { (it as? Notes)?.notation }.toMutableList()
val notesList = upcomingNotesList.mapNotNull { getPrintableString(it) }.toMutableList()
var notesIndex = upcomingNotesListIndex
val currentNote = notesList.getOrNull(notesIndex)
var encodedNoteLength = 0
Expand Down Expand Up @@ -373,6 +373,16 @@ class FullscreenActivity : AppCompatActivity() {
binding.textviewNotesOnDeck.text = finalString
}

private fun getPrintableString(c: Any?): String? {
return when (c) {
is Notes -> c.notation
Symbols.GRACE_NOTE_G -> Symbols.GRACE_NOTE_G.notation
Symbols.GRACE_NOTE_D -> Symbols.GRACE_NOTE_D.notation
Symbols.GRACE_NOTE_E -> Symbols.GRACE_NOTE_E.notation
else -> null
}
}

private fun isTextTooWide(newText: String): Boolean {
val textWidth = binding.textviewNotesOnDeck.paint.measureText(newText)
return (textWidth / binding.textviewNotesOnDeck.maxLines) >= binding.textviewNotesOnDeck.measuredWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@ enum class SessionType(val displayText: String, val notes: String) {
PRESET_16("Both-hands exercise 4", "ADFĀADFADFĀḠED|_"),
PRESET_17("Both-hands exercise 5", "CEĀECEĀDFĀFDFĀ|_"),
PRESET_18("Both-hands exercise 6", "ĀFDFĀFDFḠFEĀḠED|_"),

PRESET_19("Gracenotes 1", "GǥA_AǥB_BǥC_CǥB_BǥA_AǥG|_"),
PRESET_20("Gracenotes 2", "GđA_AđB_BđC_CđB_BđA_AđG|_"),
PRESET_21("Gracenotes 3", "GɇA_AɇB_BɇC_CɇB_BɇA_AɇG|_"),
PRESET_22("Gracenotes 4", "ǥGǥAǥBǥCǥDǥEǥFǥEǥDǥCǥBǥAǥG|_"),
PRESET_23("Gracenotes 5", "đGđAđBđCđDđEđFđEđDđCđBđAđG|_"),
PRESET_24("Gracenotes 6", "ɇGɇAɇBɇCɇDɇEɇFɇEɇDɇCɇBɇAɇG|_"),
PRESET_25("Gracenotes 7", "ǥGđGɇGǥAđAɇAǥBđBɇBǥCđCɇCǥCđCɇCǥBđBɇBǥAđAɇAǥGđGɇG|_"),
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ class StaffView @JvmOverloads constructor(
color = Color.BLACK;strokeWidth = 5f;textSize = 420f;textScaleX = 0.5f;isAntiAlias =
true;
}
val bk6 = Paint().apply {
color = Color.BLACK;strokeWidth = 5f;textSize = 100f;textScaleX = 1f;isAntiAlias = true
}
val y1 = Paint().apply { color = Color.RED;strokeWidth = 5f;textSize = 30f;isAntiAlias = true }
var p1 = bk3
var showingNote: Any = Notes.LOW_G
var labelNoteName = false
var labelLedgerLines = false
Expand Down Expand Up @@ -122,6 +126,21 @@ class StaffView @JvmOverloads constructor(
if (showingNote is Notes) {
drawQuarterNo(canvas)
} else {
when (showingNote) {
Symbols.GRACE_NOTE_G -> {
my_y = 100f + (50 * 1).toFloat()
p1 = bk6
}
Symbols.GRACE_NOTE_D -> {
my_y = 100f + (50 * 4).toFloat()
p1 = bk6
}
Symbols.GRACE_NOTE_E -> {
my_y = 100f + (50 * 3).toFloat()
p1 = bk6
}
else -> p1 = bk3
}
drawSymbolNo(canvas)
}
}
Expand All @@ -138,7 +157,7 @@ class StaffView @JvmOverloads constructor(
}

private fun drawSymbolNo(canvas: Canvas?) {
canvas?.drawText((showingNote as Symbols).visual, my_x, my_y, bk3)
canvas?.drawText((showingNote as Symbols).visual, my_x, my_y, p1)
}

private fun Float.dp2px(): Float {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.heiligbasil.bagpipeschantermusicnotespractice

import com.heiligbasil.bagpipeschantermusicnotespractice.Constants.CHAR_BAR_END
import com.heiligbasil.bagpipeschantermusicnotespractice.Constants.CHAR_GRACENOTE

enum class Symbols(val notation: String, val visual: String) {
END_BAR(notation = "|", visual = CHAR_BAR_END),
PAUSE(notation = "_", visual = ""),
GRACE_NOTE_G(notation = "ǥ", visual = CHAR_GRACENOTE),
GRACE_NOTE_D(notation = "đ", visual = CHAR_GRACENOTE),
GRACE_NOTE_E(notation = "ɇ", visual = CHAR_GRACENOTE),
}

0 comments on commit fbc9ed2

Please sign in to comment.