Created
October 27, 2018 21:02
-
-
Save battermann/17ae21c0366eb632fbf93e95bca10fbf to your computer and use it in GitHub Desktop.
Music Elm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MusicTheory.Music exposing | |
( Control(..) | |
, Division(..) | |
, Duration(..) | |
, Music(..) | |
, Primitive(..) | |
, PrimitiveGroup(..) | |
, TiedOrSeparate(..) | |
, dotted | |
, eighth | |
, half | |
, oneHundredTwentyEighth | |
, quarter | |
, sixteenth | |
, sixtyFourth | |
, thirtySecond | |
, whole | |
, withTie | |
) | |
import MusicTheory.Letter exposing (Letter(..)) | |
import MusicTheory.Octave exposing (five, four) | |
import MusicTheory.Pitch as Pitch exposing (Pitch, flat, natural, pitch, sharp) | |
type PrimitiveGroup a | |
= Single (Primitive a) | |
| Duplet (Primitive a) (Primitive a) | |
| Triplet (Primitive a) (Primitive a) (Primitive a) | |
| Quadruplet (Primitive a) (Primitive a) (Primitive a) (Primitive a) | |
| Quintuplet (Primitive a) (Primitive a) (Primitive a) (Primitive a) (Primitive a) | |
type Division | |
= Whole | |
| Half | |
| Quarter | |
| Eighth | |
| Sixteenth | |
| ThirtySecond | |
| SixtyFourth | |
| OneHundredTwentyEighth | |
type Duration | |
= Normal Division TiedOrSeparate | |
| Dotted Division TiedOrSeparate | |
| DoubleDotted Division TiedOrSeparate | |
| TripleDotted Division TiedOrSeparate | |
type TiedOrSeparate | |
= Tied | |
| Separate | |
type Primitive a | |
= Note Duration a | |
| Rest Duration | |
type Control | |
= Control | |
type Music a | |
= Primitives (PrimitiveGroup a) | |
| Seq (Music a) (Music a) | |
| Par (Music a) (Music a) | |
| Modify Control (Music a) | |
whole : Duration | |
whole = | |
Normal Whole Separate | |
half : Duration | |
half = | |
Normal Half Separate | |
quarter : Duration | |
quarter = | |
Normal Quarter Separate | |
eighth : Duration | |
eighth = | |
Normal Eighth Separate | |
sixteenth : Duration | |
sixteenth = | |
Normal Sixteenth Separate | |
thirtySecond : Duration | |
thirtySecond = | |
Normal ThirtySecond Separate | |
sixtyFourth : Duration | |
sixtyFourth = | |
Normal SixtyFourth Separate | |
oneHundredTwentyEighth : Duration | |
oneHundredTwentyEighth = | |
Normal OneHundredTwentyEighth Separate | |
withTie : Duration -> Duration | |
withTie duration = | |
case duration of | |
Normal div _ -> | |
Normal div Tied | |
Dotted div _ -> | |
Dotted div Tied | |
DoubleDotted div _ -> | |
DoubleDotted div Tied | |
TripleDotted div _ -> | |
TripleDotted div Tied | |
dotted : Duration -> Duration | |
dotted duration = | |
case duration of | |
Normal d t -> | |
Dotted d t | |
Dotted d t -> | |
Dotted d t | |
DoubleDotted d t -> | |
Dotted d t | |
TripleDotted d t -> | |
Dotted d t | |
--- Example | |
twoFiveOne : Music Pitch | |
twoFiveOne = | |
let | |
dMinor = | |
Par (Primitives (Single (Note quarter (pitch D natural four)))) <| | |
Par (Primitives (Single (Note quarter (pitch F natural four)))) <| | |
Primitives (Single (Note quarter (pitch A natural four))) | |
gMajor = | |
Par (Primitives (Single (Note quarter (pitch D natural four)))) <| | |
Par (Primitives (Single (Note quarter (pitch G natural four)))) <| | |
Primitives (Single (Note quarter (pitch B natural four))) | |
cMajor = | |
Par (Primitives (Single (Note quarter (pitch C natural four)))) <| | |
Par (Primitives (Single (Note quarter (pitch E natural four)))) <| | |
Primitives (Single (Note quarter (pitch G natural four))) | |
in | |
Seq dMinor <| Seq gMajor cMajor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment