module Sound.Tidal.Chords where

{-
    Chords.hs - For .. chords
    Copyright (C) 2020, Alex McLean and contributors

    This library is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this library.  If not, see <http://www.gnu.org/licenses/>.
-}

import Data.Maybe

import Sound.Tidal.Pattern

major :: Num a => [a]
major :: [a]
major = [a
0,a
4,a
7]
minor :: Num a => [a]
minor :: [a]
minor = [a
0,a
3,a
7]
major7 :: Num a => [a]
major7 :: [a]
major7 = [a
0,a
4,a
7,a
11]
dom7 :: Num a => [a]
dom7 :: [a]
dom7 = [a
0,a
4,a
7,a
10]
minor7 :: Num a => [a]
minor7 :: [a]
minor7 = [a
0,a
3,a
7,a
10]
aug :: Num a => [a]
aug :: [a]
aug = [a
0,a
4,a
8]
dim :: Num a => [a]
dim :: [a]
dim = [a
0,a
3,a
6]
dim7 :: Num a => [a]
dim7 :: [a]
dim7 = [a
0,a
3,a
6,a
9]
one :: Num a => [a]
one :: [a]
one = [a
0]
five :: Num a => [a]
five :: [a]
five = [a
0,a
7]
plus :: Num a => [a]
plus :: [a]
plus = [a
0,a
4,a
8]
sharp5 :: Num a => [a]
sharp5 :: [a]
sharp5 = [a
0,a
4,a
8]
msharp5 :: Num a => [a]
msharp5 :: [a]
msharp5 = [a
0,a
3,a
8]
sus2 :: Num a => [a]
sus2 :: [a]
sus2 = [a
0,a
2,a
7]
sus4 :: Num a => [a]
sus4 :: [a]
sus4 = [a
0,a
5,a
7]
six :: Num a => [a]
six :: [a]
six = [a
0,a
4,a
7,a
9]
m6 :: Num a => [a]
m6 :: [a]
m6 = [a
0,a
3,a
7,a
9]
sevenSus2 :: Num a => [a]
sevenSus2 :: [a]
sevenSus2 = [a
0,a
2,a
7,a
10]
sevenSus4 :: Num a => [a]
sevenSus4 :: [a]
sevenSus4 = [a
0,a
5,a
7,a
10]
sevenFlat5 :: Num a => [a]
sevenFlat5 :: [a]
sevenFlat5 = [a
0,a
4,a
6,a
10]
m7flat5 :: Num a => [a]
m7flat5 :: [a]
m7flat5 = [a
0,a
3,a
6,a
10]
sevenSharp5 :: Num a => [a]
sevenSharp5 :: [a]
sevenSharp5 = [a
0,a
4,a
8,a
10]
m7sharp5 :: Num a => [a]
m7sharp5 :: [a]
m7sharp5 = [a
0,a
3,a
8,a
10]
nine :: Num a => [a]
nine :: [a]
nine = [a
0,a
4,a
7,a
10,a
14]
m9 :: Num a => [a]
m9 :: [a]
m9 = [a
0,a
3,a
7,a
10,a
14]
m7sharp9 :: Num a => [a]
m7sharp9 :: [a]
m7sharp9 = [a
0,a
3,a
7,a
10,a
14]
maj9 :: Num a => [a]
maj9 :: [a]
maj9 = [a
0,a
4,a
7,a
11,a
14]
nineSus4 :: Num a => [a]
nineSus4 :: [a]
nineSus4 = [a
0,a
5,a
7,a
10,a
14]
sixby9 :: Num a => [a]
sixby9 :: [a]
sixby9 = [a
0,a
4,a
7,a
9,a
14]
m6by9 :: Num a => [a]
m6by9 :: [a]
m6by9 = [a
0,a
3,a
9,a
7,a
14]
sevenFlat9 :: Num a => [a]
sevenFlat9 :: [a]
sevenFlat9 = [a
0,a
4,a
7,a
10,a
13]
m7flat9 :: Num a => [a]
m7flat9 :: [a]
m7flat9 = [a
0,a
3,a
7,a
10,a
13]
sevenFlat10 :: Num a => [a]
sevenFlat10 :: [a]
sevenFlat10 = [a
0,a
4,a
7,a
10,a
15]
nineSharp5 :: Num a => [a]
nineSharp5 :: [a]
nineSharp5 = [a
0,a
1,a
13]
m9sharp5 :: Num a => [a]
m9sharp5 :: [a]
m9sharp5 = [a
0,a
1,a
14]
sevenSharp5flat9 :: Num a => [a]
sevenSharp5flat9 :: [a]
sevenSharp5flat9 = [a
0,a
4,a
8,a
10,a
13]
m7sharp5flat9 :: Num a => [a]
m7sharp5flat9 :: [a]
m7sharp5flat9 = [a
0,a
3,a
8,a
10,a
13]
eleven :: Num a => [a]
eleven :: [a]
eleven = [a
0,a
4,a
7,a
10,a
14,a
17]
m11 :: Num a => [a]
m11 :: [a]
m11 = [a
0,a
3,a
7,a
10,a
14,a
17]
maj11 :: Num a => [a]
maj11 :: [a]
maj11 = [a
0,a
4,a
7,a
11,a
14,a
17]
elevenSharp :: Num a => [a]
elevenSharp :: [a]
elevenSharp = [a
0,a
4,a
7,a
10,a
14,a
18]
m11sharp :: Num a => [a]
m11sharp :: [a]
m11sharp = [a
0,a
3,a
7,a
10,a
14,a
18]
thirteen :: Num a => [a]
thirteen :: [a]
thirteen = [a
0,a
4,a
7,a
10,a
14,a
17,a
21]
m13 :: Num a => [a]
m13 :: [a]
m13 = [a
0,a
3,a
7,a
10,a
14,a
17,a
21]

