mezzo-0.2.0.0: Typesafe music composition

Copyright(c) Dima Szamozvancev
LicenseMIT
Maintainerds709@cam.ac.uk
Stabilityexperimental
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

Mezzo.Model.Types

Contents

Description

Types modeling basic musical constructs at the type level.

Synopsis

Note properties

data PitchClass Source #

The diatonic pitch class of the note.

Constructors

C 
D 
E 
F 
G 
A 
B 

Instances

Primitive PitchClass C Source # 

Associated Types

type Rep C (a :: C) :: * Source #

Methods

prim :: sing a -> Rep C a Source #

pretty :: sing a -> String Source #

Primitive PitchClass D Source # 

Associated Types

type Rep D (a :: D) :: * Source #

Methods

prim :: sing a -> Rep D a Source #

pretty :: sing a -> String Source #

Primitive PitchClass E Source # 

Associated Types

type Rep E (a :: E) :: * Source #

Methods

prim :: sing a -> Rep E a Source #

pretty :: sing a -> String Source #

Primitive PitchClass F Source # 

Associated Types

type Rep F (a :: F) :: * Source #

Methods

prim :: sing a -> Rep F a Source #

pretty :: sing a -> String Source #

Primitive PitchClass G Source # 

Associated Types

type Rep G (a :: G) :: * Source #

Methods

prim :: sing a -> Rep G a Source #

pretty :: sing a -> String Source #

Primitive PitchClass A Source # 

Associated Types

type Rep A (a :: A) :: * Source #

Methods

prim :: sing a -> Rep A a Source #

pretty :: sing a -> String Source #

Primitive PitchClass B Source # 

Associated Types

type Rep B (a :: B) :: * Source #

Methods

prim :: sing a -> Rep B a Source #

pretty :: sing a -> String Source #

type Rep PitchClass C Source # 
type Rep PitchClass D Source # 
type Rep PitchClass E Source # 
type Rep PitchClass F Source # 
type Rep PitchClass G Source # 
type Rep PitchClass A Source # 
type Rep PitchClass B Source # 

data Accidental Source #

The accidental applied to a note.

Constructors

Natural 
Flat 
Sharp 

Instances

Primitive Accidental Natural Source # 

Associated Types

type Rep Natural (a :: Natural) :: * Source #

Methods

prim :: sing a -> Rep Natural a Source #

pretty :: sing a -> String Source #

Primitive Accidental Flat Source # 

Associated Types

type Rep Flat (a :: Flat) :: * Source #

Methods

prim :: sing a -> Rep Flat a Source #

pretty :: sing a -> String Source #

Primitive Accidental Sharp Source # 

Associated Types

type Rep Sharp (a :: Sharp) :: * Source #

Methods

prim :: sing a -> Rep Sharp a Source #

pretty :: sing a -> String Source #

type Rep Accidental Natural Source # 
type Rep Accidental Flat Source # 
type Rep Accidental Sharp Source # 

data OctaveNum Source #

The octave where the note resides (middle C is Oct4).

Constructors

Oct_1 
Oct0 
Oct1 
Oct2 
Oct3 
Oct4 
Oct5 
Oct6 
Oct7 
Oct8 

Instances

Primitive OctaveNum Oct_1 Source # 

Associated Types

type Rep Oct_1 (a :: Oct_1) :: * Source #

Methods

prim :: sing a -> Rep Oct_1 a Source #

pretty :: sing a -> String Source #

Primitive OctaveNum Oct0 Source # 

Associated Types

type Rep Oct0 (a :: Oct0) :: * Source #

Methods

prim :: sing a -> Rep Oct0 a Source #

pretty :: sing a -> String Source #

Primitive OctaveNum Oct1 Source # 

Associated Types

type Rep Oct1 (a :: Oct1) :: * Source #

Methods

prim :: sing a -> Rep Oct1 a Source #

pretty :: sing a -> String Source #

Primitive OctaveNum Oct2 Source # 

Associated Types

type Rep Oct2 (a :: Oct2) :: * Source #

Methods

prim :: sing a -> Rep Oct2 a Source #

pretty :: sing a -> String Source #

Primitive OctaveNum Oct3 Source # 

Associated Types

type Rep Oct3 (a :: Oct3) :: * Source #

Methods

