diff --git a/.idea/misc.xml b/.idea/misc.xml index c6cbeaf..447e0d3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -12,6 +12,7 @@ + diff --git a/.idea/misc.xml b/.idea/misc.xml index c6cbeaf..447e0d3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -12,6 +12,7 @@ + diff --git a/app/build.gradle b/app/build.gradle index 4ba42b6..914b12b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -51,6 +51,7 @@ implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.gridlayout:gridlayout:1.0.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' diff --git a/.idea/misc.xml b/.idea/misc.xml index c6cbeaf..447e0d3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -12,6 +12,7 @@ + diff --git a/app/build.gradle b/app/build.gradle index 4ba42b6..914b12b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -51,6 +51,7 @@ implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.gridlayout:gridlayout:1.0.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 89a97e6..f5a798f 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -7,13 +7,19 @@ import com.lukas.music.ui.fragments.CreditsFragment import com.lukas.music.ui.fragments.InstrumentListFragment import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.fragments.SongFragment import com.lukas.music.ui.tab.PageListener import com.lukas.music.ui.tab.TabAdapter import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding - private val tabFragments = listOf(PlayFragment(), InstrumentListFragment(), CreditsFragment()) + private val tabFragments = listOf( + PlayFragment(), + SongFragment(), + InstrumentListFragment(), + CreditsFragment(), + ) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/.idea/misc.xml b/.idea/misc.xml index c6cbeaf..447e0d3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -12,6 +12,7 @@ + diff --git a/app/build.gradle b/app/build.gradle index 4ba42b6..914b12b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -51,6 +51,7 @@ implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.gridlayout:gridlayout:1.0.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 89a97e6..f5a798f 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -7,13 +7,19 @@ import com.lukas.music.ui.fragments.CreditsFragment import com.lukas.music.ui.fragments.InstrumentListFragment import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.fragments.SongFragment import com.lukas.music.ui.tab.PageListener import com.lukas.music.ui.tab.TabAdapter import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding - private val tabFragments = listOf(PlayFragment(), InstrumentListFragment(), CreditsFragment()) + private val tabFragments = listOf( + PlayFragment(), + SongFragment(), + InstrumentListFragment(), + CreditsFragment(), + ) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/lukas/music/song/Chord.kt b/app/src/main/java/com/lukas/music/song/Chord.kt deleted file mode 100644 index 36ad846..0000000 --- a/app/src/main/java/com/lukas/music/song/Chord.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.lukas.music.song - -import com.lukas.music.song.note.Note - -class Chord(val note: Int, private val chordType: ChordType) { - fun getNotes(root: Note): Array { - return Array(chordType.notes.size) { root + note + chordType.notes[it] } - } -} \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index c6cbeaf..447e0d3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -12,6 +12,7 @@ + diff --git a/app/build.gradle b/app/build.gradle index 4ba42b6..914b12b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -51,6 +51,7 @@ implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.gridlayout:gridlayout:1.0.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 89a97e6..f5a798f 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -7,13 +7,19 @@ import com.lukas.music.ui.fragments.CreditsFragment import com.lukas.music.ui.fragments.InstrumentListFragment import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.fragments.SongFragment import com.lukas.music.ui.tab.PageListener import com.lukas.music.ui.tab.TabAdapter import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding - private val tabFragments = listOf(PlayFragment(), InstrumentListFragment(), CreditsFragment()) + private val tabFragments = listOf( + PlayFragment(), + SongFragment(), + InstrumentListFragment(), + CreditsFragment(), + ) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/lukas/music/song/Chord.kt b/app/src/main/java/com/lukas/music/song/Chord.kt deleted file mode 100644 index 36ad846..0000000 --- a/app/src/main/java/com/lukas/music/song/Chord.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.lukas.music.song - -import com.lukas.music.song.note.Note - -class Chord(val note: Int, private val chordType: ChordType) { - fun getNotes(root: Note): Array { - return Array(chordType.notes.size) { root + note + chordType.notes[it] } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/ChordProgression.kt deleted file mode 100644 index 144c272..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordProgression.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.lukas.music.song - -class ChordProgression(val chords: List) { - private var index = 0 - - fun step(): Chord { - val result = chords[index] - index++ - index %= chords.size - return result - } -} \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index c6cbeaf..447e0d3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -12,6 +12,7 @@ + diff --git a/app/build.gradle b/app/build.gradle index 4ba42b6..914b12b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -51,6 +51,7 @@ implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.gridlayout:gridlayout:1.0.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 89a97e6..f5a798f 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -7,13 +7,19 @@ import com.lukas.music.ui.fragments.CreditsFragment import com.lukas.music.ui.fragments.InstrumentListFragment import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.fragments.SongFragment import com.lukas.music.ui.tab.PageListener import com.lukas.music.ui.tab.TabAdapter import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding - private val tabFragments = listOf(PlayFragment(), InstrumentListFragment(), CreditsFragment()) + private val tabFragments = listOf( + PlayFragment(), + SongFragment(), + InstrumentListFragment(), + CreditsFragment(), + ) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/lukas/music/song/Chord.kt b/app/src/main/java/com/lukas/music/song/Chord.kt deleted file mode 100644 index 36ad846..0000000 --- a/app/src/main/java/com/lukas/music/song/Chord.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.lukas.music.song - -import com.lukas.music.song.note.Note - -class Chord(val note: Int, private val chordType: ChordType) { - fun getNotes(root: Note): Array { - return Array(chordType.notes.size) { root + note + chordType.notes[it] } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/ChordProgression.kt deleted file mode 100644 index 144c272..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordProgression.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.lukas.music.song - -class ChordProgression(val chords: List) { - private var index = 0 - - fun step(): Chord { - val result = chords[index] - index++ - index %= chords.size - return result - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordType.kt b/app/src/main/java/com/lukas/music/song/ChordType.kt deleted file mode 100644 index 5cab319..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordType.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.lukas.music.song - -enum class ChordType(val notes: Array) { - Major(arrayOf(0, 4, 7)), - Minor(arrayOf(0, 3, 7)), - ; -} \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index c6cbeaf..447e0d3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -12,6 +12,7 @@ + diff --git a/app/build.gradle b/app/build.gradle index 4ba42b6..914b12b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -51,6 +51,7 @@ implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.gridlayout:gridlayout:1.0.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 89a97e6..f5a798f 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -7,13 +7,19 @@ import com.lukas.music.ui.fragments.CreditsFragment import com.lukas.music.ui.fragments.InstrumentListFragment import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.fragments.SongFragment import com.lukas.music.ui.tab.PageListener import com.lukas.music.ui.tab.TabAdapter import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding - private val tabFragments = listOf(PlayFragment(), InstrumentListFragment(), CreditsFragment()) + private val tabFragments = listOf( + PlayFragment(), + SongFragment(), + InstrumentListFragment(), + CreditsFragment(), + ) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/lukas/music/song/Chord.kt b/app/src/main/java/com/lukas/music/song/Chord.kt deleted file mode 100644 index 36ad846..0000000 --- a/app/src/main/java/com/lukas/music/song/Chord.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.lukas.music.song - -import com.lukas.music.song.note.Note - -class Chord(val note: Int, private val chordType: ChordType) { - fun getNotes(root: Note): Array { - return Array(chordType.notes.size) { root + note + chordType.notes[it] } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/ChordProgression.kt deleted file mode 100644 index 144c272..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordProgression.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.lukas.music.song - -class ChordProgression(val chords: List) { - private var index = 0 - - fun step(): Chord { - val result = chords[index] - index++ - index %= chords.size - return result - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordType.kt b/app/src/main/java/com/lukas/music/song/ChordType.kt deleted file mode 100644 index 5cab319..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordType.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.lukas.music.song - -enum class ChordType(val notes: Array) { - Major(arrayOf(0, 4, 7)), - Minor(arrayOf(0, 3, 7)), - ; -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/Song.kt b/app/src/main/java/com/lukas/music/song/Song.kt index ae8c5e2..ebea238 100644 --- a/app/src/main/java/com/lukas/music/song/Song.kt +++ b/app/src/main/java/com/lukas/music/song/Song.kt @@ -4,15 +4,17 @@ import android.os.Looper import android.widget.RadioButton import com.lukas.music.instruments.Instrument +import com.lukas.music.song.chords.Chord +import com.lukas.music.song.chords.ChordProgression import com.lukas.music.song.note.Note class Song( private val root: Note, - private val chordProgression: ChordProgression, + val chordProgression: ChordProgression, val beats: Int ) { private var beat = 0 - private var chord: Chord = chordProgression.chords[0] + private var chord: Chord = chordProgression.step() val stepButtons = mutableListOf() fun step() { @@ -35,14 +37,7 @@ companion object { var currentSong = Song( Note.NOTES[69], - ChordProgression( - listOf( - Chord(0, ChordType.Major), - Chord(5, ChordType.Major), - Chord(2, ChordType.Minor), - Chord(7, ChordType.Major), - ) - ), + ChordProgression(), 4 ) } diff --git a/.idea/misc.xml b/.idea/misc.xml index c6cbeaf..447e0d3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -12,6 +12,7 @@ + diff --git a/app/build.gradle b/app/build.gradle index 4ba42b6..914b12b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -51,6 +51,7 @@ implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.gridlayout:gridlayout:1.0.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 89a97e6..f5a798f 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -7,13 +7,19 @@ import com.lukas.music.ui.fragments.CreditsFragment import com.lukas.music.ui.fragments.InstrumentListFragment import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.fragments.SongFragment import com.lukas.music.ui.tab.PageListener import com.lukas.music.ui.tab.TabAdapter import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding - private val tabFragments = listOf(PlayFragment(), InstrumentListFragment(), CreditsFragment()) + private val tabFragments = listOf( + PlayFragment(), + SongFragment(), + InstrumentListFragment(), + CreditsFragment(), + ) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/lukas/music/song/Chord.kt b/app/src/main/java/com/lukas/music/song/Chord.kt deleted file mode 100644 index 36ad846..0000000 --- a/app/src/main/java/com/lukas/music/song/Chord.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.lukas.music.song - -import com.lukas.music.song.note.Note - -class Chord(val note: Int, private val chordType: ChordType) { - fun getNotes(root: Note): Array { - return Array(chordType.notes.size) { root + note + chordType.notes[it] } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/ChordProgression.kt deleted file mode 100644 index 144c272..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordProgression.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.lukas.music.song - -class ChordProgression(val chords: List) { - private var index = 0 - - fun step(): Chord { - val result = chords[index] - index++ - index %= chords.size - return result - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordType.kt b/app/src/main/java/com/lukas/music/song/ChordType.kt deleted file mode 100644 index 5cab319..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordType.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.lukas.music.song - -enum class ChordType(val notes: Array) { - Major(arrayOf(0, 4, 7)), - Minor(arrayOf(0, 3, 7)), - ; -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/Song.kt b/app/src/main/java/com/lukas/music/song/Song.kt index ae8c5e2..ebea238 100644 --- a/app/src/main/java/com/lukas/music/song/Song.kt +++ b/app/src/main/java/com/lukas/music/song/Song.kt @@ -4,15 +4,17 @@ import android.os.Looper import android.widget.RadioButton import com.lukas.music.instruments.Instrument +import com.lukas.music.song.chords.Chord +import com.lukas.music.song.chords.ChordProgression import com.lukas.music.song.note.Note class Song( private val root: Note, - private val chordProgression: ChordProgression, + val chordProgression: ChordProgression, val beats: Int ) { private var beat = 0 - private var chord: Chord = chordProgression.chords[0] + private var chord: Chord = chordProgression.step() val stepButtons = mutableListOf() fun step() { @@ -35,14 +37,7 @@ companion object { var currentSong = Song( Note.NOTES[69], - ChordProgression( - listOf( - Chord(0, ChordType.Major), - Chord(5, ChordType.Major), - Chord(2, ChordType.Minor), - Chord(7, ChordType.Major), - ) - ), + ChordProgression(), 4 ) } 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 new file mode 100644 index 0000000..9480a25 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/Chord.kt @@ -0,0 +1,13 @@ +package com.lukas.music.song.chords + +import com.lukas.music.song.note.Note + +class Chord(val note: Int, private val chordType: ChordType) { + fun getNotes(root: Note): Array { + return Array(chordType.notes.size) { root + note + chordType.notes[it] } + } + + override fun toString(): String { + return "$note -> $chordType" + } +} \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index c6cbeaf..447e0d3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -12,6 +12,7 @@ + diff --git a/app/build.gradle b/app/build.gradle index 4ba42b6..914b12b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -51,6 +51,7 @@ implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.gridlayout:gridlayout:1.0.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 89a97e6..f5a798f 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -7,13 +7,19 @@ import com.lukas.music.ui.fragments.CreditsFragment import com.lukas.music.ui.fragments.InstrumentListFragment import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.fragments.SongFragment import com.lukas.music.ui.tab.PageListener import com.lukas.music.ui.tab.TabAdapter import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding - private val tabFragments = listOf(PlayFragment(), InstrumentListFragment(), CreditsFragment()) + private val tabFragments = listOf( + PlayFragment(), + SongFragment(), + InstrumentListFragment(), + CreditsFragment(), + ) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/lukas/music/song/Chord.kt b/app/src/main/java/com/lukas/music/song/Chord.kt deleted file mode 100644 index 36ad846..0000000 --- a/app/src/main/java/com/lukas/music/song/Chord.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.lukas.music.song - -import com.lukas.music.song.note.Note - -class Chord(val note: Int, private val chordType: ChordType) { - fun getNotes(root: Note): Array { - return Array(chordType.notes.size) { root + note + chordType.notes[it] } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/ChordProgression.kt deleted file mode 100644 index 144c272..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordProgression.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.lukas.music.song - -class ChordProgression(val chords: List) { - private var index = 0 - - fun step(): Chord { - val result = chords[index] - index++ - index %= chords.size - return result - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordType.kt b/app/src/main/java/com/lukas/music/song/ChordType.kt deleted file mode 100644 index 5cab319..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordType.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.lukas.music.song - -enum class ChordType(val notes: Array) { - Major(arrayOf(0, 4, 7)), - Minor(arrayOf(0, 3, 7)), - ; -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/Song.kt b/app/src/main/java/com/lukas/music/song/Song.kt index ae8c5e2..ebea238 100644 --- a/app/src/main/java/com/lukas/music/song/Song.kt +++ b/app/src/main/java/com/lukas/music/song/Song.kt @@ -4,15 +4,17 @@ import android.os.Looper import android.widget.RadioButton import com.lukas.music.instruments.Instrument +import com.lukas.music.song.chords.Chord +import com.lukas.music.song.chords.ChordProgression import com.lukas.music.song.note.Note class Song( private val root: Note, - private val chordProgression: ChordProgression, + val chordProgression: ChordProgression, val beats: Int ) { private var beat = 0 - private var chord: Chord = chordProgression.chords[0] + private var chord: Chord = chordProgression.step() val stepButtons = mutableListOf() fun step() { @@ -35,14 +37,7 @@ companion object { var currentSong = Song( Note.NOTES[69], - ChordProgression( - listOf( - Chord(0, ChordType.Major), - Chord(5, ChordType.Major), - Chord(2, ChordType.Minor), - Chord(7, ChordType.Major), - ) - ), + ChordProgression(), 4 ) } 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 new file mode 100644 index 0000000..9480a25 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/Chord.kt @@ -0,0 +1,13 @@ +package com.lukas.music.song.chords + +import com.lukas.music.song.note.Note + +class Chord(val note: Int, private val chordType: ChordType) { + fun getNotes(root: Note): Array { + return Array(chordType.notes.size) { root + note + chordType.notes[it] } + } + + override fun toString(): String { + return "$note -> $chordType" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt new file mode 100644 index 0000000..2e189b4 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt @@ -0,0 +1,19 @@ +package com.lukas.music.song.chords + +class ChordProgression { + // TODO: special handler for increasing or decreasing measuresPerPhrase + val measuresPerPhrase: Int = 4 + val phrases = mutableListOf(Phrase(), Phrase()) + + private var position = 0 + fun step(): Chord { + val phrase = phrases[position] + return phrase.step(this) + } + + operator fun inc(): ChordProgression { + position++ + position %= phrases.size + return this + } +} \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index c6cbeaf..447e0d3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -12,6 +12,7 @@ + diff --git a/app/build.gradle b/app/build.gradle index 4ba42b6..914b12b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -51,6 +51,7 @@ implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.gridlayout:gridlayout:1.0.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 89a97e6..f5a798f 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -7,13 +7,19 @@ import com.lukas.music.ui.fragments.CreditsFragment import com.lukas.music.ui.fragments.InstrumentListFragment import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.fragments.SongFragment import com.lukas.music.ui.tab.PageListener import com.lukas.music.ui.tab.TabAdapter import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding - private val tabFragments = listOf(PlayFragment(), InstrumentListFragment(), CreditsFragment()) + private val tabFragments = listOf( + PlayFragment(), + SongFragment(), + InstrumentListFragment(), + CreditsFragment(), + ) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/lukas/music/song/Chord.kt b/app/src/main/java/com/lukas/music/song/Chord.kt deleted file mode 100644 index 36ad846..0000000 --- a/app/src/main/java/com/lukas/music/song/Chord.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.lukas.music.song - -import com.lukas.music.song.note.Note - -class Chord(val note: Int, private val chordType: ChordType) { - fun getNotes(root: Note): Array { - return Array(chordType.notes.size) { root + note + chordType.notes[it] } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/ChordProgression.kt deleted file mode 100644 index 144c272..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordProgression.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.lukas.music.song - -class ChordProgression(val chords: List) { - private var index = 0 - - fun step(): Chord { - val result = chords[index] - index++ - index %= chords.size - return result - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordType.kt b/app/src/main/java/com/lukas/music/song/ChordType.kt deleted file mode 100644 index 5cab319..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordType.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.lukas.music.song - -enum class ChordType(val notes: Array) { - Major(arrayOf(0, 4, 7)), - Minor(arrayOf(0, 3, 7)), - ; -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/Song.kt b/app/src/main/java/com/lukas/music/song/Song.kt index ae8c5e2..ebea238 100644 --- a/app/src/main/java/com/lukas/music/song/Song.kt +++ b/app/src/main/java/com/lukas/music/song/Song.kt @@ -4,15 +4,17 @@ import android.os.Looper import android.widget.RadioButton import com.lukas.music.instruments.Instrument +import com.lukas.music.song.chords.Chord +import com.lukas.music.song.chords.ChordProgression import com.lukas.music.song.note.Note class Song( private val root: Note, - private val chordProgression: ChordProgression, + val chordProgression: ChordProgression, val beats: Int ) { private var beat = 0 - private var chord: Chord = chordProgression.chords[0] + private var chord: Chord = chordProgression.step() val stepButtons = mutableListOf() fun step() { @@ -35,14 +37,7 @@ companion object { var currentSong = Song( Note.NOTES[69], - ChordProgression( - listOf( - Chord(0, ChordType.Major), - Chord(5, ChordType.Major), - Chord(2, ChordType.Minor), - Chord(7, ChordType.Major), - ) - ), + ChordProgression(), 4 ) } 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 new file mode 100644 index 0000000..9480a25 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/Chord.kt @@ -0,0 +1,13 @@ +package com.lukas.music.song.chords + +import com.lukas.music.song.note.Note + +class Chord(val note: Int, private val chordType: ChordType) { + fun getNotes(root: Note): Array { + return Array(chordType.notes.size) { root + note + chordType.notes[it] } + } + + override fun toString(): String { + return "$note -> $chordType" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt new file mode 100644 index 0000000..2e189b4 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt @@ -0,0 +1,19 @@ +package com.lukas.music.song.chords + +class ChordProgression { + // TODO: special handler for increasing or decreasing measuresPerPhrase + val measuresPerPhrase: Int = 4 + val phrases = mutableListOf(Phrase(), Phrase()) + + private var position = 0 + fun step(): Chord { + val phrase = phrases[position] + return phrase.step(this) + } + + operator fun inc(): ChordProgression { + position++ + position %= phrases.size + return this + } +} \ 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 new file mode 100644 index 0000000..3e03feb --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/ChordType.kt @@ -0,0 +1,11 @@ +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"), + ; + + override fun toString(): String { + return asString + } +} \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index c6cbeaf..447e0d3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -12,6 +12,7 @@ + diff --git a/app/build.gradle b/app/build.gradle index 4ba42b6..914b12b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -51,6 +51,7 @@ implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.gridlayout:gridlayout:1.0.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 89a97e6..f5a798f 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -7,13 +7,19 @@ import com.lukas.music.ui.fragments.CreditsFragment import com.lukas.music.ui.fragments.InstrumentListFragment import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.fragments.SongFragment import com.lukas.music.ui.tab.PageListener import com.lukas.music.ui.tab.TabAdapter import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding - private val tabFragments = listOf(PlayFragment(), InstrumentListFragment(), CreditsFragment()) + private val tabFragments = listOf( + PlayFragment(), + SongFragment(), + InstrumentListFragment(), + CreditsFragment(), + ) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/lukas/music/song/Chord.kt b/app/src/main/java/com/lukas/music/song/Chord.kt deleted file mode 100644 index 36ad846..0000000 --- a/app/src/main/java/com/lukas/music/song/Chord.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.lukas.music.song - -import com.lukas.music.song.note.Note - -class Chord(val note: Int, private val chordType: ChordType) { - fun getNotes(root: Note): Array { - return Array(chordType.notes.size) { root + note + chordType.notes[it] } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/ChordProgression.kt deleted file mode 100644 index 144c272..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordProgression.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.lukas.music.song - -class ChordProgression(val chords: List) { - private var index = 0 - - fun step(): Chord { - val result = chords[index] - index++ - index %= chords.size - return result - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordType.kt b/app/src/main/java/com/lukas/music/song/ChordType.kt deleted file mode 100644 index 5cab319..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordType.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.lukas.music.song - -enum class ChordType(val notes: Array) { - Major(arrayOf(0, 4, 7)), - Minor(arrayOf(0, 3, 7)), - ; -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/Song.kt b/app/src/main/java/com/lukas/music/song/Song.kt index ae8c5e2..ebea238 100644 --- a/app/src/main/java/com/lukas/music/song/Song.kt +++ b/app/src/main/java/com/lukas/music/song/Song.kt @@ -4,15 +4,17 @@ import android.os.Looper import android.widget.RadioButton import com.lukas.music.instruments.Instrument +import com.lukas.music.song.chords.Chord +import com.lukas.music.song.chords.ChordProgression import com.lukas.music.song.note.Note class Song( private val root: Note, - private val chordProgression: ChordProgression, + val chordProgression: ChordProgression, val beats: Int ) { private var beat = 0 - private var chord: Chord = chordProgression.chords[0] + private var chord: Chord = chordProgression.step() val stepButtons = mutableListOf() fun step() { @@ -35,14 +37,7 @@ companion object { var currentSong = Song( Note.NOTES[69], - ChordProgression( - listOf( - Chord(0, ChordType.Major), - Chord(5, ChordType.Major), - Chord(2, ChordType.Minor), - Chord(7, ChordType.Major), - ) - ), + ChordProgression(), 4 ) } 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 new file mode 100644 index 0000000..9480a25 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/Chord.kt @@ -0,0 +1,13 @@ +package com.lukas.music.song.chords + +import com.lukas.music.song.note.Note + +class Chord(val note: Int, private val chordType: ChordType) { + fun getNotes(root: Note): Array { + return Array(chordType.notes.size) { root + note + chordType.notes[it] } + } + + override fun toString(): String { + return "$note -> $chordType" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt new file mode 100644 index 0000000..2e189b4 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt @@ -0,0 +1,19 @@ +package com.lukas.music.song.chords + +class ChordProgression { + // TODO: special handler for increasing or decreasing measuresPerPhrase + val measuresPerPhrase: Int = 4 + val phrases = mutableListOf(Phrase(), Phrase()) + + private var position = 0 + fun step(): Chord { + val phrase = phrases[position] + return phrase.step(this) + } + + operator fun inc(): ChordProgression { + position++ + position %= phrases.size + return this + } +} \ 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 new file mode 100644 index 0000000..3e03feb --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/ChordType.kt @@ -0,0 +1,11 @@ +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"), + ; + + override fun toString(): String { + return asString + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/chords/Phrase.kt b/app/src/main/java/com/lukas/music/song/chords/Phrase.kt new file mode 100644 index 0000000..76d4259 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/Phrase.kt @@ -0,0 +1,21 @@ +package com.lukas.music.song.chords + +class Phrase { + val chords = mutableListOf( + Chord(0, ChordType.Major), + Chord(5, ChordType.Major), + Chord(2, ChordType.Minor), + Chord(7, ChordType.Major), + ) + + var position = 0 + fun step(parent: ChordProgression): Chord { + var parent: ChordProgression = parent + position++ + if (position >= chords.size) { + position = 0 + parent++ + } + return chords[position] + } +} \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index c6cbeaf..447e0d3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -12,6 +12,7 @@ + diff --git a/app/build.gradle b/app/build.gradle index 4ba42b6..914b12b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -51,6 +51,7 @@ implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.gridlayout:gridlayout:1.0.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 89a97e6..f5a798f 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -7,13 +7,19 @@ import com.lukas.music.ui.fragments.CreditsFragment import com.lukas.music.ui.fragments.InstrumentListFragment import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.fragments.SongFragment import com.lukas.music.ui.tab.PageListener import com.lukas.music.ui.tab.TabAdapter import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding - private val tabFragments = listOf(PlayFragment(), InstrumentListFragment(), CreditsFragment()) + private val tabFragments = listOf( + PlayFragment(), + SongFragment(), + InstrumentListFragment(), + CreditsFragment(), + ) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/lukas/music/song/Chord.kt b/app/src/main/java/com/lukas/music/song/Chord.kt deleted file mode 100644 index 36ad846..0000000 --- a/app/src/main/java/com/lukas/music/song/Chord.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.lukas.music.song - -import com.lukas.music.song.note.Note - -class Chord(val note: Int, private val chordType: ChordType) { - fun getNotes(root: Note): Array { - return Array(chordType.notes.size) { root + note + chordType.notes[it] } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/ChordProgression.kt deleted file mode 100644 index 144c272..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordProgression.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.lukas.music.song - -class ChordProgression(val chords: List) { - private var index = 0 - - fun step(): Chord { - val result = chords[index] - index++ - index %= chords.size - return result - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordType.kt b/app/src/main/java/com/lukas/music/song/ChordType.kt deleted file mode 100644 index 5cab319..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordType.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.lukas.music.song - -enum class ChordType(val notes: Array) { - Major(arrayOf(0, 4, 7)), - Minor(arrayOf(0, 3, 7)), - ; -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/Song.kt b/app/src/main/java/com/lukas/music/song/Song.kt index ae8c5e2..ebea238 100644 --- a/app/src/main/java/com/lukas/music/song/Song.kt +++ b/app/src/main/java/com/lukas/music/song/Song.kt @@ -4,15 +4,17 @@ import android.os.Looper import android.widget.RadioButton import com.lukas.music.instruments.Instrument +import com.lukas.music.song.chords.Chord +import com.lukas.music.song.chords.ChordProgression import com.lukas.music.song.note.Note class Song( private val root: Note, - private val chordProgression: ChordProgression, + val chordProgression: ChordProgression, val beats: Int ) { private var beat = 0 - private var chord: Chord = chordProgression.chords[0] + private var chord: Chord = chordProgression.step() val stepButtons = mutableListOf() fun step() { @@ -35,14 +37,7 @@ companion object { var currentSong = Song( Note.NOTES[69], - ChordProgression( - listOf( - Chord(0, ChordType.Major), - Chord(5, ChordType.Major), - Chord(2, ChordType.Minor), - Chord(7, ChordType.Major), - ) - ), + ChordProgression(), 4 ) } 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 new file mode 100644 index 0000000..9480a25 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/Chord.kt @@ -0,0 +1,13 @@ +package com.lukas.music.song.chords + +import com.lukas.music.song.note.Note + +class Chord(val note: Int, private val chordType: ChordType) { + fun getNotes(root: Note): Array { + return Array(chordType.notes.size) { root + note + chordType.notes[it] } + } + + override fun toString(): String { + return "$note -> $chordType" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt new file mode 100644 index 0000000..2e189b4 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt @@ -0,0 +1,19 @@ +package com.lukas.music.song.chords + +class ChordProgression { + // TODO: special handler for increasing or decreasing measuresPerPhrase + val measuresPerPhrase: Int = 4 + val phrases = mutableListOf(Phrase(), Phrase()) + + private var position = 0 + fun step(): Chord { + val phrase = phrases[position] + return phrase.step(this) + } + + operator fun inc(): ChordProgression { + position++ + position %= phrases.size + return this + } +} \ 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 new file mode 100644 index 0000000..3e03feb --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/ChordType.kt @@ -0,0 +1,11 @@ +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"), + ; + + override fun toString(): String { + return asString + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/chords/Phrase.kt b/app/src/main/java/com/lukas/music/song/chords/Phrase.kt new file mode 100644 index 0000000..76d4259 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/Phrase.kt @@ -0,0 +1,21 @@ +package com.lukas.music.song.chords + +class Phrase { + val chords = mutableListOf( + Chord(0, ChordType.Major), + Chord(5, ChordType.Major), + Chord(2, ChordType.Minor), + Chord(7, ChordType.Major), + ) + + var position = 0 + fun step(parent: ChordProgression): Chord { + var parent: ChordProgression = parent + position++ + if (position >= chords.size) { + position = 0 + parent++ + } + return chords[position] + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/InstrumentAdapter.kt b/app/src/main/java/com/lukas/music/ui/InstrumentAdapter.kt deleted file mode 100644 index d6900a7..0000000 --- a/app/src/main/java/com/lukas/music/ui/InstrumentAdapter.kt +++ /dev/null @@ -1,57 +0,0 @@ -package com.lukas.music.ui - -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.AdapterView -import android.widget.ArrayAdapter -import androidx.recyclerview.widget.RecyclerView -import com.lukas.music.databinding.FragmentInstrumentBinding -import com.lukas.music.instruments.Instrument -import com.lukas.music.instruments.Waveform - - -class InstrumentAdapter : RecyclerView.Adapter() { - class InstrumentViewHolder(val binding: FragmentInstrumentBinding) : - RecyclerView.ViewHolder(binding.root), AdapterView.OnItemSelectedListener { - lateinit var instrument: Instrument - - init { - val adapter = ArrayAdapter( - binding.root.context, - android.R.layout.simple_spinner_dropdown_item, Waveform.VALUES - ) - binding.waveformSelection.adapter = adapter - binding.waveformSelection.onItemSelectedListener = this - } - - override fun onItemSelected( - adapterView: AdapterView<*>?, - view: View?, - position: Int, - id: Long - ) { - instrument.waveform = Waveform.VALUES[position] - } - - override fun onNothingSelected(adapterView: AdapterView<*>?) { - } - } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): InstrumentViewHolder { - val context = parent.context - val inflater = LayoutInflater.from(context) - val binding = FragmentInstrumentBinding.inflate(inflater, parent, false) - return InstrumentViewHolder(binding) - } - - override fun onBindViewHolder(holder: InstrumentViewHolder, position: Int) { - val instrument = Instrument.instruments[position] - holder.instrument = instrument - instrument.applyToView(holder.binding) - } - - override fun getItemCount(): Int { - return Instrument.instruments.size - } -} \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index c6cbeaf..447e0d3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -12,6 +12,7 @@ + diff --git a/app/build.gradle b/app/build.gradle index 4ba42b6..914b12b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -51,6 +51,7 @@ implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.gridlayout:gridlayout:1.0.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 89a97e6..f5a798f 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -7,13 +7,19 @@ import com.lukas.music.ui.fragments.CreditsFragment import com.lukas.music.ui.fragments.InstrumentListFragment import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.fragments.SongFragment import com.lukas.music.ui.tab.PageListener import com.lukas.music.ui.tab.TabAdapter import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding - private val tabFragments = listOf(PlayFragment(), InstrumentListFragment(), CreditsFragment()) + private val tabFragments = listOf( + PlayFragment(), + SongFragment(), + InstrumentListFragment(), + CreditsFragment(), + ) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/lukas/music/song/Chord.kt b/app/src/main/java/com/lukas/music/song/Chord.kt deleted file mode 100644 index 36ad846..0000000 --- a/app/src/main/java/com/lukas/music/song/Chord.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.lukas.music.song - -import com.lukas.music.song.note.Note - -class Chord(val note: Int, private val chordType: ChordType) { - fun getNotes(root: Note): Array { - return Array(chordType.notes.size) { root + note + chordType.notes[it] } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/ChordProgression.kt deleted file mode 100644 index 144c272..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordProgression.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.lukas.music.song - -class ChordProgression(val chords: List) { - private var index = 0 - - fun step(): Chord { - val result = chords[index] - index++ - index %= chords.size - return result - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordType.kt b/app/src/main/java/com/lukas/music/song/ChordType.kt deleted file mode 100644 index 5cab319..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordType.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.lukas.music.song - -enum class ChordType(val notes: Array) { - Major(arrayOf(0, 4, 7)), - Minor(arrayOf(0, 3, 7)), - ; -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/Song.kt b/app/src/main/java/com/lukas/music/song/Song.kt index ae8c5e2..ebea238 100644 --- a/app/src/main/java/com/lukas/music/song/Song.kt +++ b/app/src/main/java/com/lukas/music/song/Song.kt @@ -4,15 +4,17 @@ import android.os.Looper import android.widget.RadioButton import com.lukas.music.instruments.Instrument +import com.lukas.music.song.chords.Chord +import com.lukas.music.song.chords.ChordProgression import com.lukas.music.song.note.Note class Song( private val root: Note, - private val chordProgression: ChordProgression, + val chordProgression: ChordProgression, val beats: Int ) { private var beat = 0 - private var chord: Chord = chordProgression.chords[0] + private var chord: Chord = chordProgression.step() val stepButtons = mutableListOf() fun step() { @@ -35,14 +37,7 @@ companion object { var currentSong = Song( Note.NOTES[69], - ChordProgression( - listOf( - Chord(0, ChordType.Major), - Chord(5, ChordType.Major), - Chord(2, ChordType.Minor), - Chord(7, ChordType.Major), - ) - ), + ChordProgression(), 4 ) } 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 new file mode 100644 index 0000000..9480a25 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/Chord.kt @@ -0,0 +1,13 @@ +package com.lukas.music.song.chords + +import com.lukas.music.song.note.Note + +class Chord(val note: Int, private val chordType: ChordType) { + fun getNotes(root: Note): Array { + return Array(chordType.notes.size) { root + note + chordType.notes[it] } + } + + override fun toString(): String { + return "$note -> $chordType" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt new file mode 100644 index 0000000..2e189b4 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt @@ -0,0 +1,19 @@ +package com.lukas.music.song.chords + +class ChordProgression { + // TODO: special handler for increasing or decreasing measuresPerPhrase + val measuresPerPhrase: Int = 4 + val phrases = mutableListOf(Phrase(), Phrase()) + + private var position = 0 + fun step(): Chord { + val phrase = phrases[position] + return phrase.step(this) + } + + operator fun inc(): ChordProgression { + position++ + position %= phrases.size + return this + } +} \ 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 new file mode 100644 index 0000000..3e03feb --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/ChordType.kt @@ -0,0 +1,11 @@ +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"), + ; + + override fun toString(): String { + return asString + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/chords/Phrase.kt b/app/src/main/java/com/lukas/music/song/chords/Phrase.kt new file mode 100644 index 0000000..76d4259 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/Phrase.kt @@ -0,0 +1,21 @@ +package com.lukas.music.song.chords + +class Phrase { + val chords = mutableListOf( + Chord(0, ChordType.Major), + Chord(5, ChordType.Major), + Chord(2, ChordType.Minor), + Chord(7, ChordType.Major), + ) + + var position = 0 + fun step(parent: ChordProgression): Chord { + var parent: ChordProgression = parent + position++ + if (position >= chords.size) { + position = 0 + parent++ + } + return chords[position] + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/InstrumentAdapter.kt b/app/src/main/java/com/lukas/music/ui/InstrumentAdapter.kt deleted file mode 100644 index d6900a7..0000000 --- a/app/src/main/java/com/lukas/music/ui/InstrumentAdapter.kt +++ /dev/null @@ -1,57 +0,0 @@ -package com.lukas.music.ui - -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.AdapterView -import android.widget.ArrayAdapter -import androidx.recyclerview.widget.RecyclerView -import com.lukas.music.databinding.FragmentInstrumentBinding -import com.lukas.music.instruments.Instrument -import com.lukas.music.instruments.Waveform - - -class InstrumentAdapter : RecyclerView.Adapter() { - class InstrumentViewHolder(val binding: FragmentInstrumentBinding) : - RecyclerView.ViewHolder(binding.root), AdapterView.OnItemSelectedListener { - lateinit var instrument: Instrument - - init { - val adapter = ArrayAdapter( - binding.root.context, - android.R.layout.simple_spinner_dropdown_item, Waveform.VALUES - ) - binding.waveformSelection.adapter = adapter - binding.waveformSelection.onItemSelectedListener = this - } - - override fun onItemSelected( - adapterView: AdapterView<*>?, - view: View?, - position: Int, - id: Long - ) { - instrument.waveform = Waveform.VALUES[position] - } - - override fun onNothingSelected(adapterView: AdapterView<*>?) { - } - } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): InstrumentViewHolder { - val context = parent.context - val inflater = LayoutInflater.from(context) - val binding = FragmentInstrumentBinding.inflate(inflater, parent, false) - return InstrumentViewHolder(binding) - } - - override fun onBindViewHolder(holder: InstrumentViewHolder, position: Int) { - val instrument = Instrument.instruments[position] - holder.instrument = instrument - instrument.applyToView(holder.binding) - } - - override fun getItemCount(): Int { - return Instrument.instruments.size - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt new file mode 100644 index 0000000..6f36573 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt @@ -0,0 +1,57 @@ +package com.lukas.music.ui.adapters + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.AdapterView +import android.widget.ArrayAdapter +import androidx.recyclerview.widget.RecyclerView +import com.lukas.music.databinding.FragmentInstrumentBinding +import com.lukas.music.instruments.Instrument +import com.lukas.music.instruments.Waveform + + +class InstrumentAdapter : RecyclerView.Adapter() { + class InstrumentViewHolder(val binding: FragmentInstrumentBinding) : + RecyclerView.ViewHolder(binding.root), AdapterView.OnItemSelectedListener { + lateinit var instrument: Instrument + + init { + val adapter = ArrayAdapter( + binding.root.context, + android.R.layout.simple_spinner_dropdown_item, Waveform.VALUES + ) + binding.waveformSelection.adapter = adapter + binding.waveformSelection.onItemSelectedListener = this + } + + override fun onItemSelected( + adapterView: AdapterView<*>?, + view: View?, + position: Int, + id: Long + ) { + instrument.waveform = Waveform.VALUES[position] + } + + override fun onNothingSelected(adapterView: AdapterView<*>?) { + } + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): InstrumentViewHolder { + val context = parent.context + val inflater = LayoutInflater.from(context) + val binding = FragmentInstrumentBinding.inflate(inflater, parent, false) + return InstrumentViewHolder(binding) + } + + override fun onBindViewHolder(holder: InstrumentViewHolder, position: Int) { + val instrument = Instrument.instruments[position] + holder.instrument = instrument + instrument.applyToView(holder.binding) + } + + override fun getItemCount(): Int { + return Instrument.instruments.size + } +} \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index c6cbeaf..447e0d3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -12,6 +12,7 @@ + diff --git a/app/build.gradle b/app/build.gradle index 4ba42b6..914b12b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -51,6 +51,7 @@ implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.gridlayout:gridlayout:1.0.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 89a97e6..f5a798f 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -7,13 +7,19 @@ import com.lukas.music.ui.fragments.CreditsFragment import com.lukas.music.ui.fragments.InstrumentListFragment import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.fragments.SongFragment import com.lukas.music.ui.tab.PageListener import com.lukas.music.ui.tab.TabAdapter import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding - private val tabFragments = listOf(PlayFragment(), InstrumentListFragment(), CreditsFragment()) + private val tabFragments = listOf( + PlayFragment(), + SongFragment(), + InstrumentListFragment(), + CreditsFragment(), + ) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/lukas/music/song/Chord.kt b/app/src/main/java/com/lukas/music/song/Chord.kt deleted file mode 100644 index 36ad846..0000000 --- a/app/src/main/java/com/lukas/music/song/Chord.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.lukas.music.song - -import com.lukas.music.song.note.Note - -class Chord(val note: Int, private val chordType: ChordType) { - fun getNotes(root: Note): Array { - return Array(chordType.notes.size) { root + note + chordType.notes[it] } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/ChordProgression.kt deleted file mode 100644 index 144c272..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordProgression.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.lukas.music.song - -class ChordProgression(val chords: List) { - private var index = 0 - - fun step(): Chord { - val result = chords[index] - index++ - index %= chords.size - return result - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordType.kt b/app/src/main/java/com/lukas/music/song/ChordType.kt deleted file mode 100644 index 5cab319..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordType.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.lukas.music.song - -enum class ChordType(val notes: Array) { - Major(arrayOf(0, 4, 7)), - Minor(arrayOf(0, 3, 7)), - ; -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/Song.kt b/app/src/main/java/com/lukas/music/song/Song.kt index ae8c5e2..ebea238 100644 --- a/app/src/main/java/com/lukas/music/song/Song.kt +++ b/app/src/main/java/com/lukas/music/song/Song.kt @@ -4,15 +4,17 @@ import android.os.Looper import android.widget.RadioButton import com.lukas.music.instruments.Instrument +import com.lukas.music.song.chords.Chord +import com.lukas.music.song.chords.ChordProgression import com.lukas.music.song.note.Note class Song( private val root: Note, - private val chordProgression: ChordProgression, + val chordProgression: ChordProgression, val beats: Int ) { private var beat = 0 - private var chord: Chord = chordProgression.chords[0] + private var chord: Chord = chordProgression.step() val stepButtons = mutableListOf() fun step() { @@ -35,14 +37,7 @@ companion object { var currentSong = Song( Note.NOTES[69], - ChordProgression( - listOf( - Chord(0, ChordType.Major), - Chord(5, ChordType.Major), - Chord(2, ChordType.Minor), - Chord(7, ChordType.Major), - ) - ), + ChordProgression(), 4 ) } 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 new file mode 100644 index 0000000..9480a25 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/Chord.kt @@ -0,0 +1,13 @@ +package com.lukas.music.song.chords + +import com.lukas.music.song.note.Note + +class Chord(val note: Int, private val chordType: ChordType) { + fun getNotes(root: Note): Array { + return Array(chordType.notes.size) { root + note + chordType.notes[it] } + } + + override fun toString(): String { + return "$note -> $chordType" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt new file mode 100644 index 0000000..2e189b4 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt @@ -0,0 +1,19 @@ +package com.lukas.music.song.chords + +class ChordProgression { + // TODO: special handler for increasing or decreasing measuresPerPhrase + val measuresPerPhrase: Int = 4 + val phrases = mutableListOf(Phrase(), Phrase()) + + private var position = 0 + fun step(): Chord { + val phrase = phrases[position] + return phrase.step(this) + } + + operator fun inc(): ChordProgression { + position++ + position %= phrases.size + return this + } +} \ 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 new file mode 100644 index 0000000..3e03feb --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/ChordType.kt @@ -0,0 +1,11 @@ +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"), + ; + + override fun toString(): String { + return asString + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/chords/Phrase.kt b/app/src/main/java/com/lukas/music/song/chords/Phrase.kt new file mode 100644 index 0000000..76d4259 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/Phrase.kt @@ -0,0 +1,21 @@ +package com.lukas.music.song.chords + +class Phrase { + val chords = mutableListOf( + Chord(0, ChordType.Major), + Chord(5, ChordType.Major), + Chord(2, ChordType.Minor), + Chord(7, ChordType.Major), + ) + + var position = 0 + fun step(parent: ChordProgression): Chord { + var parent: ChordProgression = parent + position++ + if (position >= chords.size) { + position = 0 + parent++ + } + return chords[position] + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/InstrumentAdapter.kt b/app/src/main/java/com/lukas/music/ui/InstrumentAdapter.kt deleted file mode 100644 index d6900a7..0000000 --- a/app/src/main/java/com/lukas/music/ui/InstrumentAdapter.kt +++ /dev/null @@ -1,57 +0,0 @@ -package com.lukas.music.ui - -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.AdapterView -import android.widget.ArrayAdapter -import androidx.recyclerview.widget.RecyclerView -import com.lukas.music.databinding.FragmentInstrumentBinding -import com.lukas.music.instruments.Instrument -import com.lukas.music.instruments.Waveform - - -class InstrumentAdapter : RecyclerView.Adapter() { - class InstrumentViewHolder(val binding: FragmentInstrumentBinding) : - RecyclerView.ViewHolder(binding.root), AdapterView.OnItemSelectedListener { - lateinit var instrument: Instrument - - init { - val adapter = ArrayAdapter( - binding.root.context, - android.R.layout.simple_spinner_dropdown_item, Waveform.VALUES - ) - binding.waveformSelection.adapter = adapter - binding.waveformSelection.onItemSelectedListener = this - } - - override fun onItemSelected( - adapterView: AdapterView<*>?, - view: View?, - position: Int, - id: Long - ) { - instrument.waveform = Waveform.VALUES[position] - } - - override fun onNothingSelected(adapterView: AdapterView<*>?) { - } - } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): InstrumentViewHolder { - val context = parent.context - val inflater = LayoutInflater.from(context) - val binding = FragmentInstrumentBinding.inflate(inflater, parent, false) - return InstrumentViewHolder(binding) - } - - override fun onBindViewHolder(holder: InstrumentViewHolder, position: Int) { - val instrument = Instrument.instruments[position] - holder.instrument = instrument - instrument.applyToView(holder.binding) - } - - override fun getItemCount(): Int { - return Instrument.instruments.size - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt new file mode 100644 index 0000000..6f36573 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt @@ -0,0 +1,57 @@ +package com.lukas.music.ui.adapters + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.AdapterView +import android.widget.ArrayAdapter +import androidx.recyclerview.widget.RecyclerView +import com.lukas.music.databinding.FragmentInstrumentBinding +import com.lukas.music.instruments.Instrument +import com.lukas.music.instruments.Waveform + + +class InstrumentAdapter : RecyclerView.Adapter() { + class InstrumentViewHolder(val binding: FragmentInstrumentBinding) : + RecyclerView.ViewHolder(binding.root), AdapterView.OnItemSelectedListener { + lateinit var instrument: Instrument + + init { + val adapter = ArrayAdapter( + binding.root.context, + android.R.layout.simple_spinner_dropdown_item, Waveform.VALUES + ) + binding.waveformSelection.adapter = adapter + binding.waveformSelection.onItemSelectedListener = this + } + + override fun onItemSelected( + adapterView: AdapterView<*>?, + view: View?, + position: Int, + id: Long + ) { + instrument.waveform = Waveform.VALUES[position] + } + + override fun onNothingSelected(adapterView: AdapterView<*>?) { + } + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): InstrumentViewHolder { + val context = parent.context + val inflater = LayoutInflater.from(context) + val binding = FragmentInstrumentBinding.inflate(inflater, parent, false) + return InstrumentViewHolder(binding) + } + + override fun onBindViewHolder(holder: InstrumentViewHolder, position: Int) { + val instrument = Instrument.instruments[position] + holder.instrument = instrument + instrument.applyToView(holder.binding) + } + + override fun getItemCount(): Int { + return Instrument.instruments.size + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt index ddc76f2..290284c 100644 --- a/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt +++ b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt @@ -1,10 +1,10 @@ package com.lukas.music.ui.fragments import android.os.Bundle -import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.fragment.app.Fragment import com.lukas.music.R class CreditsFragment : Fragment() { @@ -14,13 +14,4 @@ ): View? { return inflater.inflate(R.layout.fragment_credits, container, false) } - - companion object { - @JvmStatic - fun newInstance() = - CreditsFragment().apply { - arguments = Bundle().apply { - } - } - } } \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index c6cbeaf..447e0d3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -12,6 +12,7 @@ + diff --git a/app/build.gradle b/app/build.gradle index 4ba42b6..914b12b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -51,6 +51,7 @@ implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.gridlayout:gridlayout:1.0.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 89a97e6..f5a798f 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -7,13 +7,19 @@ import com.lukas.music.ui.fragments.CreditsFragment import com.lukas.music.ui.fragments.InstrumentListFragment import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.fragments.SongFragment import com.lukas.music.ui.tab.PageListener import com.lukas.music.ui.tab.TabAdapter import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding - private val tabFragments = listOf(PlayFragment(), InstrumentListFragment(), CreditsFragment()) + private val tabFragments = listOf( + PlayFragment(), + SongFragment(), + InstrumentListFragment(), + CreditsFragment(), + ) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/lukas/music/song/Chord.kt b/app/src/main/java/com/lukas/music/song/Chord.kt deleted file mode 100644 index 36ad846..0000000 --- a/app/src/main/java/com/lukas/music/song/Chord.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.lukas.music.song - -import com.lukas.music.song.note.Note - -class Chord(val note: Int, private val chordType: ChordType) { - fun getNotes(root: Note): Array { - return Array(chordType.notes.size) { root + note + chordType.notes[it] } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/ChordProgression.kt deleted file mode 100644 index 144c272..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordProgression.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.lukas.music.song - -class ChordProgression(val chords: List) { - private var index = 0 - - fun step(): Chord { - val result = chords[index] - index++ - index %= chords.size - return result - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordType.kt b/app/src/main/java/com/lukas/music/song/ChordType.kt deleted file mode 100644 index 5cab319..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordType.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.lukas.music.song - -enum class ChordType(val notes: Array) { - Major(arrayOf(0, 4, 7)), - Minor(arrayOf(0, 3, 7)), - ; -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/Song.kt b/app/src/main/java/com/lukas/music/song/Song.kt index ae8c5e2..ebea238 100644 --- a/app/src/main/java/com/lukas/music/song/Song.kt +++ b/app/src/main/java/com/lukas/music/song/Song.kt @@ -4,15 +4,17 @@ import android.os.Looper import android.widget.RadioButton import com.lukas.music.instruments.Instrument +import com.lukas.music.song.chords.Chord +import com.lukas.music.song.chords.ChordProgression import com.lukas.music.song.note.Note class Song( private val root: Note, - private val chordProgression: ChordProgression, + val chordProgression: ChordProgression, val beats: Int ) { private var beat = 0 - private var chord: Chord = chordProgression.chords[0] + private var chord: Chord = chordProgression.step() val stepButtons = mutableListOf() fun step() { @@ -35,14 +37,7 @@ companion object { var currentSong = Song( Note.NOTES[69], - ChordProgression( - listOf( - Chord(0, ChordType.Major), - Chord(5, ChordType.Major), - Chord(2, ChordType.Minor), - Chord(7, ChordType.Major), - ) - ), + ChordProgression(), 4 ) } 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 new file mode 100644 index 0000000..9480a25 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/Chord.kt @@ -0,0 +1,13 @@ +package com.lukas.music.song.chords + +import com.lukas.music.song.note.Note + +class Chord(val note: Int, private val chordType: ChordType) { + fun getNotes(root: Note): Array { + return Array(chordType.notes.size) { root + note + chordType.notes[it] } + } + + override fun toString(): String { + return "$note -> $chordType" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt new file mode 100644 index 0000000..2e189b4 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt @@ -0,0 +1,19 @@ +package com.lukas.music.song.chords + +class ChordProgression { + // TODO: special handler for increasing or decreasing measuresPerPhrase + val measuresPerPhrase: Int = 4 + val phrases = mutableListOf(Phrase(), Phrase()) + + private var position = 0 + fun step(): Chord { + val phrase = phrases[position] + return phrase.step(this) + } + + operator fun inc(): ChordProgression { + position++ + position %= phrases.size + return this + } +} \ 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 new file mode 100644 index 0000000..3e03feb --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/ChordType.kt @@ -0,0 +1,11 @@ +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"), + ; + + override fun toString(): String { + return asString + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/chords/Phrase.kt b/app/src/main/java/com/lukas/music/song/chords/Phrase.kt new file mode 100644 index 0000000..76d4259 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/Phrase.kt @@ -0,0 +1,21 @@ +package com.lukas.music.song.chords + +class Phrase { + val chords = mutableListOf( + Chord(0, ChordType.Major), + Chord(5, ChordType.Major), + Chord(2, ChordType.Minor), + Chord(7, ChordType.Major), + ) + + var position = 0 + fun step(parent: ChordProgression): Chord { + var parent: ChordProgression = parent + position++ + if (position >= chords.size) { + position = 0 + parent++ + } + return chords[position] + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/InstrumentAdapter.kt b/app/src/main/java/com/lukas/music/ui/InstrumentAdapter.kt deleted file mode 100644 index d6900a7..0000000 --- a/app/src/main/java/com/lukas/music/ui/InstrumentAdapter.kt +++ /dev/null @@ -1,57 +0,0 @@ -package com.lukas.music.ui - -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.AdapterView -import android.widget.ArrayAdapter -import androidx.recyclerview.widget.RecyclerView -import com.lukas.music.databinding.FragmentInstrumentBinding -import com.lukas.music.instruments.Instrument -import com.lukas.music.instruments.Waveform - - -class InstrumentAdapter : RecyclerView.Adapter() { - class InstrumentViewHolder(val binding: FragmentInstrumentBinding) : - RecyclerView.ViewHolder(binding.root), AdapterView.OnItemSelectedListener { - lateinit var instrument: Instrument - - init { - val adapter = ArrayAdapter( - binding.root.context, - android.R.layout.simple_spinner_dropdown_item, Waveform.VALUES - ) - binding.waveformSelection.adapter = adapter - binding.waveformSelection.onItemSelectedListener = this - } - - override fun onItemSelected( - adapterView: AdapterView<*>?, - view: View?, - position: Int, - id: Long - ) { - instrument.waveform = Waveform.VALUES[position] - } - - override fun onNothingSelected(adapterView: AdapterView<*>?) { - } - } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): InstrumentViewHolder { - val context = parent.context - val inflater = LayoutInflater.from(context) - val binding = FragmentInstrumentBinding.inflate(inflater, parent, false) - return InstrumentViewHolder(binding) - } - - override fun onBindViewHolder(holder: InstrumentViewHolder, position: Int) { - val instrument = Instrument.instruments[position] - holder.instrument = instrument - instrument.applyToView(holder.binding) - } - - override fun getItemCount(): Int { - return Instrument.instruments.size - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt new file mode 100644 index 0000000..6f36573 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt @@ -0,0 +1,57 @@ +package com.lukas.music.ui.adapters + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.AdapterView +import android.widget.ArrayAdapter +import androidx.recyclerview.widget.RecyclerView +import com.lukas.music.databinding.FragmentInstrumentBinding +import com.lukas.music.instruments.Instrument +import com.lukas.music.instruments.Waveform + + +class InstrumentAdapter : RecyclerView.Adapter() { + class InstrumentViewHolder(val binding: FragmentInstrumentBinding) : + RecyclerView.ViewHolder(binding.root), AdapterView.OnItemSelectedListener { + lateinit var instrument: Instrument + + init { + val adapter = ArrayAdapter( + binding.root.context, + android.R.layout.simple_spinner_dropdown_item, Waveform.VALUES + ) + binding.waveformSelection.adapter = adapter + binding.waveformSelection.onItemSelectedListener = this + } + + override fun onItemSelected( + adapterView: AdapterView<*>?, + view: View?, + position: Int, + id: Long + ) { + instrument.waveform = Waveform.VALUES[position] + } + + override fun onNothingSelected(adapterView: AdapterView<*>?) { + } + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): InstrumentViewHolder { + val context = parent.context + val inflater = LayoutInflater.from(context) + val binding = FragmentInstrumentBinding.inflate(inflater, parent, false) + return InstrumentViewHolder(binding) + } + + override fun onBindViewHolder(holder: InstrumentViewHolder, position: Int) { + val instrument = Instrument.instruments[position] + holder.instrument = instrument + instrument.applyToView(holder.binding) + } + + override fun getItemCount(): Int { + return Instrument.instruments.size + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt index ddc76f2..290284c 100644 --- a/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt +++ b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt @@ -1,10 +1,10 @@ package com.lukas.music.ui.fragments import android.os.Bundle -import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.fragment.app.Fragment import com.lukas.music.R class CreditsFragment : Fragment() { @@ -14,13 +14,4 @@ ): View? { return inflater.inflate(R.layout.fragment_credits, container, false) } - - companion object { - @JvmStatic - fun newInstance() = - CreditsFragment().apply { - arguments = Bundle().apply { - } - } - } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt index 4bbc6ba..6b77049 100644 --- a/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt +++ b/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt @@ -1,17 +1,13 @@ package com.lukas.music.ui.fragments import android.os.Bundle -import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView -import com.lukas.music.MainActivity -import com.lukas.music.R import com.lukas.music.databinding.FragmentInstrumentListBinding -import com.lukas.music.databinding.FragmentPlayBinding -import com.lukas.music.ui.InstrumentAdapter +import com.lukas.music.ui.adapters.InstrumentAdapter class InstrumentListFragment : Fragment() { lateinit var binding: FragmentInstrumentListBinding diff --git a/.idea/misc.xml b/.idea/misc.xml index c6cbeaf..447e0d3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -12,6 +12,7 @@ + diff --git a/app/build.gradle b/app/build.gradle index 4ba42b6..914b12b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -51,6 +51,7 @@ implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.gridlayout:gridlayout:1.0.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 89a97e6..f5a798f 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -7,13 +7,19 @@ import com.lukas.music.ui.fragments.CreditsFragment import com.lukas.music.ui.fragments.InstrumentListFragment import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.fragments.SongFragment import com.lukas.music.ui.tab.PageListener import com.lukas.music.ui.tab.TabAdapter import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding - private val tabFragments = listOf(PlayFragment(), InstrumentListFragment(), CreditsFragment()) + private val tabFragments = listOf( + PlayFragment(), + SongFragment(), + InstrumentListFragment(), + CreditsFragment(), + ) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/lukas/music/song/Chord.kt b/app/src/main/java/com/lukas/music/song/Chord.kt deleted file mode 100644 index 36ad846..0000000 --- a/app/src/main/java/com/lukas/music/song/Chord.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.lukas.music.song - -import com.lukas.music.song.note.Note - -class Chord(val note: Int, private val chordType: ChordType) { - fun getNotes(root: Note): Array { - return Array(chordType.notes.size) { root + note + chordType.notes[it] } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/ChordProgression.kt deleted file mode 100644 index 144c272..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordProgression.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.lukas.music.song - -class ChordProgression(val chords: List) { - private var index = 0 - - fun step(): Chord { - val result = chords[index] - index++ - index %= chords.size - return result - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordType.kt b/app/src/main/java/com/lukas/music/song/ChordType.kt deleted file mode 100644 index 5cab319..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordType.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.lukas.music.song - -enum class ChordType(val notes: Array) { - Major(arrayOf(0, 4, 7)), - Minor(arrayOf(0, 3, 7)), - ; -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/Song.kt b/app/src/main/java/com/lukas/music/song/Song.kt index ae8c5e2..ebea238 100644 --- a/app/src/main/java/com/lukas/music/song/Song.kt +++ b/app/src/main/java/com/lukas/music/song/Song.kt @@ -4,15 +4,17 @@ import android.os.Looper import android.widget.RadioButton import com.lukas.music.instruments.Instrument +import com.lukas.music.song.chords.Chord +import com.lukas.music.song.chords.ChordProgression import com.lukas.music.song.note.Note class Song( private val root: Note, - private val chordProgression: ChordProgression, + val chordProgression: ChordProgression, val beats: Int ) { private var beat = 0 - private var chord: Chord = chordProgression.chords[0] + private var chord: Chord = chordProgression.step() val stepButtons = mutableListOf() fun step() { @@ -35,14 +37,7 @@ companion object { var currentSong = Song( Note.NOTES[69], - ChordProgression( - listOf( - Chord(0, ChordType.Major), - Chord(5, ChordType.Major), - Chord(2, ChordType.Minor), - Chord(7, ChordType.Major), - ) - ), + ChordProgression(), 4 ) } 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 new file mode 100644 index 0000000..9480a25 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/Chord.kt @@ -0,0 +1,13 @@ +package com.lukas.music.song.chords + +import com.lukas.music.song.note.Note + +class Chord(val note: Int, private val chordType: ChordType) { + fun getNotes(root: Note): Array { + return Array(chordType.notes.size) { root + note + chordType.notes[it] } + } + + override fun toString(): String { + return "$note -> $chordType" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt new file mode 100644 index 0000000..2e189b4 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt @@ -0,0 +1,19 @@ +package com.lukas.music.song.chords + +class ChordProgression { + // TODO: special handler for increasing or decreasing measuresPerPhrase + val measuresPerPhrase: Int = 4 + val phrases = mutableListOf(Phrase(), Phrase()) + + private var position = 0 + fun step(): Chord { + val phrase = phrases[position] + return phrase.step(this) + } + + operator fun inc(): ChordProgression { + position++ + position %= phrases.size + return this + } +} \ 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 new file mode 100644 index 0000000..3e03feb --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/ChordType.kt @@ -0,0 +1,11 @@ +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"), + ; + + override fun toString(): String { + return asString + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/chords/Phrase.kt b/app/src/main/java/com/lukas/music/song/chords/Phrase.kt new file mode 100644 index 0000000..76d4259 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/Phrase.kt @@ -0,0 +1,21 @@ +package com.lukas.music.song.chords + +class Phrase { + val chords = mutableListOf( + Chord(0, ChordType.Major), + Chord(5, ChordType.Major), + Chord(2, ChordType.Minor), + Chord(7, ChordType.Major), + ) + + var position = 0 + fun step(parent: ChordProgression): Chord { + var parent: ChordProgression = parent + position++ + if (position >= chords.size) { + position = 0 + parent++ + } + return chords[position] + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/InstrumentAdapter.kt b/app/src/main/java/com/lukas/music/ui/InstrumentAdapter.kt deleted file mode 100644 index d6900a7..0000000 --- a/app/src/main/java/com/lukas/music/ui/InstrumentAdapter.kt +++ /dev/null @@ -1,57 +0,0 @@ -package com.lukas.music.ui - -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.AdapterView -import android.widget.ArrayAdapter -import androidx.recyclerview.widget.RecyclerView -import com.lukas.music.databinding.FragmentInstrumentBinding -import com.lukas.music.instruments.Instrument -import com.lukas.music.instruments.Waveform - - -class InstrumentAdapter : RecyclerView.Adapter() { - class InstrumentViewHolder(val binding: FragmentInstrumentBinding) : - RecyclerView.ViewHolder(binding.root), AdapterView.OnItemSelectedListener { - lateinit var instrument: Instrument - - init { - val adapter = ArrayAdapter( - binding.root.context, - android.R.layout.simple_spinner_dropdown_item, Waveform.VALUES - ) - binding.waveformSelection.adapter = adapter - binding.waveformSelection.onItemSelectedListener = this - } - - override fun onItemSelected( - adapterView: AdapterView<*>?, - view: View?, - position: Int, - id: Long - ) { - instrument.waveform = Waveform.VALUES[position] - } - - override fun onNothingSelected(adapterView: AdapterView<*>?) { - } - } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): InstrumentViewHolder { - val context = parent.context - val inflater = LayoutInflater.from(context) - val binding = FragmentInstrumentBinding.inflate(inflater, parent, false) - return InstrumentViewHolder(binding) - } - - override fun onBindViewHolder(holder: InstrumentViewHolder, position: Int) { - val instrument = Instrument.instruments[position] - holder.instrument = instrument - instrument.applyToView(holder.binding) - } - - override fun getItemCount(): Int { - return Instrument.instruments.size - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt new file mode 100644 index 0000000..6f36573 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt @@ -0,0 +1,57 @@ +package com.lukas.music.ui.adapters + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.AdapterView +import android.widget.ArrayAdapter +import androidx.recyclerview.widget.RecyclerView +import com.lukas.music.databinding.FragmentInstrumentBinding +import com.lukas.music.instruments.Instrument +import com.lukas.music.instruments.Waveform + + +class InstrumentAdapter : RecyclerView.Adapter() { + class InstrumentViewHolder(val binding: FragmentInstrumentBinding) : + RecyclerView.ViewHolder(binding.root), AdapterView.OnItemSelectedListener { + lateinit var instrument: Instrument + + init { + val adapter = ArrayAdapter( + binding.root.context, + android.R.layout.simple_spinner_dropdown_item, Waveform.VALUES + ) + binding.waveformSelection.adapter = adapter + binding.waveformSelection.onItemSelectedListener = this + } + + override fun onItemSelected( + adapterView: AdapterView<*>?, + view: View?, + position: Int, + id: Long + ) { + instrument.waveform = Waveform.VALUES[position] + } + + override fun onNothingSelected(adapterView: AdapterView<*>?) { + } + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): InstrumentViewHolder { + val context = parent.context + val inflater = LayoutInflater.from(context) + val binding = FragmentInstrumentBinding.inflate(inflater, parent, false) + return InstrumentViewHolder(binding) + } + + override fun onBindViewHolder(holder: InstrumentViewHolder, position: Int) { + val instrument = Instrument.instruments[position] + holder.instrument = instrument + instrument.applyToView(holder.binding) + } + + override fun getItemCount(): Int { + return Instrument.instruments.size + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt index ddc76f2..290284c 100644 --- a/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt +++ b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt @@ -1,10 +1,10 @@ package com.lukas.music.ui.fragments import android.os.Bundle -import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.fragment.app.Fragment import com.lukas.music.R class CreditsFragment : Fragment() { @@ -14,13 +14,4 @@ ): View? { return inflater.inflate(R.layout.fragment_credits, container, false) } - - companion object { - @JvmStatic - fun newInstance() = - CreditsFragment().apply { - arguments = Bundle().apply { - } - } - } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt index 4bbc6ba..6b77049 100644 --- a/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt +++ b/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt @@ -1,17 +1,13 @@ package com.lukas.music.ui.fragments import android.os.Bundle -import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView -import com.lukas.music.MainActivity -import com.lukas.music.R import com.lukas.music.databinding.FragmentInstrumentListBinding -import com.lukas.music.databinding.FragmentPlayBinding -import com.lukas.music.ui.InstrumentAdapter +import com.lukas.music.ui.adapters.InstrumentAdapter class InstrumentListFragment : Fragment() { lateinit var binding: FragmentInstrumentListBinding 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 new file mode 100644 index 0000000..395fba0 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/SongFragment.kt @@ -0,0 +1,33 @@ +package com.lukas.music.ui.fragments + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TableRow +import android.widget.TextView +import androidx.fragment.app.Fragment +import com.lukas.music.databinding.FragmentSongBinding +import com.lukas.music.song.Song + +class SongFragment : Fragment() { + private lateinit var binding: FragmentSongBinding + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + binding = FragmentSongBinding.inflate(inflater) + binding.chords.isStretchAllColumns = true + for (phrase in Song.currentSong.chordProgression.phrases) { + val row = TableRow(binding.root.context) + for (chord in phrase.chords) { + val text = TextView(binding.root.context) + text.text = chord.toString() + row.addView(text) + } + binding.chords.addView(row) + } + return binding.root + } +} \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index c6cbeaf..447e0d3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -12,6 +12,7 @@ + diff --git a/app/build.gradle b/app/build.gradle index 4ba42b6..914b12b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -51,6 +51,7 @@ implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.gridlayout:gridlayout:1.0.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 89a97e6..f5a798f 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -7,13 +7,19 @@ import com.lukas.music.ui.fragments.CreditsFragment import com.lukas.music.ui.fragments.InstrumentListFragment import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.fragments.SongFragment import com.lukas.music.ui.tab.PageListener import com.lukas.music.ui.tab.TabAdapter import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding - private val tabFragments = listOf(PlayFragment(), InstrumentListFragment(), CreditsFragment()) + private val tabFragments = listOf( + PlayFragment(), + SongFragment(), + InstrumentListFragment(), + CreditsFragment(), + ) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/lukas/music/song/Chord.kt b/app/src/main/java/com/lukas/music/song/Chord.kt deleted file mode 100644 index 36ad846..0000000 --- a/app/src/main/java/com/lukas/music/song/Chord.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.lukas.music.song - -import com.lukas.music.song.note.Note - -class Chord(val note: Int, private val chordType: ChordType) { - fun getNotes(root: Note): Array { - return Array(chordType.notes.size) { root + note + chordType.notes[it] } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/ChordProgression.kt deleted file mode 100644 index 144c272..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordProgression.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.lukas.music.song - -class ChordProgression(val chords: List) { - private var index = 0 - - fun step(): Chord { - val result = chords[index] - index++ - index %= chords.size - return result - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordType.kt b/app/src/main/java/com/lukas/music/song/ChordType.kt deleted file mode 100644 index 5cab319..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordType.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.lukas.music.song - -enum class ChordType(val notes: Array) { - Major(arrayOf(0, 4, 7)), - Minor(arrayOf(0, 3, 7)), - ; -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/Song.kt b/app/src/main/java/com/lukas/music/song/Song.kt index ae8c5e2..ebea238 100644 --- a/app/src/main/java/com/lukas/music/song/Song.kt +++ b/app/src/main/java/com/lukas/music/song/Song.kt @@ -4,15 +4,17 @@ import android.os.Looper import android.widget.RadioButton import com.lukas.music.instruments.Instrument +import com.lukas.music.song.chords.Chord +import com.lukas.music.song.chords.ChordProgression import com.lukas.music.song.note.Note class Song( private val root: Note, - private val chordProgression: ChordProgression, + val chordProgression: ChordProgression, val beats: Int ) { private var beat = 0 - private var chord: Chord = chordProgression.chords[0] + private var chord: Chord = chordProgression.step() val stepButtons = mutableListOf() fun step() { @@ -35,14 +37,7 @@ companion object { var currentSong = Song( Note.NOTES[69], - ChordProgression( - listOf( - Chord(0, ChordType.Major), - Chord(5, ChordType.Major), - Chord(2, ChordType.Minor), - Chord(7, ChordType.Major), - ) - ), + ChordProgression(), 4 ) } 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 new file mode 100644 index 0000000..9480a25 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/Chord.kt @@ -0,0 +1,13 @@ +package com.lukas.music.song.chords + +import com.lukas.music.song.note.Note + +class Chord(val note: Int, private val chordType: ChordType) { + fun getNotes(root: Note): Array { + return Array(chordType.notes.size) { root + note + chordType.notes[it] } + } + + override fun toString(): String { + return "$note -> $chordType" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt new file mode 100644 index 0000000..2e189b4 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt @@ -0,0 +1,19 @@ +package com.lukas.music.song.chords + +class ChordProgression { + // TODO: special handler for increasing or decreasing measuresPerPhrase + val measuresPerPhrase: Int = 4 + val phrases = mutableListOf(Phrase(), Phrase()) + + private var position = 0 + fun step(): Chord { + val phrase = phrases[position] + return phrase.step(this) + } + + operator fun inc(): ChordProgression { + position++ + position %= phrases.size + return this + } +} \ 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 new file mode 100644 index 0000000..3e03feb --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/ChordType.kt @@ -0,0 +1,11 @@ +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"), + ; + + override fun toString(): String { + return asString + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/chords/Phrase.kt b/app/src/main/java/com/lukas/music/song/chords/Phrase.kt new file mode 100644 index 0000000..76d4259 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/Phrase.kt @@ -0,0 +1,21 @@ +package com.lukas.music.song.chords + +class Phrase { + val chords = mutableListOf( + Chord(0, ChordType.Major), + Chord(5, ChordType.Major), + Chord(2, ChordType.Minor), + Chord(7, ChordType.Major), + ) + + var position = 0 + fun step(parent: ChordProgression): Chord { + var parent: ChordProgression = parent + position++ + if (position >= chords.size) { + position = 0 + parent++ + } + return chords[position] + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/InstrumentAdapter.kt b/app/src/main/java/com/lukas/music/ui/InstrumentAdapter.kt deleted file mode 100644 index d6900a7..0000000 --- a/app/src/main/java/com/lukas/music/ui/InstrumentAdapter.kt +++ /dev/null @@ -1,57 +0,0 @@ -package com.lukas.music.ui - -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.AdapterView -import android.widget.ArrayAdapter -import androidx.recyclerview.widget.RecyclerView -import com.lukas.music.databinding.FragmentInstrumentBinding -import com.lukas.music.instruments.Instrument -import com.lukas.music.instruments.Waveform - - -class InstrumentAdapter : RecyclerView.Adapter() { - class InstrumentViewHolder(val binding: FragmentInstrumentBinding) : - RecyclerView.ViewHolder(binding.root), AdapterView.OnItemSelectedListener { - lateinit var instrument: Instrument - - init { - val adapter = ArrayAdapter( - binding.root.context, - android.R.layout.simple_spinner_dropdown_item, Waveform.VALUES - ) - binding.waveformSelection.adapter = adapter - binding.waveformSelection.onItemSelectedListener = this - } - - override fun onItemSelected( - adapterView: AdapterView<*>?, - view: View?, - position: Int, - id: Long - ) { - instrument.waveform = Waveform.VALUES[position] - } - - override fun onNothingSelected(adapterView: AdapterView<*>?) { - } - } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): InstrumentViewHolder { - val context = parent.context - val inflater = LayoutInflater.from(context) - val binding = FragmentInstrumentBinding.inflate(inflater, parent, false) - return InstrumentViewHolder(binding) - } - - override fun onBindViewHolder(holder: InstrumentViewHolder, position: Int) { - val instrument = Instrument.instruments[position] - holder.instrument = instrument - instrument.applyToView(holder.binding) - } - - override fun getItemCount(): Int { - return Instrument.instruments.size - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt new file mode 100644 index 0000000..6f36573 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt @@ -0,0 +1,57 @@ +package com.lukas.music.ui.adapters + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.AdapterView +import android.widget.ArrayAdapter +import androidx.recyclerview.widget.RecyclerView +import com.lukas.music.databinding.FragmentInstrumentBinding +import com.lukas.music.instruments.Instrument +import com.lukas.music.instruments.Waveform + + +class InstrumentAdapter : RecyclerView.Adapter() { + class InstrumentViewHolder(val binding: FragmentInstrumentBinding) : + RecyclerView.ViewHolder(binding.root), AdapterView.OnItemSelectedListener { + lateinit var instrument: Instrument + + init { + val adapter = ArrayAdapter( + binding.root.context, + android.R.layout.simple_spinner_dropdown_item, Waveform.VALUES + ) + binding.waveformSelection.adapter = adapter + binding.waveformSelection.onItemSelectedListener = this + } + + override fun onItemSelected( + adapterView: AdapterView<*>?, + view: View?, + position: Int, + id: Long + ) { + instrument.waveform = Waveform.VALUES[position] + } + + override fun onNothingSelected(adapterView: AdapterView<*>?) { + } + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): InstrumentViewHolder { + val context = parent.context + val inflater = LayoutInflater.from(context) + val binding = FragmentInstrumentBinding.inflate(inflater, parent, false) + return InstrumentViewHolder(binding) + } + + override fun onBindViewHolder(holder: InstrumentViewHolder, position: Int) { + val instrument = Instrument.instruments[position] + holder.instrument = instrument + instrument.applyToView(holder.binding) + } + + override fun getItemCount(): Int { + return Instrument.instruments.size + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt index ddc76f2..290284c 100644 --- a/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt +++ b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt @@ -1,10 +1,10 @@ package com.lukas.music.ui.fragments import android.os.Bundle -import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.fragment.app.Fragment import com.lukas.music.R class CreditsFragment : Fragment() { @@ -14,13 +14,4 @@ ): View? { return inflater.inflate(R.layout.fragment_credits, container, false) } - - companion object { - @JvmStatic - fun newInstance() = - CreditsFragment().apply { - arguments = Bundle().apply { - } - } - } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt index 4bbc6ba..6b77049 100644 --- a/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt +++ b/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt @@ -1,17 +1,13 @@ package com.lukas.music.ui.fragments import android.os.Bundle -import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView -import com.lukas.music.MainActivity -import com.lukas.music.R import com.lukas.music.databinding.FragmentInstrumentListBinding -import com.lukas.music.databinding.FragmentPlayBinding -import com.lukas.music.ui.InstrumentAdapter +import com.lukas.music.ui.adapters.InstrumentAdapter class InstrumentListFragment : Fragment() { lateinit var binding: FragmentInstrumentListBinding 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 new file mode 100644 index 0000000..395fba0 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/SongFragment.kt @@ -0,0 +1,33 @@ +package com.lukas.music.ui.fragments + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TableRow +import android.widget.TextView +import androidx.fragment.app.Fragment +import com.lukas.music.databinding.FragmentSongBinding +import com.lukas.music.song.Song + +class SongFragment : Fragment() { + private lateinit var binding: FragmentSongBinding + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + binding = FragmentSongBinding.inflate(inflater) + binding.chords.isStretchAllColumns = true + for (phrase in Song.currentSong.chordProgression.phrases) { + val row = TableRow(binding.root.context) + for (chord in phrase.chords) { + val text = TextView(binding.root.context) + text.text = chord.toString() + row.addView(text) + } + binding.chords.addView(row) + } + return binding.root + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 1992e0f..3eaf701 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -17,12 +17,17 @@ + android:text="@string/play_tab" /> + android:text="@string/song_tab" /> + + + diff --git a/app/build.gradle b/app/build.gradle index 4ba42b6..914b12b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -51,6 +51,7 @@ implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.gridlayout:gridlayout:1.0.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 89a97e6..f5a798f 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -7,13 +7,19 @@ import com.lukas.music.ui.fragments.CreditsFragment import com.lukas.music.ui.fragments.InstrumentListFragment import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.fragments.SongFragment import com.lukas.music.ui.tab.PageListener import com.lukas.music.ui.tab.TabAdapter import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding - private val tabFragments = listOf(PlayFragment(), InstrumentListFragment(), CreditsFragment()) + private val tabFragments = listOf( + PlayFragment(), + SongFragment(), + InstrumentListFragment(), + CreditsFragment(), + ) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/lukas/music/song/Chord.kt b/app/src/main/java/com/lukas/music/song/Chord.kt deleted file mode 100644 index 36ad846..0000000 --- a/app/src/main/java/com/lukas/music/song/Chord.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.lukas.music.song - -import com.lukas.music.song.note.Note - -class Chord(val note: Int, private val chordType: ChordType) { - fun getNotes(root: Note): Array { - return Array(chordType.notes.size) { root + note + chordType.notes[it] } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/ChordProgression.kt deleted file mode 100644 index 144c272..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordProgression.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.lukas.music.song - -class ChordProgression(val chords: List) { - private var index = 0 - - fun step(): Chord { - val result = chords[index] - index++ - index %= chords.size - return result - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordType.kt b/app/src/main/java/com/lukas/music/song/ChordType.kt deleted file mode 100644 index 5cab319..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordType.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.lukas.music.song - -enum class ChordType(val notes: Array) { - Major(arrayOf(0, 4, 7)), - Minor(arrayOf(0, 3, 7)), - ; -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/Song.kt b/app/src/main/java/com/lukas/music/song/Song.kt index ae8c5e2..ebea238 100644 --- a/app/src/main/java/com/lukas/music/song/Song.kt +++ b/app/src/main/java/com/lukas/music/song/Song.kt @@ -4,15 +4,17 @@ import android.os.Looper import android.widget.RadioButton import com.lukas.music.instruments.Instrument +import com.lukas.music.song.chords.Chord +import com.lukas.music.song.chords.ChordProgression import com.lukas.music.song.note.Note class Song( private val root: Note, - private val chordProgression: ChordProgression, + val chordProgression: ChordProgression, val beats: Int ) { private var beat = 0 - private var chord: Chord = chordProgression.chords[0] + private var chord: Chord = chordProgression.step() val stepButtons = mutableListOf() fun step() { @@ -35,14 +37,7 @@ companion object { var currentSong = Song( Note.NOTES[69], - ChordProgression( - listOf( - Chord(0, ChordType.Major), - Chord(5, ChordType.Major), - Chord(2, ChordType.Minor), - Chord(7, ChordType.Major), - ) - ), + ChordProgression(), 4 ) } 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 new file mode 100644 index 0000000..9480a25 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/Chord.kt @@ -0,0 +1,13 @@ +package com.lukas.music.song.chords + +import com.lukas.music.song.note.Note + +class Chord(val note: Int, private val chordType: ChordType) { + fun getNotes(root: Note): Array { + return Array(chordType.notes.size) { root + note + chordType.notes[it] } + } + + override fun toString(): String { + return "$note -> $chordType" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt new file mode 100644 index 0000000..2e189b4 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt @@ -0,0 +1,19 @@ +package com.lukas.music.song.chords + +class ChordProgression { + // TODO: special handler for increasing or decreasing measuresPerPhrase + val measuresPerPhrase: Int = 4 + val phrases = mutableListOf(Phrase(), Phrase()) + + private var position = 0 + fun step(): Chord { + val phrase = phrases[position] + return phrase.step(this) + } + + operator fun inc(): ChordProgression { + position++ + position %= phrases.size + return this + } +} \ 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 new file mode 100644 index 0000000..3e03feb --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/ChordType.kt @@ -0,0 +1,11 @@ +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"), + ; + + override fun toString(): String { + return asString + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/chords/Phrase.kt b/app/src/main/java/com/lukas/music/song/chords/Phrase.kt new file mode 100644 index 0000000..76d4259 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/Phrase.kt @@ -0,0 +1,21 @@ +package com.lukas.music.song.chords + +class Phrase { + val chords = mutableListOf( + Chord(0, ChordType.Major), + Chord(5, ChordType.Major), + Chord(2, ChordType.Minor), + Chord(7, ChordType.Major), + ) + + var position = 0 + fun step(parent: ChordProgression): Chord { + var parent: ChordProgression = parent + position++ + if (position >= chords.size) { + position = 0 + parent++ + } + return chords[position] + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/InstrumentAdapter.kt b/app/src/main/java/com/lukas/music/ui/InstrumentAdapter.kt deleted file mode 100644 index d6900a7..0000000 --- a/app/src/main/java/com/lukas/music/ui/InstrumentAdapter.kt +++ /dev/null @@ -1,57 +0,0 @@ -package com.lukas.music.ui - -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.AdapterView -import android.widget.ArrayAdapter -import androidx.recyclerview.widget.RecyclerView -import com.lukas.music.databinding.FragmentInstrumentBinding -import com.lukas.music.instruments.Instrument -import com.lukas.music.instruments.Waveform - - -class InstrumentAdapter : RecyclerView.Adapter() { - class InstrumentViewHolder(val binding: FragmentInstrumentBinding) : - RecyclerView.ViewHolder(binding.root), AdapterView.OnItemSelectedListener { - lateinit var instrument: Instrument - - init { - val adapter = ArrayAdapter( - binding.root.context, - android.R.layout.simple_spinner_dropdown_item, Waveform.VALUES - ) - binding.waveformSelection.adapter = adapter - binding.waveformSelection.onItemSelectedListener = this - } - - override fun onItemSelected( - adapterView: AdapterView<*>?, - view: View?, - position: Int, - id: Long - ) { - instrument.waveform = Waveform.VALUES[position] - } - - override fun onNothingSelected(adapterView: AdapterView<*>?) { - } - } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): InstrumentViewHolder { - val context = parent.context - val inflater = LayoutInflater.from(context) - val binding = FragmentInstrumentBinding.inflate(inflater, parent, false) - return InstrumentViewHolder(binding) - } - - override fun onBindViewHolder(holder: InstrumentViewHolder, position: Int) { - val instrument = Instrument.instruments[position] - holder.instrument = instrument - instrument.applyToView(holder.binding) - } - - override fun getItemCount(): Int { - return Instrument.instruments.size - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt new file mode 100644 index 0000000..6f36573 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt @@ -0,0 +1,57 @@ +package com.lukas.music.ui.adapters + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.AdapterView +import android.widget.ArrayAdapter +import androidx.recyclerview.widget.RecyclerView +import com.lukas.music.databinding.FragmentInstrumentBinding +import com.lukas.music.instruments.Instrument +import com.lukas.music.instruments.Waveform + + +class InstrumentAdapter : RecyclerView.Adapter() { + class InstrumentViewHolder(val binding: FragmentInstrumentBinding) : + RecyclerView.ViewHolder(binding.root), AdapterView.OnItemSelectedListener { + lateinit var instrument: Instrument + + init { + val adapter = ArrayAdapter( + binding.root.context, + android.R.layout.simple_spinner_dropdown_item, Waveform.VALUES + ) + binding.waveformSelection.adapter = adapter + binding.waveformSelection.onItemSelectedListener = this + } + + override fun onItemSelected( + adapterView: AdapterView<*>?, + view: View?, + position: Int, + id: Long + ) { + instrument.waveform = Waveform.VALUES[position] + } + + override fun onNothingSelected(adapterView: AdapterView<*>?) { + } + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): InstrumentViewHolder { + val context = parent.context + val inflater = LayoutInflater.from(context) + val binding = FragmentInstrumentBinding.inflate(inflater, parent, false) + return InstrumentViewHolder(binding) + } + + override fun onBindViewHolder(holder: InstrumentViewHolder, position: Int) { + val instrument = Instrument.instruments[position] + holder.instrument = instrument + instrument.applyToView(holder.binding) + } + + override fun getItemCount(): Int { + return Instrument.instruments.size + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt index ddc76f2..290284c 100644 --- a/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt +++ b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt @@ -1,10 +1,10 @@ package com.lukas.music.ui.fragments import android.os.Bundle -import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.fragment.app.Fragment import com.lukas.music.R class CreditsFragment : Fragment() { @@ -14,13 +14,4 @@ ): View? { return inflater.inflate(R.layout.fragment_credits, container, false) } - - companion object { - @JvmStatic - fun newInstance() = - CreditsFragment().apply { - arguments = Bundle().apply { - } - } - } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt index 4bbc6ba..6b77049 100644 --- a/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt +++ b/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt @@ -1,17 +1,13 @@ package com.lukas.music.ui.fragments import android.os.Bundle -import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView -import com.lukas.music.MainActivity -import com.lukas.music.R import com.lukas.music.databinding.FragmentInstrumentListBinding -import com.lukas.music.databinding.FragmentPlayBinding -import com.lukas.music.ui.InstrumentAdapter +import com.lukas.music.ui.adapters.InstrumentAdapter class InstrumentListFragment : Fragment() { lateinit var binding: FragmentInstrumentListBinding 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 new file mode 100644 index 0000000..395fba0 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/SongFragment.kt @@ -0,0 +1,33 @@ +package com.lukas.music.ui.fragments + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TableRow +import android.widget.TextView +import androidx.fragment.app.Fragment +import com.lukas.music.databinding.FragmentSongBinding +import com.lukas.music.song.Song + +class SongFragment : Fragment() { + private lateinit var binding: FragmentSongBinding + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + binding = FragmentSongBinding.inflate(inflater) + binding.chords.isStretchAllColumns = true + for (phrase in Song.currentSong.chordProgression.phrases) { + val row = TableRow(binding.root.context) + for (chord in phrase.chords) { + val text = TextView(binding.root.context) + text.text = chord.toString() + row.addView(text) + } + binding.chords.addView(row) + } + return binding.root + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 1992e0f..3eaf701 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -17,12 +17,17 @@ + android:text="@string/play_tab" /> + android:text="@string/song_tab" /> + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index c6cbeaf..447e0d3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -12,6 +12,7 @@ + diff --git a/app/build.gradle b/app/build.gradle index 4ba42b6..914b12b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -51,6 +51,7 @@ implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.gridlayout:gridlayout:1.0.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 89a97e6..f5a798f 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -7,13 +7,19 @@ import com.lukas.music.ui.fragments.CreditsFragment import com.lukas.music.ui.fragments.InstrumentListFragment import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.fragments.SongFragment import com.lukas.music.ui.tab.PageListener import com.lukas.music.ui.tab.TabAdapter import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding - private val tabFragments = listOf(PlayFragment(), InstrumentListFragment(), CreditsFragment()) + private val tabFragments = listOf( + PlayFragment(), + SongFragment(), + InstrumentListFragment(), + CreditsFragment(), + ) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/lukas/music/song/Chord.kt b/app/src/main/java/com/lukas/music/song/Chord.kt deleted file mode 100644 index 36ad846..0000000 --- a/app/src/main/java/com/lukas/music/song/Chord.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.lukas.music.song - -import com.lukas.music.song.note.Note - -class Chord(val note: Int, private val chordType: ChordType) { - fun getNotes(root: Note): Array { - return Array(chordType.notes.size) { root + note + chordType.notes[it] } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/ChordProgression.kt deleted file mode 100644 index 144c272..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordProgression.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.lukas.music.song - -class ChordProgression(val chords: List) { - private var index = 0 - - fun step(): Chord { - val result = chords[index] - index++ - index %= chords.size - return result - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/ChordType.kt b/app/src/main/java/com/lukas/music/song/ChordType.kt deleted file mode 100644 index 5cab319..0000000 --- a/app/src/main/java/com/lukas/music/song/ChordType.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.lukas.music.song - -enum class ChordType(val notes: Array) { - Major(arrayOf(0, 4, 7)), - Minor(arrayOf(0, 3, 7)), - ; -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/Song.kt b/app/src/main/java/com/lukas/music/song/Song.kt index ae8c5e2..ebea238 100644 --- a/app/src/main/java/com/lukas/music/song/Song.kt +++ b/app/src/main/java/com/lukas/music/song/Song.kt @@ -4,15 +4,17 @@ import android.os.Looper import android.widget.RadioButton import com.lukas.music.instruments.Instrument +import com.lukas.music.song.chords.Chord +import com.lukas.music.song.chords.ChordProgression import com.lukas.music.song.note.Note class Song( private val root: Note, - private val chordProgression: ChordProgression, + val chordProgression: ChordProgression, val beats: Int ) { private var beat = 0 - private var chord: Chord = chordProgression.chords[0] + private var chord: Chord = chordProgression.step() val stepButtons = mutableListOf() fun step() { @@ -35,14 +37,7 @@ companion object { var currentSong = Song( Note.NOTES[69], - ChordProgression( - listOf( - Chord(0, ChordType.Major), - Chord(5, ChordType.Major), - Chord(2, ChordType.Minor), - Chord(7, ChordType.Major), - ) - ), + ChordProgression(), 4 ) } 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 new file mode 100644 index 0000000..9480a25 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/Chord.kt @@ -0,0 +1,13 @@ +package com.lukas.music.song.chords + +import com.lukas.music.song.note.Note + +class Chord(val note: Int, private val chordType: ChordType) { + fun getNotes(root: Note): Array { + return Array(chordType.notes.size) { root + note + chordType.notes[it] } + } + + override fun toString(): String { + return "$note -> $chordType" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt b/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt new file mode 100644 index 0000000..2e189b4 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/ChordProgression.kt @@ -0,0 +1,19 @@ +package com.lukas.music.song.chords + +class ChordProgression { + // TODO: special handler for increasing or decreasing measuresPerPhrase + val measuresPerPhrase: Int = 4 + val phrases = mutableListOf(Phrase(), Phrase()) + + private var position = 0 + fun step(): Chord { + val phrase = phrases[position] + return phrase.step(this) + } + + operator fun inc(): ChordProgression { + position++ + position %= phrases.size + return this + } +} \ 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 new file mode 100644 index 0000000..3e03feb --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/ChordType.kt @@ -0,0 +1,11 @@ +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"), + ; + + override fun toString(): String { + return asString + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/chords/Phrase.kt b/app/src/main/java/com/lukas/music/song/chords/Phrase.kt new file mode 100644 index 0000000..76d4259 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/chords/Phrase.kt @@ -0,0 +1,21 @@ +package com.lukas.music.song.chords + +class Phrase { + val chords = mutableListOf( + Chord(0, ChordType.Major), + Chord(5, ChordType.Major), + Chord(2, ChordType.Minor), + Chord(7, ChordType.Major), + ) + + var position = 0 + fun step(parent: ChordProgression): Chord { + var parent: ChordProgression = parent + position++ + if (position >= chords.size) { + position = 0 + parent++ + } + return chords[position] + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/InstrumentAdapter.kt b/app/src/main/java/com/lukas/music/ui/InstrumentAdapter.kt deleted file mode 100644 index d6900a7..0000000 --- a/app/src/main/java/com/lukas/music/ui/InstrumentAdapter.kt +++ /dev/null @@ -1,57 +0,0 @@ -package com.lukas.music.ui - -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.AdapterView -import android.widget.ArrayAdapter -import androidx.recyclerview.widget.RecyclerView -import com.lukas.music.databinding.FragmentInstrumentBinding -import com.lukas.music.instruments.Instrument -import com.lukas.music.instruments.Waveform - - -class InstrumentAdapter : RecyclerView.Adapter() { - class InstrumentViewHolder(val binding: FragmentInstrumentBinding) : - RecyclerView.ViewHolder(binding.root), AdapterView.OnItemSelectedListener { - lateinit var instrument: Instrument - - init { - val adapter = ArrayAdapter( - binding.root.context, - android.R.layout.simple_spinner_dropdown_item, Waveform.VALUES - ) - binding.waveformSelection.adapter = adapter - binding.waveformSelection.onItemSelectedListener = this - } - - override fun onItemSelected( - adapterView: AdapterView<*>?, - view: View?, - position: Int, - id: Long - ) { - instrument.waveform = Waveform.VALUES[position] - } - - override fun onNothingSelected(adapterView: AdapterView<*>?) { - } - } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): InstrumentViewHolder { - val context = parent.context - val inflater = LayoutInflater.from(context) - val binding = FragmentInstrumentBinding.inflate(inflater, parent, false) - return InstrumentViewHolder(binding) - } - - override fun onBindViewHolder(holder: InstrumentViewHolder, position: Int) { - val instrument = Instrument.instruments[position] - holder.instrument = instrument - instrument.applyToView(holder.binding) - } - - override fun getItemCount(): Int { - return Instrument.instruments.size - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt new file mode 100644 index 0000000..6f36573 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt @@ -0,0 +1,57 @@ +package com.lukas.music.ui.adapters + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.AdapterView +import android.widget.ArrayAdapter +import androidx.recyclerview.widget.RecyclerView +import com.lukas.music.databinding.FragmentInstrumentBinding +import com.lukas.music.instruments.Instrument +import com.lukas.music.instruments.Waveform + + +class InstrumentAdapter : RecyclerView.Adapter() { + class InstrumentViewHolder(val binding: FragmentInstrumentBinding) : + RecyclerView.ViewHolder(binding.root), AdapterView.OnItemSelectedListener { + lateinit var instrument: Instrument + + init { + val adapter = ArrayAdapter( + binding.root.context, + android.R.layout.simple_spinner_dropdown_item, Waveform.VALUES + ) + binding.waveformSelection.adapter = adapter + binding.waveformSelection.onItemSelectedListener = this + } + + override fun onItemSelected( + adapterView: AdapterView<*>?, + view: View?, + position: Int, + id: Long + ) { + instrument.waveform = Waveform.VALUES[position] + } + + override fun onNothingSelected(adapterView: AdapterView<*>?) { + } + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): InstrumentViewHolder { + val context = parent.context + val inflater = LayoutInflater.from(context) + val binding = FragmentInstrumentBinding.inflate(inflater, parent, false) + return InstrumentViewHolder(binding) + } + + override fun onBindViewHolder(holder: InstrumentViewHolder, position: Int) { + val instrument = Instrument.instruments[position] + holder.instrument = instrument + instrument.applyToView(holder.binding) + } + + override fun getItemCount(): Int { + return Instrument.instruments.size + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt index ddc76f2..290284c 100644 --- a/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt +++ b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt @@ -1,10 +1,10 @@ package com.lukas.music.ui.fragments import android.os.Bundle -import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.fragment.app.Fragment import com.lukas.music.R class CreditsFragment : Fragment() { @@ -14,13 +14,4 @@ ): View? { return inflater.inflate(R.layout.fragment_credits, container, false) } - - companion object { - @JvmStatic - fun newInstance() = - CreditsFragment().apply { - arguments = Bundle().apply { - } - } - } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt index 4bbc6ba..6b77049 100644 --- a/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt +++ b/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt @@ -1,17 +1,13 @@ package com.lukas.music.ui.fragments import android.os.Bundle -import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView -import com.lukas.music.MainActivity -import com.lukas.music.R import com.lukas.music.databinding.FragmentInstrumentListBinding -import com.lukas.music.databinding.FragmentPlayBinding -import com.lukas.music.ui.InstrumentAdapter +import com.lukas.music.ui.adapters.InstrumentAdapter class InstrumentListFragment : Fragment() { lateinit var binding: FragmentInstrumentListBinding 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 new file mode 100644 index 0000000..395fba0 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/SongFragment.kt @@ -0,0 +1,33 @@ +package com.lukas.music.ui.fragments + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TableRow +import android.widget.TextView +import androidx.fragment.app.Fragment +import com.lukas.music.databinding.FragmentSongBinding +import com.lukas.music.song.Song + +class SongFragment : Fragment() { + private lateinit var binding: FragmentSongBinding + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + binding = FragmentSongBinding.inflate(inflater) + binding.chords.isStretchAllColumns = true + for (phrase in Song.currentSong.chordProgression.phrases) { + val row = TableRow(binding.root.context) + for (chord in phrase.chords) { + val text = TextView(binding.root.context) + text.text = chord.toString() + row.addView(text) + } + binding.chords.addView(row) + } + return binding.root + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 1992e0f..3eaf701 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -17,12 +17,17 @@ + android:text="@string/play_tab" /> + android:text="@string/song_tab" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 83f27ab..6e8239a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,5 +1,8 @@ Music + Play + Song + Instruments Credits this app was created by Lukas Eisenhauer start or stop the song