-- Copyright 2013 Evan Laforge
-- This program is distributed under the terms of the GNU General Public
-- License 3.0, see COPYING or http://www.gnu.org/licenses/gpl-3.0.txt

-- | Scales can keep their symbols with them in the 'Pitch.Scale.scale_symbols'
-- field, but there are a number of symbols that are common between a number of
-- scales.  If I define them once here I can avoid loading them redundantly.
module Derive.Scale.Symbols where
import qualified Data.Text as Text

import qualified Ui.Symbol as Symbol
import qualified Perform.Pitch as Pitch
import Global


symbols :: [Symbol.Symbol]
symbols :: [Symbol]
symbols = [Symbol]
dotted_numbers [Symbol] -> [Symbol] -> [Symbol]
forall a. Semigroup a => a -> a -> a
<> [Symbol]
staff_symbols [Symbol] -> [Symbol] -> [Symbol]
forall a. Semigroup a => a -> a -> a
<> [Symbol]
工尺譜

-- * dotted numbers

dotted_number :: Int -> Int -> Pitch.Note
dotted_number :: Int -> Int -> Note
dotted_number Int
num Int
oct
    | Int
oct Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = Text -> Note
Pitch.Note Text
nums
    | Int
oct Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0 = Text -> Note
Pitch.Note (Text -> Note) -> Text -> Note
forall a b. (a -> b) -> a -> b
$ Text
"`" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
nums Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text -> Text
Text.replicate (Int -> Int
forall a. Num a => a -> a
abs Int
oct) Text
"." Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"`"
    | Bool
otherwise = Text -> Note
Pitch.Note (Text -> Note) -> Text -> Note
forall a b. (a -> b) -> a -> b
$ Text
"`" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
nums Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text -> Text
Text.replicate Int
oct Text
"^" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"`"
    where nums :: Text
nums = Int -> Text
forall a. Show a => a -> Text
showt Int
num

dot :: Symbol.Glyph
dot :: Glyph
dot = Text -> Glyph
Symbol.glyph Text
"•" -- unicode \x2022

dot_above :: Text -> Symbol.Symbol
dot_above :: Text -> Symbol
dot_above Text
s = Text -> Bool -> [Glyph] -> Symbol
Symbol.Symbol (Text
s Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"^") Bool
True
    [Text -> Glyph
Symbol.glyph Text
s, Int -> (Double, Double) -> Glyph -> Glyph
Symbol.glyph_at Int
0 (Double
0.5, -Double
0.3) Glyph
dot]

dot2_above :: Text -> Symbol.Symbol
dot2_above :: Text -> Symbol
dot2_above Text
s = Text -> Bool -> [Glyph] -> Symbol
Symbol.Symbol (Text
s Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"^^") Bool
True
    [Text -> Glyph
Symbol.glyph Text
s,
        Int -> (Double, Double) -> Glyph -> Glyph
Symbol.glyph_at Int
0 (-Double
0.3, -Double
0.3) Glyph
dot,
        Int -> (Double, Double) -> Glyph -> Glyph
Symbol.glyph_at Int
0 (Double
0.5, -Double
0.3) Glyph
dot]

dot_below :: Text -> Symbol.Symbol
dot_below :: Text -> Symbol
dot_below Text
s = Text -> Bool -> [Glyph] -> Symbol
Symbol.Symbol (Text
s Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
".") Bool
True
    [Text -> Glyph
Symbol.glyph Text
s, Int -> (Double, Double) -> Glyph -> Glyph
Symbol.glyph_at Int
0 (Double
0.5, Double
0.3) Glyph
dot]

dot2_below :: Text -> Symbol.Symbol
dot2_below :: Text -> Symbol
dot2_below Text
s = Text -> Bool -> [Glyph] -> Symbol
Symbol.Symbol (Text
s Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"..") Bool
True
    [ Text -> Glyph
Symbol.glyph Text
s
    , Int -> (Double, Double) -> Glyph -> Glyph
Symbol.glyph_at Int
0 (-Double
0.3, Double
0.3) Glyph
dot
    , Int -> (Double, Double) -> Glyph -> Glyph
Symbol.glyph_at Int
0 (Double
0.5, Double
0.3) Glyph
dot
    ]

dotted_numbers :: [Symbol.Symbol]
dotted_numbers :: [Symbol]
dotted_numbers = (Text -> Symbol) -> [Text] -> [Symbol]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Symbol
dot_above [Text]
cs [Symbol] -> [Symbol] -> [Symbol]
forall a. Semigroup a => a -> a -> a
<> (Text -> Symbol) -> [Text] -> [Symbol]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Symbol
dot2_above
        [Text]
