chordSpecToIntervals :: ChordSpec -> [IntervalPattern]
chordSpecToIntervals (ChordSpec {..}) =
    root : (catMaybes $ third : fifth : main : added : [])
    where
        ipat x y = IntervalPatternValue { interval = x, inversionsAllowed = y }
        inversions x = ipat x True
        noInversions x = ipat x False
        root = ExactlyOne $ noInversions (In.Interval 0)

        chordQ = fromMaybe MajorChord chordQuality
        -- @TODO ugly stuff
        makeInterval (q, n) =
            In.Interval $ neutralI + modI
            where
                neutralI =
                    case n of
                        7 -> 11
                        6 -> 9
                        9 -> 14
                        10 -> 16
                        11 -> 17 -- ??
                modI =
                    case fromMaybe Major q of
                        Major -> 0
                        Minor -> -1
                        Augmented -> 1
                        Diminished -> -2
                        Dominant -> error "ugh"

        third = Just . ExactlyOne . noInversions $
            (case chordQ of
                MajorChord -> In.maj3
                MinorChord -> In.min3)
        fifth = Just . ExactlyOne . inversions $ In.perf5
        main = ExactlyOne . inversions . makeInterval <$> mainInterval
        added = Nothing
chordSpecToIntervals :: ChordSpec -> [IntervalPattern]
chordSpecToIntervals (ChordSpec {..}) =
    root : (catMaybes $ third : fifth : main : added : [])
    where
        ipat x y = IntervalPatternValue { interval = x, inversionsAllowed = y }
        inversions x = ipat x True
        noInversions x = ipat x False
        root = ExactlyOne $ noInversions (In.Interval 0)

        chordQ = fromMaybe MajorChord chordQuality
        -- @TODO ugly stuff
        makeInterval (q, n) =
            In.Interval $ neutralI + modI
            where
                neutralI =
                    case n of
                        7 -> 11
                        6 -> 9
                        9 -> 14
                        10 -> 16
                        11 -> 17 -- ??
                modI =
                    case fromMaybe Major q of
                        Major -> 0
                        Minor -> -1
                        Augmented -> 1
                        Diminished -> -2
                        Dominant -> error "ugh"

        third = Just . ExactlyOne . noInversions $
            (case chordQ of
                MajorChord -> In.maj3
                MinorChord -> In.min3)
        fifth = Just . ExactlyOne . inversions $ In.perf5
        main = ExactlyOne . inversions . makeInterval <$> mainInterval
        added = Nothing
chordSpecToIntervals (ChordSpec {..}) =
    root : (catMaybes $ third : fifth : main : added : [])
    where
        ipat x y = IntervalPatternValue { interval = x, inversionsAllowed = y }
        inversions x = ipat x True
        noInversions x = ipat x False
        root = ExactlyOne $ noInversions (In.Interval 0)

        chordQ = fromMaybe MajorChord chordQuality
        -- @TODO ugly stuff
        makeInterval (q, n) =
            In.Interval $ neutralI + modI
            where
                neutralI =
                    case n of
                        7 -> 11
                        6 -> 9
                        9 -> 14
                        10 -> 16
                        11 -> 17 -- ??
                modI =
                    case fromMaybe Major q of
                        Major -> 0
                        Minor -> -1
                        Augmented -> 1
                        Diminished -> -2
                        Dominant -> error "ugh"

        third = Just . ExactlyOne . noInversions $
            (case chordQ of
                MajorChord -> In.maj3
                MinorChord -> In.min3)
        fifth = Just . ExactlyOne . inversions $ In.perf5
        main = ExactlyOne . inversions . makeInterval <$> mainInterval
        added = Nothing