Data.hs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. {-# LANGUAGE TemplateHaskell #-}
  2. module Hypsibius.Data where
  3. import Data.Sequence (Seq)
  4. import Data.Text (Text)
  5. import Data.Word (Word8)
  6. import Lens.Family2.TH
  7. -- | XXX: This is a temporary definition of 'Oscillator' for early
  8. -- prototyping purposes.
  9. data Oscillator
  10. = OscSine
  11. | OscSquare
  12. deriving (Eq, Show)
  13. -- | XXX: This is a temporary definition of 'Instrument' for early
  14. -- prototyping purposes.
  15. data Instrument = Instrument
  16. { _instrSource :: Oscillator
  17. } deriving (Eq, Show)
  18. $(makeLenses ''Instrument)
  19. -- | We'll maintain a list of instruments and refer to them using
  20. -- indices. For type safety, here is a wrapper around those
  21. -- indices.
  22. newtype InstrRef = InstrRef { _fromInstrRef :: Int }
  23. deriving (Eq, Show)
  24. $(makeLenses ''InstrRef)
  25. -- | A 'Note' here is an individual element of a scale, which we'll
  26. -- maintain a unique list of on a per-song basis, and most of the time
  27. -- we'll use indices into that list. A 'Note' has a frequency represented
  28. -- in cents and an appearance that the user will see when running the
  29. -- program, which should be no more than a few characters long.
  30. data Note = Note
  31. { _noteCents :: Double
  32. , _noteAppearance :: Text
  33. } deriving (Eq, Show)
  34. $(makeLenses ''Note)
  35. -- | We'll maintain a list of notes and refer to them using indices. For type
  36. -- safety, here is a wrapper around those indices.
  37. newtype NoteRef = NoteRef { _fromNoteRef :: Int }
  38. deriving (Eq, Show)
  39. $(makeLenses ''NoteRef)
  40. -- | A 'Scale' has a name, a total number of cents (which will almost always be
  41. -- 1200 for traditional scales) and a list of notes associated with it.
  42. data Scale = Scale
  43. { _scaleName :: Text
  44. , _scaleTotalCents :: Double
  45. , _scaleNotes :: Seq Note
  46. } deriving (Eq, Show)
  47. $(makeLenses ''Scale)
  48. -- | An 'Event' is a typical event associated with a song.
  49. data Event = Event
  50. deriving (Eq, Show)
  51. data Beats
  52. = BeatsSimple Word8
  53. | BeatsAdditive [Word8]
  54. | BeatsFractional Word8 Word8
  55. deriving (Eq, Show)
  56. $(makeTraversals ''Beats)
  57. data Signature = Signature
  58. { _sigPerBar :: Beats
  59. , _sigBeatUnit :: Word8
  60. } deriving (Eq, Show)
  61. $(makeLenses ''Signature)
  62. data TrackChunk = TrackChunk
  63. { _tcSignature :: Signature
  64. } deriving (Eq, Show)
  65. data Track = Track
  66. {
  67. } deriving (Eq, Show)
  68. data Song = Song
  69. { _songScale :: Scale
  70. , _songTracks :: Seq Track
  71. } deriving (Eq, Show)
  72. $(makeLenses ''Song)