package mg.dot.feufaro.midi

enum class Dynamic(val velocity: Int, val label: String, val factor: Float) {
    PPP(16,  "ppp", 16f  / 80f),
    PP (33,  "pp",  33f  / 80f),
    P  (49,  "p",   49f  / 80f),
    MP (64,  "mp",  64f  / 80f),
    MF (80,  "mf",  1.00f),
    F  (96,  "f",   96f  / 80f),
    FF (112, "ff",  112f / 80f),
    FFF(126, "fff", 126f / 80f);

    companion object {
        fun fromVelocity(v: Int): Dynamic =
            entries.minByOrNull { kotlin.math.abs(it.velocity - v) } ?: MF
    }
}