music-pitch-literal 1.7.1 → 1.7.2
raw patch · 5 files changed
+85/−8 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Music.Pitch.Alterable: alter :: Alterable a => Int -> a -> a
+ Music.Pitch.Augmentable: augmentN :: Augmentable a => Int -> a -> a
+ Music.Pitch.Literal.Interval: instance HasResolution a => IsInterval (Fixed a)
+ Music.Pitch.Literal.Interval: instance Integral a => IsInterval (Ratio a)
+ Music.Pitch.Literal.Interval: instance IsInterval Float
+ Music.Pitch.Literal.Interval: instance IsInterval Int
+ Music.Pitch.Literal.Interval: instance IsInterval Word
+ Music.Pitch.Literal.Pitch: instance HasResolution a => IsPitch (Fixed a)
+ Music.Pitch.Literal.Pitch: instance Integral a => IsPitch (Ratio a)
+ Music.Pitch.Literal.Pitch: instance IsPitch Float
+ Music.Pitch.Literal.Pitch: instance IsPitch Int
+ Music.Pitch.Literal.Pitch: instance IsPitch Word
Files
- music-pitch-literal.cabal +1/−1
- src/Music/Pitch/Alterable.hs +15/−0
- src/Music/Pitch/Augmentable.hs +11/−0
- src/Music/Pitch/Literal/Interval.hs +26/−2
- src/Music/Pitch/Literal/Pitch.hs +32/−5
music-pitch-literal.cabal view
@@ -1,6 +1,6 @@ name: music-pitch-literal-version: 1.7.1+version: 1.7.2 author: Hans Hoglund maintainer: Hans Hoglund license: BSD3
src/Music/Pitch/Alterable.hs view
@@ -16,6 +16,7 @@ module Music.Pitch.Alterable ( -- * Alterable class Alterable(..),+ alter, ) where import Data.Ratio@@ -62,3 +63,17 @@ instance Alterable a => Alterable (b, a) where sharpen = fmap sharpen flatten = fmap flatten++{-+sharpened :: Alterable a => Iso' a a+sharpened = iso sharpen flatten++flattened :: Alterable a => Iso' a a+flattened = iso flatten sharpen+-}++alter :: Alterable a => Int -> a -> a+alter n x+ | n < 0 = iterate flatten x !! n+ | n == 0 = x+ | n > 0 = iterate sharpen x !! n
src/Music/Pitch/Augmentable.hs view
@@ -16,6 +16,7 @@ module Music.Pitch.Augmentable ( -- * Augmentable class Augmentable(..),+ augmentN, ) where import Data.Ratio@@ -59,3 +60,13 @@ augment = fmap augment diminish = fmap diminish +{-+augmented :: Augmentable a => Iso' a a+augmented = iso augment diminish+-}++augmentN :: Augmentable a => Int -> a -> a+augmentN n x+ | n < 0 = iterate diminish x !! n+ | n == 0 = x+ | n > 0 = iterate augment x !! n
src/Music/Pitch/Literal/Interval.hs view
@@ -17,9 +17,13 @@ module Music.Pitch.Literal.Interval ( + -- * IsInterval class IsInterval(..), IntervalL(..), + -- * Literal values+ + -- ** Simple intervals d1, _P1, _A1, d2, m2, _M2, _A2, d3, m3, _M3, _A3,@@ -28,6 +32,7 @@ d6, m6, _M6, _A6, d7, m7, _M7, _A7, + -- ** One-octave compounds d8, _P8, _A8, d9, m9, _M9, _A9, d10, m10, _M10, _A10,@@ -36,12 +41,16 @@ d13, m13, _M13, _A13, d14, m14, _M14, _A14, + -- ** Two-octave compounds d15, _P15, _A15, ) where -import Data.Semigroup-import Control.Applicative+import Control.Applicative+import Data.Fixed+import Data.Ratio+import Data.Semigroup+import Data.Word newtype IntervalL = IntervalL (Integer, Integer, Integer) -- (octaves, diatonic steps, chromatic steps)@@ -66,6 +75,21 @@ instance (Monoid b, IsInterval a) => IsInterval (b, a) where fromInterval = pure . fromInterval++instance IsInterval Int where+ fromInterval x = fromIntegral (fromInterval x :: Integer)++instance IsInterval Word where+ fromInterval x = fromIntegral (fromInterval x :: Integer)++instance IsInterval Float where+ fromInterval x = realToFrac (fromInterval x :: Double)++instance HasResolution a => IsInterval (Fixed a) where+ fromInterval x = realToFrac (fromInterval x :: Double)++instance Integral a => IsInterval (Ratio a) where+ fromInterval x = realToFrac (fromInterval x :: Double) instance IsInterval Double where fromInterval = fromIntegral . asInteger . fromInterval
src/Music/Pitch/Literal/Pitch.hs view
@@ -17,33 +17,45 @@ module Music.Pitch.Literal.Pitch ( + -- * IsPitch class IsPitch(..), PitchL(..),-+ + -- * Literal values+ + -- ** Two octaves up cs'', ds'', es'', fs'', gs'', as'', bs'', c'' , d'' , e'' , f'' , g'' , a'' , b'' , cb'', db'', eb'', fb'', gb'', ab'', bb'', + -- ** One octave up cs' , ds' , es' , fs' , gs' , as' , bs' , c' , d' , e' , f' , g' , a' , b' , cb' , db' , eb' , fb' , gb' , ab' , bb' , + -- ** Standard octave cs , ds , es , fs , gs , as , bs , c , d , e , f , g , a , b , cb , db , eb , fb , gb , ab , bb , + -- ** One octave down cs_ , ds_ , es_ , fs_ , gs_ , as_ , bs_ , c_ , d_ , e_ , f_ , g_ , a_ , b_ , cb_ , db_ , eb_ , fb_ , gb_ , ab_ , bb_ , + -- ** Two octaves down cs__, ds__, es__, fs__, gs__, as__, bs__, c__ , d__ , e__ , f__ , g__ , a__ , b__ , cb__, db__, eb__, fb__, gb__, ab__, bb__ ) where -import Data.Semigroup-import Control.Applicative+import Control.Applicative+import Data.Fixed+import Data.Int+import Data.Ratio+import Data.Semigroup+import Data.Word -- Pitch literal, defined as @(class, alteration, octave)@, where --@@ -51,11 +63,11 @@ -- -- * @alteration@ is the number of semitones, i.e. 0 is natural, 1 for sharp 2 for double sharp, -1 for flat and -2 for double flat. -- Alteration is in 'Maybe' because some pitch representations differ between explicit and explicit accidentals, i.e. a diatonic--- pitch type may assume @(0,Nothing,4)@ to mean C sharp rather than C.+-- pitch type may assume @(0,Nothing,...)@ to mean C sharp rather than C. -- -- * @octave@ is octave number in scientific pitch notation. ----- Middle C is represented by the pitch literal @(0, Nothing, 4)@.+-- Middle C is represented by the pitch literal @(0, Nothing, 0)@. -- newtype PitchL = PitchL { getPitchL :: (Int, Maybe Double, Int) } deriving (Eq, Show, Ord)@@ -80,6 +92,21 @@ instance (Monoid b, IsPitch a) => IsPitch (b, a) where fromPitch = pure . fromPitch++instance IsPitch Int where+ fromPitch x = fromIntegral (fromPitch x :: Integer)++instance IsPitch Word where+ fromPitch x = fromIntegral (fromPitch x :: Integer)++instance IsPitch Float where+ fromPitch x = realToFrac (fromPitch x :: Double)++instance HasResolution a => IsPitch (Fixed a) where+ fromPitch x = realToFrac (fromPitch x :: Double)++instance Integral a => IsPitch (Ratio a) where+ fromPitch x = realToFrac (fromPitch x :: Double) instance IsPitch Double where fromPitch (PitchL (pc, sem, oct)) = fromIntegral $ semitones sem + diatonic pc + oct * 12