music-pitch 1.6 → 1.6.1
raw patch · 12 files changed
+252/−345 lines, 12 files
Files
- music-pitch.cabal +34/−38
- src/Music/Pitch.hs +1/−1
- src/Music/Pitch/Alterable.hs +0/−56
- src/Music/Pitch/Augmentable.hs +0/−52
- src/Music/Pitch/Common.hs +121/−117
- src/Music/Pitch/Common/Harmony.hs +7/−0
- src/Music/Pitch/Common/Interval.hs +45/−37
- src/Music/Pitch/Common/Pitch.hs +15/−23
- src/Music/Pitch/Common/Semitones.hs +5/−3
- src/Music/Pitch/Common/Spell.hs +18/−18
- src/Music/Pitch/Koizumi.hs +3/−0
- src/Music/Pitch/Tokawa.hs +3/−0
music-pitch.cabal view
@@ -1,15 +1,15 @@ -name: music-pitch-version: 1.6-cabal-version: >= 1.10-author: Hans Hoglund-maintainer: Hans Hoglund-license: BSD3-license-file: COPYING-synopsis: Abstract representation of musical pitch.-category: Music-tested-with: GHC-build-type: Simple+name: music-pitch+version: 1.6.1+cabal-version: >= 1.10+author: Hans Hoglund+maintainer: Hans Hoglund+license: BSD3+license-file: COPYING+synopsis: Abstract representation of musical pitch.+category: Music+tested-with: GHC+build-type: Simple description: This package provides various representations of musical pitch.@@ -23,32 +23,28 @@ <http://music-suite.github.io>. source-repository head- type: git- location: git://github.com/music-suite/music-pitch.git+ type: git+ location: git://github.com/music-suite/music-pitch.git library - build-depends: - base >= 4 && < 5,- time,- random,- containers,- semigroups,- semigroupoids,- music-pitch-literal == 1.6,- vector-space-- hs-source-dirs: src- default-language: Haskell2010- exposed-modules:- Music.Pitch- Music.Pitch.Absolute- Music.Pitch.Alterable- Music.Pitch.Augmentable- Music.Pitch.Common- Music.Pitch.Common.Interval- Music.Pitch.Common.Pitch- Music.Pitch.Common.Semitones- Music.Pitch.Common.Spell- Music.Pitch.Common.Harmony- Music.Pitch.Intonation- other-modules:+ build-depends: base >= 4 && < 5,+ time,+ random,+ containers,+ semigroups,+ semigroupoids,+ music-pitch-literal == 1.6,+ vector-space+ exposed-modules: Music.Pitch+ Music.Pitch.Absolute+ Music.Pitch.Common+ Music.Pitch.Common.Interval+ Music.Pitch.Common.Pitch+ Music.Pitch.Common.Semitones+ Music.Pitch.Common.Spell+ Music.Pitch.Common.Harmony+ Music.Pitch.Koizumi+ Music.Pitch.Tokawa+ Music.Pitch.Intonation+ hs-source-dirs: src+ default-language: Haskell2010
src/Music/Pitch.hs view
@@ -36,7 +36,7 @@ -- -- | Pitch and intervals, as defined in Common Music Theory (CMT). -- --- -- -- Includes representation of common practice pitches and intervalssuch as /c sharp/, + -- -- Includes representation of common practice pitches and intervals such as /c sharp/, -- -- /diminished second/ and so on. module Music.Pitch.Common,
− src/Music/Pitch/Alterable.hs
@@ -1,56 +0,0 @@--{-# LANGUAGE GeneralizedNewtypeDeriving, StandaloneDeriving #-}----------------------------------------------------------------------------------------- |--- Copyright : (c) Hans Hoglund 2012------ License : BSD-style------ Maintainer : hans@hanshoglund.se--- Stability : experimental--- Portability : non-portable (TF,GNTD)-------------------------------------------------------------------------------------------module Music.Pitch.Alterable (- -- * Alterable class- Alterable(..),- ) where--import Data.Ratio---- |--- Class of things that can be altered.------ > accidental (sharpen a) = sharpen (accidental a)--- > accidental (flatten a) = flatten (accidental a)--- > sharpen . flatten = id----class Alterable a where- -- | - -- Increase the given pitch by one.- -- - sharpen :: a -> a-- -- | - -- Decrease the given pitch by one.- -- - flatten :: a -> a---instance Alterable a => Alterable (b -> a) where- sharpen = fmap sharpen- flatten = fmap flatten--instance Alterable Double where- sharpen = (+ 1)- flatten = (subtract 1)--instance Alterable Integer where- sharpen = (+ 1)- flatten = (subtract 1)--instance Integral a => Alterable (Ratio a) where- sharpen = (+ 1)- flatten = (subtract 1)
− src/Music/Pitch/Augmentable.hs
@@ -1,52 +0,0 @@--{-# LANGUAGE GeneralizedNewtypeDeriving, StandaloneDeriving #-}----------------------------------------------------------------------------------------- |--- Copyright : (c) Hans Hoglund 2012------ License : BSD-style------ Maintainer : hans@hanshoglund.se--- Stability : experimental--- Portability : non-portable (TF,GNTD)-------------------------------------------------------------------------------------------module Music.Pitch.Augmentable (- -- * Augmentable class- Augmentable(..),- ) where--import Data.Ratio---- |--- Class of types that can be augmented.------ > quality (augment a) = augment (quality a)--- > quality (diminish a) = diminish (quality a)--- > augment . diminish = id----class Augmentable a where-- -- | - -- Increase the size of this interval by one.- --- augment :: a -> a-- -- | - -- Decrease the size of this interval by one.- --- diminish :: a -> a--instance Augmentable Double where- augment = (+ 1)- diminish = (subtract 1)--instance Augmentable Integer where- augment = (+ 1)- diminish = (subtract 1)--instance Integral a => Augmentable (Ratio a) where- augment = (+ 1)- diminish = (subtract 1)
src/Music/Pitch/Common.hs view
@@ -14,126 +14,130 @@ ------------------------------------------------------------------------------------- module Music.Pitch.Common (- -- * Enharmonic representation- -- ** Octaves- Octaves,- HasOctaves(..),-- -- ** Steps- Steps,- HasSteps(..),-- -- ** Semitones- Semitones,- HasSemitones(..),- semitone,- tone,- ditone,- tritone,- isSemitone,- isTone,- isTritone,- - -- ** Enharmonic equivalence- (=:=),- (/:=),-- -- * Pitches- -- ** Name type- Name(..),-- -- ** Accidental type- Accidental,- doubleFlat, - flat, - natural, - sharp, - doubleSharp,-- -- *** Inspecting accidentals- isNatural,- isSharpened,- isFlattened,- isStandard,-- -- ** Pitch type- Pitch, - pitch,- name,- accidental,- asPitch,-- -- module Music.Pitch.Common.Name,- -- module Music.Pitch.Common.Accidental,- -- module Music.Pitch.Common.Pitch,-- -- * Intervals- -- ** Number type- Number,- HasNumber(..), - unison,- prime,- second,- third,- fourth,- fifth,- sixth,- seventh,- octave,- ninth,- tenth,- twelfth, - duodecim,- thirteenth,- fourteenth,- fifteenth,-- -- ** Quality type- Quality(..), - HasQuality(..),- invertQuality,- isPerfect,- isMajor,- isMinor,- isAugmented,- isDiminished,-- -- ** Interval type- Interval,-- -- *** Creating intervals- interval,- perfect,- major,- minor,- augmented,- diminished,- doublyAugmented,- doublyDiminished,- asInterval,-- -- *** Inspecting intervals- isNegative,- isPositive,- isNonNegative,- isPerfectUnison,- isStep,- isLeap,-- -- *** Simple and compound intervals- isSimple,- isCompound,- separate,- simple,+ -- -- * Enharmonic representation+ -- -- ** Octaves+ -- Octaves,+ -- -- HasOctaves(..),+ -- + -- -- ** Steps+ -- -- Steps,+ -- -- HasSteps(..),+ -- + -- -- ** Semitones+ -- Semitones,+ -- HasSemitones(..),+ -- semitone,+ -- tone,+ -- ditone,+ -- tritone,+ -- isSemitone,+ -- isTone,+ -- isTritone,+ -- + -- -- ** Enharmonic equivalence+ -- (=:=),+ -- (/:=),+ -- + -- -- * Pitches+ -- -- ** Name type+ -- Name(..),+ -- + -- -- ** Accidental type+ -- Accidental,+ -- doubleFlat, + -- flat, + -- natural, + -- sharp, + -- doubleSharp,+ -- + -- -- *** Inspecting accidentals+ -- isNatural,+ -- isSharpened,+ -- isFlattened,+ -- isStandard,+ -- + -- -- ** Pitch type+ -- Pitch, + -- pitch,+ -- name,+ -- accidental,+ -- asPitch,+ -- + -- -- module Music.Pitch.Common.Name,+ -- -- module Music.Pitch.Common.Accidental,+ -- -- module Music.Pitch.Common.Pitch,+ -- + -- -- * Intervals+ -- -- ** Number type+ -- Number,+ -- HasNumber(..), + -- unison,+ -- prime,+ -- second,+ -- third,+ -- fourth,+ -- fifth,+ -- sixth,+ -- seventh,+ -- octave,+ -- ninth,+ -- tenth,+ -- twelfth, + -- duodecim,+ -- thirteenth,+ -- fourteenth,+ -- fifteenth,+ -- + -- -- ** Quality type+ -- Quality(..), + -- HasQuality(..),+ -- invertQuality,+ -- isPerfect,+ -- isMajor,+ -- isMinor,+ -- isAugmented,+ -- isDiminished,+ -- + -- -- ** Interval type+ -- Interval,+ -- + -- -- *** Creating intervals+ -- interval,+ -- perfect,+ -- major,+ -- minor,+ -- augmented,+ -- diminished,+ -- doublyAugmented,+ -- doublyDiminished,+ -- asInterval,+ -- + -- -- *** Inspecting intervals+ -- isNegative,+ -- isPositive,+ -- isNonNegative,+ -- isPerfectUnison,+ -- isStep,+ -- isLeap,+ -- + -- -- *** Simple and compound intervals+ -- isSimple,+ -- isCompound,+ -- separate,+ -- octaves,+ -- simple,+ -- + -- -- *** Inversion+ -- invert, - -- *** Inversion- invert,+ -- * Enharmonic representation+ module Music.Pitch.Common.Semitones, - -- module Music.Pitch.Common.Number,- -- module Music.Pitch.Common.Quality,- -- module Music.Pitch.Common.Interval,+ -- * Non-enharmonic representation+ module Music.Pitch.Common.Interval,+ module Music.Pitch.Common.Pitch, - -- * Miscellaneous+ -- * Utility module Music.Pitch.Common.Spell, module Music.Pitch.Common.Harmony, )
src/Music/Pitch/Common/Harmony.hs view
@@ -15,6 +15,13 @@ import Data.Set (Set) import qualified Data.Set as Set +{-+ TODO+ Generalize simple like this:+ > (number (asInterval (m9))-(fromIntegral $ signum (m9))) `mod` 7+ +-}+ -- | Whether the given interval is a (harmonic) dissonance. isDissonance :: Interval -> Bool isDissonance x = case number (simple x) of
src/Music/Pitch/Common/Interval.hs view
@@ -51,7 +51,7 @@ Interval, -- *** Creating intervals- interval,+ mkInterval, perfect, major, minor,@@ -61,6 +61,7 @@ doublyDiminished, -- *** Inspecting intervals+ octaves, isNegative, isPositive, isNonNegative,@@ -80,7 +81,7 @@ -- * Utility asInterval, intervalDiff,- interval',+ mkInterval', ) where import Data.Maybe@@ -244,73 +245,73 @@ instance Show Number where { show = show . getNumber } instance HasNumber Number where number = id -unison :: Number-prime :: Number-second :: Number-third :: Number-fourth :: Number-fifth :: Number-sixth :: Number-seventh :: Number-octave :: Number-ninth :: Number-tenth :: Number-eleventh :: Number-twelfth :: Number-duodecim :: Number-thirteenth :: Number-fourteenth :: Number-fifteenth :: Number -- | A synonym for @1@.+unison :: Number unison = 1 -- | A synonym for @2@.+prime :: Number prime = 1 -- | A synonym for @3@.+second :: Number second = 2 -- | A synonym for @4@.+third :: Number third = 3 -- | A synonym for @5@.+fourth :: Number fourth = 4 -- | A synonym for @6@.+fifth :: Number fifth = 5 -- | A synonym for @7@.+sixth :: Number sixth = 6 -- | A synonym for @8@.+seventh :: Number seventh = 7 -- | A synonym for @9@.+octave :: Number octave = 8 -- | A synonym for @10@.+ninth :: Number ninth = 9 -- | A synonym for @11@.+tenth :: Number tenth = 10 -- | A synonym for @12@.+eleventh :: Number eleventh = 11 -- | A synonym for @13@.+twelfth :: Number twelfth = 12 -- | A synonym for @14@.+duodecim :: Number duodecim = 12 -- | A synonym for @15@.+thirteenth :: Number thirteenth = 13 -- | A synonym for @16@.+fourteenth :: Number fourteenth = 14 -- | A synonym for @17@.+fifteenth :: Number fifteenth = 15 class HasNumber a where@@ -430,15 +431,16 @@ augment (Interval (o, d, c)) = Interval (o, d, c + 1) diminish (Interval (o, d, c)) = Interval (o, d, c - 1) -instance HasOctaves Interval where- octaves = fst . separate+-- |+-- Returns the non-simple part of an interval.+--+-- > (perfect octave)^*x + y = z iff y = simple z+--+octaves = fst . separate instance HasSemitones Interval where semitones (Interval (o, d, c)) = fromIntegral $ o * 12 + c -instance HasSteps Interval where- steps a = fromIntegral $ semitones a `mod` 12- instance IsInterval Interval where fromInterval (IntervalL (o,d,c)) = Interval (fromIntegral o, fromIntegral d, fromIntegral c) @@ -455,40 +457,46 @@ -- major interval instead. Given 'Major' or 'Minor' with a number indicating a perfect -- consonance, 'interval' returns a perfect or diminished interval respectively. ---interval :: Quality -> Number -> Interval-interval quality number = interval' (qualityToDiff (isPerfectNumber diatonic) quality) (fromIntegral number)+mkInterval :: Quality -> Number -> Interval+mkInterval quality number = mkInterval' (qualityToDiff (isPerfectNumber diatonic) quality) (fromIntegral number) where (_, diatonic) = (fromIntegral $ number - 1) `divMod` 7 -interval' :: Int -> Int -> Interval-interval' diff number = Interval (octave, diatonic, diatonicToChromatic diatonic + diff)+mkInterval' :: Int -> Int -> Interval+mkInterval' diff number = Interval (octave, diatonic, diatonicToChromatic diatonic + diff) where (octave, diatonic) = (number - 1) `divMod` 7 - -- | Creates a perfect interval. -- If given an inperfect number, constructs a major interval.-perfect = interval Perfect+perfect :: Number -> Interval+perfect = mkInterval Perfect -- | Creates a major interval. -- If given a perfect number, constructs a perfect interval.-major = interval Major+major :: Number -> Interval+major = mkInterval Major -- | Creates a minor interval. -- If given a perfect number, constructs a diminished interval.-minor = interval Minor+minor :: Number -> Interval+minor = mkInterval Minor -- | Creates an augmented interval.-augmented = interval (Augmented 1)+augmented :: Number -> Interval+augmented = mkInterval (Augmented 1) -- | Creates a diminished interval.-diminished = interval (Diminished 1)+diminished :: Number -> Interval+diminished = mkInterval (Diminished 1) -- | Creates a doubly augmented interval.-doublyAugmented = interval (Augmented 2)+doublyAugmented :: Number -> Interval+doublyAugmented = mkInterval (Augmented 2) -- | Creates a doubly diminished interval.-doublyDiminished = interval (Diminished 2)+doublyDiminished :: Number -> Interval+doublyDiminished = mkInterval (Diminished 2) invertDiatonic :: Num a => a -> a@@ -631,6 +639,6 @@ go 6 = 11 {-# DEPRECATED intervalDiff "This should be hidden" #-}-{-# DEPRECATED interval' "This should be hidden "#-}+{-# DEPRECATED mkInterval' "This should be hidden "#-} replicate' n = replicate (fromIntegral n)
src/Music/Pitch/Common/Pitch.hs view
@@ -19,16 +19,16 @@ module Music.Pitch.Common.Pitch ( -- * Accidentals Accidental,- doubleFlat, - flat, natural, + flat, sharp, + doubleFlat, doubleSharp, -- ** Inspecting accidentals isNatural,- isSharpened, isFlattened,+ isSharpened, isStandard, -- ** Name@@ -36,11 +36,10 @@ -- * Pitch Pitch, - pitch,+ mkPitch, name, accidental,- asPitch,- middleC,+ asPitch ) where import Data.Maybe@@ -65,7 +64,7 @@ -- An accidental is either flat, natural or sharp. -- -- This representation allows for an arbitrary number of flats or sharps rather than just--- single (the ♯ and ♭ symbols) and double (i.e. the /x/ and ♭♭ symbols).+-- single and double. -- -- The 'Num' and 'Enum' instances treat 'Accidental' as the number of altered semitones, -- i.e. a double flat is @-2@, natural @0@ and so on.@@ -88,11 +87,11 @@ -- | -- Magic instance that allow us to write @c sharp@ instead of @sharpen c@.--- Requires @FlexibleInstances@. -- instance (IsPitch a, Alterable a) => IsPitch (Accidental -> a) where fromPitch l 1 = sharpen (fromPitch l) fromPitch l (-1) = flatten (fromPitch l)+-- Requires FlexibleInstances sharp, flat, natural, doubleFlat, doubleSharp :: Accidental @@ -124,7 +123,7 @@ -- | Returns whether this is a standard accidental, i.e.--- either a double flat, flat, natural, sharp or doubl sharp.+-- either a double flat, flat, natural, sharp or double sharp. isStandard :: Accidental -> Bool isStandard a = abs a < 2 @@ -222,8 +221,8 @@ -- | -- Creates a pitch from name accidental. ---pitch :: Name -> Accidental -> Pitch-pitch name acc = Pitch $ interval' (fromIntegral acc) (fromEnum name + 1)+mkPitch :: Name -> Accidental -> Pitch+mkPitch name acc = Pitch $ mkInterval' (fromIntegral acc) (fromEnum name + 1) -- | -- Returns the name of a pitch.@@ -231,7 +230,9 @@ -- To convert a pitch to a numeric type, use 'octaves', 'steps' or 'semitones' -- on the relevant interval type, for example: ----- @ semitones (a' .-. 'middleC') @+-- @+-- semitones ('a\'' .-. 'c')+-- @ -- name :: Pitch -> Name name = toEnum . fromIntegral . pred . number . simple . getPitch@@ -244,15 +245,6 @@ accidental :: Pitch -> Accidental accidental = fromIntegral . intervalDiff . simple . getPitch --- instance HasOctaves Pitch where--- octaves = octaves . getPitch--- --- instance HasSemitones Pitch where--- semitones = semitones . getPitch--- --- instance HasSteps Pitch where--- steps = steps . getPitch- -- | The same as 'c', but fixed to 'Pitch'. This is useful if you want -- to treat 'Pitch' as an affine space around middle C, that is /C4/ in Scientific Pitch Notation. middleC :: Pitch@@ -260,9 +252,9 @@ instance IsPitch Pitch where fromPitch (PitchL (c, a, o)) =- Pitch $ interval' (qual a) (c + 1)+ Pitch $ mkInterval' (qual a) (c + 1) ^+^- (perfect octave^* fromIntegral (o - 4))+ (perfect octave^* fromIntegral o) where qual Nothing = 0 qual (Just n) = round n
src/Music/Pitch/Common/Semitones.hs view
@@ -19,11 +19,11 @@ -- * Types -- ** Octaves Octaves,- HasOctaves(..),+ -- HasOctaves(..), -- ** Steps Steps,- HasSteps(..),+ -- HasSteps(..), -- ** Semitones Semitones,@@ -84,8 +84,9 @@ deriving (Eq, Ord, Num, Enum, Real, Integral) instance Show Steps where { show = show . getSteps }-instance HasSteps Steps where { steps = id }+-- instance HasSteps Steps where { steps = id } +{- -- | -- Class of intervals that has a number of 'Steps'. --@@ -100,6 +101,7 @@ -- > octaves (-m7) = -1 -- steps :: a -> Steps+-}
src/Music/Pitch/Common/Spell.hs view
@@ -23,12 +23,12 @@ -- * Spelling type Spelling, spell,- spelledWith,+ spelled, -- ** Standard spellings- modal,- sharps,- flats,+ modally,+ usingSharps,+ usingFlats, ) where import Data.VectorSpace@@ -69,9 +69,9 @@ -- -- Examples: ----- > spell sharps tritone == _A4--- > spell flats tritone == d5--- > spell modal tone == _M2+-- > spell usingSharps tritone == _A4+-- > spell usingFlats tritone == d5+-- > spell modally tone == _M2 -- type Spelling = Semitones -> Number @@ -85,7 +85,7 @@ (octaves, steps) = semitones x `divMod` 12 num = fromIntegral (spelling steps) diff = fromIntegral steps - fromIntegral (diatonicToChromatic num)- in interval' diff (num + 1) ^+^ _P8^*(fromIntegral octaves)+ in mkInterval' diff (num + 1) ^+^ _P8^*(fromIntegral octaves) where diatonicToChromatic = go where@@ -100,21 +100,21 @@ -- | -- Flipped version of 'spell'. To be used infix, as in: ----- > d5 `spelledWith` sharps+-- > d5 `spelled` usingSharps -- -spelledWith :: HasSemitones a => a -> Spelling -> Interval-spelledWith = flip spell+spelled :: HasSemitones a => a -> Spelling -> Interval+spelled = flip spell -- | -- Spell using the most the most common accidentals. Double sharps and flats are not -- preserved. ----- This spelling is particularly useful for modal music with C or F as tonic.+-- This spelling is particularly useful for modal music where the tonic is C. -- -- > c cs d eb e f fs g gs a bb b ---modal :: Spelling-modal = go+modally :: Spelling+modally = go where go 0 = 0 go 1 = 0@@ -134,8 +134,8 @@ -- -- > c cs d ds e f fs g gs a as b ---sharps :: Spelling-sharps = go+usingSharps :: Spelling+usingSharps = go where go 0 = 0 go 1 = 0@@ -155,8 +155,8 @@ -- -- > c db d eb e f gb g ab a bb b ---flats :: Spelling-flats = go+usingFlats :: Spelling+usingFlats = go where go 0 = 0 go 1 = 1
+ src/Music/Pitch/Koizumi.hs view
@@ -0,0 +1,3 @@++module Music.Pitch.Koizumi where+
+ src/Music/Pitch/Tokawa.hs view
@@ -0,0 +1,3 @@++module Music.Pitch.Tokawa where+