Update for newer Brick + initial efforts towards s-exp data rep
Getty Ritter
7 years ago
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)) |
23 | 23 | default-extensions: OverloadedStrings, |
24 | 24 | ScopedTypeVariables |
25 | 25 | ghc-options: -Wall -threaded |
26 |
build-depends: base >=4.7 && <4. |
|
26 | build-depends: base >=4.7 && <4.10 | |
27 | 27 | , brick |
28 | 28 | , lens-family-core |
29 | 29 | , lens-family-th |
31 | 31 | , containers |
32 | 32 | , vty |
33 | 33 | , data-default |
34 | , s-cargot | |
34 | 35 | default-language: Haskell2010 |
3 | 3 | module Hypsibius.Data where |
4 | 4 | |
5 | 5 | import Data.Sequence (Seq) |
6 | import qualified Data.Sequence as S | |
7 | 6 | import Data.Text (Text) |
8 | 7 | import Data.Word (Word8) |
9 | 8 | import Lens.Family2.TH |
10 | 9 | |
10 | -- | XXX: This is a temporary definition of 'Oscillator' for early | |
11 | -- prototyping purposes. | |
11 | 12 | data Oscillator |
12 | 13 | = OscSine |
13 | 14 | | OscSquare |
14 | 15 | deriving (Eq, Show) |
15 | 16 | |
17 | -- | XXX: This is a temporary definition of 'Instrument' for early | |
18 | -- prototyping purposes. | |
16 | 19 | data Instrument = Instrument |
17 | 20 | { _instrSource :: Oscillator |
18 | 21 | } deriving (Eq, Show) |
19 | 22 | |
20 | 23 | $(makeLenses ''Instrument) |
21 | 24 | |
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. | |
22 | 29 | newtype InstrRef = InstrRef { _fromInstrRef :: Int } |
23 | 30 | deriving (Eq, Show) |
24 | 31 | |
25 | 32 | $(makeLenses ''InstrRef) |
26 | 33 | |
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. | |
27 | 39 | data Note = Note |
28 | 40 | { _noteCents :: Double |
29 | 41 | , _noteAppearance :: Text |
31 | 43 | |
32 | 44 | $(makeLenses ''Note) |
33 | 45 | |
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. | |
34 | 48 | newtype NoteRef = NoteRef { _fromNoteRef :: Int } |
35 | 49 | deriving (Eq, Show) |
36 | 50 | |
37 | 51 | $(makeLenses ''NoteRef) |
38 | 52 | |
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. | |
39 | 55 | data Scale = Scale |
40 | 56 | { _scaleName :: Text |
41 | 57 | , _scaleTotalCents :: Double |
44 | 60 | |
45 | 61 | $(makeLenses ''Scale) |
46 | 62 | |
63 | -- | An 'Event' is a typical event associated with a song. | |
47 | 64 | data Event = Event |
48 | 65 | deriving (Eq, Show) |
49 | ||
50 | data Track = Track | |
51 | { | |
52 | } deriving (Eq, Show) | |
53 | 66 | |
54 | 67 | data Beats |
55 | 68 | = BeatsSimple Word8 |
59 | 72 | |
60 | 73 | $(makeTraversals ''Beats) |
61 | 74 | |
75 | ||
62 | 76 | data Signature = Signature |
63 | 77 | { _sigPerBar :: Beats |
64 | 78 | , _sigBeatUnit :: Word8 |
66 | 80 | |
67 | 81 | $(makeLenses ''Signature) |
68 | 82 | |
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 | ||
69 | 95 | data Song = Song |
70 | 96 | { _songScale :: Scale |
71 | 97 | , _songTracks :: Seq Track |
1 | 1 | module Hypsibius.Event where |
2 | 2 | |
3 |
import Brick ( |
|
3 | import Brick (BrickEvent, EventM, Next) | |
4 | 4 | import qualified Brick |
5 | 5 | import qualified Graphics.Vty.Input.Events as Vty |
6 | 6 | |
7 | 7 | import qualified Hypsibius.State as State |
8 | 8 | |
9 |
data Event = |
|
9 | data Event = Event | |
10 | 10 | |
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 | |
13 | 13 | handle s _ = Brick.continue s |
14 | 14 | |
15 | 15 | initialize :: State.State -> EventM Int State.State |
2 | 2 | |
3 | 3 | module Hypsibius.Formats.Scale (parse) where |
4 | 4 | |
5 | import Data.SCargot | |
6 | import Data.SCargot.Repr.Basic | |
5 | 7 | import Data.Sequence (Seq) |
6 | 8 | import qualified Data.Sequence as S |
7 | 9 | import Data.Text (Text) |
8 |
|
|
10 | -- import qualified Data.Text as T | |
9 | 11 | |
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 | {- | |
11 | 28 | |
12 | 29 | parse :: Text -> Either String (Seq Note) |
13 | 30 | parse t = case T.lines t of |
23 | 40 | let n = Note (read (T.unpack cents)) name |
24 | 41 | in (n S.<|) <$> parseLines ls |
25 | 42 | rs -> Left ("Bad declaration: " ++ show rs) |
43 | -} |
1 | 1 | module Main where |
2 | 2 | |
3 | 3 | import Brick |
4 |
import qualified |
|
4 | import qualified Brick.BChan as Brick | |
5 | 5 | import Data.Default (def) |
6 | 6 | import qualified Graphics.Vty as Vty |
7 | 7 | |
17 | 17 | , appChooseCursor = \_ _ -> Nothing |
18 | 18 | , appHandleEvent = Event.handle |
19 | 19 | , appStartEvent = Event.initialize |
20 | , appAttrMap = def | |
21 | , appLiftVtyEvent = Event.VtyEvent | |
20 | , appAttrMap = \ _ -> attrMap mempty [] | |
22 | 21 | } |
23 | 22 | |
24 | 23 | main :: IO () |
25 | 24 | 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 | |
28 | 27 | return () |