{-# LANGUAGE OverloadedStrings #-}
module AcousticBrainz.LowLevel.Algorithm.Key where
import Data.Aeson
import Data.Aeson.Types
import Data.Scientific
data Output = Output
{ _key :: Text
, _scale :: Scale
, _strength :: Scientific
, _tuningDiatonicStrength :: Scientific
} deriving(Eq, Ord, Read, Show)
instance FromJSON Output where
parseJSON = withObject "key" $ \v -> Output
<$> v .: "key_key"
<*> v .: "key_scale"
<*> v .: "key_strength"
<*> v .: "tuning_diatonic_strength"
data Scale = Major | Minor deriving(Eq, Ord, Read, Show)
instance FromJSON Scale where
parseJSON = withText "scale" $ \t ->
if t == "major"
then return Major
else if t == "minor"
then return Minor
else fail $ "Invalid key scale: " <> toString t