Browse Source

Switched data format to Adnot

Getty Ritter 7 years ago
parent
commit
eaaec43ba3

+ 18 - 16
data/scales/12tet.hps

@@ -1,16 +1,18 @@
- ;; this is a basic twelve-tone scale
-(hypsibius-scale
- :name "twelve-tone equal temperament"
- :size 1200
- (note "A"  0)
- (note "A♯" 100 :color black)
- (note "B"  200)
- (note "C"  300)
- (note "C♯" 400 :color black)
- (note "D"  500)
- (note "D♯" 600 :color black)
- (note "E"  700)
- (note "F"  800)
- (note "F♯" 900 :color black)
- (note "G"  1000)
- (note "G♯" 1100 :color black))
+# this is a basic twelve-tone scale
+{ name "twelve-tone equal temperament"
+  size 1200
+  notes [
+    (note "A"  0)
+    (note "A♯" 100 black)
+    (note "B"  200)
+    (note "C"  300)
+    (note "C♯" 400 black)
+    (note "D"  500)
+    (note "D♯" 600 black)
+    (note "E"  700)
+    (note "F"  800)
+    (note "F♯" 900 black)
+    (note "G"  1000)
+    (note "G♯" 1100 black)
+  ]
+}

+ 24 - 21
data/scales/19tet.hps

@@ -1,22 +1,25 @@
-hypsibius scale
 # nineteen-tone equal temperament
-
-   0 A
-  63 A♯
- 126 B♭
- 189 B
- 253 B♯
- 316 C
- 379 C♯
- 442 D♭
- 505 D
- 568 D♯
- 632 E♭
- 695 E
- 758 E♯
- 821 F
- 884 F♯
- 947 G♭
-1011 G
-1074 G♯
-1137 A♭
+{ name "nineteen-tone equal temperament"
+  size 1200
+  notes [
+    (note "A" 0)
+    (note "A♯" 63)
+    (note "B♭" 126)
+    (note "B" 189)
+    (note "B♯" 253)
+    (note "C" 316)
+    (note "C♯" 379)
+    (note "D♭" 442)
+    (note "D" 505)
+    (note "D♯" 568)
+    (note "E♭" 632)
+    (note "E" 695)
+    (note "E♯" 758)
+    (note "F" 821)
+    (note "F♯" 884)
+    (note "G♭" 947)
+    (note "G" 1011)
+    (note "G♯" 1074)
+    (note "A♭" 1137)
+  ]
+}

+ 17 - 14
data/scales/just-intonation.hps

@@ -1,15 +1,18 @@
-hypsibius scale
 # the twelve-tone scale in just intonation
-
-   0.00  C
- 111.72  C♯
- 203.91  D
- 315.64  D♯
- 386.31  E
- 498.04  F
- 582.51  F♯
- 701.96  G
- 813.69  G♯
- 884.36  A
- 996.09  A♯
-1088.27  B
+{ name "twelve-tone just intonation"
+  size 1200
+  notes [
+    (note "A"  0)
+    (note "A♯" 111.72 black)
+    (note "B"  203.91)
+    (note "C"  315.64)
+    (note "C♯" 386.31 black)
+    (note "D"  498.04)
+    (note "D♯" 582.51 black)
+    (note "E"  701.96)
+    (note "F"  813.69)
+    (note "F♯" 884.36 black)
+    (note "G"  996.09)
+    (note "G♯" 1088.27 black)
+  ]
+}

+ 2 - 1
hypsibius.cabal

@@ -28,8 +28,9 @@ executable hypsibius
                      , lens-family-core
                      , lens-family-th
                      , text
+                     , bytestring
                      , containers
                      , vty
                      , data-default
-                     , s-cargot
+                     , adnot
   default-language:    Haskell2010

+ 21 - 1
src/Hypsibius/Data.hs

@@ -1,7 +1,10 @@
 {-# LANGUAGE TemplateHaskell #-}
+{-# LANGUAGE OverloadedLists #-}
+{-# LANGUAGE GADTs #-}
 
 module Hypsibius.Data where
 
+import           Data.Adnot
 import           Data.Sequence (Seq)
 import           Data.Text (Text)
 import           Data.Word (Word8)
@@ -39,8 +42,20 @@ $(makeLenses ''InstrRef)
 data Note = Note
   { _noteCents      :: Double
   , _noteAppearance :: Text
+  , _noteColor      :: Maybe Text
   } deriving (Eq, Show)
 
+instance FromAdnot Note where
+  parseAdnot = withSum "Note" go
+    where go "note" [name, cents] =
+            Note <$> parseAdnot cents <*> parseAdnot name <*> pure Nothing
+          go "note" [name, cents, color] =
+            Note <$> parseAdnot cents
+                 <*> parseAdnot name
+                 <*> (Just <$> parseAdnot color)
+          go "note" _ = fail "Unknown argument structure"
+          go c _ = fail ("Expected note, got " ++ show c)
+
 $(makeLenses ''Note)
 
 -- | We'll maintain a list of notes and refer to them using indices. For type
@@ -58,6 +73,12 @@ data Scale = Scale
   , _scaleNotes      :: Seq Note
   } deriving (Eq, Show)
 
+instance FromAdnot Scale where
+  parseAdnot = withProduct "Scale" $ \o ->
+    Scale <$> o .: "name"
+          <*> o .: "size"
+          <*> o .: "notes"
+
 $(makeLenses ''Scale)
 
 -- | An 'Event' is a typical event associated with a song.
@@ -91,7 +112,6 @@ data Track = Track
   } deriving (Eq, Show)
 
 
-
 data Song = Song
   { _songScale  :: Scale
   , _songTracks :: Seq Track

+ 5 - 5
src/Hypsibius/Formats.hs

@@ -1,10 +1,10 @@
 module Hypsibius.Formats where
 
+import           Data.Adnot
 import           Data.Sequence (Seq)
-import qualified Data.Text.IO as T
+import qualified Data.ByteString as BS
 
-import qualified Hypsibius.Formats.Scale as Scale
-import           Hypsibius.Data (Note)
+import           Hypsibius.Data
 
-readScale :: FilePath -> IO (Either String (Seq Note))
-readScale = fmap Scale.parse . T.readFile
+readScale :: FilePath -> IO (Either String Scale)
+readScale = fmap decode . BS.readFile

+ 2 - 17
src/Hypsibius/Formats/Scale.hs

@@ -1,29 +1,13 @@
 {-# LANGUAGE ViewPatterns #-}
 
-module Hypsibius.Formats.Scale (parse) where
+module Hypsibius.Formats.Scale where
 
-import           Data.SCargot
-import           Data.SCargot.Repr.Basic
+import           Data.Adnot
 import           Data.Sequence (Seq)
 import qualified Data.Sequence as S
-import           Data.Text (Text)
 
 import           Hypsibius.Data (Note(..), Scale(..))
 
-data Atom
-  = AIdent  Text
-  | AString Text
-  | AInt    Integer
-  | AFloat  Double
-  | AKWord Text
-    deriving (Eq, Show)
-
-parseScale :: Text -> Either String Scale
-parseScale = undefined
-
-parse = undefined
-
 {-
 
 parse :: Text -> Either String (Seq Note)