-- Copyright 2023 Evan Laforge
-- This program is distributed under the terms of the GNU General Public
-- License 3.0, see COPYING or http://www.gnu.org/licenses/gpl-3.0.txt

{-# LANGUAGE TypeFamilies #-}
-- | 'Affine' and instances.
-- module Util.Affine (Affine(..), (.-^)) where
module Util.Affine where
import qualified Data.Time as Time


-- | Simplified version of AffineSpace from the vector-space package.
--
-- Num gives access to negate and (+) and (*).  It's probably technically too
-- much because it also has fromInteger, but I don't think I need the whole
-- AdditiveGroup etc. alternative numeric hierarchy.
class Num (Diff p) => Affine p where
    type Diff p
    (.-.) :: p -> p -> Diff p
    (.+^) :: p -> Diff p -> p

(.-^) :: Affine p => p -> Diff p -> p
p
p .-^ :: forall p. Affine p => p -> Diff p -> p
.-^ Diff p
diff = p
p forall p. Affine p => p -> Diff p -> p
.+^ (-Diff p
diff)

-- * base types

instance Affine Time.UTCTime where
    type Diff Time.UTCTime = Time.NominalDiffTime
    .-. :: UTCTime -> UTCTime -> Diff UTCTime
(.-.) = UTCTime -> UTCTime -> NominalDiffTime
Time.diffUTCTime
    .+^ :: UTCTime -> Diff UTCTime -> UTCTime
(.+^) = forall a b c. (a -> b -> c) -> b -> a -> c
flip NominalDiffTime -> UTCTime -> UTCTime
Time.addUTCTime

-- Match (+) and (-).
infixl 6 .+^
infixl 6 .-^
infixl 6 .-.

-- I could put in the basic numeric types, but why?

-- * pitch

-- | Absolute chromatic steps.
newtype Chromatic = Chromatic Int
    deriving (Int -> Chromatic -> ShowS
[Chromatic] -> ShowS
Chromatic -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Chromatic] -> ShowS
$cshowList :: [Chromatic] -> ShowS
show :: Chromatic -> String
$cshow :: Chromatic -> String
showsPrec :: Int -> Chromatic -> ShowS
$cshowsPrec :: Int -> Chromatic -> ShowS
Show, Chromatic -> Chromatic -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Chromatic -> Chromatic -> Bool
$c/= :: Chromatic -> Chromatic -> Bool
== :: Chromatic -> Chromatic -> Bool
$c== :: Chromatic -> Chromatic -> Bool
Eq, Eq Chromatic
Chromatic -> Chromatic -> Bool
Chromatic -> Chromatic -> Ordering
Chromatic -> Chromatic -> Chromatic
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Chromatic -> Chromatic -> Chromatic
$cmin :: Chromatic -> Chromatic -> Chromatic
max :: Chromatic -> Chromatic -> Chromatic
$cmax :: Chromatic -> Chromatic -> Chromatic
>= :: Chromatic -> Chromatic -> Bool
$c>= :: Chromatic -> Chromatic -> Bool
> :: Chromatic -> Chromatic -> Bool
$c> :: Chromatic -> Chromatic -> Bool
<= :: Chromatic -> Chromatic -> Bool
$c<= :: Chromatic -> Chromatic -> Bool
< :: Chromatic -> Chromatic -> Bool
$c< :: Chromatic -> Chromatic -> Bool
compare :: Chromatic -> Chromatic -> Ordering
$ccompare :: Chromatic -> Chromatic -> Ordering
Ord)
-- | Relative chromatic steps, modulo pc_per_octave.
newtype ChromaticSteps = ChromaticSteps Int
    deriving (Int -> ChromaticSteps -> ShowS
[ChromaticSteps] -> ShowS
ChromaticSteps -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ChromaticSteps] -> ShowS
$cshowList :: [ChromaticSteps] -> ShowS
show :: ChromaticSteps -> String
$cshow :: ChromaticSteps -> String
showsPrec :: Int -> ChromaticSteps -> ShowS
$cshowsPrec :: Int -> ChromaticSteps -> ShowS
Show, ChromaticSteps -> ChromaticSteps -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ChromaticSteps -> ChromaticSteps -> Bool
$c/= :: ChromaticSteps -> ChromaticSteps -> Bool
== :: ChromaticSteps -> ChromaticSteps -> Bool
$c== :: ChromaticSteps -> ChromaticSteps -> Bool
Eq, Eq ChromaticSteps
ChromaticSteps -> ChromaticSteps -> Bool
ChromaticSteps -> ChromaticSteps -> Ordering
ChromaticSteps -> ChromaticSteps -> ChromaticSteps
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ChromaticSteps -> ChromaticSteps -> ChromaticSteps
$cmin :: ChromaticSteps -> ChromaticSteps -> ChromaticSteps
max :: ChromaticSteps -> ChromaticSteps -> ChromaticSteps
$cmax :: ChromaticSteps -> ChromaticSteps -> ChromaticSteps
>= :: ChromaticSteps -> ChromaticSteps -> Bool
$c>= :: ChromaticSteps -> ChromaticSteps -> Bool
> :: ChromaticSteps -> ChromaticSteps -> Bool
$c> :: ChromaticSteps -> ChromaticSteps -> Bool
<= :: ChromaticSteps -> ChromaticSteps -> Bool
$c<= :: ChromaticSteps -> ChromaticSteps -> Bool
< :: ChromaticSteps -> ChromaticSteps -> Bool
$c< :: ChromaticSteps -> ChromaticSteps -> Bool
compare :: ChromaticSteps -> ChromaticSteps -> Ordering
$ccompare :: ChromaticSteps -> ChromaticSteps -> Ordering
Ord, Int -> ChromaticSteps
ChromaticSteps -> Int
ChromaticSteps -> [ChromaticSteps]
ChromaticSteps -> ChromaticSteps
ChromaticSteps -> ChromaticSteps -> [ChromaticSteps]
ChromaticSteps
-> ChromaticSteps -> ChromaticSteps -> [ChromaticSteps]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: ChromaticSteps
-> ChromaticSteps -> ChromaticSteps -> [ChromaticSteps]
$cenumFromThenTo :: ChromaticSteps
-> ChromaticSteps -> ChromaticSteps -> [ChromaticSteps]
enumFromTo :: ChromaticSteps -> ChromaticSteps -> [ChromaticSteps]
$cenumFromTo :: ChromaticSteps -> ChromaticSteps -> [ChromaticSteps]
enumFromThen :: ChromaticSteps -> ChromaticSteps -> [ChromaticSteps]
$cenumFromThen :: ChromaticSteps -> ChromaticSteps -> [ChromaticSteps]
enumFrom :: ChromaticSteps -> [ChromaticSteps]
$cenumFrom :: ChromaticSteps -> [ChromaticSteps]
fromEnum :: ChromaticSteps -> Int
$cfromEnum :: ChromaticSteps -> Int
toEnum :: Int -> ChromaticSteps
$ctoEnum :: Int -> ChromaticSteps
pred :: ChromaticSteps -> ChromaticSteps
$cpred :: ChromaticSteps -> ChromaticSteps
succ :: ChromaticSteps -> ChromaticSteps
$csucc :: ChromaticSteps -> ChromaticSteps
Enum, Integer -> ChromaticSteps
ChromaticSteps -> ChromaticSteps
ChromaticSteps -> ChromaticSteps -> ChromaticSteps
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
fromInteger :: Integer -> ChromaticSteps
$cfromInteger :: Integer -> ChromaticSteps
signum :: ChromaticSteps -> ChromaticSteps
$csignum :: ChromaticSteps -> ChromaticSteps
abs :: ChromaticSteps -> ChromaticSteps
$cabs :: ChromaticSteps -> ChromaticSteps
negate :: ChromaticSteps -> ChromaticSteps
$cnegate :: ChromaticSteps -> ChromaticSteps
* :: ChromaticSteps -> ChromaticSteps -> ChromaticSteps
$c* :: ChromaticSteps -> ChromaticSteps -> ChromaticSteps
- :: ChromaticSteps -> ChromaticSteps -> ChromaticSteps
$c- :: ChromaticSteps -> ChromaticSteps -> ChromaticSteps
+ :: ChromaticSteps -> ChromaticSteps -> ChromaticSteps
$c+ :: ChromaticSteps -> ChromaticSteps -> ChromaticSteps
Num, Num ChromaticSteps
Ord ChromaticSteps
ChromaticSteps -> Rational
forall a. Num a -> Ord a -> (a -> Rational) -> Real a
toRational :: ChromaticSteps -> Rational
$ctoRational :: ChromaticSteps -> Rational
Real, Enum ChromaticSteps
Real ChromaticSteps
ChromaticSteps -> Integer
ChromaticSteps
-> ChromaticSteps -> (ChromaticSteps, ChromaticSteps)
ChromaticSteps -> ChromaticSteps -> ChromaticSteps
forall a.
Real a
-> Enum a
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> (a, a))
-> (a -> a -> (a, a))
-> (a -> Integer)
-> Integral a
toInteger :: ChromaticSteps -> Integer
$ctoInteger :: ChromaticSteps -> Integer
divMod :: ChromaticSteps
-> ChromaticSteps -> (ChromaticSteps, ChromaticSteps)
$cdivMod :: ChromaticSteps
-> ChromaticSteps -> (ChromaticSteps, ChromaticSteps)
quotRem :: ChromaticSteps
-> ChromaticSteps -> (ChromaticSteps, ChromaticSteps)
$cquotRem :: ChromaticSteps
-> ChromaticSteps -> (ChromaticSteps, ChromaticSteps)
mod :: ChromaticSteps -> ChromaticSteps -> ChromaticSteps
$cmod :: ChromaticSteps -> ChromaticSteps -> ChromaticSteps
div :: ChromaticSteps -> ChromaticSteps -> ChromaticSteps
$cdiv :: ChromaticSteps -> ChromaticSteps -> ChromaticSteps
rem :: ChromaticSteps -> ChromaticSteps -> ChromaticSteps
$crem :: ChromaticSteps -> ChromaticSteps -> ChromaticSteps
quot :: ChromaticSteps -> ChromaticSteps -> ChromaticSteps
$cquot :: ChromaticSteps -> ChromaticSteps -> ChromaticSteps
Integral)

