diff --git a/app/src/main/java/com/lukas/music/instruments/Instrument.kt b/app/src/main/java/com/lukas/music/instruments/Instrument.kt index c8c3511..6006bb7 100644 --- a/app/src/main/java/com/lukas/music/instruments/Instrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/Instrument.kt @@ -16,6 +16,7 @@ import com.lukas.music.song.voice.Voice abstract class Instrument(var name: String) { + lateinit var voice: Voice abstract var waveform: Waveform abstract var volume: Float abstract var muted: Boolean diff --git a/app/src/main/java/com/lukas/music/instruments/Instrument.kt b/app/src/main/java/com/lukas/music/instruments/Instrument.kt index c8c3511..6006bb7 100644 --- a/app/src/main/java/com/lukas/music/instruments/Instrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/Instrument.kt @@ -16,6 +16,7 @@ import com.lukas.music.song.voice.Voice abstract class Instrument(var name: String) { + lateinit var voice: Voice abstract var waveform: Waveform abstract var volume: Float abstract var muted: Boolean 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 a3123f2..33b8a7d 100644 --- a/app/src/main/java/com/lukas/music/song/Song.kt +++ b/app/src/main/java/com/lukas/music/song/Song.kt @@ -20,6 +20,17 @@ val beats: Int ) : Cycle(beats) { val chordProgression = ChordProgression() + var soloInstrument: Instrument? = null + set(value) { + field = value + value?.let { + for (instrument in Instrument.instruments) { + if (instrument != value) { + instrument.stop() + } + } + } + } init { for (i in 0 until beats) { @@ -34,8 +45,12 @@ super.step() val chord = chordProgression.currentItem?.currentItem ?: return index val chordNotes = chord.getNotes(root) - for (voice in Instrument.voice) { - voice.step(root, chordNotes) + soloInstrument?.let { + it.voice.step(root, chordNotes) + } ?: run { + for (voice in Instrument.voice) { + voice.step(root, chordNotes) + } } return index } diff --git a/app/src/main/java/com/lukas/music/instruments/Instrument.kt b/app/src/main/java/com/lukas/music/instruments/Instrument.kt index c8c3511..6006bb7 100644 --- a/app/src/main/java/com/lukas/music/instruments/Instrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/Instrument.kt @@ -16,6 +16,7 @@ import com.lukas.music.song.voice.Voice abstract class Instrument(var name: String) { + lateinit var voice: Voice abstract var waveform: Waveform abstract var volume: Float abstract var muted: Boolean 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 a3123f2..33b8a7d 100644 --- a/app/src/main/java/com/lukas/music/song/Song.kt +++ b/app/src/main/java/com/lukas/music/song/Song.kt @@ -20,6 +20,17 @@ val beats: Int ) : Cycle(beats) { val chordProgression = ChordProgression() + var soloInstrument: Instrument? = null + set(value) { + field = value + value?.let { + for (instrument in Instrument.instruments) { + if (instrument != value) { + instrument.stop() + } + } + } + } init { for (i in 0 until beats) { @@ -34,8 +45,12 @@ super.step() val chord = chordProgression.currentItem?.currentItem ?: return index val chordNotes = chord.getNotes(root) - for (voice in Instrument.voice) { - voice.step(root, chordNotes) + soloInstrument?.let { + it.voice.step(root, chordNotes) + } ?: run { + for (voice in Instrument.voice) { + voice.step(root, chordNotes) + } } return index } 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 f7fca94..9a58ec0 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 @@ -17,4 +17,10 @@ abstract val steps: List abstract fun step(root: Note, chord: Array) + + init { + // TODO: fix this (have voice be an attribute of Instrument)! + // TODO: introduce DefaultVoices and CustomVoice + instrument.voice = this + } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/instruments/Instrument.kt b/app/src/main/java/com/lukas/music/instruments/Instrument.kt index c8c3511..6006bb7 100644 --- a/app/src/main/java/com/lukas/music/instruments/Instrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/Instrument.kt @@ -16,6 +16,7 @@ import com.lukas.music.song.voice.Voice abstract class Instrument(var name: String) { + lateinit var voice: Voice abstract var waveform: Waveform abstract var volume: Float abstract var muted: Boolean 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 a3123f2..33b8a7d 100644 --- a/app/src/main/java/com/lukas/music/song/Song.kt +++ b/app/src/main/java/com/lukas/music/song/Song.kt @@ -20,6 +20,17 @@ val beats: Int ) : Cycle(beats) { val chordProgression = ChordProgression() + var soloInstrument: Instrument? = null + set(value) { + field = value + value?.let { + for (instrument in Instrument.instruments) { + if (instrument != value) { + instrument.stop() + } + } + } + } init { for (i in 0 until beats) { @@ -34,8 +45,12 @@ super.step() val chord = chordProgression.currentItem?.currentItem ?: return index val chordNotes = chord.getNotes(root) - for (voice in Instrument.voice) { - voice.step(root, chordNotes) + soloInstrument?.let { + it.voice.step(root, chordNotes) + } ?: run { + for (voice in Instrument.voice) { + voice.step(root, chordNotes) + } } return index } 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 f7fca94..9a58ec0 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 @@ -17,4 +17,10 @@ abstract val steps: List abstract fun step(root: Note, chord: Array) + + init { + // TODO: fix this (have voice be an attribute of Instrument)! + // TODO: introduce DefaultVoices and CustomVoice + instrument.voice = this + } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt index 687fd6a..01faccf 100644 --- a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt +++ b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt @@ -15,14 +15,32 @@ import com.lukas.music.R import com.lukas.music.databinding.FragmentInstrumentBinding import com.lukas.music.instruments.Instrument +import com.lukas.music.song.Song import com.lukas.music.ui.fragments.EditInstrumentFragment import com.lukas.music.util.setupToggle +import com.lukas.music.util.updateToggle class InstrumentViewHolder( val binding: FragmentInstrumentBinding, private val childFragmentManager: FragmentManager ) : RecyclerView.ViewHolder(binding.root) { + init { + HOLDERS += this + } + + var solo: Boolean = false + set(value) { + if (value) { + for (holder in HOLDERS) { + holder.solo = false + } + Song.currentSong.soloInstrument = instrument + } + field = value + binding.soloButton.updateToggle(this::solo, R.color.blue) + } + var instrument: Instrument? = null set(value) { field = value @@ -32,5 +50,14 @@ EditInstrumentFragment(instrument!!, this).showNow(childFragmentManager, "") } binding.muteButton.setupToggle(instrument!!::muted, R.color.red) + binding.soloButton.setupToggle(this::solo, R.color.blue) { + if (!it) { + Song.currentSong.soloInstrument = null + } + } } + + companion object { + val HOLDERS = mutableListOf() + } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/instruments/Instrument.kt b/app/src/main/java/com/lukas/music/instruments/Instrument.kt index c8c3511..6006bb7 100644 --- a/app/src/main/java/com/lukas/music/instruments/Instrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/Instrument.kt @@ -16,6 +16,7 @@ import com.lukas.music.song.voice.Voice abstract class Instrument(var name: String) { + lateinit var voice: Voice abstract var waveform: Waveform abstract var volume: Float abstract var muted: Boolean 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 a3123f2..33b8a7d 100644 --- a/app/src/main/java/com/lukas/music/song/Song.kt +++ b/app/src/main/java/com/lukas/music/song/Song.kt @@ -20,6 +20,17 @@ val beats: Int ) : Cycle(beats) { val chordProgression = ChordProgression() + var soloInstrument: Instrument? = null + set(value) { + field = value + value?.let { + for (instrument in Instrument.instruments) { + if (instrument != value) { + instrument.stop() + } + } + } + } init { for (i in 0 until beats) { @@ -34,8 +45,12 @@ super.step() val chord = chordProgression.currentItem?.currentItem ?: return index val chordNotes = chord.getNotes(root) - for (voice in Instrument.voice) { - voice.step(root, chordNotes) + soloInstrument?.let { + it.voice.step(root, chordNotes) + } ?: run { + for (voice in Instrument.voice) { + voice.step(root, chordNotes) + } } return index } 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 f7fca94..9a58ec0 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 @@ -17,4 +17,10 @@ abstract val steps: List abstract fun step(root: Note, chord: Array) + + init { + // TODO: fix this (have voice be an attribute of Instrument)! + // TODO: introduce DefaultVoices and CustomVoice + instrument.voice = this + } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt index 687fd6a..01faccf 100644 --- a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt +++ b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt @@ -15,14 +15,32 @@ import com.lukas.music.R import com.lukas.music.databinding.FragmentInstrumentBinding import com.lukas.music.instruments.Instrument +import com.lukas.music.song.Song import com.lukas.music.ui.fragments.EditInstrumentFragment import com.lukas.music.util.setupToggle +import com.lukas.music.util.updateToggle class InstrumentViewHolder( val binding: FragmentInstrumentBinding, private val childFragmentManager: FragmentManager ) : RecyclerView.ViewHolder(binding.root) { + init { + HOLDERS += this + } + + var solo: Boolean = false + set(value) { + if (value) { + for (holder in HOLDERS) { + holder.solo = false + } + Song.currentSong.soloInstrument = instrument + } + field = value + binding.soloButton.updateToggle(this::solo, R.color.blue) + } + var instrument: Instrument? = null set(value) { field = value @@ -32,5 +50,14 @@ EditInstrumentFragment(instrument!!, this).showNow(childFragmentManager, "") } binding.muteButton.setupToggle(instrument!!::muted, R.color.red) + binding.soloButton.setupToggle(this::solo, R.color.blue) { + if (!it) { + Song.currentSong.soloInstrument = null + } + } } + + companion object { + val HOLDERS = mutableListOf() + } } \ No newline at end of file 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 b033fb0..51d6026 100644 --- a/app/src/main/java/com/lukas/music/util/UIUtil.kt +++ b/app/src/main/java/com/lukas/music/util/UIUtil.kt @@ -39,13 +39,20 @@ this.progress = initialProgress } -fun Button.setupToggle(target: KMutableProperty0, activeColor: Int) { +fun Button.setupToggle( + target: KMutableProperty0, + activeColor: Int, + callback: (Boolean) -> Unit = {} +) { setOnClickListener { target.set(!target.get()) - setBackgroundColor( - ContextCompat.getColor(context, if (target.get()) activeColor else R.color.gray_0x60) - ) + updateToggle(target, activeColor) + callback(target.get()) } + updateToggle(target, activeColor) +} + +fun Button.updateToggle(target: KMutableProperty0, activeColor: Int) { setBackgroundColor( ContextCompat.getColor(context, if (target.get()) activeColor else R.color.gray_0x60) ) diff --git a/app/src/main/java/com/lukas/music/instruments/Instrument.kt b/app/src/main/java/com/lukas/music/instruments/Instrument.kt index c8c3511..6006bb7 100644 --- a/app/src/main/java/com/lukas/music/instruments/Instrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/Instrument.kt @@ -16,6 +16,7 @@ import com.lukas.music.song.voice.Voice abstract class Instrument(var name: String) { + lateinit var voice: Voice abstract var waveform: Waveform abstract var volume: Float abstract var muted: Boolean 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 a3123f2..33b8a7d 100644 --- a/app/src/main/java/com/lukas/music/song/Song.kt +++ b/app/src/main/java/com/lukas/music/song/Song.kt @@ -20,6 +20,17 @@ val beats: Int ) : Cycle(beats) { val chordProgression = ChordProgression() + var soloInstrument: Instrument? = null + set(value) { + field = value + value?.let { + for (instrument in Instrument.instruments) { + if (instrument != value) { + instrument.stop() + } + } + } + } init { for (i in 0 until beats) { @@ -34,8 +45,12 @@ super.step() val chord = chordProgression.currentItem?.currentItem ?: return index val chordNotes = chord.getNotes(root) - for (voice in Instrument.voice) { - voice.step(root, chordNotes) + soloInstrument?.let { + it.voice.step(root, chordNotes) + } ?: run { + for (voice in Instrument.voice) { + voice.step(root, chordNotes) + } } return index } 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 f7fca94..9a58ec0 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 @@ -17,4 +17,10 @@ abstract val steps: List abstract fun step(root: Note, chord: Array) + + init { + // TODO: fix this (have voice be an attribute of Instrument)! + // TODO: introduce DefaultVoices and CustomVoice + instrument.voice = this + } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt index 687fd6a..01faccf 100644 --- a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt +++ b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt @@ -15,14 +15,32 @@ import com.lukas.music.R import com.lukas.music.databinding.FragmentInstrumentBinding import com.lukas.music.instruments.Instrument +import com.lukas.music.song.Song import com.lukas.music.ui.fragments.EditInstrumentFragment import com.lukas.music.util.setupToggle +import com.lukas.music.util.updateToggle class InstrumentViewHolder( val binding: FragmentInstrumentBinding, private val childFragmentManager: FragmentManager ) : RecyclerView.ViewHolder(binding.root) { + init { + HOLDERS += this + } + + var solo: Boolean = false + set(value) { + if (value) { + for (holder in HOLDERS) { + holder.solo = false + } + Song.currentSong.soloInstrument = instrument + } + field = value + binding.soloButton.updateToggle(this::solo, R.color.blue) + } + var instrument: Instrument? = null set(value) { field = value @@ -32,5 +50,14 @@ EditInstrumentFragment(instrument!!, this).showNow(childFragmentManager, "") } binding.muteButton.setupToggle(instrument!!::muted, R.color.red) + binding.soloButton.setupToggle(this::solo, R.color.blue) { + if (!it) { + Song.currentSong.soloInstrument = null + } + } } + + companion object { + val HOLDERS = mutableListOf() + } } \ No newline at end of file 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 b033fb0..51d6026 100644 --- a/app/src/main/java/com/lukas/music/util/UIUtil.kt +++ b/app/src/main/java/com/lukas/music/util/UIUtil.kt @@ -39,13 +39,20 @@ this.progress = initialProgress } -fun Button.setupToggle(target: KMutableProperty0, activeColor: Int) { +fun Button.setupToggle( + target: KMutableProperty0, + activeColor: Int, + callback: (Boolean) -> Unit = {} +) { setOnClickListener { target.set(!target.get()) - setBackgroundColor( - ContextCompat.getColor(context, if (target.get()) activeColor else R.color.gray_0x60) - ) + updateToggle(target, activeColor) + callback(target.get()) } + updateToggle(target, activeColor) +} + +fun Button.updateToggle(target: KMutableProperty0, activeColor: Int) { setBackgroundColor( ContextCompat.getColor(context, if (target.get()) activeColor else R.color.gray_0x60) ) diff --git a/app/src/main/res/layout/fragment_instrument.xml b/app/src/main/res/layout/fragment_instrument.xml index df3fb5c..98ebf5b 100644 --- a/app/src/main/res/layout/fragment_instrument.xml +++ b/app/src/main/res/layout/fragment_instrument.xml @@ -29,6 +29,7 @@ android:layout_marginTop="20dp" android:layout_marginEnd="20dp" android:text="@string/placeholder" + android:textSize="16sp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> @@ -53,13 +54,24 @@ android:id="@+id/muteButton" android:layout_width="50dp" android:layout_height="50dp" - android:layout_marginStart="16dp" + android:layout_marginStart="32dp" android:backgroundTint="@color/gray_0x60" android:text="M" app:layout_constraintBottom_toBottomOf="@+id/editInstrumentButton" app:layout_constraintStart_toEndOf="@+id/editInstrumentButton" app:layout_constraintTop_toTopOf="@+id/editInstrumentButton" /> +