module Music.Score.Harmonics (
HasHarmonic(..),
HarmonicT(..),
harmonic,
artificial,
) where
import Control.Applicative
import Control.Comonad
import Control.Lens hiding (transform)
import Data.Foldable
import Data.Foldable
import Data.Functor.Couple
import Data.Ratio
import Data.Semigroup
import Data.Typeable
import Data.Word
import Music.Dynamics.Literal
import Music.Pitch.Alterable
import Music.Pitch.Augmentable
import Music.Pitch.Literal
import Music.Score.Part
import Music.Score.Phrases
import Music.Time
class HasHarmonic a where
setNatural :: Bool -> a -> a
setHarmonic :: Int -> a -> a
newtype HarmonicT a = HarmonicT { getHarmonicT :: Couple (Any, Sum Int) a }
deriving (
Eq, Show, Ord, Functor, Foldable, Typeable,
Applicative, Monad, Comonad
)
instance HasHarmonic a => HasHarmonic (b, a) where
setNatural b = fmap (setNatural b)
setHarmonic n = fmap (setHarmonic n)
instance HasHarmonic a => HasHarmonic (Couple b a) where
setNatural b = fmap (setNatural b)
setHarmonic n = fmap (setHarmonic n)
instance HasHarmonic a => HasHarmonic [a] where
setNatural b = fmap (setNatural b)
setHarmonic n = fmap (setHarmonic n)
instance HasHarmonic a => HasHarmonic (Score a) where
setNatural b = fmap (setNatural b)
setHarmonic n = fmap (setHarmonic n)
instance Wrapped (HarmonicT a) where
type Unwrapped (HarmonicT a) = Couple (Any, Sum Int) a
_Wrapped' = iso getHarmonicT HarmonicT
instance Rewrapped (HarmonicT a) (HarmonicT b)
instance HasHarmonic (HarmonicT a) where
setNatural b = over (_Wrapped'._Wrapped') $ \((_,n),x) -> ((Any b,n),x)
setHarmonic n = over (_Wrapped'._Wrapped') $ \((nat,_),x) -> ((nat,Sum n),x)
deriving instance Num a => Num (HarmonicT a)
deriving instance Fractional a => Fractional (HarmonicT a)
deriving instance Floating a => Floating (HarmonicT a)
deriving instance Enum a => Enum (HarmonicT a)
deriving instance Bounded a => Bounded (HarmonicT a)
deriving instance (Num a, Ord a, Real a) => Real (HarmonicT a)
deriving instance (Real a, Enum a, Integral a) => Integral (HarmonicT a)
harmonic :: HasHarmonic a => Int -> a -> a
harmonic n = setNatural True . setHarmonic n
artificial :: HasHarmonic a => a -> a
artificial = setNatural False . setHarmonic 3