prim :: sing a -> Rep Oct3 a Source #

pretty :: sing a -> String Source #

Primitive OctaveNum Oct4 Source # 

Associated Types

type Rep Oct4 (a :: Oct4) :: * Source #

Methods

prim :: sing a -> Rep Oct4 a Source #

pretty :: sing a -> String Source #

Primitive OctaveNum Oct5 Source # 

Associated Types

type Rep Oct5 (a :: Oct5) :: * Source #

Methods

prim :: sing a -> Rep Oct5 a Source #

pretty :: sing a -> String Source #

Primitive OctaveNum Oct6 Source # 

Associated Types

type Rep Oct6 (a :: Oct6) :: * Source #

Methods

prim :: sing a -> Rep Oct6 a Source #

pretty :: sing a -> String Source #

Primitive OctaveNum Oct7 Source # 

Associated Types

type Rep Oct7 (a :: Oct7) :: * Source #

Methods

prim :: sing a -> Rep Oct7 a Source #

pretty :: sing a -> String Source #

Primitive OctaveNum Oct8 Source # 

Associated Types

type Rep Oct8 (a :: Oct8) :: * Source #

Methods

prim :: sing a -> Rep Oct8 a Source #

pretty :: sing a -> String Source #

type Rep OctaveNum Oct_1 Source # 
type Rep OctaveNum Oct0 Source # 
type Rep OctaveNum Oct1 Source # 
type Rep OctaveNum Oct2 Source # 
type Rep OctaveNum Oct3 Source # 
type Rep OctaveNum Oct4 Source # 
type Rep OctaveNum Oct5 Source # 
type Rep OctaveNum Oct6 Source # 
type Rep OctaveNum Oct7 Source # 
type Rep OctaveNum Oct8 Source # 

type Duration = Nat Source #

The duration of the note (a whole note has duration 32).

Singleton types for note properties

data PC pc where Source #

The singleton type for PitchClass.

Constructors

PC :: Primitive pc => PC pc 

data Acc acc where Source #

The singleton type for Accidental.

Constructors

Acc :: Primitive acc => Acc acc 

data Oct oct where Source #

The singleton type for Octave.

Constructors

Oct :: Primitive oct => Oct oct 

data Dur dur where Source #

The singleton type for Duration.

Constructors

Dur :: Primitive dur => Dur dur 

Pitches

data PitchType where Source #

The type of pitches.

Constructors

Pitch :: PitchClass -> Accidental -> OctaveNum -> PitchType

A pitch made up of a pitch class, an accidental and an octave.

Silence :: PitchType

Silence, the pitch of rests.

Instances

Primitive PitchType Silence Source # 

Associated Types

type Rep Silence (a :: Silence) :: * Source #

Methods

prim :: sing a -> Rep Silence a Source #

pretty :: sing a -> String Source #

(IntRep PitchClass pc, IntRep Accidental acc, IntRep OctaveNum oct) => Primitive PitchType (Pitch pc acc oct) Source # 

Associated Types

type Rep (Pitch pc acc oct) (a :: Pitch pc acc oct) :: * Source #

Methods

prim :: sing a -> Rep (Pitch pc acc oct) a Source #

pretty :: sing a -> String Source #

type Rep PitchType Silence Source # 
type Rep PitchType (Pitch pc acc oct) Source # 
type Rep PitchType (Pitch pc acc oct) = Int

data Pit p where Source #

The singleton type for pitches.

Constructors

Pit :: Primitive p => Pit p 

type family (p :: PitchType) =?= (q :: PitchType) :: Bool where ... Source #

Enharmonic equality of pitches.

Equations

Silence =?= Silence = True 
Silence =?= _ = False 
_ =?= Silence = False 
(Pitch pc acc oct) =?= (Pitch pc acc oct) = True 
(Pitch C Flat o1) =?= (Pitch B Natural o2) = o1 .~. OctSucc o2 
(Pitch C Natural o1) =?= (Pitch B Sharp o2) = o1 .~. OctSucc o2 
(Pitch E Natural oct) =?= (Pitch F Flat oct) = True 
(Pitch E Sharp oct) =?= (Pitch F Natural oct) = True 
(Pitch F Flat oct) =?= (Pitch E Natural oct) = True 
(Pitch F Natural oct) =?= (Pitch E Sharp oct) = True 
(Pitch B Natural o1) =?= (Pitch C Flat o2) = OctSucc o1 .~. o2 
(Pitch B Sharp o1) =?= (Pitch C Natural o2) = OctSucc o1 .~. o2 
(Pitch pc1 Sharp oct) =?= (Pitch pc2 Flat oct) = ClassSucc pc1 .~. pc2 
(Pitch pc1 Flat oct) =?= (Pitch pc2 Sharp oct) = pc1 .~. ClassSucc pc2 
_ =?= _ = False 

