Demo entry 6754790

Triadic Transformations

   

Submitted by anonymous on Jul 21, 2018 at 23:43
Language: Kotlin. Code size: 1.7 kB.

data class Triad(val root: PitchClass,
                 val third: PitchClass,
                 val fifth: PitchClass) {

    fun parallel() = Triad(root = root,
            third = when {
                isMinor() -> third.transpose(desiredInterval = 1)
                isMajor() -> third.transpose(desiredInterval = -1)
                else -> onNonMinorOrMajorTriad()
            },
            fifth = fifth)

    fun relative() = when {
        isMinor() -> Triad(root = third,
                third = fifth,
                fifth = root.transpose(-1, -2))
        isMajor() -> Triad(root = fifth.transpose(1, 2),
                third = root,
                fifth = third)
        else -> onNonMinorOrMajorTriad()
    }

    fun leadingTone() = when {
        isMinor() -> Triad(root = fifth.transpose(1, 1),
                third = root,
                fifth = third)
        isMajor() -> Triad(root = third,
                third = fifth,
                fifth = root.transpose(-1, -1))
        else -> onNonMinorOrMajorTriad()
    }

    fun nebenverwandt() = relative().leadingTone().parallel()

    fun slide() = leadingTone().parallel().relative()

    fun hexatonicPole() = leadingTone().parallel().leadingTone()

    private fun isMinor() = root.isMinorThird(third) && third.isMajorThird(fifth)
    private fun isMajor() = root.isMajorThird(third) && third.isMinorThird(fifth)
    private fun isDiminished() = root.isMinorThird(third) && third.isMinorThird(fifth)
    private fun isAugmented() = root.isMajorThird(third) && fifth.isMajorThird(fifth)

    private fun onNonMinorOrMajorTriad(): Nothing =
            error("Triad was neither minor nor major")
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).