diff --git a/app/src/main/java/com/lukas/music/EditVoiceFragment.kt b/app/src/main/java/com/lukas/music/EditVoiceFragment.kt index c121d46..56f21e6 100644 --- a/app/src/main/java/com/lukas/music/EditVoiceFragment.kt +++ b/app/src/main/java/com/lukas/music/EditVoiceFragment.kt @@ -14,11 +14,17 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.TableRow +import androidx.core.view.setMargins import androidx.fragment.app.DialogFragment +import com.google.android.material.button.MaterialButton import com.lukas.music.databinding.FragmentEditVoiceBinding +import com.lukas.music.song.Song import com.lukas.music.song.voice.Voice +import com.lukas.music.util.ArrayProperty +import com.lukas.music.util.setupToggle -class EditVoiceFragment(val voice: Voice) : DialogFragment() { +class EditVoiceFragment(private val voice: Voice) : DialogFragment() { private lateinit var binding: FragmentEditVoiceBinding override fun onCreateView( @@ -26,6 +32,17 @@ savedInstanceState: Bundle? ): View? { binding = FragmentEditVoiceBinding.inflate(inflater) + for (row in 0 until voice.noteCount) { + val rowLayout = TableRow(binding.root.context) + for (column in 0 until Song.currentSong.beats) { + val button = MaterialButton(binding.root.context) + button.layoutParams = buttonLayout + button.setupToggle(ArrayProperty(voice.noteActive[column], row), R.color.blue) + rowLayout.addView(button) + } + binding.noteGrid.addView(rowLayout) + } + binding.noteGrid.isStretchAllColumns = true binding.closeButton.setOnClickListener { dismiss() } @@ -39,4 +56,12 @@ ViewGroup.LayoutParams.WRAP_CONTENT ) } + + companion object { + val buttonLayout = TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT) + + init { + buttonLayout.setMargins(5) + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/EditVoiceFragment.kt b/app/src/main/java/com/lukas/music/EditVoiceFragment.kt index c121d46..56f21e6 100644 --- a/app/src/main/java/com/lukas/music/EditVoiceFragment.kt +++ b/app/src/main/java/com/lukas/music/EditVoiceFragment.kt @@ -14,11 +14,17 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.TableRow +import androidx.core.view.setMargins import androidx.fragment.app.DialogFragment +import com.google.android.material.button.MaterialButton import com.lukas.music.databinding.FragmentEditVoiceBinding +import com.lukas.music.song.Song import com.lukas.music.song.voice.Voice +import com.lukas.music.util.ArrayProperty +import com.lukas.music.util.setupToggle -class EditVoiceFragment(val voice: Voice) : DialogFragment() { +class EditVoiceFragment(private val voice: Voice) : DialogFragment() { private lateinit var binding: FragmentEditVoiceBinding override fun onCreateView( @@ -26,6 +32,17 @@ savedInstanceState: Bundle? ): View? { binding = FragmentEditVoiceBinding.inflate(inflater) + for (row in 0 until voice.noteCount) { + val rowLayout = TableRow(binding.root.context) + for (column in 0 until Song.currentSong.beats) { + val button = MaterialButton(binding.root.context) + button.layoutParams = buttonLayout + button.setupToggle(ArrayProperty(voice.noteActive[column], row), R.color.blue) + rowLayout.addView(button) + } + binding.noteGrid.addView(rowLayout) + } + binding.noteGrid.isStretchAllColumns = true binding.closeButton.setOnClickListener { dismiss() } @@ -39,4 +56,12 @@ ViewGroup.LayoutParams.WRAP_CONTENT ) } + + companion object { + val buttonLayout = TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT) + + init { + buttonLayout.setMargins(5) + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt b/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt index a23bbbd..4706068 100644 --- a/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt +++ b/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt @@ -21,6 +21,8 @@ arrayOf(false) ) + override val noteCount: Int = 1 + override fun getNotes(root: Note, chordNotes: Array): Array { return arrayOf(chordNotes[0] - 24) } diff --git a/app/src/main/java/com/lukas/music/EditVoiceFragment.kt b/app/src/main/java/com/lukas/music/EditVoiceFragment.kt index c121d46..56f21e6 100644 --- a/app/src/main/java/com/lukas/music/EditVoiceFragment.kt +++ b/app/src/main/java/com/lukas/music/EditVoiceFragment.kt @@ -14,11 +14,17 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.TableRow +import androidx.core.view.setMargins import androidx.fragment.app.DialogFragment +import com.google.android.material.button.MaterialButton import com.lukas.music.databinding.FragmentEditVoiceBinding +import com.lukas.music.song.Song import com.lukas.music.song.voice.Voice +import com.lukas.music.util.ArrayProperty +import com.lukas.music.util.setupToggle -class EditVoiceFragment(val voice: Voice) : DialogFragment() { +class EditVoiceFragment(private val voice: Voice) : DialogFragment() { private lateinit var binding: FragmentEditVoiceBinding override fun onCreateView( @@ -26,6 +32,17 @@ savedInstanceState: Bundle? ): View? { binding = FragmentEditVoiceBinding.inflate(inflater) + for (row in 0 until voice.noteCount) { + val rowLayout = TableRow(binding.root.context) + for (column in 0 until Song.currentSong.beats) { + val button = MaterialButton(binding.root.context) + button.layoutParams = buttonLayout + button.setupToggle(ArrayProperty(voice.noteActive[column], row), R.color.blue) + rowLayout.addView(button) + } + binding.noteGrid.addView(rowLayout) + } + binding.noteGrid.isStretchAllColumns = true binding.closeButton.setOnClickListener { dismiss() } @@ -39,4 +56,12 @@ ViewGroup.LayoutParams.WRAP_CONTENT ) } + + companion object { + val buttonLayout = TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT) + + init { + buttonLayout.setMargins(5) + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt b/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt index a23bbbd..4706068 100644 --- a/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt +++ b/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt @@ -21,6 +21,8 @@ arrayOf(false) ) + override val noteCount: Int = 1 + override fun getNotes(root: Note, chordNotes: Array): Array { return arrayOf(chordNotes[0] - 24) } diff --git a/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt b/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt index 8f43cac..ab7117f 100644 --- a/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt +++ b/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt @@ -20,6 +20,7 @@ Array(3) { false }, Array(3) { true }, ) + override val noteCount: Int = 3 override fun getNotes(root: Note, chordNotes: Array): Array { return chordNotes diff --git a/app/src/main/java/com/lukas/music/EditVoiceFragment.kt b/app/src/main/java/com/lukas/music/EditVoiceFragment.kt index c121d46..56f21e6 100644 --- a/app/src/main/java/com/lukas/music/EditVoiceFragment.kt +++ b/app/src/main/java/com/lukas/music/EditVoiceFragment.kt @@ -14,11 +14,17 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.TableRow +import androidx.core.view.setMargins import androidx.fragment.app.DialogFragment +import com.google.android.material.button.MaterialButton import com.lukas.music.databinding.FragmentEditVoiceBinding +import com.lukas.music.song.Song import com.lukas.music.song.voice.Voice +import com.lukas.music.util.ArrayProperty +import com.lukas.music.util.setupToggle -class EditVoiceFragment(val voice: Voice) : DialogFragment() { +class EditVoiceFragment(private val voice: Voice) : DialogFragment() { private lateinit var binding: FragmentEditVoiceBinding override fun onCreateView( @@ -26,6 +32,17 @@ savedInstanceState: Bundle? ): View? { binding = FragmentEditVoiceBinding.inflate(inflater) + for (row in 0 until voice.noteCount) { + val rowLayout = TableRow(binding.root.context) + for (column in 0 until Song.currentSong.beats) { + val button = MaterialButton(binding.root.context) + button.layoutParams = buttonLayout + button.setupToggle(ArrayProperty(voice.noteActive[column], row), R.color.blue) + rowLayout.addView(button) + } + binding.noteGrid.addView(rowLayout) + } + binding.noteGrid.isStretchAllColumns = true binding.closeButton.setOnClickListener { dismiss() } @@ -39,4 +56,12 @@ ViewGroup.LayoutParams.WRAP_CONTENT ) } + + companion object { + val buttonLayout = TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT) + + init { + buttonLayout.setMargins(5) + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt b/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt index a23bbbd..4706068 100644 --- a/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt +++ b/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt @@ -21,6 +21,8 @@ arrayOf(false) ) + override val noteCount: Int = 1 + override fun getNotes(root: Note, chordNotes: Array): Array { return arrayOf(chordNotes[0] - 24) } diff --git a/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt b/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt index 8f43cac..ab7117f 100644 --- a/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt +++ b/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt @@ -20,6 +20,7 @@ Array(3) { false }, Array(3) { true }, ) + override val noteCount: Int = 3 override fun getNotes(root: Note, chordNotes: Array): Array { return chordNotes diff --git a/app/src/main/java/com/lukas/music/song/voice/Voice.kt b/app/src/main/java/com/lukas/music/song/voice/Voice.kt index 42865a5..4f56c2a 100644 --- a/app/src/main/java/com/lukas/music/song/voice/Voice.kt +++ b/app/src/main/java/com/lukas/music/song/voice/Voice.kt @@ -16,6 +16,7 @@ abstract class Voice(val instrument: Instrument) { abstract var noteActive: Array> + abstract val noteCount: Int abstract fun getNotes(root: Note, chordNotes: Array): Array diff --git a/app/src/main/java/com/lukas/music/EditVoiceFragment.kt b/app/src/main/java/com/lukas/music/EditVoiceFragment.kt index c121d46..56f21e6 100644 --- a/app/src/main/java/com/lukas/music/EditVoiceFragment.kt +++ b/app/src/main/java/com/lukas/music/EditVoiceFragment.kt @@ -14,11 +14,17 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.TableRow +import androidx.core.view.setMargins import androidx.fragment.app.DialogFragment +import com.google.android.material.button.MaterialButton import com.lukas.music.databinding.FragmentEditVoiceBinding +import com.lukas.music.song.Song import com.lukas.music.song.voice.Voice +import com.lukas.music.util.ArrayProperty +import com.lukas.music.util.setupToggle -class EditVoiceFragment(val voice: Voice) : DialogFragment() { +class EditVoiceFragment(private val voice: Voice) : DialogFragment() { private lateinit var binding: FragmentEditVoiceBinding override fun onCreateView( @@ -26,6 +32,17 @@ savedInstanceState: Bundle? ): View? { binding = FragmentEditVoiceBinding.inflate(inflater) + for (row in 0 until voice.noteCount) { + val rowLayout = TableRow(binding.root.context) + for (column in 0 until Song.currentSong.beats) { + val button = MaterialButton(binding.root.context) + button.layoutParams = buttonLayout + button.setupToggle(ArrayProperty(voice.noteActive[column], row), R.color.blue) + rowLayout.addView(button) + } + binding.noteGrid.addView(rowLayout) + } + binding.noteGrid.isStretchAllColumns = true binding.closeButton.setOnClickListener { dismiss() } @@ -39,4 +56,12 @@ ViewGroup.LayoutParams.WRAP_CONTENT ) } + + companion object { + val buttonLayout = TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT) + + init { + buttonLayout.setMargins(5) + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt b/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt index a23bbbd..4706068 100644 --- a/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt +++ b/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt @@ -21,6 +21,8 @@ arrayOf(false) ) + override val noteCount: Int = 1 + override fun getNotes(root: Note, chordNotes: Array): Array { return arrayOf(chordNotes[0] - 24) } diff --git a/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt b/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt index 8f43cac..ab7117f 100644 --- a/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt +++ b/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt @@ -20,6 +20,7 @@ Array(3) { false }, Array(3) { true }, ) + override val noteCount: Int = 3 override fun getNotes(root: Note, chordNotes: Array): Array { return chordNotes diff --git a/app/src/main/java/com/lukas/music/song/voice/Voice.kt b/app/src/main/java/com/lukas/music/song/voice/Voice.kt index 42865a5..4f56c2a 100644 --- a/app/src/main/java/com/lukas/music/song/voice/Voice.kt +++ b/app/src/main/java/com/lukas/music/song/voice/Voice.kt @@ -16,6 +16,7 @@ abstract class Voice(val instrument: Instrument) { abstract var noteActive: Array> + abstract val noteCount: Int abstract fun getNotes(root: Note, chordNotes: Array): Array diff --git a/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt index 605906a..0020ae8 100644 --- a/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt +++ b/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt @@ -57,6 +57,9 @@ Voice.DEFAULT_VOICE_NAMES, Voice.DEFAULT_VOICES.indexOf(instrument.voice::class) ) { + if (instrument.voice::class == Voice.DEFAULT_VOICES[it]) { + return@setup + } instrument.voice = Voice.DEFAULT_VOICES[it].constructors.first().call(instrument) } binding.editVoiceButton.setOnClickListener { diff --git a/app/src/main/java/com/lukas/music/EditVoiceFragment.kt b/app/src/main/java/com/lukas/music/EditVoiceFragment.kt index c121d46..56f21e6 100644 --- a/app/src/main/java/com/lukas/music/EditVoiceFragment.kt +++ b/app/src/main/java/com/lukas/music/EditVoiceFragment.kt @@ -14,11 +14,17 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.TableRow +import androidx.core.view.setMargins import androidx.fragment.app.DialogFragment +import com.google.android.material.button.MaterialButton import com.lukas.music.databinding.FragmentEditVoiceBinding +import com.lukas.music.song.Song import com.lukas.music.song.voice.Voice +import com.lukas.music.util.ArrayProperty +import com.lukas.music.util.setupToggle -class EditVoiceFragment(val voice: Voice) : DialogFragment() { +class EditVoiceFragment(private val voice: Voice) : DialogFragment() { private lateinit var binding: FragmentEditVoiceBinding override fun onCreateView( @@ -26,6 +32,17 @@ savedInstanceState: Bundle? ): View? { binding = FragmentEditVoiceBinding.inflate(inflater) + for (row in 0 until voice.noteCount) { + val rowLayout = TableRow(binding.root.context) + for (column in 0 until Song.currentSong.beats) { + val button = MaterialButton(binding.root.context) + button.layoutParams = buttonLayout + button.setupToggle(ArrayProperty(voice.noteActive[column], row), R.color.blue) + rowLayout.addView(button) + } + binding.noteGrid.addView(rowLayout) + } + binding.noteGrid.isStretchAllColumns = true binding.closeButton.setOnClickListener { dismiss() } @@ -39,4 +56,12 @@ ViewGroup.LayoutParams.WRAP_CONTENT ) } + + companion object { + val buttonLayout = TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT) + + init { + buttonLayout.setMargins(5) + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt b/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt index a23bbbd..4706068 100644 --- a/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt +++ b/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt @@ -21,6 +21,8 @@ arrayOf(false) ) + override val noteCount: Int = 1 + override fun getNotes(root: Note, chordNotes: Array): Array { return arrayOf(chordNotes[0] - 24) } diff --git a/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt b/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt index 8f43cac..ab7117f 100644 --- a/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt +++ b/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt @@ -20,6 +20,7 @@ Array(3) { false }, Array(3) { true }, ) + override val noteCount: Int = 3 override fun getNotes(root: Note, chordNotes: Array): Array { return chordNotes diff --git a/app/src/main/java/com/lukas/music/song/voice/Voice.kt b/app/src/main/java/com/lukas/music/song/voice/Voice.kt index 42865a5..4f56c2a 100644 --- a/app/src/main/java/com/lukas/music/song/voice/Voice.kt +++ b/app/src/main/java/com/lukas/music/song/voice/Voice.kt @@ -16,6 +16,7 @@ abstract class Voice(val instrument: Instrument) { abstract var noteActive: Array> + abstract val noteCount: Int abstract fun getNotes(root: Note, chordNotes: Array): Array diff --git a/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt index 605906a..0020ae8 100644 --- a/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt +++ b/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt @@ -57,6 +57,9 @@ Voice.DEFAULT_VOICE_NAMES, Voice.DEFAULT_VOICES.indexOf(instrument.voice::class) ) { + if (instrument.voice::class == Voice.DEFAULT_VOICES[it]) { + return@setup + } instrument.voice = Voice.DEFAULT_VOICES[it].constructors.first().call(instrument) } binding.editVoiceButton.setOnClickListener { diff --git a/app/src/main/java/com/lukas/music/util/ArrayProperty.kt b/app/src/main/java/com/lukas/music/util/ArrayProperty.kt new file mode 100644 index 0000000..938f07c --- /dev/null +++ b/app/src/main/java/com/lukas/music/util/ArrayProperty.kt @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2022 Lukas Eisenhauer + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or(at your option) any later version. + * + * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + */ + +package com.lukas.music.util + +import kotlin.reflect.* + +class ArrayProperty(private val array: Array, private val position: Int) : + KMutableProperty0 { + override val annotations: List = listOf() + override val isAbstract: Boolean = false + override val isFinal: Boolean = false + override val isOpen: Boolean = false + override val isSuspend: Boolean = false + override val name: String = "TODO" + override val parameters: List = listOf() + override val returnType: KType get() = TODO() + override val typeParameters: List = listOf() + override val visibility: KVisibility? = KVisibility.PUBLIC + override fun call(vararg args: Any?): T = TODO() + override fun callBy(args: Map): T = TODO() + override val setter: KMutableProperty0.Setter get() = TODO() + + + override val isConst: Boolean = false + override val isLateinit: Boolean = false + override val getter: KProperty0.Getter get() = TODO() + + + override fun getDelegate(): Any? = null + override fun invoke(): T = TODO() + + override fun set(value: T) { + array[position] = value + } + + + override fun get(): T = array[position] +} diff --git a/app/src/main/java/com/lukas/music/EditVoiceFragment.kt b/app/src/main/java/com/lukas/music/EditVoiceFragment.kt index c121d46..56f21e6 100644 --- a/app/src/main/java/com/lukas/music/EditVoiceFragment.kt +++ b/app/src/main/java/com/lukas/music/EditVoiceFragment.kt @@ -14,11 +14,17 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.TableRow +import androidx.core.view.setMargins import androidx.fragment.app.DialogFragment +import com.google.android.material.button.MaterialButton import com.lukas.music.databinding.FragmentEditVoiceBinding +import com.lukas.music.song.Song import com.lukas.music.song.voice.Voice +import com.lukas.music.util.ArrayProperty +import com.lukas.music.util.setupToggle -class EditVoiceFragment(val voice: Voice) : DialogFragment() { +class EditVoiceFragment(private val voice: Voice) : DialogFragment() { private lateinit var binding: FragmentEditVoiceBinding override fun onCreateView( @@ -26,6 +32,17 @@ savedInstanceState: Bundle? ): View? { binding = FragmentEditVoiceBinding.inflate(inflater) + for (row in 0 until voice.noteCount) { + val rowLayout = TableRow(binding.root.context) + for (column in 0 until Song.currentSong.beats) { + val button = MaterialButton(binding.root.context) + button.layoutParams = buttonLayout + button.setupToggle(ArrayProperty(voice.noteActive[column], row), R.color.blue) + rowLayout.addView(button) + } + binding.noteGrid.addView(rowLayout) + } + binding.noteGrid.isStretchAllColumns = true binding.closeButton.setOnClickListener { dismiss() } @@ -39,4 +56,12 @@ ViewGroup.LayoutParams.WRAP_CONTENT ) } + + companion object { + val buttonLayout = TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT) + + init { + buttonLayout.setMargins(5) + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt b/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt index a23bbbd..4706068 100644 --- a/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt +++ b/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt @@ -21,6 +21,8 @@ arrayOf(false) ) + override val noteCount: Int = 1 + override fun getNotes(root: Note, chordNotes: Array): Array { return arrayOf(chordNotes[0] - 24) } diff --git a/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt b/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt index 8f43cac..ab7117f 100644 --- a/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt +++ b/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt @@ -20,6 +20,7 @@ Array(3) { false }, Array(3) { true }, ) + override val noteCount: Int = 3 override fun getNotes(root: Note, chordNotes: Array): Array { return chordNotes diff --git a/app/src/main/java/com/lukas/music/song/voice/Voice.kt b/app/src/main/java/com/lukas/music/song/voice/Voice.kt index 42865a5..4f56c2a 100644 --- a/app/src/main/java/com/lukas/music/song/voice/Voice.kt +++ b/app/src/main/java/com/lukas/music/song/voice/Voice.kt @@ -16,6 +16,7 @@ abstract class Voice(val instrument: Instrument) { abstract var noteActive: Array> + abstract val noteCount: Int abstract fun getNotes(root: Note, chordNotes: Array): Array diff --git a/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt index 605906a..0020ae8 100644 --- a/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt +++ b/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt @@ -57,6 +57,9 @@ Voice.DEFAULT_VOICE_NAMES, Voice.DEFAULT_VOICES.indexOf(instrument.voice::class) ) { + if (instrument.voice::class == Voice.DEFAULT_VOICES[it]) { + return@setup + } instrument.voice = Voice.DEFAULT_VOICES[it].constructors.first().call(instrument) } binding.editVoiceButton.setOnClickListener { diff --git a/app/src/main/java/com/lukas/music/util/ArrayProperty.kt b/app/src/main/java/com/lukas/music/util/ArrayProperty.kt new file mode 100644 index 0000000..938f07c --- /dev/null +++ b/app/src/main/java/com/lukas/music/util/ArrayProperty.kt @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2022 Lukas Eisenhauer + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or(at your option) any later version. + * + * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + */ + +package com.lukas.music.util + +import kotlin.reflect.* + +class ArrayProperty(private val array: Array, private val position: Int) : + KMutableProperty0 { + override val annotations: List = listOf() + override val isAbstract: Boolean = false + override val isFinal: Boolean = false + override val isOpen: Boolean = false + override val isSuspend: Boolean = false + override val name: String = "TODO" + override val parameters: List = listOf() + override val returnType: KType get() = TODO() + override val typeParameters: List = listOf() + override val visibility: KVisibility? = KVisibility.PUBLIC + override fun call(vararg args: Any?): T = TODO() + override fun callBy(args: Map): T = TODO() + override val setter: KMutableProperty0.Setter get() = TODO() + + + override val isConst: Boolean = false + override val isLateinit: Boolean = false + override val getter: KProperty0.Getter get() = TODO() + + + override fun getDelegate(): Any? = null + override fun invoke(): T = TODO() + + override fun set(value: T) { + array[position] = value + } + + + override fun get(): T = array[position] +} diff --git a/app/src/main/java/com/lukas/music/util/UIUtil.kt b/app/src/main/java/com/lukas/music/util/UIUtil.kt index 5b7dbe3..da897c5 100644 --- a/app/src/main/java/com/lukas/music/util/UIUtil.kt +++ b/app/src/main/java/com/lukas/music/util/UIUtil.kt @@ -113,7 +113,9 @@ android.R.layout.simple_spinner_dropdown_item, items ) spinnerSetupMain(arrayAdapter, target.get().ordinal) { - target.set(items[it]) + if (target.get() != items[it]) { + target.set(items[it]) + } callback(it) } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/EditVoiceFragment.kt b/app/src/main/java/com/lukas/music/EditVoiceFragment.kt index c121d46..56f21e6 100644 --- a/app/src/main/java/com/lukas/music/EditVoiceFragment.kt +++ b/app/src/main/java/com/lukas/music/EditVoiceFragment.kt @@ -14,11 +14,17 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.TableRow +import androidx.core.view.setMargins import androidx.fragment.app.DialogFragment +import com.google.android.material.button.MaterialButton import com.lukas.music.databinding.FragmentEditVoiceBinding +import com.lukas.music.song.Song import com.lukas.music.song.voice.Voice +import com.lukas.music.util.ArrayProperty +import com.lukas.music.util.setupToggle -class EditVoiceFragment(val voice: Voice) : DialogFragment() { +class EditVoiceFragment(private val voice: Voice) : DialogFragment() { private lateinit var binding: FragmentEditVoiceBinding override fun onCreateView( @@ -26,6 +32,17 @@ savedInstanceState: Bundle? ): View? { binding = FragmentEditVoiceBinding.inflate(inflater) + for (row in 0 until voice.noteCount) { + val rowLayout = TableRow(binding.root.context) + for (column in 0 until Song.currentSong.beats) { + val button = MaterialButton(binding.root.context) + button.layoutParams = buttonLayout + button.setupToggle(ArrayProperty(voice.noteActive[column], row), R.color.blue) + rowLayout.addView(button) + } + binding.noteGrid.addView(rowLayout) + } + binding.noteGrid.isStretchAllColumns = true binding.closeButton.setOnClickListener { dismiss() } @@ -39,4 +56,12 @@ ViewGroup.LayoutParams.WRAP_CONTENT ) } + + companion object { + val buttonLayout = TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT) + + init { + buttonLayout.setMargins(5) + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt b/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt index a23bbbd..4706068 100644 --- a/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt +++ b/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt @@ -21,6 +21,8 @@ arrayOf(false) ) + override val noteCount: Int = 1 + override fun getNotes(root: Note, chordNotes: Array): Array { return arrayOf(chordNotes[0] - 24) } diff --git a/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt b/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt index 8f43cac..ab7117f 100644 --- a/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt +++ b/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt @@ -20,6 +20,7 @@ Array(3) { false }, Array(3) { true }, ) + override val noteCount: Int = 3 override fun getNotes(root: Note, chordNotes: Array): Array { return chordNotes diff --git a/app/src/main/java/com/lukas/music/song/voice/Voice.kt b/app/src/main/java/com/lukas/music/song/voice/Voice.kt index 42865a5..4f56c2a 100644 --- a/app/src/main/java/com/lukas/music/song/voice/Voice.kt +++ b/app/src/main/java/com/lukas/music/song/voice/Voice.kt @@ -16,6 +16,7 @@ abstract class Voice(val instrument: Instrument) { abstract var noteActive: Array> + abstract val noteCount: Int abstract fun getNotes(root: Note, chordNotes: Array): Array diff --git a/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt index 605906a..0020ae8 100644 --- a/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt +++ b/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt @@ -57,6 +57,9 @@ Voice.DEFAULT_VOICE_NAMES, Voice.DEFAULT_VOICES.indexOf(instrument.voice::class) ) { + if (instrument.voice::class == Voice.DEFAULT_VOICES[it]) { + return@setup + } instrument.voice = Voice.DEFAULT_VOICES[it].constructors.first().call(instrument) } binding.editVoiceButton.setOnClickListener { diff --git a/app/src/main/java/com/lukas/music/util/ArrayProperty.kt b/app/src/main/java/com/lukas/music/util/ArrayProperty.kt new file mode 100644 index 0000000..938f07c --- /dev/null +++ b/app/src/main/java/com/lukas/music/util/ArrayProperty.kt @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2022 Lukas Eisenhauer + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or(at your option) any later version. + * + * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + */ + +package com.lukas.music.util + +import kotlin.reflect.* + +class ArrayProperty(private val array: Array, private val position: Int) : + KMutableProperty0 { + override val annotations: List = listOf() + override val isAbstract: Boolean = false + override val isFinal: Boolean = false + override val isOpen: Boolean = false + override val isSuspend: Boolean = false + override val name: String = "TODO" + override val parameters: List = listOf() + override val returnType: KType get() = TODO() + override val typeParameters: List = listOf() + override val visibility: KVisibility? = KVisibility.PUBLIC + override fun call(vararg args: Any?): T = TODO() + override fun callBy(args: Map): T = TODO() + override val setter: KMutableProperty0.Setter get() = TODO() + + + override val isConst: Boolean = false + override val isLateinit: Boolean = false + override val getter: KProperty0.Getter get() = TODO() + + + override fun getDelegate(): Any? = null + override fun invoke(): T = TODO() + + override fun set(value: T) { + array[position] = value + } + + + override fun get(): T = array[position] +} diff --git a/app/src/main/java/com/lukas/music/util/UIUtil.kt b/app/src/main/java/com/lukas/music/util/UIUtil.kt index 5b7dbe3..da897c5 100644 --- a/app/src/main/java/com/lukas/music/util/UIUtil.kt +++ b/app/src/main/java/com/lukas/music/util/UIUtil.kt @@ -113,7 +113,9 @@ android.R.layout.simple_spinner_dropdown_item, items ) spinnerSetupMain(arrayAdapter, target.get().ordinal) { - target.set(items[it]) + if (target.get() != items[it]) { + target.set(items[it]) + } callback(it) } } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_edit_voice.xml b/app/src/main/res/layout/fragment_edit_voice.xml index 629be4a..b29b2c7 100644 --- a/app/src/main/res/layout/fragment_edit_voice.xml +++ b/app/src/main/res/layout/fragment_edit_voice.xml @@ -32,7 +32,7 @@ app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toBottomOf="@+id/noteGrid" /> \ No newline at end of file