cs [Symbol] -> [Symbol] -> [Symbol]
forall a. Semigroup a => a -> a -> a
<> (Text -> Symbol) -> [Text] -> [Symbol]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Symbol
dot_below [Text]
cs [Symbol] -> [Symbol] -> [Symbol]
forall a. Semigroup a => a -> a -> a
<> (Text -> Symbol) -> [Text] -> [Symbol]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Symbol
dot2_below [Text]
cs
    where
    -- If some scale wants higher numbers, they are easy to add.
    cs :: [Text]
cs = (Integer -> Text) -> [Integer] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map Integer -> Text
forall a. Show a => a -> Text
showt [Integer
0..Integer
9]


-- * staff notation

staff_symbols :: [Symbol.Symbol]
staff_symbols :: [Symbol]
staff_symbols =
    [ Text -> [Glyph] -> Symbol
Symbol.symbol Text
"#" [Text -> Int -> Glyph
g Text
"\x266f" Int
1]
    -- bravura: e263
    , Text -> [Glyph] -> Symbol
Symbol.symbol Text
"##" [Text -> Int -> Glyph
g Text
"\x1d12a" Int
10]
    , Text -> [Glyph] -> Symbol
Symbol.symbol Text
"b" [Text -> Int -> Glyph
g Text
"\x266d" Int
1]
    -- bravura: e264
    , Text -> [Glyph] -> Symbol
Symbol.symbol Text
"bb" [Text -> Int -> Glyph
g Text
"\x1d12b" Int
4]
    , Text -> [Glyph] -> Symbol
Symbol.symbol Text
"n" [Text -> Int -> Glyph
g Text
"\x266e" Int
1]
    ]
    where g :: Text -> Int -> Glyph
g Text
str Int
size = (Text -> Glyph
Symbol.glyph Text
str) { glyph_size :: Int
Symbol.glyph_size = Int
size }


-- * 南管的工尺譜

工尺譜 :: [Symbol.Symbol]
工尺譜 :: [Symbol]
工尺譜 =
    -- TODO fix names later
    [ Text -> Text -> Symbol
Symbol.simple Text
"si" Text
"士"
    , Text -> Text -> Symbol
Symbol.simple Text
"e" Text
"下"
    , Text -> Text -> Symbol
Symbol.simple Text
"che" Text
"ㄨ" -- bopo \x3128 ㄨ
    , Text -> Text -> Symbol
Symbol.simple Text
"gong" Text
"工"
    , Text -> Text -> Symbol
Symbol.simple Text
"liu" Text
"六"

    -- 琵琶手法
    , Text -> Text -> Symbol
Symbol.simple Text
"kou" Text
"口"
    , Text -> Text -> Symbol
Symbol.simple Text
"upstroke" Text
"㇀" -- \x31c0
    , Text -> Text -> Symbol
Symbol.simple Text
"L" Text
"㇄" -- \x31c4
    -- \x2020 at least until I can make a better one
    , Text -> [Glyph] -> Symbol
placed Text
"dagger" [(Text -> Glyph
Symbol.glyph Text
"†") { glyph_size :: Int
Symbol.glyph_size = Int
4 }]
    , Text -> [Glyph] -> Symbol
placed Text
"wu1"
        [ Text -> (Double, Double) -> Glyph
glyph_at Text
wu (Double
0, Double
0)
        , Text -> (Double, Double) -> Glyph
glyph_at Text
dian (-Double
0.5, Double
0)
        ]
    , Text -> [Glyph] -> Symbol
placed Text
"wu666"
        [ Text -> (Double, Double) -> Glyph
glyph_at Text
wu (Double
0, Double
0)
        , Text -> (Double, Double) -> Glyph
glyph_at Text
dian (-Double
0.5, Double
0)
        , Text -> (Double, Double) -> Glyph
glyph_at Text
dian (Double
0, Double
0.5)
        ]
    , Text -> [Glyph] -> Symbol
placed Text
"wu866"
        [ Text -> (Double, Double) -> Glyph
glyph_at Text
wu (Double
0, Double
0)
        , Text -> (Double, Double) -> Glyph
glyph_at Text
dian (-Double
0.5, Double
0.2)
        , Text -> (Double, Double) -> Glyph
glyph_at Text
dian (-Double
0.5, -Double
0.2)
        ]

    -- meter
    , Text -> Text -> Symbol
Symbol.simple Text
"ling" Text
"○"
    , Text -> Text -> Symbol
Symbol.simple Text
"dian" Text
dian
    ]
    where
    placed :: Text -> [Glyph] -> Symbol
placed Text
name [Glyph]
glyphs = Text -> Bool -> [Glyph] -> Symbol
Symbol.Symbol Text
name Bool
True [Glyph]
glyphs
    glyph_at :: Text -> (Double, Double) -> Glyph
glyph_at Text
str (Double, Double)
align = (Text -> Glyph
Symbol.glyph Text
str) { glyph_align :: (Double, Double)
Symbol.glyph_align = (Double, Double)
align }
    dian :: Text
dian = Text
"、"
    wu :: Text
wu = Text
"ㄨ"