type family (p1 :: PitchType) <<=? (p2 :: PitchType) where ... infixl 3 Source #

Greater than or equal to for pitches.

Equations

p1 <<=? p2 = PitchToNat p1 <=? PitchToNat p2 

type family (p1 :: PitchType) <<? (p2 :: PitchType) where ... infixl 3 Source #

Greater than for pitches.

Equations

p1 <<? p2 = (p1 <<=? p2) .&&. Not (p1 .~. p2) 

Harmonic types

data Mode Source #

The mode of a key: major or minor.

Constructors

MajorMode 
MinorMode 

Instances

Primitive Mode MajorMode Source # 

Associated Types

type Rep MajorMode (a :: MajorMode) :: * Source #

Methods

prim :: sing a -> Rep MajorMode a Source #

pretty :: sing a -> String Source #

Primitive Mode MinorMode Source # 

Associated Types

type Rep MinorMode (a :: MinorMode) :: * Source #

Methods

prim :: sing a -> Rep MinorMode a Source #

pretty :: sing a -> String Source #

type Rep Mode MajorMode Source # 
type Rep Mode MinorMode Source # 

data ScaleDegree Source #

The seven scale degrees.

Constructors

I 
II 
III 
IV 
V 
VI 
VII 

Instances

Primitive ScaleDegree I Source # 

Associated Types

type Rep I (a :: I) :: * Source #

Methods

prim :: sing a -> Rep I a Source #

pretty :: sing a -> String Source #

Primitive ScaleDegree II Source # 

Associated Types

type Rep II (a :: II) :: * Source #

Methods

prim :: sing a -> Rep II a Source #

pretty :: sing a -> String Source #

Primitive ScaleDegree III Source # 

Associated Types

type Rep III (a :: III) :: * Source #

Methods

prim :: sing a -> Rep III a Source #

pretty :: sing a -> String Source #

Primitive ScaleDegree IV Source # 

Associated Types

type Rep IV (a :: IV) :: * Source #

Methods

prim :: sing a -> Rep IV a Source #

pretty :: sing a -> String Source #

Primitive ScaleDegree V Source # 

Associated Types

type Rep V (a :: V) :: * Source #

Methods

prim :: sing a -> Rep V a Source #

pretty :: sing a -> String Source #

Primitive ScaleDegree VI Source # 

Associated Types

type Rep VI (a :: VI) :: * Source #

Methods

prim :: sing a -> Rep VI a Source #

pretty :: sing a -> String Source #

Primitive ScaleDegree VII Source # 

Associated Types

type Rep VII (a :: VII) :: * Source #

Methods

prim :: sing a -> Rep VII a Source #

pretty :: sing a -> String Source #

type Rep ScaleDegree I Source # 
type Rep ScaleDegree II Source # 
type Rep ScaleDegree III Source # 
type Rep ScaleDegree IV Source # 
type Rep ScaleDegree V Source # 
type Rep ScaleDegree VI Source # 
type Rep ScaleDegree VII Source # 

data KeyType Source #

The of a scale, chord or piece.

Instances

(IntRep PitchClass pc, IntRep Accidental acc, IntRep Mode mo) => Primitive KeyType (Key pc acc mo) Source # 

Associated Types

type Rep (Key pc acc mo) (a :: Key pc acc mo) :: * Source #

Methods

prim :: sing a -> Rep (Key pc acc mo) a Source #

pretty :: sing a -> String Source #

type Rep KeyType (Key pc acc mo) Source # 
type Rep KeyType (Key pc acc mo) = Int

data RootType where Source #

The root of a chord.

Constructors

PitchRoot :: PitchType -> RootType

A pitch constructs a diatonic root.

DegreeRoot :: KeyType -> ScaleDegree -> RootType

