music-score-1.7.1: Musical score and part representation.

Portabilitynon-portable (TF,GNTD)
Stabilityexperimental
Maintainerhans@hanshoglund.se
Safe HaskellNone

Music.Score.Pitch

Contents

Description

Provides functions for manipulating pitch.

Synopsis

Pitch type functions

type family Pitch s :: *Source

This type fuction is used to retrive the pitch type for a given concrete type.

For types representing pitch, it is generally Identity, i.e

 Pitch Integer ~ Integer
 Pitch Double ~ Double

and so on.

For containers, Pitch provides a morphism:

 Pitch (c,a)             ~ Pitch a
 Pitch [a]               ~ Pitch a
 Pitch (Note a)          ~ Pitch a
 Pitch (Delayed a)       ~ Pitch a
 Pitch (Stretched a)     ~ Pitch a
 Pitch (Voice a)         ~ Pitch a
 Pitch (Chord a)         ~ Pitch a
 Pitch (Track a)         ~ Pitch a
 Pitch (Score a)         ~ Pitch a

type family SetPitch b s :: *Source

This type fuction is used to retrive the pitch type for a given concrete type.

For types representing pitch, it is generally Constant, i.e

 SetPitch a Double ~ a
 SetPitch a Integer ~ a

For containers, Pitch provides a morphism:

 SetPitch b (c,a)          ~ (c, SetPitch b a)
 SetPitch b [a]            ~ [SetPitch b a]
 SetPitch g (Note a)       ~ Note (SetPitch g a)
 SetPitch g (Delayed a)    ~ Delayed (SetPitch g a)
 SetPitch g (Stretched a)  ~ Stretched (SetPitch g a)
 SetPitch g (Voice a)      ~ Voice (SetPitch g a)
 SetPitch g (Chord a)      ~ Chord (SetPitch g a)
 SetPitch g (Track a)      ~ Track (SetPitch g a)
 SetPitch g (Score a)      ~ Score (SetPitch g a)

type Interval a = Diff (Pitch a)Source

Associated interval type.

Accessing pitch

class (Transformable (Pitch s), Transformable (Pitch t), SetPitch (Pitch t) s ~ t) => HasPitches s t whereSource

Class of types that provide a pitch traversal.

Methods

pitches :: Traversal s t (Pitch s) (Pitch t)Source

Access all pitches.

As this is a Traversal, you can use all combinators from the lens package, for example:

   lengthOf pitches :: HasPitches a a => a -> Int
   toListOf pitches :: HasPitches' a => a -> Pitch a
   over pitches :: HasPitches a b => a -> b

Instances

(Transformable a, ~ * a (Pitch a)) => HasPitches Bool a 
(Transformable a, ~ * a (Pitch a)) => HasPitches Char a 
(Transformable a, ~ * a (Pitch a)) => HasPitches Double a 
(Transformable a, ~ * a (Pitch a)) => HasPitches Float a 
(Transformable a, ~ * a (Pitch a)) => HasPitches Int a 
(Transformable a, ~ * a (Pitch a)) => HasPitches Integer a 
(Transformable a, ~ * a (Pitch a)) => HasPitches Ordering a 
(Transformable a, ~ * a (Pitch a)) => HasPitches () a 
(Transformable a, Transformable b, ~ * b (Pitch b)) => HasPitches (Behavior a) b 
HasPitches a b => HasPitches [a] [b] 
HasPitches a b => HasPitches (Maybe a) (Maybe b) 
HasPitches a b => HasPitches (Sum a) (Sum b) 
HasPitches a b => HasPitches (Stretched a) (Stretched b) 
HasPitches a b => HasPitches (Voice a) (Voice b) 
HasPitches a b => HasPitches (Delayed a) (Delayed b) 
HasPitches a b => HasPitches (Chord a) (Chord b) 
HasPitches a b => HasPitches (Track a) (Track b) 
HasPitches a b => HasPitches (Note a) (Note b) 
HasPitches a b => HasPitches (Score a) (Score b) 
HasPitches a b => HasPitches (TieT a) (TieT b) 
HasPitches a b => HasPitches (SlideT a) (SlideT b) 
HasPitches a b => HasPitches (TremoloT a) (TremoloT b) 
HasPitches a b => HasPitches (TextT a) (TextT b) 
HasPitches a b => HasPitches (HarmonicT a) (HarmonicT b) 
HasPitches a b => HasPitches (ColorT a) (ColorT b) 
HasPitches a b => HasPitches (Either c a) (Either c b) 
HasPitches a b => HasPitches (c, a) (c, b) 
HasPitches a b => HasPitches (Couple c a) (Couple c b) 
HasPitches a b => HasPitches (PartT p a) (PartT p b) 
HasPitches a b => HasPitches (DynamicT p a) (DynamicT p b) 
HasPitches a b => HasPitches (ArticulationT p a) (ArticulationT p b) 

class HasPitches s t => HasPitch s t whereSource

Class of types that provide a single pitch.

Methods

pitch :: Lens s t (Pitch s) (Pitch t)Source