-- | @chordate cs m n@ selects the @n@th "chord" (a chord is a list of Ints)
-- from a list of chords @cs@ and transposes it by @m@
-- chordate :: Num b => [[b]] -> b -> Int -> [b]
-- chordate cs m n = map (+m) $ cs!!n

-- | @enchord chords pn pc@ turns every note in the note pattern @pn@ into
-- a chord, selecting from the chord lists @chords@ using the index pattern
-- @pc@.  For example, @Chords.enchord [Chords.major Chords.minor] "c g" "0 1"@
-- will create a pattern of a C-major chord followed by a G-minor chord.
-- enchord :: Num a => [[a]] -> Pattern a -> Pattern Int -> Pattern a
-- enchord chords pn pc = flatpat $ (chordate chords) <$> pn <*> pc

chordTable :: Num a => [(String, [a])]
chordTable :: [(String, [a])]
chordTable = [(String
"major", [a]
forall a. Num a => [a]
major),
              (String
"maj", [a]
forall a. Num a => [a]
major),
              (String
"minor", [a]
forall a. Num a => [a]
minor),
              (String
"min", [a]
forall a. Num a => [a]
minor),
              (String
"aug", [a]
forall a. Num a => [a]
aug),
              (String
"dim", [a]
forall a. Num a => [a]
dim),
              (String
"major7", [a]
forall a. Num a => [a]
major7),
              (String
"maj7", [a]
forall a. Num a => [a]
major7),
              (String
"dom7", [a]
forall a. Num a => [a]
dom7),
              (String
"minor7", [a]
forall a. Num a => [a]
minor7),
              (String
"min7", [a]
forall a. Num a => [a]
minor7),
              (String
"dim7", [a]
forall a. Num a => [a]
dim7),
              (String
"one", [a]
forall a. Num a => [a]
one),
              (String
"1", [a]
forall a. Num a => [a]
one),
              (String
"five", [a]
forall a. Num a => [a]
five),
              (String
"5", [a]
forall a. Num a => [a]
five),
              (String
"plus", [a]
forall a. Num a => [a]
plus),
              (String
"sharp5", [a]
forall a. Num a => [a]
sharp5),
              (String
"msharp5", [a]
forall a. Num a => [a]
msharp5),
              (String
"sus2", [a]
forall a. Num a => [a]
sus2),
              (String
"sus4", [a]
forall a. Num a => [a]
sus4),
              (String
"six", [a]
forall a. Num a => [a]
six),
              (String
"6", [a]
forall a. Num a => [a]
six),
              (String
"m6", [a]
forall a. Num a => [a]
m6),
              (String
"sevenSus2", [a]
forall a. Num a => [a]
sevenSus2),
              (String
"7sus2", [a]
forall a. Num a => [a]
sevenSus2),
              (String
"sevenSus4", [a]
forall a. Num a => [a]
sevenSus4),
              (String
"7sus4", [a]
forall a. Num a => [a]
sevenSus4),
              (String
"sevenFlat5", [a]
forall a. Num a => [a]
sevenFlat5),
              (String
"7f5", [a]
forall a. Num a => [a]
sevenFlat5),
              (String
"m7flat5", [a]
forall a. Num a => [a]
m7flat5),
              (String
"m7f5", [a]
forall a. Num a => [a]
m7flat5),
              (String
"sevenSharp5", [a]
forall a. Num a => [a]
sevenSharp5),
              (String
"7s5", [a]
forall a. Num a => [a]
sevenSharp5),
              (String
"m7sharp5", [a]
forall a. Num a => [a]
m7sharp5),
              (String
"m7s5", [a]
forall a. Num a => [a]
m7sharp5),
              (String
"nine", [a]
forall a. Num a => [a]
nine),
              (String
"m9", [a]
forall a. Num a => [a]
m9),
              (String
"m7sharp9", [a]
forall a. Num a => [a]
m7sharp9),
              (String
"m7s9", [a]
forall a. Num a => [a]
m7sharp9),
              (String
"maj9", [a]
forall a. Num a => [a]
maj9),
              (String
"nineSus4", [a]
forall a. Num a => [a]
nineSus4),
              (String
"ninesus4", [a]
forall a. Num a => [a]
nineSus4),
              (String
"9sus4", [a]
forall a. Num a => [a]
nineSus4),
              (String
"sixby9", [a]
forall a. Num a => [a]
sixby9),
              (String
"6by9", [a]
forall a. Num a => [a]
sixby9),
              (String
"m6by9", [a]
forall a. Num a => [a]
m6by9),
              (String
"sevenFlat9", [a]
forall a. Num a => [a]
sevenFlat9),
              (String
"7f9", [a]
forall a. Num a => [a]
sevenFlat9),
              (String
"m7flat9", [a]
forall a. Num a => [a]
m7flat9),
              (String
"m7f9", [a]
forall a. Num a => [a]
m7flat9),
              (String
"sevenFlat10", [a]
forall a. Num a => [a]
sevenFlat10),
              (String
"7f10", [a]
forall a. Num a => [a]
sevenFlat10),
              (String
"nineSharp5", [a]
forall a. Num a => [a]
nineSharp5),
              (String
"9s5", [a]
forall a. Num a => [a]
nineSharp5),
              (String
"m9sharp5", [a]
forall a. Num a => [a]
m9sharp5),
              (String
"m9s5", [a]
forall a. Num a => [a]
m9sharp5),
              (String
"sevenSharp5flat9", [a]
forall a. Num a => [a]
sevenSharp5flat9),
              (String
"7s5f9", [a]
forall a. Num a => [a]
sevenSharp5flat9),
              (String
"m7sharp5flat9", [a]
forall a. Num a => [a]
m7sharp5flat9),
              (String
"eleven", [a]
forall a. Num a => [a]
eleven),
              (String
"11", [a]
forall a. Num a => [a]
eleven),
              (String
"m11", [a]
forall a. Num a => [a]
m11),
              (String
"maj11", [a]
forall a. Num a => [a]
maj11),
              (String
"elevenSharp", [a]
forall a. Num a => [a]
elevenSharp),
              (String
"11s", [a]
forall a. Num a => [a]
elevenSharp),
              (String
"m11sharp", [a]
forall a. Num a => [a]
m11sharp),
              (String
"m11s", [a]
forall a. Num a => [a]
m11sharp),
              (String
"thirteen", [a]
forall a. Num a => [a]
thirteen),
              (String
"13", [a]
forall a. Num a => [a]
thirteen),
              (String
"m13", [a]
forall a. Num a => [a]
m13)
             ]

chordL :: Num a => Pattern String -> Pattern [a]
chordL :: Pattern String -> Pattern [a]
chordL Pattern String
p = (\String
name -> [a] -> Maybe [a] -> [a]
forall a. a -> Maybe a -> a
fromMaybe [] (Maybe [a] -> [a]) -> Maybe [a] -> [a]
forall a b. (a -> b) -> a -> b
$ String -> [(String, [a])] -> Maybe [a]
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup String
name [(String, [a])]
forall a. Num a => [(String, [a])]
chordTable) (String -> [a]) -> Pattern String -> Pattern [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern String
p

chordList :: String
chordList :: String
chordList = [String] -> String
unwords ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ ((String, [Int]) -> String) -> [(String, [Int])] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (String, [Int]) -> String
forall a b. (a, b) -> a
fst ([(String, [Int])]
forall a. Num a => [(String, [a])]
chordTable :: [(String, [Int])])