A key and a scale degree constructs a scalar root.

Instances

IntRep PitchType p => Primitive RootType (PitchRoot p) Source # 

Associated Types

type Rep (PitchRoot p) (a :: PitchRoot p) :: * Source #

Methods

prim :: sing a -> Rep (PitchRoot p) a Source #

pretty :: sing a -> String Source #

type Rep RootType (PitchRoot p) Source # 

data Mod m Source #

The singleton type for Mode.

Constructors

Mod 

data ScaDeg sd Source #

The singleton type for ScaleDegree

Constructors

ScaDeg 

data KeyS k Source #

The singleton type for KeyType.

Constructors

KeyS 

data Root r where Source #

The singleton type for Root.

Constructors

Root :: Primitive r => Root r 

Instances

IntRep PitchType p => Primitive * (Root (PitchRoot p)) Source # 

Associated Types

type Rep (Root (PitchRoot p)) (a :: Root (PitchRoot p)) :: * Source #

Methods

prim :: sing a -> Rep (Root (PitchRoot p)) a Source #

pretty :: sing a -> String Source #

(IntRep PitchType p, (~) PitchType (RootToPitch (DegreeRoot k sd)) p, Primitive ScaleDegree sd) => Primitive * (Root (DegreeRoot k sd)) Source # 

Associated Types

type Rep (Root (DegreeRoot k sd)) (a :: Root (DegreeRoot k sd)) :: * Source #

Methods

prim :: sing a -> Rep (Root (DegreeRoot k sd)) a Source #

pretty :: sing a -> String Source #

type Rep * (Root (PitchRoot p)) Source # 
type Rep * (Root (PitchRoot p)) = Int
type Rep * (Root (DegreeRoot k sd)) Source # 
type Rep * (Root (DegreeRoot k sd)) = Int

type family RootToPitch (dr :: RootType) :: PitchType where ... Source #

Convert a root to a pitch.

Note: the default octave for scalar roots is Oct2.

Equations

RootToPitch (PitchRoot p) = p 
RootToPitch (DegreeRoot (Key pc acc m) d) = HalfStepsUpBy (Pitch pc acc Oct2) (DegreeOffset m d) 

type family PitchToNat (p :: PitchType) :: Nat where ... Source #

Convert a pitch to a natural number (equal to its MIDI code).

Equations

PitchToNat Silence = TypeError (Text "Can't convert a rest to a number.") 
PitchToNat (Pitch C Natural Oct_1) = 0 
PitchToNat (Pitch C Sharp Oct_1) = 1 
PitchToNat (Pitch D Flat Oct_1) = 1 
PitchToNat (Pitch C Natural Oct1) = 24 
PitchToNat (Pitch C Natural Oct2) = 36 
PitchToNat (Pitch C Natural Oct3) = 48 
PitchToNat (Pitch C Natural Oct4) = 60 
PitchToNat (Pitch C Natural Oct5) = 72 
PitchToNat (Pitch C Natural Oct6) = 84 
PitchToNat p = 1 + PitchToNat (HalfStepDown p) 

type family Sharpen (r :: RootType) :: RootType where ... Source #

Sharpen a root.

Equations

Sharpen r = PitchRoot (HalfStepUp (RootToPitch r)) 

type family Flatten (r :: RootType) :: RootType where ... Source #

Flatten a root.

Equations

Flatten r = PitchRoot (HalfStepDown (RootToPitch r)) 

type family Dot (d :: Duration) :: Duration where ... Source #

Form a dotted duration.

Equations

Dot 1 = TypeError (Text "Can't have dotted thirty-seconds.") 
Dot n = n + HalfOf n 

type family FromRoot (r :: RootType) (d :: Nat) :: Partiture 1 d where ... Source #

Create a new partiture with one voice of the given pitch.

Equations

FromRoot r d = (RootToPitch r +*+ d) :-- None 

type family FromSilence (d :: Nat) :: Partiture 1 d where ... Source #

Create a new partiture with one voice of silence.

Equations

FromSilence d = (Silence +*+ d) :-- None 

Specialised musical vector types

type Voice l = OptVector PitchType l Source #

A Voice is made up of a sequence of pitch repetitions.

type Partiture n l = Matrix PitchType n l Source #

