diff --git a/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt b/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt index f7983ad..c5f565c 100644 --- a/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt @@ -79,7 +79,7 @@ } fun applyEffectAttributes(effect: Effect) { - applyEffectAttributes(id, effect.type.ordinal, effect.parameter1) + applyEffectAttributes(id, effect.type.ordinal, effect.parameters[0].value) } private external fun createInstrument(): Int diff --git a/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt b/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt index f7983ad..c5f565c 100644 --- a/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt @@ -79,7 +79,7 @@ } fun applyEffectAttributes(effect: Effect) { - applyEffectAttributes(id, effect.type.ordinal, effect.parameter1) + applyEffectAttributes(id, effect.type.ordinal, effect.parameters[0].value) } private external fun createInstrument(): Int diff --git a/app/src/main/java/com/lukas/music/instruments/effect/Effect.kt b/app/src/main/java/com/lukas/music/instruments/effect/Effect.kt index 8a3c4eb..ea81afb 100644 --- a/app/src/main/java/com/lukas/music/instruments/effect/Effect.kt +++ b/app/src/main/java/com/lukas/music/instruments/effect/Effect.kt @@ -13,14 +13,7 @@ import com.lukas.music.instruments.Instrument class Effect(val type: EffectType, private val instrument: Instrument) { - var parameter1: Float = 1.0f - set(value) { - field = value - instrument.updateEffects() - } - var parameter1Percent: Int - get() = (parameter1 * 100).toInt() - set(value) { - parameter1 = value.toFloat() / 100f - } + val parameters = Array(type.parameterDescriptions.size) { + EffectParameter(type.parameterDescriptions[it], instrument) + } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt b/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt index f7983ad..c5f565c 100644 --- a/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt @@ -79,7 +79,7 @@ } fun applyEffectAttributes(effect: Effect) { - applyEffectAttributes(id, effect.type.ordinal, effect.parameter1) + applyEffectAttributes(id, effect.type.ordinal, effect.parameters[0].value) } private external fun createInstrument(): Int diff --git a/app/src/main/java/com/lukas/music/instruments/effect/Effect.kt b/app/src/main/java/com/lukas/music/instruments/effect/Effect.kt index 8a3c4eb..ea81afb 100644 --- a/app/src/main/java/com/lukas/music/instruments/effect/Effect.kt +++ b/app/src/main/java/com/lukas/music/instruments/effect/Effect.kt @@ -13,14 +13,7 @@ import com.lukas.music.instruments.Instrument class Effect(val type: EffectType, private val instrument: Instrument) { - var parameter1: Float = 1.0f - set(value) { - field = value - instrument.updateEffects() - } - var parameter1Percent: Int - get() = (parameter1 * 100).toInt() - set(value) { - parameter1 = value.toFloat() / 100f - } + val parameters = Array(type.parameterDescriptions.size) { + EffectParameter(type.parameterDescriptions[it], instrument) + } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/instruments/effect/EffectParameter.kt b/app/src/main/java/com/lukas/music/instruments/effect/EffectParameter.kt new file mode 100644 index 0000000..f54857c --- /dev/null +++ b/app/src/main/java/com/lukas/music/instruments/effect/EffectParameter.kt @@ -0,0 +1,30 @@ +/* + * 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.instruments.effect + +import com.lukas.music.instruments.Instrument +import kotlin.math.roundToInt + +class EffectParameter(val description: EffectParameterDescription, val instrument: Instrument) { + var value: Float = description.initialValue + set(value) { + field = value + instrument.updateEffects() + } + + // linear interpolation between description extrema + var percentageValue: Int + get() = ((value - description.min) / (description.max - description.min) * 100).roundToInt() + set(value) { + this.value = + description.min + (description.max - description.min) * (value.toFloat() / 100f) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt b/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt index f7983ad..c5f565c 100644 --- a/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt @@ -79,7 +79,7 @@ } fun applyEffectAttributes(effect: Effect) { - applyEffectAttributes(id, effect.type.ordinal, effect.parameter1) + applyEffectAttributes(id, effect.type.ordinal, effect.parameters[0].value) } private external fun createInstrument(): Int diff --git a/app/src/main/java/com/lukas/music/instruments/effect/Effect.kt b/app/src/main/java/com/lukas/music/instruments/effect/Effect.kt index 8a3c4eb..ea81afb 100644 --- a/app/src/main/java/com/lukas/music/instruments/effect/Effect.kt +++ b/app/src/main/java/com/lukas/music/instruments/effect/Effect.kt @@ -13,14 +13,7 @@ import com.lukas.music.instruments.Instrument class Effect(val type: EffectType, private val instrument: Instrument) { - var parameter1: Float = 1.0f - set(value) { - field = value - instrument.updateEffects() - } - var parameter1Percent: Int - get() = (parameter1 * 100).toInt() - set(value) { - parameter1 = value.toFloat() / 100f - } + val parameters = Array(type.parameterDescriptions.size) { + EffectParameter(type.parameterDescriptions[it], instrument) + } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/instruments/effect/EffectParameter.kt b/app/src/main/java/com/lukas/music/instruments/effect/EffectParameter.kt new file mode 100644 index 0000000..f54857c --- /dev/null +++ b/app/src/main/java/com/lukas/music/instruments/effect/EffectParameter.kt @@ -0,0 +1,30 @@ +/* + * 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.instruments.effect + +import com.lukas.music.instruments.Instrument +import kotlin.math.roundToInt + +class EffectParameter(val description: EffectParameterDescription, val instrument: Instrument) { + var value: Float = description.initialValue + set(value) { + field = value + instrument.updateEffects() + } + + // linear interpolation between description extrema + var percentageValue: Int + get() = ((value - description.min) / (description.max - description.min) * 100).roundToInt() + set(value) { + this.value = + description.min + (description.max - description.min) * (value.toFloat() / 100f) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/instruments/effect/EffectParameterDescription.kt b/app/src/main/java/com/lukas/music/instruments/effect/EffectParameterDescription.kt new file mode 100644 index 0000000..25c6260 --- /dev/null +++ b/app/src/main/java/com/lukas/music/instruments/effect/EffectParameterDescription.kt @@ -0,0 +1,18 @@ +/* + * 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.instruments.effect + +class EffectParameterDescription( + val min: Float, + val max: Float, + val initialValue: Float, + val text: (EffectParameter) -> String, +) \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt b/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt index f7983ad..c5f565c 100644 --- a/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt @@ -79,7 +79,7 @@ } fun applyEffectAttributes(effect: Effect) { - applyEffectAttributes(id, effect.type.ordinal, effect.parameter1) + applyEffectAttributes(id, effect.type.ordinal, effect.parameters[0].value) } private external fun createInstrument(): Int diff --git a/app/src/main/java/com/lukas/music/instruments/effect/Effect.kt b/app/src/main/java/com/lukas/music/instruments/effect/Effect.kt index 8a3c4eb..ea81afb 100644 --- a/app/src/main/java/com/lukas/music/instruments/effect/Effect.kt +++ b/app/src/main/java/com/lukas/music/instruments/effect/Effect.kt @@ -13,14 +13,7 @@ import com.lukas.music.instruments.Instrument class Effect(val type: EffectType, private val instrument: Instrument) { - var parameter1: Float = 1.0f - set(value) { - field = value - instrument.updateEffects() - } - var parameter1Percent: Int - get() = (parameter1 * 100).toInt() - set(value) { - parameter1 = value.toFloat() / 100f - } + val parameters = Array(type.parameterDescriptions.size) { + EffectParameter(type.parameterDescriptions[it], instrument) + } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/instruments/effect/EffectParameter.kt b/app/src/main/java/com/lukas/music/instruments/effect/EffectParameter.kt new file mode 100644 index 0000000..f54857c --- /dev/null +++ b/app/src/main/java/com/lukas/music/instruments/effect/EffectParameter.kt @@ -0,0 +1,30 @@ +/* + * 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.instruments.effect + +import com.lukas.music.instruments.Instrument +import kotlin.math.roundToInt + +class EffectParameter(val description: EffectParameterDescription, val instrument: Instrument) { + var value: Float = description.initialValue + set(value) { + field = value + instrument.updateEffects() + } + + // linear interpolation between description extrema + var percentageValue: Int + get() = ((value - description.min) / (description.max - description.min) * 100).roundToInt() + set(value) { + this.value = + description.min + (description.max - description.min) * (value.toFloat() / 100f) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/instruments/effect/EffectParameterDescription.kt b/app/src/main/java/com/lukas/music/instruments/effect/EffectParameterDescription.kt new file mode 100644 index 0000000..25c6260 --- /dev/null +++ b/app/src/main/java/com/lukas/music/instruments/effect/EffectParameterDescription.kt @@ -0,0 +1,18 @@ +/* + * 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.instruments.effect + +class EffectParameterDescription( + val min: Float, + val max: Float, + val initialValue: Float, + val text: (EffectParameter) -> String, +) \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/instruments/effect/EffectType.kt b/app/src/main/java/com/lukas/music/instruments/effect/EffectType.kt index 98edbbb..027a6c2 100644 --- a/app/src/main/java/com/lukas/music/instruments/effect/EffectType.kt +++ b/app/src/main/java/com/lukas/music/instruments/effect/EffectType.kt @@ -10,15 +10,24 @@ package com.lukas.music.instruments.effect -import kotlin.math.roundToInt +import com.lukas.music.util.format enum class EffectType( - val description: String, - val parameter1Text: (Int) -> String, + val title: String, + val parameterDescriptions: Array ) { - LowPass("low pass filter", { "cutoff: ${(it.toFloat() / 100f).roundToInt()} octaves" }), + LowPass("low pass filter", + arrayOf( + EffectParameterDescription(-1f, 3f, 1f) { + "cutoff: ${it.value.format(1)} octaves" + } + )), ; + override fun toString(): String { + return title + } + companion object { val VALUES = values() } diff --git a/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt b/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt index f7983ad..c5f565c 100644 --- a/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt @@ -79,7 +79,7 @@ } fun applyEffectAttributes(effect: Effect) { - applyEffectAttributes(id, effect.type.ordinal, effect.parameter1) + applyEffectAttributes(id, effect.type.ordinal, effect.parameters[0].value) } private external fun createInstrument(): Int diff --git a/app/src/main/java/com/lukas/music/instruments/effect/Effect.kt b/app/src/main/java/com/lukas/music/instruments/effect/Effect.kt index 8a3c4eb..ea81afb 100644 --- a/app/src/main/java/com/lukas/music/instruments/effect/Effect.kt +++ b/app/src/main/java/com/lukas/music/instruments/effect/Effect.kt @@ -13,14 +13,7 @@ import com.lukas.music.instruments.Instrument class Effect(val type: EffectType, private val instrument: Instrument) { - var parameter1: Float = 1.0f - set(value) { - field = value - instrument.updateEffects() - } - var parameter1Percent: Int - get() = (parameter1 * 100).toInt() - set(value) { - parameter1 = value.toFloat() / 100f - } + val parameters = Array(type.parameterDescriptions.size) { + EffectParameter(type.parameterDescriptions[it], instrument) + } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/instruments/effect/EffectParameter.kt b/app/src/main/java/com/lukas/music/instruments/effect/EffectParameter.kt new file mode 100644 index 0000000..f54857c --- /dev/null +++ b/app/src/main/java/com/lukas/music/instruments/effect/EffectParameter.kt @@ -0,0 +1,30 @@ +/* + * 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.instruments.effect + +import com.lukas.music.instruments.Instrument +import kotlin.math.roundToInt + +class EffectParameter(val description: EffectParameterDescription, val instrument: Instrument) { + var value: Float = description.initialValue + set(value) { + field = value + instrument.updateEffects() + } + + // linear interpolation between description extrema + var percentageValue: Int + get() = ((value - description.min) / (description.max - description.min) * 100).roundToInt() + set(value) { + this.value = + description.min + (description.max - description.min) * (value.toFloat() / 100f) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/instruments/effect/EffectParameterDescription.kt b/app/src/main/java/com/lukas/music/instruments/effect/EffectParameterDescription.kt new file mode 100644 index 0000000..25c6260 --- /dev/null +++ b/app/src/main/java/com/lukas/music/instruments/effect/EffectParameterDescription.kt @@ -0,0 +1,18 @@ +/* + * 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.instruments.effect + +class EffectParameterDescription( + val min: Float, + val max: Float, + val initialValue: Float, + val text: (EffectParameter) -> String, +) \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/instruments/effect/EffectType.kt b/app/src/main/java/com/lukas/music/instruments/effect/EffectType.kt index 98edbbb..027a6c2 100644 --- a/app/src/main/java/com/lukas/music/instruments/effect/EffectType.kt +++ b/app/src/main/java/com/lukas/music/instruments/effect/EffectType.kt @@ -10,15 +10,24 @@ package com.lukas.music.instruments.effect -import kotlin.math.roundToInt +import com.lukas.music.util.format enum class EffectType( - val description: String, - val parameter1Text: (Int) -> String, + val title: String, + val parameterDescriptions: Array ) { - LowPass("low pass filter", { "cutoff: ${(it.toFloat() / 100f).roundToInt()} octaves" }), + LowPass("low pass filter", + arrayOf( + EffectParameterDescription(-1f, 3f, 1f) { + "cutoff: ${it.value.format(1)} octaves" + } + )), ; + override fun toString(): String { + return title + } + companion object { val VALUES = values() } diff --git a/app/src/main/java/com/lukas/music/ui/fragments/EffectFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/EffectFragment.kt index c004620..dc9edfa 100644 --- a/app/src/main/java/com/lukas/music/ui/fragments/EffectFragment.kt +++ b/app/src/main/java/com/lukas/music/ui/fragments/EffectFragment.kt @@ -27,9 +27,10 @@ savedInstanceState: Bundle? ): View? { binding = FragmentEffectBinding.inflate(inflater) - binding.effectName.text = effect.type.description - binding.parameter1SeekBar.smartSetup(-100, 300, effect::parameter1Percent) { - binding.parameter1Text.text = effect.type.parameter1Text(it) + binding.effectName.text = effect.type.toString() + binding.parameter1SeekBar.smartSetup(0, 100, effect.parameters[0]::percentageValue) { + binding.parameter1Text.text = + effect.parameters[0].description.text(effect.parameters[0]) } return binding.root } diff --git a/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt b/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt index f7983ad..c5f565c 100644 --- a/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt @@ -79,7 +79,7 @@ } fun applyEffectAttributes(effect: Effect) { - applyEffectAttributes(id, effect.type.ordinal, effect.parameter1) + applyEffectAttributes(id, effect.type.ordinal, effect.parameters[0].value) } private external fun createInstrument(): Int diff --git a/app/src/main/java/com/lukas/music/instruments/effect/Effect.kt b/app/src/main/java/com/lukas/music/instruments/effect/Effect.kt index 8a3c4eb..ea81afb 100644 --- a/app/src/main/java/com/lukas/music/instruments/effect/Effect.kt +++ b/app/src/main/java/com/lukas/music/instruments/effect/Effect.kt @@ -13,14 +13,7 @@ import com.lukas.music.instruments.Instrument class Effect(val type: EffectType, private val instrument: Instrument) { - var parameter1: Float = 1.0f - set(value) { - field = value - instrument.updateEffects() - } - var parameter1Percent: Int - get() = (parameter1 * 100).toInt() - set(value) { - parameter1 = value.toFloat() / 100f - } + val parameters = Array(type.parameterDescriptions.size) { + EffectParameter(type.parameterDescriptions[it], instrument) + } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/instruments/effect/EffectParameter.kt b/app/src/main/java/com/lukas/music/instruments/effect/EffectParameter.kt new file mode 100644 index 0000000..f54857c --- /dev/null +++ b/app/src/main/java/com/lukas/music/instruments/effect/EffectParameter.kt @@ -0,0 +1,30 @@ +/* + * 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.instruments.effect + +import com.lukas.music.instruments.Instrument +import kotlin.math.roundToInt + +class EffectParameter(val description: EffectParameterDescription, val instrument: Instrument) { + var value: Float = description.initialValue + set(value) { + field = value + instrument.updateEffects() + } + + // linear interpolation between description extrema + var percentageValue: Int + get() = ((value - description.min) / (description.max - description.min) * 100).roundToInt() + set(value) { + this.value = + description.min + (description.max - description.min) * (value.toFloat() / 100f) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/instruments/effect/EffectParameterDescription.kt b/app/src/main/java/com/lukas/music/instruments/effect/EffectParameterDescription.kt new file mode 100644 index 0000000..25c6260 --- /dev/null +++ b/app/src/main/java/com/lukas/music/instruments/effect/EffectParameterDescription.kt @@ -0,0 +1,18 @@ +/* + * 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.instruments.effect + +class EffectParameterDescription( + val min: Float, + val max: Float, + val initialValue: Float, + val text: (EffectParameter) -> String, +) \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/instruments/effect/EffectType.kt b/app/src/main/java/com/lukas/music/instruments/effect/EffectType.kt index 98edbbb..027a6c2 100644 --- a/app/src/main/java/com/lukas/music/instruments/effect/EffectType.kt +++ b/app/src/main/java/com/lukas/music/instruments/effect/EffectType.kt @@ -10,15 +10,24 @@ package com.lukas.music.instruments.effect -import kotlin.math.roundToInt +import com.lukas.music.util.format enum class EffectType( - val description: String, - val parameter1Text: (Int) -> String, + val title: String, + val parameterDescriptions: Array ) { - LowPass("low pass filter", { "cutoff: ${(it.toFloat() / 100f).roundToInt()} octaves" }), + LowPass("low pass filter", + arrayOf( + EffectParameterDescription(-1f, 3f, 1f) { + "cutoff: ${it.value.format(1)} octaves" + } + )), ; + override fun toString(): String { + return title + } + companion object { val VALUES = values() } diff --git a/app/src/main/java/com/lukas/music/ui/fragments/EffectFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/EffectFragment.kt index c004620..dc9edfa 100644 --- a/app/src/main/java/com/lukas/music/ui/fragments/EffectFragment.kt +++ b/app/src/main/java/com/lukas/music/ui/fragments/EffectFragment.kt @@ -27,9 +27,10 @@ savedInstanceState: Bundle? ): View? { binding = FragmentEffectBinding.inflate(inflater) - binding.effectName.text = effect.type.description - binding.parameter1SeekBar.smartSetup(-100, 300, effect::parameter1Percent) { - binding.parameter1Text.text = effect.type.parameter1Text(it) + binding.effectName.text = effect.type.toString() + binding.parameter1SeekBar.smartSetup(0, 100, effect.parameters[0]::percentageValue) { + binding.parameter1Text.text = + effect.parameters[0].description.text(effect.parameters[0]) } return binding.root } diff --git a/app/src/main/java/com/lukas/music/util/MathUtil.kt b/app/src/main/java/com/lukas/music/util/MathUtil.kt new file mode 100644 index 0000000..20b063b --- /dev/null +++ b/app/src/main/java/com/lukas/music/util/MathUtil.kt @@ -0,0 +1,15 @@ +/* + * 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 + +fun Double.format(digits: Int) = "%.${digits}f".format(this) + +fun Float.format(digits: Int) = "%.${digits}f".format(this) \ No newline at end of file