instance Affine Chromatic where
    type Diff Chromatic = ChromaticSteps
    Chromatic Int
a .-. :: Chromatic -> Chromatic -> Diff Chromatic
.-. Chromatic Int
b = Int -> ChromaticSteps
ChromaticSteps (Int
a forall a. Num a => a -> a -> a
- Int
b)
    Chromatic Int
p .+^ :: Chromatic -> Diff Chromatic -> Chromatic
.+^ ChromaticSteps Int
v = Int -> Chromatic
Chromatic (Int
p forall a. Num a => a -> a -> a
+ Int
v)

newtype Diatonic = Diatonic Int
    deriving (Int -> Diatonic -> ShowS
[Diatonic] -> ShowS
Diatonic -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Diatonic] -> ShowS
$cshowList :: [Diatonic] -> ShowS
show :: Diatonic -> String
$cshow :: Diatonic -> String
showsPrec :: Int -> Diatonic -> ShowS
$cshowsPrec :: Int -> Diatonic -> ShowS
Show, Diatonic -> Diatonic -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Diatonic -> Diatonic -> Bool
$c/= :: Diatonic -> Diatonic -> Bool
== :: Diatonic -> Diatonic -> Bool
$c== :: Diatonic -> Diatonic -> Bool
Eq, Eq Diatonic
Diatonic -> Diatonic -> Bool
Diatonic -> Diatonic -> Ordering
Diatonic -> Diatonic -> Diatonic
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Diatonic -> Diatonic -> Diatonic
$cmin :: Diatonic -> Diatonic -> Diatonic
max :: Diatonic -> Diatonic -> Diatonic
$cmax :: Diatonic -> Diatonic -> Diatonic
>= :: Diatonic -> Diatonic -> Bool
$c>= :: Diatonic -> Diatonic -> Bool
> :: Diatonic -> Diatonic -> Bool
$c> :: Diatonic -> Diatonic -> Bool
<= :: Diatonic -> Diatonic -> Bool
$c<= :: Diatonic -> Diatonic -> Bool
< :: Diatonic -> Diatonic -> Bool
$c< :: Diatonic -> Diatonic -> Bool
compare :: Diatonic -> Diatonic -> Ordering
$ccompare :: Diatonic -> Diatonic -> Ordering
Ord)
newtype DiatonicSteps = DiatonicSteps Int
    deriving (Int -> DiatonicSteps -> ShowS
[DiatonicSteps] -> ShowS
DiatonicSteps -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DiatonicSteps] -> ShowS
$cshowList :: [DiatonicSteps] -> ShowS
show :: DiatonicSteps -> String
$cshow :: DiatonicSteps -> String
showsPrec :: Int -> DiatonicSteps -> ShowS
$cshowsPrec :: Int -> DiatonicSteps -> ShowS
Show, DiatonicSteps -> DiatonicSteps -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DiatonicSteps -> DiatonicSteps -> Bool
$c/= :: DiatonicSteps -> DiatonicSteps -> Bool
== :: DiatonicSteps -> DiatonicSteps -> Bool
$c== :: DiatonicSteps -> DiatonicSteps -> Bool
Eq, Eq DiatonicSteps
DiatonicSteps -> DiatonicSteps -> Bool
DiatonicSteps -> DiatonicSteps -> Ordering
DiatonicSteps -> DiatonicSteps -> DiatonicSteps
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: DiatonicSteps -> DiatonicSteps -> DiatonicSteps
$cmin :: DiatonicSteps -> DiatonicSteps -> DiatonicSteps
max :: DiatonicSteps -> DiatonicSteps -> DiatonicSteps
$cmax :: DiatonicSteps -> DiatonicSteps -> DiatonicSteps
>= :: DiatonicSteps -> DiatonicSteps -> Bool
$c>= :: DiatonicSteps -> DiatonicSteps -> Bool
> :: DiatonicSteps -> DiatonicSteps -> Bool
$c> :: DiatonicSteps -> DiatonicSteps -> Bool
<= :: DiatonicSteps -> DiatonicSteps -> Bool
$c<= :: DiatonicSteps -> DiatonicSteps -> Bool
< :: DiatonicSteps -> DiatonicSteps -> Bool
$c< :: DiatonicSteps -> DiatonicSteps -> Bool
compare :: DiatonicSteps -> DiatonicSteps -> Ordering
$ccompare :: DiatonicSteps -> DiatonicSteps -> Ordering
Ord, Int -> DiatonicSteps
DiatonicSteps -> Int
DiatonicSteps -> [DiatonicSteps]
DiatonicSteps -> DiatonicSteps
DiatonicSteps -> DiatonicSteps -> [DiatonicSteps]
DiatonicSteps -> DiatonicSteps -> DiatonicSteps -> [DiatonicSteps]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: DiatonicSteps -> DiatonicSteps -> DiatonicSteps -> [DiatonicSteps]
$cenumFromThenTo :: DiatonicSteps -> DiatonicSteps -> DiatonicSteps -> [DiatonicSteps]
enumFromTo :: DiatonicSteps -> DiatonicSteps -> [DiatonicSteps]
$cenumFromTo :: DiatonicSteps -> DiatonicSteps -> [DiatonicSteps]
enumFromThen :: DiatonicSteps -> DiatonicSteps -> [DiatonicSteps]
$cenumFromThen :: DiatonicSteps -> DiatonicSteps -> [DiatonicSteps]
enumFrom :: DiatonicSteps -> [DiatonicSteps]
$cenumFrom :: DiatonicSteps -> [DiatonicSteps]
fromEnum :: DiatonicSteps -> Int
$cfromEnum :: DiatonicSteps -> Int
toEnum :: Int -> DiatonicSteps
$ctoEnum :: Int -> DiatonicSteps
pred :: DiatonicSteps -> DiatonicSteps
$cpred :: DiatonicSteps -> DiatonicSteps
succ :: DiatonicSteps -> DiatonicSteps
$csucc :: DiatonicSteps -> DiatonicSteps
Enum, Integer -> DiatonicSteps
DiatonicSteps -> DiatonicSteps
DiatonicSteps -> DiatonicSteps -> DiatonicSteps
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
fromInteger :: Integer -> DiatonicSteps
$cfromInteger :: Integer -> DiatonicSteps
signum :: DiatonicSteps -> DiatonicSteps
$csignum :: DiatonicSteps -> DiatonicSteps
abs :: DiatonicSteps -> DiatonicSteps
$cabs :: DiatonicSteps -> DiatonicSteps
negate :: DiatonicSteps -> DiatonicSteps
$cnegate :: DiatonicSteps -> DiatonicSteps
* :: DiatonicSteps -> DiatonicSteps -> DiatonicSteps
$c* :: DiatonicSteps -> DiatonicSteps -> DiatonicSteps
- :: DiatonicSteps -> DiatonicSteps -> DiatonicSteps
$c- :: DiatonicSteps -> DiatonicSteps -> DiatonicSteps
+ :: DiatonicSteps -> DiatonicSteps -> DiatonicSteps
$c+ :: DiatonicSteps -> DiatonicSteps -> DiatonicSteps
Num, Num DiatonicSteps
Ord DiatonicSteps
DiatonicSteps -> Rational
forall a. Num a -> Ord a -> (a -> Rational) -> Real a
toRational :: DiatonicSteps -> Rational
$ctoRational :: DiatonicSteps -> Rational
Real, Enum DiatonicSteps
Real DiatonicSteps
DiatonicSteps -> Integer
DiatonicSteps -> DiatonicSteps -> (DiatonicSteps, DiatonicSteps)
DiatonicSteps -> DiatonicSteps -> DiatonicSteps
forall a.
Real a
-> Enum a
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> (a, a))
-> (a -> a -> (a, a))
-> (a -> Integer)
-> Integral a
toInteger :: DiatonicSteps -> Integer
$ctoInteger :: DiatonicSteps -> Integer
divMod :: DiatonicSteps -> DiatonicSteps -> (DiatonicSteps, DiatonicSteps)
$cdivMod :: DiatonicSteps -> DiatonicSteps -> (DiatonicSteps, DiatonicSteps)
quotRem :: DiatonicSteps -> DiatonicSteps -> (DiatonicSteps, DiatonicSteps)
$cquotRem :: DiatonicSteps -> DiatonicSteps -> (DiatonicSteps, DiatonicSteps)
mod :: DiatonicSteps -> DiatonicSteps -> DiatonicSteps
$cmod :: DiatonicSteps -> DiatonicSteps -> DiatonicSteps
div :: DiatonicSteps -> DiatonicSteps -> DiatonicSteps
$cdiv :: DiatonicSteps -> DiatonicSteps -> DiatonicSteps
rem :: DiatonicSteps -> DiatonicSteps -> DiatonicSteps
$crem :: DiatonicSteps -> DiatonicSteps -> DiatonicSteps
quot :: DiatonicSteps -> DiatonicSteps -> DiatonicSteps
$cquot :: DiatonicSteps -> DiatonicSteps -> DiatonicSteps
Integral)