A Partiture is made up of a fixed number of voices.

Intervals

data IntervalSize Source #

The size of the interval.

data IntervalClass Source #

The class of the interval.

Constructors

Maj 
Perf 
Min 
Aug 
Dim 

data IntervalType where Source #

The type of intervals.

Constructors

Interval :: IntervalClass -> IntervalSize -> IntervalType

An interval smaller than 13 semitones, where musical rules can still be enforced.

Compound :: IntervalType

An interval larger than 13 semitones, which is large enough so that dissonance effects are not significant.

type family MakeInterval (p1 :: PitchType) (p2 :: PitchType) :: IntervalType where ... Source #

Make an interval from two arbitrary pitches.

Equations

MakeInterval Silence Silence = TypeError (Text "Can't make intervals from rests.") 
MakeInterval Silence p2 = TypeError (Text "Can't make intervals from rests.") 
MakeInterval p1 Silence = TypeError (Text "Can't make intervals from rests.") 
MakeInterval p1 p2 = If (p1 <<=? p2) (MakeIntervalOrd p1 p2) (MakeIntervalOrd p2 p1) 

type family HalfStepsUpBy (p :: PitchType) (n :: Nat) :: PitchType where ... Source #

Move a pitch up by the specified number of semitones.

Equations

HalfStepsUpBy p 0 = p 
HalfStepsUpBy p n = HalfStepUp (HalfStepsUpBy p (n - 1)) 

type family HalfStepsDownBy (p :: PitchType) (n :: Nat) :: PitchType where ... Source #

Move a pitch down by the specified number of semitones.

Equations

HalfStepsDownBy p 0 = p 
HalfStepsDownBy p n = HalfStepDown (HalfStepsDownBy p (n - 1)) 

type family RaiseBy (p :: PitchType) (i :: IntervalType) :: PitchType where ... Source #

Raise a pitch by an interval.

Equations

RaiseBy Silence _ = Silence 
RaiseBy _ Compound = TypeError (Text "Can't shift by compound interval") 
RaiseBy p (Interval Min is) = HalfStepDown (HalfStepsUpBy p (IntervalWidth (Interval Min is) + 1)) 
RaiseBy p (Interval Dim is) = HalfStepDown (HalfStepsUpBy p (IntervalWidth (Interval Dim is) + 1)) 
RaiseBy p i = HalfStepsUpBy p (IntervalWidth i) 

type family LowerBy (p :: PitchType) (i :: IntervalType) :: PitchType where ... Source #

Lower a pitch by an interval.

Equations

LowerBy Silence _ = Silence 
LowerBy _ Compound = TypeError (Text "Can't shift by compound interval") 
LowerBy p (Interval Maj is) = HalfStepUp (HalfStepsDownBy p (IntervalWidth (Interval Maj is) + 1)) 
LowerBy p (Interval Aug is) = HalfStepUp (HalfStepsDownBy p (IntervalWidth (Interval Aug is) + 1)) 
LowerBy p i = HalfStepsDownBy p (IntervalWidth i) 

type family RaiseAllBy' (ps :: Vector PitchType n) (i :: IntervalType) :: Vector PitchType n where ... Source #

Raise multiple pitches by an interval.

Equations

RaiseAllBy' None _ = None 
RaiseAllBy' (p :-- ps) i = RaiseBy p i :-- RaiseAllBy' ps i 

type family LowerAllBy' (ps :: Vector PitchType n) (i :: IntervalType) :: Vector PitchType n where ... Source #

Lower multiple pitches by an interval.

Equations

LowerAllBy' None _ = None 
LowerAllBy' (p :-- ps) i = LowerBy p i :-- LowerAllBy' ps i 

type family RaiseByOct (p :: PitchType) :: PitchType where ... Source #

Raise a pitch by an octave.

type family LowerByOct (p :: PitchType) :: PitchType where ... Source #

Lower a pitch by an octave.

type family RaiseAllByOct (ps :: Voice l) :: Voice l where ... Source #

Equations

RaiseAllByOct v = RaiseAllBy v (Interval Perf Octave) 

Orphan instances

KnownNat n => Primitive Nat n Source # 

Associated Types

type Rep n (a :: n) :: * Source #

Methods

prim :: sing a -> Rep n a Source #

pretty :: sing a -> String Source #