diff --git a/.idea/misc.xml b/.idea/misc.xml
index b121fe2..9b588fa 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -10,7 +10,7 @@
-
+
diff --git a/.idea/misc.xml b/.idea/misc.xml
index b121fe2..9b588fa 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -10,7 +10,7 @@
-
+
diff --git a/app/src/main/java/com/lukas/music/song/chords/Chord.kt b/app/src/main/java/com/lukas/music/song/chords/Chord.kt
index fedb465..85e530b 100644
--- a/app/src/main/java/com/lukas/music/song/chords/Chord.kt
+++ b/app/src/main/java/com/lukas/music/song/chords/Chord.kt
@@ -14,6 +14,7 @@
import com.lukas.music.song.note.Note
class Chord {
+ var accidental = Accidental.None
val accidentals: Array = arrayOf(Accidental.None, Accidental.None, null, null)
var note: Int = 0
@@ -37,7 +38,7 @@
var octave = 0
while (resultIndex < NOTE_COUNT) {
if (accidentalIndex == 0) {
- result[resultIndex] = root + note + 12 * octave
+ result[resultIndex] = root + note + 12 * octave + accidental.distance
resultIndex++
} else if (accidentals[accidentalIndex - 1] != null) {
result[resultIndex] = root + note + when (accidentalIndex) {
@@ -46,7 +47,7 @@
3 -> 10
4 -> 14
else -> 0
- } + accidentals[accidentalIndex - 1]!!.distance + 12 * octave
+ } + accidentals[accidentalIndex - 1]!!.distance + 12 * octave + accidental.distance
resultIndex++
}
accidentalIndex++
@@ -64,7 +65,7 @@
fun toString(displayChordNames: Boolean, root: Note): String {
var result = if (displayChordNames) {
- (root + note).noteName.toString()
+ (root + note + accidental.distance).noteName.toString()
} else {
interval.toString()
}
@@ -101,6 +102,6 @@
}
companion object {
- val NOTE_COUNT = 5
+ const val NOTE_COUNT = 5
}
}
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index b121fe2..9b588fa 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -10,7 +10,7 @@
-
+
diff --git a/app/src/main/java/com/lukas/music/song/chords/Chord.kt b/app/src/main/java/com/lukas/music/song/chords/Chord.kt
index fedb465..85e530b 100644
--- a/app/src/main/java/com/lukas/music/song/chords/Chord.kt
+++ b/app/src/main/java/com/lukas/music/song/chords/Chord.kt
@@ -14,6 +14,7 @@
import com.lukas.music.song.note.Note
class Chord {
+ var accidental = Accidental.None
val accidentals: Array = arrayOf(Accidental.None, Accidental.None, null, null)
var note: Int = 0
@@ -37,7 +38,7 @@
var octave = 0
while (resultIndex < NOTE_COUNT) {
if (accidentalIndex == 0) {
- result[resultIndex] = root + note + 12 * octave
+ result[resultIndex] = root + note + 12 * octave + accidental.distance
resultIndex++
} else if (accidentals[accidentalIndex - 1] != null) {
result[resultIndex] = root + note + when (accidentalIndex) {
@@ -46,7 +47,7 @@
3 -> 10
4 -> 14
else -> 0
- } + accidentals[accidentalIndex - 1]!!.distance + 12 * octave
+ } + accidentals[accidentalIndex - 1]!!.distance + 12 * octave + accidental.distance
resultIndex++
}
accidentalIndex++
@@ -64,7 +65,7 @@
fun toString(displayChordNames: Boolean, root: Note): String {
var result = if (displayChordNames) {
- (root + note).noteName.toString()
+ (root + note + accidental.distance).noteName.toString()
} else {
interval.toString()
}
@@ -101,6 +102,6 @@
}
companion object {
- val NOTE_COUNT = 5
+ const val NOTE_COUNT = 5
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/lukas/music/ui/fragments/EditChordFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/EditChordFragment.kt
index ea02f1e..9e618ed 100644
--- a/app/src/main/java/com/lukas/music/ui/fragments/EditChordFragment.kt
+++ b/app/src/main/java/com/lukas/music/ui/fragments/EditChordFragment.kt
@@ -25,10 +25,7 @@
import com.lukas.music.song.chords.Accidental
import com.lukas.music.song.chords.Chord
import com.lukas.music.song.chords.Interval
-import com.lukas.music.util.EasyDialogFragment
-import com.lukas.music.util.UIUtil
-import com.lukas.music.util.setup
-import com.lukas.music.util.updateToggle
+import com.lukas.music.util.*
class EditChordFragment(private val chord: Chord, private val songFragment: SongFragment) :
EasyDialogFragment() {
@@ -38,6 +35,12 @@
savedInstanceState: Bundle?
): View? {
binding = FragmentEditChordBinding.inflate(inflater)
+ Array(Accidental.VALUES.size) {
+ val button = MaterialButton(binding.root.context)
+ button.layoutParams = UIUtil.cardLayout
+ binding.accidentalSelection.addView(button)
+ return@Array button
+ }.setupEnumSelection(chord::accidental, Accidental.VALUES, callback = { update() })
setupPitchSpinner()
setupEditor()
binding.exitButton.setOnClickListener {
diff --git a/.idea/misc.xml b/.idea/misc.xml
index b121fe2..9b588fa 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -10,7 +10,7 @@
-
+
diff --git a/app/src/main/java/com/lukas/music/song/chords/Chord.kt b/app/src/main/java/com/lukas/music/song/chords/Chord.kt
index fedb465..85e530b 100644
--- a/app/src/main/java/com/lukas/music/song/chords/Chord.kt
+++ b/app/src/main/java/com/lukas/music/song/chords/Chord.kt
@@ -14,6 +14,7 @@
import com.lukas.music.song.note.Note
class Chord {
+ var accidental = Accidental.None
val accidentals: Array = arrayOf(Accidental.None, Accidental.None, null, null)
var note: Int = 0
@@ -37,7 +38,7 @@
var octave = 0
while (resultIndex < NOTE_COUNT) {
if (accidentalIndex == 0) {
- result[resultIndex] = root + note + 12 * octave
+ result[resultIndex] = root + note + 12 * octave + accidental.distance
resultIndex++
} else if (accidentals[accidentalIndex - 1] != null) {
result[resultIndex] = root + note + when (accidentalIndex) {
@@ -46,7 +47,7 @@
3 -> 10
4 -> 14
else -> 0
- } + accidentals[accidentalIndex - 1]!!.distance + 12 * octave
+ } + accidentals[accidentalIndex - 1]!!.distance + 12 * octave + accidental.distance
resultIndex++
}
accidentalIndex++
@@ -64,7 +65,7 @@
fun toString(displayChordNames: Boolean, root: Note): String {
var result = if (displayChordNames) {
- (root + note).noteName.toString()
+ (root + note + accidental.distance).noteName.toString()
} else {
interval.toString()
}
@@ -101,6 +102,6 @@
}
companion object {
- val NOTE_COUNT = 5
+ const val NOTE_COUNT = 5
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/lukas/music/ui/fragments/EditChordFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/EditChordFragment.kt
index ea02f1e..9e618ed 100644
--- a/app/src/main/java/com/lukas/music/ui/fragments/EditChordFragment.kt
+++ b/app/src/main/java/com/lukas/music/ui/fragments/EditChordFragment.kt
@@ -25,10 +25,7 @@
import com.lukas.music.song.chords.Accidental
import com.lukas.music.song.chords.Chord
import com.lukas.music.song.chords.Interval
-import com.lukas.music.util.EasyDialogFragment
-import com.lukas.music.util.UIUtil
-import com.lukas.music.util.setup
-import com.lukas.music.util.updateToggle
+import com.lukas.music.util.*
class EditChordFragment(private val chord: Chord, private val songFragment: SongFragment) :
EasyDialogFragment() {
@@ -38,6 +35,12 @@
savedInstanceState: Bundle?
): View? {
binding = FragmentEditChordBinding.inflate(inflater)
+ Array(Accidental.VALUES.size) {
+ val button = MaterialButton(binding.root.context)
+ button.layoutParams = UIUtil.cardLayout
+ binding.accidentalSelection.addView(button)
+ return@Array button
+ }.setupEnumSelection(chord::accidental, Accidental.VALUES, callback = { update() })
setupPitchSpinner()
setupEditor()
binding.exitButton.setOnClickListener {
diff --git a/app/src/main/java/com/lukas/music/util/UIUtil.kt b/app/src/main/java/com/lukas/music/util/UIUtil.kt
index cd3ba77..6ae1bd9 100644
--- a/app/src/main/java/com/lukas/music/util/UIUtil.kt
+++ b/app/src/main/java/com/lukas/music/util/UIUtil.kt
@@ -16,6 +16,7 @@
import androidx.core.view.setMargins
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView
+import com.google.android.material.button.MaterialButton
import com.lukas.music.R
import kotlin.reflect.KMutableProperty0
@@ -189,3 +190,31 @@
cardLayout.setMargins(5)
}
}
+
+fun Array.setupEnumSelection(
+ target: KMutableProperty0,
+ values: Array,
+ activeColor: Int = R.color.blue,
+ inactiveColor: Int = R.color.gray_0x60,
+ callback: () -> Unit = {},
+) {
+ fun update() {
+ for ((i, currentButton) in withIndex()) {
+ currentButton.setBackgroundColor(
+ ContextCompat.getColor(
+ currentButton.context,
+ if (target.get() == values[i]) activeColor else inactiveColor
+ )
+ )
+ }
+ callback()
+ }
+ for ((i, button) in withIndex()) {
+ button.text = values[i].toString()
+ button.setOnClickListener {
+ target.set(values[i])
+ update()
+ }
+ }
+ update()
+}
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index b121fe2..9b588fa 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -10,7 +10,7 @@
-
+
diff --git a/app/src/main/java/com/lukas/music/song/chords/Chord.kt b/app/src/main/java/com/lukas/music/song/chords/Chord.kt
index fedb465..85e530b 100644
--- a/app/src/main/java/com/lukas/music/song/chords/Chord.kt
+++ b/app/src/main/java/com/lukas/music/song/chords/Chord.kt
@@ -14,6 +14,7 @@
import com.lukas.music.song.note.Note
class Chord {
+ var accidental = Accidental.None
val accidentals: Array = arrayOf(Accidental.None, Accidental.None, null, null)
var note: Int = 0
@@ -37,7 +38,7 @@
var octave = 0
while (resultIndex < NOTE_COUNT) {
if (accidentalIndex == 0) {
- result[resultIndex] = root + note + 12 * octave
+ result[resultIndex] = root + note + 12 * octave + accidental.distance
resultIndex++
} else if (accidentals[accidentalIndex - 1] != null) {
result[resultIndex] = root + note + when (accidentalIndex) {
@@ -46,7 +47,7 @@
3 -> 10
4 -> 14
else -> 0
- } + accidentals[accidentalIndex - 1]!!.distance + 12 * octave
+ } + accidentals[accidentalIndex - 1]!!.distance + 12 * octave + accidental.distance
resultIndex++
}
accidentalIndex++
@@ -64,7 +65,7 @@
fun toString(displayChordNames: Boolean, root: Note): String {
var result = if (displayChordNames) {
- (root + note).noteName.toString()
+ (root + note + accidental.distance).noteName.toString()
} else {
interval.toString()
}
@@ -101,6 +102,6 @@
}
companion object {
- val NOTE_COUNT = 5
+ const val NOTE_COUNT = 5
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/lukas/music/ui/fragments/EditChordFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/EditChordFragment.kt
index ea02f1e..9e618ed 100644
--- a/app/src/main/java/com/lukas/music/ui/fragments/EditChordFragment.kt
+++ b/app/src/main/java/com/lukas/music/ui/fragments/EditChordFragment.kt
@@ -25,10 +25,7 @@
import com.lukas.music.song.chords.Accidental
import com.lukas.music.song.chords.Chord
import com.lukas.music.song.chords.Interval
-import com.lukas.music.util.EasyDialogFragment
-import com.lukas.music.util.UIUtil
-import com.lukas.music.util.setup
-import com.lukas.music.util.updateToggle
+import com.lukas.music.util.*
class EditChordFragment(private val chord: Chord, private val songFragment: SongFragment) :
EasyDialogFragment() {
@@ -38,6 +35,12 @@
savedInstanceState: Bundle?
): View? {
binding = FragmentEditChordBinding.inflate(inflater)
+ Array(Accidental.VALUES.size) {
+ val button = MaterialButton(binding.root.context)
+ button.layoutParams = UIUtil.cardLayout
+ binding.accidentalSelection.addView(button)
+ return@Array button
+ }.setupEnumSelection(chord::accidental, Accidental.VALUES, callback = { update() })
setupPitchSpinner()
setupEditor()
binding.exitButton.setOnClickListener {
diff --git a/app/src/main/java/com/lukas/music/util/UIUtil.kt b/app/src/main/java/com/lukas/music/util/UIUtil.kt
index cd3ba77..6ae1bd9 100644
--- a/app/src/main/java/com/lukas/music/util/UIUtil.kt
+++ b/app/src/main/java/com/lukas/music/util/UIUtil.kt
@@ -16,6 +16,7 @@
import androidx.core.view.setMargins
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView
+import com.google.android.material.button.MaterialButton
import com.lukas.music.R
import kotlin.reflect.KMutableProperty0
@@ -189,3 +190,31 @@
cardLayout.setMargins(5)
}
}
+
+fun Array.setupEnumSelection(
+ target: KMutableProperty0,
+ values: Array,
+ activeColor: Int = R.color.blue,
+ inactiveColor: Int = R.color.gray_0x60,
+ callback: () -> Unit = {},
+) {
+ fun update() {
+ for ((i, currentButton) in withIndex()) {
+ currentButton.setBackgroundColor(
+ ContextCompat.getColor(
+ currentButton.context,
+ if (target.get() == values[i]) activeColor else inactiveColor
+ )
+ )
+ }
+ callback()
+ }
+ for ((i, button) in withIndex()) {
+ button.text = values[i].toString()
+ button.setOnClickListener {
+ target.set(values[i])
+ update()
+ }
+ }
+ update()
+}
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_edit_chord.xml b/app/src/main/res/layout/fragment_edit_chord.xml
index 7913046..8b34d22 100644
--- a/app/src/main/res/layout/fragment_edit_chord.xml
+++ b/app/src/main/res/layout/fragment_edit_chord.xml
@@ -37,7 +37,7 @@
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView5"
- app:layout_constraintTop_toBottomOf="@+id/textView4" />
+ app:layout_constraintTop_toBottomOf="@+id/accidentalSelection" />
+
+
\ No newline at end of file