instance Affine Diatonic where
    type Diff Diatonic = DiatonicSteps
    Diatonic Int
a .-. :: Diatonic -> Diatonic -> Diff Diatonic
.-. Diatonic Int
b = Int -> DiatonicSteps
DiatonicSteps (Int
a forall a. Num a => a -> a -> a
- Int
b)
    Diatonic Int
p .+^ :: Diatonic -> Diff Diatonic -> Diatonic
.+^ DiatonicSteps Int
v = Int -> Diatonic
Diatonic (Int
p forall a. Num a => a -> a -> a
+ Int
v)

-- I'd like to put these in RealFrac so I can get round, floor, properFraction,
-- but that also gives realToFrac, which could then coerce between absolute and
-- relative, which defeats the purpose of keeping them separate.  Also it would
-- force me to put FChromatic and FDiatonic into Num, which would let me add
-- them, which also defeats the purpose.

newtype FChromatic = FChromatic Double
    deriving (Int -> FChromatic -> ShowS
[FChromatic] -> ShowS
FChromatic -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FChromatic] -> ShowS
$cshowList :: [FChromatic] -> ShowS
show :: FChromatic -> String
$cshow :: FChromatic -> String
showsPrec :: Int -> FChromatic -> ShowS
$cshowsPrec :: Int -> FChromatic -> ShowS
Show, FChromatic -> FChromatic -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FChromatic -> FChromatic -> Bool
$c/= :: FChromatic -> FChromatic -> Bool
== :: FChromatic -> FChromatic -> Bool
$c== :: FChromatic -> FChromatic -> Bool
Eq, Eq FChromatic
FChromatic -> FChromatic -> Bool
FChromatic -> FChromatic -> Ordering
FChromatic -> FChromatic -> FChromatic
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: FChromatic -> FChromatic -> FChromatic
$cmin :: FChromatic -> FChromatic -> FChromatic
max :: FChromatic -> FChromatic -> FChromatic
$cmax :: FChromatic -> FChromatic -> FChromatic
>= :: FChromatic -> FChromatic -> Bool
$c>= :: FChromatic -> FChromatic -> Bool
> :: FChromatic -> FChromatic -> Bool
$c> :: FChromatic -> FChromatic -> Bool
<= :: FChromatic -> FChromatic -> Bool
$c<= :: FChromatic -> FChromatic -> Bool
< :: FChromatic -> FChromatic -> Bool
$c< :: FChromatic -> FChromatic -> Bool
compare :: FChromatic -> FChromatic -> Ordering
$ccompare :: FChromatic -> FChromatic -> Ordering
Ord)
newtype FChromaticSteps = FChromaticSteps Double
    deriving (Int -> FChromaticSteps -> ShowS
[FChromaticSteps] -> ShowS
FChromaticSteps -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FChromaticSteps] -> ShowS
$cshowList :: [FChromaticSteps] -> ShowS
show :: FChromaticSteps -> String
$cshow :: FChromaticSteps -> String
showsPrec :: Int -> FChromaticSteps -> ShowS
$cshowsPrec :: Int -> FChromaticSteps -> ShowS
Show, FChromaticSteps -> FChromaticSteps -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FChromaticSteps -> FChromaticSteps -> Bool
$c/= :: FChromaticSteps -> FChromaticSteps -> Bool
== :: FChromaticSteps -> FChromaticSteps -> Bool
$c== :: FChromaticSteps -> FChromaticSteps -> Bool
Eq, Eq FChromaticSteps
FChromaticSteps -> FChromaticSteps -> Bool
FChromaticSteps -> FChromaticSteps -> Ordering
FChromaticSteps -> FChromaticSteps -> FChromaticSteps
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: FChromaticSteps -> FChromaticSteps -> FChromaticSteps
$cmin :: FChromaticSteps -> FChromaticSteps -> FChromaticSteps
max :: FChromaticSteps -> FChromaticSteps -> FChromaticSteps
$cmax :: FChromaticSteps -> FChromaticSteps -> FChromaticSteps
>= :: FChromaticSteps -> FChromaticSteps -> Bool
$c>= :: FChromaticSteps -> FChromaticSteps -> Bool
> :: FChromaticSteps -> FChromaticSteps -> Bool
$c> :: FChromaticSteps -> FChromaticSteps -> Bool
<= :: FChromaticSteps -> FChromaticSteps -> Bool
$c<= :: FChromaticSteps -> FChromaticSteps -> Bool
< :: FChromaticSteps -> FChromaticSteps -> Bool
$c< :: FChromaticSteps -> FChromaticSteps -> Bool
compare :: FChromaticSteps -> FChromaticSteps -> Ordering
$ccompare :: FChromaticSteps -> FChromaticSteps -> Ordering
Ord, Integer -> FChromaticSteps
FChromaticSteps -> FChromaticSteps
FChromaticSteps -> FChromaticSteps -> FChromaticSteps
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
fromInteger :: Integer -> FChromaticSteps
$cfromInteger :: Integer -> FChromaticSteps
signum :: FChromaticSteps -> FChromaticSteps
$csignum :: FChromaticSteps -> FChromaticSteps
abs :: FChromaticSteps -> FChromaticSteps
$cabs :: FChromaticSteps -> FChromaticSteps
negate :: FChromaticSteps -> FChromaticSteps
$cnegate :: FChromaticSteps -> FChromaticSteps
* :: FChromaticSteps -> FChromaticSteps -> FChromaticSteps
$c* :: FChromaticSteps -> FChromaticSteps -> FChromaticSteps
- :: FChromaticSteps -> FChromaticSteps -> FChromaticSteps
$c- :: FChromaticSteps -> FChromaticSteps -> FChromaticSteps
+ :: FChromaticSteps -> FChromaticSteps -> FChromaticSteps
$c+ :: FChromaticSteps -> FChromaticSteps -> FChromaticSteps
Num)

