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 de1ba1b..61dac11 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 @@ -3,22 +3,22 @@ import com.lukas.music.song.note.Note class Chord(val note: Int, private val chordType: ChordType) { + private val interval = Interval(note) + fun getNotes(root: Note): Array { return Array(chordType.notes.size) { root + note + chordType.notes[it] } } override fun toString(): String { - return "$note($chordType)" + return chordType.transform(interval.toString()) } fun toString(displayChordNames: Boolean, root: Note): String { - if (displayChordNames) { - val noteName = (root + note).noteName - if (chordType == ChordType.Major) { - return noteName.toString().uppercase() - } - return noteName.toString().lowercase() + val base = if (displayChordNames) { + (root + note).noteName.toString() + } else { + interval.toString() } - return toString() + return chordType.transform(base) } } \ No newline at end of file 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 de1ba1b..61dac11 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 @@ -3,22 +3,22 @@ import com.lukas.music.song.note.Note class Chord(val note: Int, private val chordType: ChordType) { + private val interval = Interval(note) + fun getNotes(root: Note): Array { return Array(chordType.notes.size) { root + note + chordType.notes[it] } } override fun toString(): String { - return "$note($chordType)" + return chordType.transform(interval.toString()) } fun toString(displayChordNames: Boolean, root: Note): String { - if (displayChordNames) { - val noteName = (root + note).noteName - if (chordType == ChordType.Major) { - return noteName.toString().uppercase() - } - return noteName.toString().lowercase() + val base = if (displayChordNames) { + (root + note).noteName.toString() + } else { + interval.toString() } - return toString() + return chordType.transform(base) } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/chords/ChordType.kt b/app/src/main/java/com/lukas/music/song/chords/ChordType.kt index 3e03feb..e53189a 100644 --- a/app/src/main/java/com/lukas/music/song/chords/ChordType.kt +++ b/app/src/main/java/com/lukas/music/song/chords/ChordType.kt @@ -1,8 +1,12 @@ package com.lukas.music.song.chords -enum class ChordType(val notes: Array, val asString: String) { - Major(arrayOf(0, 4, 7), "major"), - Minor(arrayOf(0, 3, 7), "minor"), +enum class ChordType( + val notes: Array, + private val asString: String, + val transform: (String) -> String +) { + Major(arrayOf(0, 4, 7), "major", { it.uppercase() }), + Minor(arrayOf(0, 3, 7), "minor", { it.lowercase() }), ; override fun toString(): String { 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 de1ba1b..61dac11 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 @@ -3,22 +3,22 @@ import com.lukas.music.song.note.Note class Chord(val note: Int, private val chordType: ChordType) { + private val interval = Interval(note) + fun getNotes(root: Note): Array { return Array(chordType.notes.size) { root + note + chordType.notes[it] } } override fun toString(): String { - return "$note($chordType)" + return chordType.transform(interval.toString()) } fun toString(displayChordNames: Boolean, root: Note): String { - if (displayChordNames) { - val noteName = (root + note).noteName - if (chordType == ChordType.Major) { - return noteName.toString().uppercase() - } - return noteName.toString().lowercase() + val base = if (displayChordNames) { + (root + note).noteName.toString() + } else { + interval.toString() } - return toString() + return chordType.transform(base) } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/chords/ChordType.kt b/app/src/main/java/com/lukas/music/song/chords/ChordType.kt index 3e03feb..e53189a 100644 --- a/app/src/main/java/com/lukas/music/song/chords/ChordType.kt +++ b/app/src/main/java/com/lukas/music/song/chords/ChordType.kt @@ -1,8 +1,12 @@ package com.lukas.music.song.chords -enum class ChordType(val notes: Array, val asString: String) { - Major(arrayOf(0, 4, 7), "major"), - Minor(arrayOf(0, 3, 7), "minor"), +enum class ChordType( + val notes: Array, + private val asString: String, + val transform: (String) -> String +) { + Major(arrayOf(0, 4, 7), "major", { it.uppercase() }), + Minor(arrayOf(0, 3, 7), "minor", { it.lowercase() }), ; override fun toString(): String { diff --git a/app/src/main/java/com/lukas/music/song/chords/Interval.kt b/app/src/main/java/com/lukas/music/song/chords/Interval.kt new file mode 100644 index 0000000..b3b4480 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/Interval.kt @@ -0,0 +1,47 @@ +package com.lukas.music.song.chords + +class Interval(private val distance: Int) { + private val name: IntervalName = when (distance) { + 0 -> IntervalName.UNISON + 1, 2 -> IntervalName.SECOND + 3, 4 -> IntervalName.THIRD + 5, 6 -> IntervalName.FOURTH + 7 -> IntervalName.FIFTH + 8, 9 -> IntervalName.SIXTH + 10, 11 -> IntervalName.SEVENTH + 12 -> IntervalName.OCTAVE + else -> throw IllegalArgumentException("cannot make interval from distance $distance") + } + private val modifier: Modifier = when (distance) { + 0, 5, 12 -> Modifier.PERFECT + 1, 3, 5, 8, 10 -> Modifier.MINOR + else -> Modifier.MAJOR + } + + override fun toString(): String { + return name.toString() + } + + enum class IntervalName(val distance: Int, val romanVersion: String) { + UNISON(0, "I"), + SECOND(1, "II"), + THIRD(3, "III"), + FOURTH(5, "IV"), + FIFTH(7, "V"), + SIXTH(8, "VI"), + SEVENTH(10, "VII"), + OCTAVE(12, "VIII") + ; + + override fun toString(): String { + return romanVersion + } + } + + enum class Modifier(val descriptor: String, val offset: Int) { + PERFECT("", 0), + MINOR("", 0), + MAJOR("", 1); + } + +} \ No newline at end of file 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 de1ba1b..61dac11 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 @@ -3,22 +3,22 @@ import com.lukas.music.song.note.Note class Chord(val note: Int, private val chordType: ChordType) { + private val interval = Interval(note) + fun getNotes(root: Note): Array { return Array(chordType.notes.size) { root + note + chordType.notes[it] } } override fun toString(): String { - return "$note($chordType)" + return chordType.transform(interval.toString()) } fun toString(displayChordNames: Boolean, root: Note): String { - if (displayChordNames) { - val noteName = (root + note).noteName - if (chordType == ChordType.Major) { - return noteName.toString().uppercase() - } - return noteName.toString().lowercase() + val base = if (displayChordNames) { + (root + note).noteName.toString() + } else { + interval.toString() } - return toString() + return chordType.transform(base) } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/chords/ChordType.kt b/app/src/main/java/com/lukas/music/song/chords/ChordType.kt index 3e03feb..e53189a 100644 --- a/app/src/main/java/com/lukas/music/song/chords/ChordType.kt +++ b/app/src/main/java/com/lukas/music/song/chords/ChordType.kt @@ -1,8 +1,12 @@ package com.lukas.music.song.chords -enum class ChordType(val notes: Array, val asString: String) { - Major(arrayOf(0, 4, 7), "major"), - Minor(arrayOf(0, 3, 7), "minor"), +enum class ChordType( + val notes: Array, + private val asString: String, + val transform: (String) -> String +) { + Major(arrayOf(0, 4, 7), "major", { it.uppercase() }), + Minor(arrayOf(0, 3, 7), "minor", { it.lowercase() }), ; override fun toString(): String { diff --git a/app/src/main/java/com/lukas/music/song/chords/Interval.kt b/app/src/main/java/com/lukas/music/song/chords/Interval.kt new file mode 100644 index 0000000..b3b4480 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/Interval.kt @@ -0,0 +1,47 @@ +package com.lukas.music.song.chords + +class Interval(private val distance: Int) { + private val name: IntervalName = when (distance) { + 0 -> IntervalName.UNISON + 1, 2 -> IntervalName.SECOND + 3, 4 -> IntervalName.THIRD + 5, 6 -> IntervalName.FOURTH + 7 -> IntervalName.FIFTH + 8, 9 -> IntervalName.SIXTH + 10, 11 -> IntervalName.SEVENTH + 12 -> IntervalName.OCTAVE + else -> throw IllegalArgumentException("cannot make interval from distance $distance") + } + private val modifier: Modifier = when (distance) { + 0, 5, 12 -> Modifier.PERFECT + 1, 3, 5, 8, 10 -> Modifier.MINOR + else -> Modifier.MAJOR + } + + override fun toString(): String { + return name.toString() + } + + enum class IntervalName(val distance: Int, val romanVersion: String) { + UNISON(0, "I"), + SECOND(1, "II"), + THIRD(3, "III"), + FOURTH(5, "IV"), + FIFTH(7, "V"), + SIXTH(8, "VI"), + SEVENTH(10, "VII"), + OCTAVE(12, "VIII") + ; + + override fun toString(): String { + return romanVersion + } + } + + enum class Modifier(val descriptor: String, val offset: Int) { + PERFECT("", 0), + MINOR("", 0), + MAJOR("", 1); + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/fragments/SongFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/SongFragment.kt index 3764536..1791310 100644 --- a/app/src/main/java/com/lukas/music/ui/fragments/SongFragment.kt +++ b/app/src/main/java/com/lukas/music/ui/fragments/SongFragment.kt @@ -65,10 +65,6 @@ updateChords() } button.setImageResource(android.R.drawable.ic_delete) - val buttonLayout = TableRow.LayoutParams( - 0, - TableRow.LayoutParams.WRAP_CONTENT - ) button.layoutParams = buttonLayout row.addView(button) binding.chords.addView(row) @@ -80,6 +76,10 @@ TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT ) + val buttonLayout = TableRow.LayoutParams( + 0, + TableRow.LayoutParams.WRAP_CONTENT + ) init { layout.setMargins(10)