Access the pitch.

As this is a Traversal, you can use all combinators from the lens package, for example:

   view pitch :: HasPitch a a
   over pitch         :: HasPitch' a => a -> Pitch a
   pitch %~ succ      :: HasPitch' a => a -> a
   pitch +~ 2         :: (HasPitch' a, Num (Pitch a)) => a -> a
   pitch .~ c         :: (HasPitch' a, IsPitch a) => a -> a

Instances

(Transformable a, ~ * a (Pitch a)) => HasPitch Bool a 
(Transformable a, ~ * a (Pitch a)) => HasPitch Char a 
(Transformable a, ~ * a (Pitch a)) => HasPitch Double a 
(Transformable a, ~ * a (Pitch a)) => HasPitch Float a 
(Transformable a, ~ * a (Pitch a)) => HasPitch Int a 
(Transformable a, ~ * a (Pitch a)) => HasPitch Integer a 
(Transformable a, ~ * a (Pitch a)) => HasPitch Ordering a 
(Transformable a, ~ * a (Pitch a)) => HasPitch () a 
(Transformable a, Transformable b, ~ * b (Pitch b)) => HasPitch (Behavior a) b 
HasPitch a b => HasPitch (Stretched a) (Stretched b) 
HasPitch a b => HasPitch (Delayed a) (Delayed b) 
HasPitch a b => HasPitch (Note a) (Note b) 
HasPitch a b => HasPitch (TieT a) (TieT b) 
HasPitch a b => HasPitch (SlideT a) (SlideT b) 
HasPitch a b => HasPitch (TremoloT a) (TremoloT b) 
HasPitch a b => HasPitch (TextT a) (TextT b) 
HasPitch a b => HasPitch (HarmonicT a) (HarmonicT b) 
HasPitch a b => HasPitch (ColorT a) (ColorT b) 
HasPitch a b => HasPitch (c, a) (c, b) 
HasPitch a b => HasPitch (Couple c a) (Couple c b) 
HasPitch a b => HasPitch (PartT p a) (PartT p b) 
HasPitch a b => HasPitch (DynamicT p a) (DynamicT p b) 
HasPitch a b => HasPitch (ArticulationT p a) (ArticulationT p b) 

Simple versions

pitch' :: (HasPitch s t, s ~ t) => Lens' s (Pitch s)Source

Pitch type.

pitches' :: (HasPitches s t, s ~ t) => Traversal' s (Pitch s)Source

Pitch type.

Converting pitch to container

Manipulating pitch

type Transposable a = (HasPitches a a, VectorSpace (Interval a), AffineSpace (Pitch a), IsInterval (Interval a), IsPitch (Pitch a), Num (Scalar (Interval a)))Source

Class of types that can be transposed, inverted and so on.

up :: Transposable a => Interval a -> a -> aSource

Transpose up.

down :: Transposable a => Interval a -> a -> aSource

Transpose down.

above :: (Semigroup a, Transposable a) => Interval a -> a -> aSource

Add the given interval above.

below :: (Semigroup a, Transposable a) => Interval a -> a -> aSource

Add the given interval below.

inv :: Transposable a => Pitch a -> a -> aSource

Deprecated: Use invertPitches

invertPitches :: Transposable a => Pitch a -> a -> aSource

Invert pitches.

octavesUp :: Transposable a => Scalar (Interval a) -> a -> aSource

Transpose up by the given number of octaves.

octavesDown :: Transposable a => Scalar (Interval a) -> a -> aSource

Transpose down by the given number of octaves.

octavesAbove :: (Semigroup a, Transposable a) => Scalar (Interval a) -> a -> aSource

Add the given octave above.

octavesBelow :: (Semigroup a, Transposable a) => Scalar (Interval a) -> a -> aSource

Add the given octave below.

fifthsUp :: Transposable a => Scalar (Interval a) -> a -> aSource

Transpose up by the given number of fifths.

fifthsDown :: Transposable a => Scalar (Interval a) -> a -> aSource

Transpose down by the given number of fifths.

fifthsAbove :: (Semigroup a, Transposable a) => Scalar (Interval a) -> a -> aSource

Add the given octave above.

fifthsBelow :: (Semigroup a, Transposable a) => Scalar (Interval a) -> a -> aSource

Add the given octave below.

Utility

_15va :: Transposable a => a -> aSource

Shorthand for octavesUp 2.

_8va :: Transposable a => a -> aSource

Shorthand for octavesUp 1.

_8vb :: Transposable a => a -> aSource

Shorthand for octavesDown 1.

_15vb :: Transposable a => a -> aSource

Shorthand for octavesDown 2.

Inspecting pitch

highestPitch :: (HasPitches' a, Ord (Pitch a)) => a -> Pitch aSource

Return the highest pitch in the given music.

lowestPitch :: (HasPitches' a, Ord (Pitch a)) => a -> Pitch aSource

Return the lowest pitch in the given music.

meanPitch :: (HasPitches' a, Fractional (Pitch a)) => a -> Pitch aSource

Return the mean pitch in the given music.

Intervals