instance Affine FChromatic where
    type Diff FChromatic = FChromaticSteps
    FChromatic Double
a .-. :: FChromatic -> FChromatic -> Diff FChromatic
.-. FChromatic Double
b = Double -> FChromaticSteps
FChromaticSteps (Double
a forall a. Num a => a -> a -> a
- Double
b)
    FChromatic Double
p .+^ :: FChromatic -> Diff FChromatic -> FChromatic
.+^ FChromaticSteps Double
v = Double -> FChromatic
FChromatic (Double
p forall a. Num a => a -> a -> a
+ Double
v)

newtype FDiatonic = FDiatonic Double
    deriving (Int -> FDiatonic -> ShowS
[FDiatonic] -> ShowS
FDiatonic -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FDiatonic] -> ShowS
$cshowList :: [FDiatonic] -> ShowS
show :: FDiatonic -> String
$cshow :: FDiatonic -> String
showsPrec :: Int -> FDiatonic -> ShowS
$cshowsPrec :: Int -> FDiatonic -> ShowS
Show, FDiatonic -> FDiatonic -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FDiatonic -> FDiatonic -> Bool
$c/= :: FDiatonic -> FDiatonic -> Bool
== :: FDiatonic -> FDiatonic -> Bool
$c== :: FDiatonic -> FDiatonic -> Bool
Eq, Eq FDiatonic
FDiatonic -> FDiatonic -> Bool
FDiatonic -> FDiatonic -> Ordering
FDiatonic -> FDiatonic -> FDiatonic
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: FDiatonic -> FDiatonic -> FDiatonic
$cmin :: FDiatonic -> FDiatonic -> FDiatonic
max :: FDiatonic -> FDiatonic -> FDiatonic
$cmax :: FDiatonic -> FDiatonic -> FDiatonic
>= :: FDiatonic -> FDiatonic -> Bool
$c>= :: FDiatonic -> FDiatonic -> Bool
> :: FDiatonic -> FDiatonic -> Bool
$c> :: FDiatonic -> FDiatonic -> Bool
<= :: FDiatonic -> FDiatonic -> Bool
$c<= :: FDiatonic -> FDiatonic -> Bool
< :: FDiatonic -> FDiatonic -> Bool
$c< :: FDiatonic -> FDiatonic -> Bool
compare :: FDiatonic -> FDiatonic -> Ordering
$ccompare :: FDiatonic -> FDiatonic -> Ordering
Ord)
newtype FDiatonicSteps = FDiatonicSteps Double
    deriving (Int -> FDiatonicSteps -> ShowS
[FDiatonicSteps] -> ShowS
FDiatonicSteps -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FDiatonicSteps] -> ShowS
$cshowList :: [FDiatonicSteps] -> ShowS
show :: FDiatonicSteps -> String
$cshow :: FDiatonicSteps -> String
showsPrec :: Int -> FDiatonicSteps -> ShowS
$cshowsPrec :: Int -> FDiatonicSteps -> ShowS
Show, FDiatonicSteps -> FDiatonicSteps -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FDiatonicSteps -> FDiatonicSteps -> Bool
$c/= :: FDiatonicSteps -> FDiatonicSteps -> Bool
== :: FDiatonicSteps -> FDiatonicSteps -> Bool
$c== :: FDiatonicSteps -> FDiatonicSteps -> Bool
Eq, Eq FDiatonicSteps
FDiatonicSteps -> FDiatonicSteps -> Bool
FDiatonicSteps -> FDiatonicSteps -> Ordering
FDiatonicSteps -> FDiatonicSteps -> FDiatonicSteps
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: FDiatonicSteps -> FDiatonicSteps -> FDiatonicSteps
$cmin :: FDiatonicSteps -> FDiatonicSteps -> FDiatonicSteps
max :: FDiatonicSteps -> FDiatonicSteps -> FDiatonicSteps
$cmax :: FDiatonicSteps -> FDiatonicSteps -> FDiatonicSteps
>= :: FDiatonicSteps -> FDiatonicSteps -> Bool
$c>= :: FDiatonicSteps -> FDiatonicSteps -> Bool
> :: FDiatonicSteps -> FDiatonicSteps -> Bool
$c> :: FDiatonicSteps -> FDiatonicSteps -> Bool
<= :: FDiatonicSteps -> FDiatonicSteps -> Bool
$c<= :: FDiatonicSteps -> FDiatonicSteps -> Bool
< :: FDiatonicSteps -> FDiatonicSteps -> Bool
$c< :: FDiatonicSteps -> FDiatonicSteps -> Bool
compare :: FDiatonicSteps -> FDiatonicSteps -> Ordering
$ccompare :: FDiatonicSteps -> FDiatonicSteps -> Ordering
Ord, Integer -> FDiatonicSteps
FDiatonicSteps -> FDiatonicSteps
FDiatonicSteps -> FDiatonicSteps -> FDiatonicSteps
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
fromInteger :: Integer -> FDiatonicSteps
$cfromInteger :: Integer -> FDiatonicSteps
signum :: FDiatonicSteps -> FDiatonicSteps
$csignum :: FDiatonicSteps -> FDiatonicSteps
abs :: FDiatonicSteps -> FDiatonicSteps
$cabs :: FDiatonicSteps -> FDiatonicSteps
negate :: FDiatonicSteps -> FDiatonicSteps
$cnegate :: FDiatonicSteps -> FDiatonicSteps
* :: FDiatonicSteps -> FDiatonicSteps -> FDiatonicSteps
$c* :: FDiatonicSteps -> FDiatonicSteps -> FDiatonicSteps
- :: FDiatonicSteps -> FDiatonicSteps -> FDiatonicSteps
$c- :: FDiatonicSteps -> FDiatonicSteps -> FDiatonicSteps
+ :: FDiatonicSteps -> FDiatonicSteps -> FDiatonicSteps
$c+ :: FDiatonicSteps -> FDiatonicSteps -> FDiatonicSteps
Num)

instance Affine FDiatonic where
    type Diff FDiatonic = FDiatonicSteps
    FDiatonic Double
a .-. :: FDiatonic -> FDiatonic -> Diff FDiatonic
.-. FDiatonic Double
b = Double -> FDiatonicSteps
FDiatonicSteps (Double
a forall a. Num a => a -> a -> a
- Double
b)
    FDiatonic Double
p .+^ :: FDiatonic -> Diff FDiatonic -> FDiatonic
.+^ FDiatonicSteps Double
v = Double -> FDiatonic
FDiatonic (Double
p forall a. Num a => a -> a -> a
+ Double
v)