gdritter repos hypsibius / 0e7644a
Update for newer Brick + initial efforts towards s-exp data rep Getty Ritter 7 years ago
6 changed file(s) with 77 addition(s) and 32 deletion(s). Collapse all Expand all
1 hypsibius scale
2 # this is a basic twelve-tone scale
3
4 0 C
5 100 C♯
6 200 D
7 300 D♯
8 400 E
9 500 F
10 600 F♯
11 700 G
12 800 G♯
13 900 A
14 1000 A♯
15 1100 B
1 ;; this is a basic twelve-tone scale
2 (hypsibius-scale
3 :name "twelve-tone equal temperament"
4 :size 1200
5 (note "A" 0)
6 (note "A♯" 100 :color black)
7 (note "B" 200)
8 (note "C" 300)
9 (note "C♯" 400 :color black)
10 (note "D" 500)
11 (note "D♯" 600 :color black)
12 (note "E" 700)
13 (note "F" 800)
14 (note "F♯" 900 :color black)
15 (note "G" 1000)
16 (note "G♯" 1100 :color black))
2323 default-extensions: OverloadedStrings,
2424 ScopedTypeVariables
2525 ghc-options: -Wall -threaded
26 build-depends: base >=4.7 && <4.9
26 build-depends: base >=4.7 && <4.10
2727 , brick
2828 , lens-family-core
2929 , lens-family-th
3131 , containers
3232 , vty
3333 , data-default
34 , s-cargot
3435 default-language: Haskell2010
33 module Hypsibius.Data where
44
55 import Data.Sequence (Seq)
6 import qualified Data.Sequence as S
76 import Data.Text (Text)
87 import Data.Word (Word8)
98 import Lens.Family2.TH
109
10 -- | XXX: This is a temporary definition of 'Oscillator' for early
11 -- prototyping purposes.
1112 data Oscillator
1213 = OscSine
1314 | OscSquare
1415 deriving (Eq, Show)
1516
17 -- | XXX: This is a temporary definition of 'Instrument' for early
18 -- prototyping purposes.
1619 data Instrument = Instrument
1720 { _instrSource :: Oscillator
1821 } deriving (Eq, Show)
1922
2023 $(makeLenses ''Instrument)
2124
25
26 -- | We'll maintain a list of instruments and refer to them using
27 -- indices. For type safety, here is a wrapper around those
28 -- indices.
2229 newtype InstrRef = InstrRef { _fromInstrRef :: Int }
2330 deriving (Eq, Show)
2431
2532 $(makeLenses ''InstrRef)
2633
34 -- | A 'Note' here is an individual element of a scale, which we'll
35 -- maintain a unique list of on a per-song basis, and most of the time
36 -- we'll use indices into that list. A 'Note' has a frequency represented
37 -- in cents and an appearance that the user will see when running the
38 -- program, which should be no more than a few characters long.
2739 data Note = Note
2840 { _noteCents :: Double
2941 , _noteAppearance :: Text
3143
3244 $(makeLenses ''Note)
3345
46 -- | We'll maintain a list of notes and refer to them using indices. For type
47 -- safety, here is a wrapper around those indices.
3448 newtype NoteRef = NoteRef { _fromNoteRef :: Int }
3549 deriving (Eq, Show)
3650
3751 $(makeLenses ''NoteRef)
3852
53 -- | A 'Scale' has a name, a total number of cents (which will almost always be
54 -- 1200 for traditional scales) and a list of notes associated with it.
3955 data Scale = Scale
4056 { _scaleName :: Text
4157 , _scaleTotalCents :: Double
4460
4561 $(makeLenses ''Scale)
4662
63 -- | An 'Event' is a typical event associated with a song.
4764 data Event = Event
4865 deriving (Eq, Show)
49
50 data Track = Track
51 {
52 } deriving (Eq, Show)
5366
5467 data Beats
5568 = BeatsSimple Word8
5972
6073 $(makeTraversals ''Beats)
6174
75
6276 data Signature = Signature
6377 { _sigPerBar :: Beats
6478 , _sigBeatUnit :: Word8
6680
6781 $(makeLenses ''Signature)
6882
83
84 data TrackChunk = TrackChunk
85 { _tcSignature :: Signature
86 } deriving (Eq, Show)
87
88
89 data Track = Track
90 {
91 } deriving (Eq, Show)
92
93
94
6995 data Song = Song
7096 { _songScale :: Scale
7197 , _songTracks :: Seq Track
11 module Hypsibius.Event where
22
3 import Brick (EventM, Next)
3 import Brick (BrickEvent, EventM, Next)
44 import qualified Brick
55 import qualified Graphics.Vty.Input.Events as Vty
66
77 import qualified Hypsibius.State as State
88
9 data Event = VtyEvent Vty.Event
9 data Event = Event
1010
11 handle :: State.State -> Event -> EventM Int (Next State.State)
12 handle s (VtyEvent (Vty.EvKey Vty.KEsc _)) = Brick.halt s
11 handle :: State.State -> BrickEvent Int Event -> EventM Int (Next State.State)
12 handle s (Brick.VtyEvent (Vty.EvKey Vty.KEsc _)) = Brick.halt s
1313 handle s _ = Brick.continue s
1414
1515 initialize :: State.State -> EventM Int State.State
22
33 module Hypsibius.Formats.Scale (parse) where
44
5 import Data.SCargot
6 import Data.SCargot.Repr.Basic
57 import Data.Sequence (Seq)
68 import qualified Data.Sequence as S
79 import Data.Text (Text)
8 import qualified Data.Text as T
10 -- import qualified Data.Text as T
911
10 import Hypsibius.Data (Note(..))
12 import Hypsibius.Data (Note(..), Scale(..))
13
14 data Atom
15 = AIdent Text
16 | AString Text
17 | AInt Integer
18 | AFloat Double
19 | AKWord Text
20 deriving (Eq, Show)
21
22 parseScale :: Text -> Either String Scale
23 parseScale = undefined
24
25 parse = undefined
26
27 {-
1128
1229 parse :: Text -> Either String (Seq Note)
1330 parse t = case T.lines t of
2340 let n = Note (read (T.unpack cents)) name
2441 in (n S.<|) <$> parseLines ls
2542 rs -> Left ("Bad declaration: " ++ show rs)
43 -}
11 module Main where
22
33 import Brick
4 import qualified Control.Concurrent.Chan as Chan
4 import qualified Brick.BChan as Brick
55 import Data.Default (def)
66 import qualified Graphics.Vty as Vty
77
1717 , appChooseCursor = \_ _ -> Nothing
1818 , appHandleEvent = Event.handle
1919 , appStartEvent = Event.initialize
20 , appAttrMap = def
21 , appLiftVtyEvent = Event.VtyEvent
20 , appAttrMap = \ _ -> attrMap mempty []
2221 }
2322
2423 main :: IO ()
2524 main = do
26 eventChan <- Chan.newChan
27 _ <- customMain (Vty.mkVty def) eventChan trackerApp State.newState
25 eventChan <- Brick.newBChan 32
26 _ <- customMain (Vty.mkVty mempty) (Just eventChan) trackerApp State.newState
2827 return ()