module ZMidi.Core.Pretty.Interp
(
ScaleMap
, scale_map
, majorScaleName
, minorScaleName
, midiScaleName
, simpleNoteName
, timeSignature
, timeSignatureName
) where
import ZMidi.Core.Datatypes
import qualified Data.IntMap as IM
import Data.Ratio
type ScaleMap = IM.IntMap (String,String)
scale_map :: ScaleMap
scale_map = IM.fromList $
[ (0, ("C", "A" ))
, (1, ("G", "E" ))
, (2, ("D", "B" ))
, (3, ("A", "F#"))
, (4, ("E", "C#"))
, (5, ("B", "G#"))
, (6, ("F#", "D#"))
, (7, ("C#", "A#"))
, (1, ("F", "D" ))
, (2, ("Bb", "G" ))
, (3, ("Eb", "C" ))
, (4, ("Ab", "F" ))
, (5, ("Db", "Bb"))
, (6, ("Gb", "Eb"))
, (7, ("Cb", "Ab"))
]
majorScaleName :: Int -> Maybe String
majorScaleName n = fmap (\(ss,_) -> ss ++ " major") $ IM.lookup n scale_map
minorScaleName :: Int -> Maybe String
minorScaleName n = fmap (\(_,ss) -> ss ++ " minor") $ IM.lookup n scale_map
midiScaleName :: MidiScaleType -> Int -> Maybe String
midiScaleName (MAJOR) n = majorScaleName n
midiScaleName (MINOR) n = minorScaleName n
midiScaleName _ _ = Nothing
simpleNoteName :: Int -> String
simpleNoteName n =
let (o,l) = n `divMod` 12
ove = show $ o 1
in pch l ++ ove
where
pch 0 = "C"
pch 1 = "C#"
pch 2 = "D"
pch 3 = "D#"
pch 4 = "E"
pch 5 = "F"
pch 6 = "F#"
pch 7 = "G"
pch 8 = "G#"
pch 9 = "A"
pch 10 = "A#"
pch 11 = "B"
pch _ = "ERROR - simpleNoteName - impossible "
timeSignature :: Int -> Int -> (Int,Int)
timeSignature nn dd = (nn, d1)
where
ddi :: Integer
ddi = fromIntegral dd
d1 :: Int
d1 = fromIntegral $ denominator $ (2::Rational) ^^ (negate ddi)
timeSignatureName :: Int -> Int -> String
timeSignatureName nn dd =
let (ni,di) = timeSignature nn dd in show ni ++ "/" ++ show di