diff --git a/app/src/main/cpp/effects/Noise.cpp b/app/src/main/cpp/effects/Noise.cpp index b858a97..3ecfd2e 100644 --- a/app/src/main/cpp/effects/Noise.cpp +++ b/app/src/main/cpp/effects/Noise.cpp @@ -14,6 +14,8 @@ void Noise::doRender(uint32_t sampleCount) { for (uint32_t i = 0; i < sampleCount; i++) { float random = ((float) rand() / (float) (RAND_MAX + 1)); - buffer[i] = (2.f * ((random * c2) + (random * c2) + (random * c2)) - 3.f * (c2 - 1.f)) * c3; + buffer[i] = + (2.f * ((random * c2) + (random * c2) + (random * c2)) - 3.f * (c2 - 1.f)) * c3 / + 10; } } \ No newline at end of file diff --git a/app/src/main/cpp/effects/Noise.cpp b/app/src/main/cpp/effects/Noise.cpp index b858a97..3ecfd2e 100644 --- a/app/src/main/cpp/effects/Noise.cpp +++ b/app/src/main/cpp/effects/Noise.cpp @@ -14,6 +14,8 @@ void Noise::doRender(uint32_t sampleCount) { for (uint32_t i = 0; i < sampleCount; i++) { float random = ((float) rand() / (float) (RAND_MAX + 1)); - buffer[i] = (2.f * ((random * c2) + (random * c2) + (random * c2)) - 3.f * (c2 - 1.f)) * c3; + buffer[i] = + (2.f * ((random * c2) + (random * c2) + (random * c2)) - 3.f * (c2 - 1.f)) * c3 / + 10; } } \ 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 cee1052..b9fa2c1 100644 --- a/app/src/main/java/com/lukas/music/instruments/Instrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/Instrument.kt @@ -13,11 +13,10 @@ import com.lukas.music.instruments.effect.Effect import com.lukas.music.instruments.effect.EffectType import com.lukas.music.song.note.Note -import com.lukas.music.song.voice.BassVoice import com.lukas.music.song.voice.Voice abstract class Instrument(var name: String) { - var voice: Voice = BassVoice(this) + var voice: Voice = Voice(this) var envelope = Envelope(this) val effects = Array(EffectType.VALUES.size) { Effect(EffectType.VALUES[it], this) diff --git a/app/src/main/cpp/effects/Noise.cpp b/app/src/main/cpp/effects/Noise.cpp index b858a97..3ecfd2e 100644 --- a/app/src/main/cpp/effects/Noise.cpp +++ b/app/src/main/cpp/effects/Noise.cpp @@ -14,6 +14,8 @@ void Noise::doRender(uint32_t sampleCount) { for (uint32_t i = 0; i < sampleCount; i++) { float random = ((float) rand() / (float) (RAND_MAX + 1)); - buffer[i] = (2.f * ((random * c2) + (random * c2) + (random * c2)) - 3.f * (c2 - 1.f)) * c3; + buffer[i] = + (2.f * ((random * c2) + (random * c2) + (random * c2)) - 3.f * (c2 - 1.f)) * c3 / + 10; } } \ 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 cee1052..b9fa2c1 100644 --- a/app/src/main/java/com/lukas/music/instruments/Instrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/Instrument.kt @@ -13,11 +13,10 @@ import com.lukas.music.instruments.effect.Effect import com.lukas.music.instruments.effect.EffectType import com.lukas.music.song.note.Note -import com.lukas.music.song.voice.BassVoice import com.lukas.music.song.voice.Voice abstract class Instrument(var name: String) { - var voice: Voice = BassVoice(this) + var voice: Voice = Voice(this) var envelope = Envelope(this) val effects = Array(EffectType.VALUES.size) { Effect(EffectType.VALUES[it], this) 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 deleted file mode 100644 index 66650a2..0000000 --- a/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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.song.voice - -import com.lukas.music.instruments.Instrument -import com.lukas.music.song.note.Note - -class BassVoice(instrument: Instrument) : Voice(instrument) { - override val noteCount: Int get() = 1 - - override fun getNotes(root: Note, chordNotes: Array): Array { - return arrayOf(chordNotes[0] - 24) - } -} \ No newline at end of file diff --git a/app/src/main/cpp/effects/Noise.cpp b/app/src/main/cpp/effects/Noise.cpp index b858a97..3ecfd2e 100644 --- a/app/src/main/cpp/effects/Noise.cpp +++ b/app/src/main/cpp/effects/Noise.cpp @@ -14,6 +14,8 @@ void Noise::doRender(uint32_t sampleCount) { for (uint32_t i = 0; i < sampleCount; i++) { float random = ((float) rand() / (float) (RAND_MAX + 1)); - buffer[i] = (2.f * ((random * c2) + (random * c2) + (random * c2)) - 3.f * (c2 - 1.f)) * c3; + buffer[i] = + (2.f * ((random * c2) + (random * c2) + (random * c2)) - 3.f * (c2 - 1.f)) * c3 / + 10; } } \ 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 cee1052..b9fa2c1 100644 --- a/app/src/main/java/com/lukas/music/instruments/Instrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/Instrument.kt @@ -13,11 +13,10 @@ import com.lukas.music.instruments.effect.Effect import com.lukas.music.instruments.effect.EffectType import com.lukas.music.song.note.Note -import com.lukas.music.song.voice.BassVoice import com.lukas.music.song.voice.Voice abstract class Instrument(var name: String) { - var voice: Voice = BassVoice(this) + var voice: Voice = Voice(this) var envelope = Envelope(this) val effects = Array(EffectType.VALUES.size) { Effect(EffectType.VALUES[it], this) 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 deleted file mode 100644 index 66650a2..0000000 --- a/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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.song.voice - -import com.lukas.music.instruments.Instrument -import com.lukas.music.song.note.Note - -class BassVoice(instrument: Instrument) : Voice(instrument) { - override val noteCount: Int get() = 1 - - override fun getNotes(root: Note, chordNotes: Array): Array { - return arrayOf(chordNotes[0] - 24) - } -} \ No newline at end of file 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 deleted file mode 100644 index 9a075bc..0000000 --- a/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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.song.voice - -import com.lukas.music.instruments.Instrument -import com.lukas.music.song.note.Note - -class ChordVoice(instrument: Instrument) : Voice(instrument) { - override val noteCount: Int get() = 3 - - override fun getNotes(root: Note, chordNotes: Array): Array { - return chordNotes - } -} \ No newline at end of file diff --git a/app/src/main/cpp/effects/Noise.cpp b/app/src/main/cpp/effects/Noise.cpp index b858a97..3ecfd2e 100644 --- a/app/src/main/cpp/effects/Noise.cpp +++ b/app/src/main/cpp/effects/Noise.cpp @@ -14,6 +14,8 @@ void Noise::doRender(uint32_t sampleCount) { for (uint32_t i = 0; i < sampleCount; i++) { float random = ((float) rand() / (float) (RAND_MAX + 1)); - buffer[i] = (2.f * ((random * c2) + (random * c2) + (random * c2)) - 3.f * (c2 - 1.f)) * c3; + buffer[i] = + (2.f * ((random * c2) + (random * c2) + (random * c2)) - 3.f * (c2 - 1.f)) * c3 / + 10; } } \ 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 cee1052..b9fa2c1 100644 --- a/app/src/main/java/com/lukas/music/instruments/Instrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/Instrument.kt @@ -13,11 +13,10 @@ import com.lukas.music.instruments.effect.Effect import com.lukas.music.instruments.effect.EffectType import com.lukas.music.song.note.Note -import com.lukas.music.song.voice.BassVoice import com.lukas.music.song.voice.Voice abstract class Instrument(var name: String) { - var voice: Voice = BassVoice(this) + var voice: Voice = Voice(this) var envelope = Envelope(this) val effects = Array(EffectType.VALUES.size) { Effect(EffectType.VALUES[it], this) 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 deleted file mode 100644 index 66650a2..0000000 --- a/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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.song.voice - -import com.lukas.music.instruments.Instrument -import com.lukas.music.song.note.Note - -class BassVoice(instrument: Instrument) : Voice(instrument) { - override val noteCount: Int get() = 1 - - override fun getNotes(root: Note, chordNotes: Array): Array { - return arrayOf(chordNotes[0] - 24) - } -} \ No newline at end of file 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 deleted file mode 100644 index 9a075bc..0000000 --- a/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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.song.voice - -import com.lukas.music.instruments.Instrument -import com.lukas.music.song.note.Note - -class ChordVoice(instrument: Instrument) : Voice(instrument) { - override val noteCount: Int get() = 3 - - override fun getNotes(root: Note, chordNotes: Array): Array { - return chordNotes - } -} \ No newline at end of file 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 aae1c2a..1408362 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 @@ -13,15 +13,20 @@ import com.lukas.music.instruments.Instrument import com.lukas.music.song.Song import com.lukas.music.song.note.Note -import kotlin.reflect.KClass -abstract class Voice(val instrument: Instrument) { - abstract val noteCount: Int - val noteActive: Array> = - Array(Song.currentSong.beats * Song.currentSong.subBeats) { Array(noteCount) { false } } +class Voice(val instrument: Instrument) { + var type: VoiceType = VoiceType.Bass + set(value) { + field = value + noteActive = + Array(Song.currentSong.beats * Song.currentSong.subBeats) { Array(value.noteCount) { false } } + } var restrikeNotes = false + lateinit var noteActive: Array> - abstract fun getNotes(root: Note, chordNotes: Array): Array + init { + type = type + } fun step(root: Note, chordNotes: Array, beat: Int, subBeat: Int) { if (instrument.muted) { @@ -29,7 +34,7 @@ } val beatIndex = beat * Song.currentSong.subBeats + subBeat val activeNotes = noteActive[beatIndex] - val notes = getNotes(root, chordNotes) + val notes = type.getNotes(root, chordNotes) for ((index, active) in activeNotes.withIndex()) { val note = notes[index] if (!active) { @@ -41,13 +46,4 @@ } } } - - companion object { - val DEFAULT_VOICES = listOf>( - BassVoice::class, - ChordVoice::class, - ) - - val DEFAULT_VOICE_NAMES = listOf("Bass", "Chord") - } } \ No newline at end of file diff --git a/app/src/main/cpp/effects/Noise.cpp b/app/src/main/cpp/effects/Noise.cpp index b858a97..3ecfd2e 100644 --- a/app/src/main/cpp/effects/Noise.cpp +++ b/app/src/main/cpp/effects/Noise.cpp @@ -14,6 +14,8 @@ void Noise::doRender(uint32_t sampleCount) { for (uint32_t i = 0; i < sampleCount; i++) { float random = ((float) rand() / (float) (RAND_MAX + 1)); - buffer[i] = (2.f * ((random * c2) + (random * c2) + (random * c2)) - 3.f * (c2 - 1.f)) * c3; + buffer[i] = + (2.f * ((random * c2) + (random * c2) + (random * c2)) - 3.f * (c2 - 1.f)) * c3 / + 10; } } \ 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 cee1052..b9fa2c1 100644 --- a/app/src/main/java/com/lukas/music/instruments/Instrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/Instrument.kt @@ -13,11 +13,10 @@ import com.lukas.music.instruments.effect.Effect import com.lukas.music.instruments.effect.EffectType import com.lukas.music.song.note.Note -import com.lukas.music.song.voice.BassVoice import com.lukas.music.song.voice.Voice abstract class Instrument(var name: String) { - var voice: Voice = BassVoice(this) + var voice: Voice = Voice(this) var envelope = Envelope(this) val effects = Array(EffectType.VALUES.size) { Effect(EffectType.VALUES[it], this) 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 deleted file mode 100644 index 66650a2..0000000 --- a/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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.song.voice - -import com.lukas.music.instruments.Instrument -import com.lukas.music.song.note.Note - -class BassVoice(instrument: Instrument) : Voice(instrument) { - override val noteCount: Int get() = 1 - - override fun getNotes(root: Note, chordNotes: Array): Array { - return arrayOf(chordNotes[0] - 24) - } -} \ No newline at end of file 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 deleted file mode 100644 index 9a075bc..0000000 --- a/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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.song.voice - -import com.lukas.music.instruments.Instrument -import com.lukas.music.song.note.Note - -class ChordVoice(instrument: Instrument) : Voice(instrument) { - override val noteCount: Int get() = 3 - - override fun getNotes(root: Note, chordNotes: Array): Array { - return chordNotes - } -} \ No newline at end of file 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 aae1c2a..1408362 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 @@ -13,15 +13,20 @@ import com.lukas.music.instruments.Instrument import com.lukas.music.song.Song import com.lukas.music.song.note.Note -import kotlin.reflect.KClass -abstract class Voice(val instrument: Instrument) { - abstract val noteCount: Int - val noteActive: Array> = - Array(Song.currentSong.beats * Song.currentSong.subBeats) { Array(noteCount) { false } } +class Voice(val instrument: Instrument) { + var type: VoiceType = VoiceType.Bass + set(value) { + field = value + noteActive = + Array(Song.currentSong.beats * Song.currentSong.subBeats) { Array(value.noteCount) { false } } + } var restrikeNotes = false + lateinit var noteActive: Array> - abstract fun getNotes(root: Note, chordNotes: Array): Array + init { + type = type + } fun step(root: Note, chordNotes: Array, beat: Int, subBeat: Int) { if (instrument.muted) { @@ -29,7 +34,7 @@ } val beatIndex = beat * Song.currentSong.subBeats + subBeat val activeNotes = noteActive[beatIndex] - val notes = getNotes(root, chordNotes) + val notes = type.getNotes(root, chordNotes) for ((index, active) in activeNotes.withIndex()) { val note = notes[index] if (!active) { @@ -41,13 +46,4 @@ } } } - - companion object { - val DEFAULT_VOICES = listOf>( - BassVoice::class, - ChordVoice::class, - ) - - val DEFAULT_VOICE_NAMES = listOf("Bass", "Chord") - } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/voice/VoiceType.kt b/app/src/main/java/com/lukas/music/song/voice/VoiceType.kt new file mode 100644 index 0000000..cba0063 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/voice/VoiceType.kt @@ -0,0 +1,32 @@ +/* + * 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.song.voice + +import com.lukas.music.song.note.Note + +enum class VoiceType( + val title: String, + val noteCount: Int, + val getNotes: (Note, Array) -> Array +) { + Bass("Bass Note", 1, { _, chordNotes -> arrayOf(chordNotes[0] - 24) }), + Chord("Chord Notes", 3, { _, chordNotes -> chordNotes }), + RootRelative("Song root relative", 12, { root, _ -> Array(12) { root + it } }), + ; + + override fun toString(): String { + return title + } + + companion object { + val VALUES = values() + } +} \ No newline at end of file diff --git a/app/src/main/cpp/effects/Noise.cpp b/app/src/main/cpp/effects/Noise.cpp index b858a97..3ecfd2e 100644 --- a/app/src/main/cpp/effects/Noise.cpp +++ b/app/src/main/cpp/effects/Noise.cpp @@ -14,6 +14,8 @@ void Noise::doRender(uint32_t sampleCount) { for (uint32_t i = 0; i < sampleCount; i++) { float random = ((float) rand() / (float) (RAND_MAX + 1)); - buffer[i] = (2.f * ((random * c2) + (random * c2) + (random * c2)) - 3.f * (c2 - 1.f)) * c3; + buffer[i] = + (2.f * ((random * c2) + (random * c2) + (random * c2)) - 3.f * (c2 - 1.f)) * c3 / + 10; } } \ 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 cee1052..b9fa2c1 100644 --- a/app/src/main/java/com/lukas/music/instruments/Instrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/Instrument.kt @@ -13,11 +13,10 @@ import com.lukas.music.instruments.effect.Effect import com.lukas.music.instruments.effect.EffectType import com.lukas.music.song.note.Note -import com.lukas.music.song.voice.BassVoice import com.lukas.music.song.voice.Voice abstract class Instrument(var name: String) { - var voice: Voice = BassVoice(this) + var voice: Voice = Voice(this) var envelope = Envelope(this) val effects = Array(EffectType.VALUES.size) { Effect(EffectType.VALUES[it], this) 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 deleted file mode 100644 index 66650a2..0000000 --- a/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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.song.voice - -import com.lukas.music.instruments.Instrument -import com.lukas.music.song.note.Note - -class BassVoice(instrument: Instrument) : Voice(instrument) { - override val noteCount: Int get() = 1 - - override fun getNotes(root: Note, chordNotes: Array): Array { - return arrayOf(chordNotes[0] - 24) - } -} \ No newline at end of file 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 deleted file mode 100644 index 9a075bc..0000000 --- a/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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.song.voice - -import com.lukas.music.instruments.Instrument -import com.lukas.music.song.note.Note - -class ChordVoice(instrument: Instrument) : Voice(instrument) { - override val noteCount: Int get() = 3 - - override fun getNotes(root: Note, chordNotes: Array): Array { - return chordNotes - } -} \ No newline at end of file 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 aae1c2a..1408362 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 @@ -13,15 +13,20 @@ import com.lukas.music.instruments.Instrument import com.lukas.music.song.Song import com.lukas.music.song.note.Note -import kotlin.reflect.KClass -abstract class Voice(val instrument: Instrument) { - abstract val noteCount: Int - val noteActive: Array> = - Array(Song.currentSong.beats * Song.currentSong.subBeats) { Array(noteCount) { false } } +class Voice(val instrument: Instrument) { + var type: VoiceType = VoiceType.Bass + set(value) { + field = value + noteActive = + Array(Song.currentSong.beats * Song.currentSong.subBeats) { Array(value.noteCount) { false } } + } var restrikeNotes = false + lateinit var noteActive: Array> - abstract fun getNotes(root: Note, chordNotes: Array): Array + init { + type = type + } fun step(root: Note, chordNotes: Array, beat: Int, subBeat: Int) { if (instrument.muted) { @@ -29,7 +34,7 @@ } val beatIndex = beat * Song.currentSong.subBeats + subBeat val activeNotes = noteActive[beatIndex] - val notes = getNotes(root, chordNotes) + val notes = type.getNotes(root, chordNotes) for ((index, active) in activeNotes.withIndex()) { val note = notes[index] if (!active) { @@ -41,13 +46,4 @@ } } } - - companion object { - val DEFAULT_VOICES = listOf>( - BassVoice::class, - ChordVoice::class, - ) - - val DEFAULT_VOICE_NAMES = listOf("Bass", "Chord") - } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/voice/VoiceType.kt b/app/src/main/java/com/lukas/music/song/voice/VoiceType.kt new file mode 100644 index 0000000..cba0063 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/voice/VoiceType.kt @@ -0,0 +1,32 @@ +/* + * 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.song.voice + +import com.lukas.music.song.note.Note + +enum class VoiceType( + val title: String, + val noteCount: Int, + val getNotes: (Note, Array) -> Array +) { + Bass("Bass Note", 1, { _, chordNotes -> arrayOf(chordNotes[0] - 24) }), + Chord("Chord Notes", 3, { _, chordNotes -> chordNotes }), + RootRelative("Song root relative", 12, { root, _ -> Array(12) { root + it } }), + ; + + override fun toString(): String { + return title + } + + companion object { + val VALUES = values() + } +} \ No newline at end of file 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 1714b49..c416df7 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 @@ -19,7 +19,7 @@ import com.lukas.music.databinding.FragmentEditInstrumentBinding import com.lukas.music.instruments.Instrument import com.lukas.music.instruments.Waveform -import com.lukas.music.song.voice.Voice +import com.lukas.music.song.voice.VoiceType import com.lukas.music.ui.adapters.InstrumentViewHolder import com.lukas.music.util.EasyDialogFragment import com.lukas.music.util.setup @@ -50,15 +50,7 @@ binding.volumeText.text = "volume: $it%" instrument.volume = it.toFloat() / 100f } - binding.voiceSelection.setup( - 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.voiceSelection.smartSetup(VoiceType.VALUES, instrument.voice::type) binding.editVoiceButton.setOnClickListener { EditVoiceFragment(instrument.voice).showNow(childFragmentManager, "") } diff --git a/app/src/main/cpp/effects/Noise.cpp b/app/src/main/cpp/effects/Noise.cpp index b858a97..3ecfd2e 100644 --- a/app/src/main/cpp/effects/Noise.cpp +++ b/app/src/main/cpp/effects/Noise.cpp @@ -14,6 +14,8 @@ void Noise::doRender(uint32_t sampleCount) { for (uint32_t i = 0; i < sampleCount; i++) { float random = ((float) rand() / (float) (RAND_MAX + 1)); - buffer[i] = (2.f * ((random * c2) + (random * c2) + (random * c2)) - 3.f * (c2 - 1.f)) * c3; + buffer[i] = + (2.f * ((random * c2) + (random * c2) + (random * c2)) - 3.f * (c2 - 1.f)) * c3 / + 10; } } \ 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 cee1052..b9fa2c1 100644 --- a/app/src/main/java/com/lukas/music/instruments/Instrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/Instrument.kt @@ -13,11 +13,10 @@ import com.lukas.music.instruments.effect.Effect import com.lukas.music.instruments.effect.EffectType import com.lukas.music.song.note.Note -import com.lukas.music.song.voice.BassVoice import com.lukas.music.song.voice.Voice abstract class Instrument(var name: String) { - var voice: Voice = BassVoice(this) + var voice: Voice = Voice(this) var envelope = Envelope(this) val effects = Array(EffectType.VALUES.size) { Effect(EffectType.VALUES[it], this) 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 deleted file mode 100644 index 66650a2..0000000 --- a/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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.song.voice - -import com.lukas.music.instruments.Instrument -import com.lukas.music.song.note.Note - -class BassVoice(instrument: Instrument) : Voice(instrument) { - override val noteCount: Int get() = 1 - - override fun getNotes(root: Note, chordNotes: Array): Array { - return arrayOf(chordNotes[0] - 24) - } -} \ No newline at end of file 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 deleted file mode 100644 index 9a075bc..0000000 --- a/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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.song.voice - -import com.lukas.music.instruments.Instrument -import com.lukas.music.song.note.Note - -class ChordVoice(instrument: Instrument) : Voice(instrument) { - override val noteCount: Int get() = 3 - - override fun getNotes(root: Note, chordNotes: Array): Array { - return chordNotes - } -} \ No newline at end of file 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 aae1c2a..1408362 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 @@ -13,15 +13,20 @@ import com.lukas.music.instruments.Instrument import com.lukas.music.song.Song import com.lukas.music.song.note.Note -import kotlin.reflect.KClass -abstract class Voice(val instrument: Instrument) { - abstract val noteCount: Int - val noteActive: Array> = - Array(Song.currentSong.beats * Song.currentSong.subBeats) { Array(noteCount) { false } } +class Voice(val instrument: Instrument) { + var type: VoiceType = VoiceType.Bass + set(value) { + field = value + noteActive = + Array(Song.currentSong.beats * Song.currentSong.subBeats) { Array(value.noteCount) { false } } + } var restrikeNotes = false + lateinit var noteActive: Array> - abstract fun getNotes(root: Note, chordNotes: Array): Array + init { + type = type + } fun step(root: Note, chordNotes: Array, beat: Int, subBeat: Int) { if (instrument.muted) { @@ -29,7 +34,7 @@ } val beatIndex = beat * Song.currentSong.subBeats + subBeat val activeNotes = noteActive[beatIndex] - val notes = getNotes(root, chordNotes) + val notes = type.getNotes(root, chordNotes) for ((index, active) in activeNotes.withIndex()) { val note = notes[index] if (!active) { @@ -41,13 +46,4 @@ } } } - - companion object { - val DEFAULT_VOICES = listOf>( - BassVoice::class, - ChordVoice::class, - ) - - val DEFAULT_VOICE_NAMES = listOf("Bass", "Chord") - } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/voice/VoiceType.kt b/app/src/main/java/com/lukas/music/song/voice/VoiceType.kt new file mode 100644 index 0000000..cba0063 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/voice/VoiceType.kt @@ -0,0 +1,32 @@ +/* + * 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.song.voice + +import com.lukas.music.song.note.Note + +enum class VoiceType( + val title: String, + val noteCount: Int, + val getNotes: (Note, Array) -> Array +) { + Bass("Bass Note", 1, { _, chordNotes -> arrayOf(chordNotes[0] - 24) }), + Chord("Chord Notes", 3, { _, chordNotes -> chordNotes }), + RootRelative("Song root relative", 12, { root, _ -> Array(12) { root + it } }), + ; + + override fun toString(): String { + return title + } + + companion object { + val VALUES = values() + } +} \ No newline at end of file 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 1714b49..c416df7 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 @@ -19,7 +19,7 @@ import com.lukas.music.databinding.FragmentEditInstrumentBinding import com.lukas.music.instruments.Instrument import com.lukas.music.instruments.Waveform -import com.lukas.music.song.voice.Voice +import com.lukas.music.song.voice.VoiceType import com.lukas.music.ui.adapters.InstrumentViewHolder import com.lukas.music.util.EasyDialogFragment import com.lukas.music.util.setup @@ -50,15 +50,7 @@ binding.volumeText.text = "volume: $it%" instrument.volume = it.toFloat() / 100f } - binding.voiceSelection.setup( - 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.voiceSelection.smartSetup(VoiceType.VALUES, instrument.voice::type) binding.editVoiceButton.setOnClickListener { EditVoiceFragment(instrument.voice).showNow(childFragmentManager, "") } diff --git a/app/src/main/java/com/lukas/music/ui/fragments/EditVoiceFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/EditVoiceFragment.kt index 5bd49b6..57dc7ed 100644 --- a/app/src/main/java/com/lukas/music/ui/fragments/EditVoiceFragment.kt +++ b/app/src/main/java/com/lukas/music/ui/fragments/EditVoiceFragment.kt @@ -32,7 +32,7 @@ ): View? { binding = FragmentEditVoiceBinding.inflate(inflater) binding.restrikeButton.setupToggle(voice::restrikeNotes, R.color.green) - for (row in voice.noteCount - 1 downTo 0) { + for (row in voice.type.noteCount - 1 downTo 0) { val rowLayout = TableRow(binding.root.context) for (column in 0 until Song.currentSong.beats * Song.currentSong.subBeats) { val button = MaterialButton(binding.root.context) @@ -53,6 +53,14 @@ return binding.root } + override fun onStart() { + super.onStart() + dialog?.window?.setLayout( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT + ) + } + companion object { val buttonLayout = TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT) diff --git a/app/src/main/cpp/effects/Noise.cpp b/app/src/main/cpp/effects/Noise.cpp index b858a97..3ecfd2e 100644 --- a/app/src/main/cpp/effects/Noise.cpp +++ b/app/src/main/cpp/effects/Noise.cpp @@ -14,6 +14,8 @@ void Noise::doRender(uint32_t sampleCount) { for (uint32_t i = 0; i < sampleCount; i++) { float random = ((float) rand() / (float) (RAND_MAX + 1)); - buffer[i] = (2.f * ((random * c2) + (random * c2) + (random * c2)) - 3.f * (c2 - 1.f)) * c3; + buffer[i] = + (2.f * ((random * c2) + (random * c2) + (random * c2)) - 3.f * (c2 - 1.f)) * c3 / + 10; } } \ 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 cee1052..b9fa2c1 100644 --- a/app/src/main/java/com/lukas/music/instruments/Instrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/Instrument.kt @@ -13,11 +13,10 @@ import com.lukas.music.instruments.effect.Effect import com.lukas.music.instruments.effect.EffectType import com.lukas.music.song.note.Note -import com.lukas.music.song.voice.BassVoice import com.lukas.music.song.voice.Voice abstract class Instrument(var name: String) { - var voice: Voice = BassVoice(this) + var voice: Voice = Voice(this) var envelope = Envelope(this) val effects = Array(EffectType.VALUES.size) { Effect(EffectType.VALUES[it], this) 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 deleted file mode 100644 index 66650a2..0000000 --- a/app/src/main/java/com/lukas/music/song/voice/BassVoice.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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.song.voice - -import com.lukas.music.instruments.Instrument -import com.lukas.music.song.note.Note - -class BassVoice(instrument: Instrument) : Voice(instrument) { - override val noteCount: Int get() = 1 - - override fun getNotes(root: Note, chordNotes: Array): Array { - return arrayOf(chordNotes[0] - 24) - } -} \ No newline at end of file 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 deleted file mode 100644 index 9a075bc..0000000 --- a/app/src/main/java/com/lukas/music/song/voice/ChordVoice.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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.song.voice - -import com.lukas.music.instruments.Instrument -import com.lukas.music.song.note.Note - -class ChordVoice(instrument: Instrument) : Voice(instrument) { - override val noteCount: Int get() = 3 - - override fun getNotes(root: Note, chordNotes: Array): Array { - return chordNotes - } -} \ No newline at end of file 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 aae1c2a..1408362 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 @@ -13,15 +13,20 @@ import com.lukas.music.instruments.Instrument import com.lukas.music.song.Song import com.lukas.music.song.note.Note -import kotlin.reflect.KClass -abstract class Voice(val instrument: Instrument) { - abstract val noteCount: Int - val noteActive: Array> = - Array(Song.currentSong.beats * Song.currentSong.subBeats) { Array(noteCount) { false } } +class Voice(val instrument: Instrument) { + var type: VoiceType = VoiceType.Bass + set(value) { + field = value + noteActive = + Array(Song.currentSong.beats * Song.currentSong.subBeats) { Array(value.noteCount) { false } } + } var restrikeNotes = false + lateinit var noteActive: Array> - abstract fun getNotes(root: Note, chordNotes: Array): Array + init { + type = type + } fun step(root: Note, chordNotes: Array, beat: Int, subBeat: Int) { if (instrument.muted) { @@ -29,7 +34,7 @@ } val beatIndex = beat * Song.currentSong.subBeats + subBeat val activeNotes = noteActive[beatIndex] - val notes = getNotes(root, chordNotes) + val notes = type.getNotes(root, chordNotes) for ((index, active) in activeNotes.withIndex()) { val note = notes[index] if (!active) { @@ -41,13 +46,4 @@ } } } - - companion object { - val DEFAULT_VOICES = listOf>( - BassVoice::class, - ChordVoice::class, - ) - - val DEFAULT_VOICE_NAMES = listOf("Bass", "Chord") - } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/song/voice/VoiceType.kt b/app/src/main/java/com/lukas/music/song/voice/VoiceType.kt new file mode 100644 index 0000000..cba0063 --- /dev/null +++ b/app/src/main/java/com/lukas/music/song/voice/VoiceType.kt @@ -0,0 +1,32 @@ +/* + * 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.song.voice + +import com.lukas.music.song.note.Note + +enum class VoiceType( + val title: String, + val noteCount: Int, + val getNotes: (Note, Array) -> Array +) { + Bass("Bass Note", 1, { _, chordNotes -> arrayOf(chordNotes[0] - 24) }), + Chord("Chord Notes", 3, { _, chordNotes -> chordNotes }), + RootRelative("Song root relative", 12, { root, _ -> Array(12) { root + it } }), + ; + + override fun toString(): String { + return title + } + + companion object { + val VALUES = values() + } +} \ No newline at end of file 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 1714b49..c416df7 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 @@ -19,7 +19,7 @@ import com.lukas.music.databinding.FragmentEditInstrumentBinding import com.lukas.music.instruments.Instrument import com.lukas.music.instruments.Waveform -import com.lukas.music.song.voice.Voice +import com.lukas.music.song.voice.VoiceType import com.lukas.music.ui.adapters.InstrumentViewHolder import com.lukas.music.util.EasyDialogFragment import com.lukas.music.util.setup @@ -50,15 +50,7 @@ binding.volumeText.text = "volume: $it%" instrument.volume = it.toFloat() / 100f } - binding.voiceSelection.setup( - 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.voiceSelection.smartSetup(VoiceType.VALUES, instrument.voice::type) binding.editVoiceButton.setOnClickListener { EditVoiceFragment(instrument.voice).showNow(childFragmentManager, "") } diff --git a/app/src/main/java/com/lukas/music/ui/fragments/EditVoiceFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/EditVoiceFragment.kt index 5bd49b6..57dc7ed 100644 --- a/app/src/main/java/com/lukas/music/ui/fragments/EditVoiceFragment.kt +++ b/app/src/main/java/com/lukas/music/ui/fragments/EditVoiceFragment.kt @@ -32,7 +32,7 @@ ): View? { binding = FragmentEditVoiceBinding.inflate(inflater) binding.restrikeButton.setupToggle(voice::restrikeNotes, R.color.green) - for (row in voice.noteCount - 1 downTo 0) { + for (row in voice.type.noteCount - 1 downTo 0) { val rowLayout = TableRow(binding.root.context) for (column in 0 until Song.currentSong.beats * Song.currentSong.subBeats) { val button = MaterialButton(binding.root.context) @@ -53,6 +53,14 @@ return binding.root } + override fun onStart() { + super.onStart() + dialog?.window?.setLayout( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT + ) + } + companion object { val buttonLayout = TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT) diff --git a/app/src/main/res/layout/fragment_edit_voice.xml b/app/src/main/res/layout/fragment_edit_voice.xml index a734c83..ff77f1b 100644 --- a/app/src/main/res/layout/fragment_edit_voice.xml +++ b/app/src/main/res/layout/fragment_edit_voice.xml @@ -28,30 +28,17 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="@+id/restrikeButton" /> - - + app:layout_constraintStart_toStartOf="parent" />