1 {-# LANGUAGE MultiParamTypeClasses, ScopedTypeVariables, TupleSections #-}
5 import Control.Concurrent
6 import Data.ReactiveValue
9 import Graphics.UI.Gtk.Board.BoardLink
10 import Graphics.UI.Gtk.Layout.BackgroundContainer
12 import RMCA.Auxiliary.RV
14 import RMCA.GUI.Buttons
15 import RMCA.GUI.LayerSettings
16 import RMCA.GUI.MainSettings
17 import RMCA.GUI.NoteSettings
18 import RMCA.Layer.Board
20 import RMCA.Translator.Jack
28 mainBox <- hBoxNew False 10
29 set window [ windowTitle := "Reactogon"
30 , containerChild := mainBox
31 , containerBorderWidth := 10
35 boardQueue <- newCBMVarRW mempty
36 chanRV <- newCBMVarRW 0
38 settingsBox <- vBoxNew False 0
39 boxPackEnd mainBox settingsBox PackNatural 0
40 (globalSettingsBox, tempoRV) <- globalSettings
41 boxPackStart settingsBox globalSettingsBox PackNatural 0
42 globalSep <- hSeparatorNew
43 boxPackStart settingsBox globalSep PackNatural 0
45 (layerSettingsVBox, layerRV) <- layerSettings chanRV boardQueue
46 boxPackStart settingsBox layerSettingsVBox PackNatural 0
47 laySep <- hSeparatorNew
48 boxPackStart settingsBox laySep PackNatural 0
50 (buttonBox, playRV, stopRV, pauseRV, recordRV) <- getButtons
51 boxPackEnd settingsBox buttonBox PackNatural 0
54 boardCont <- backgroundContainerNew
56 guiBoard <- attachGameRules game
57 centerBoard <- alignmentNew 0.5 0.5 0 0
58 containerAdd centerBoard guiBoard
59 containerAdd boardCont centerBoard
60 boxPackStart mainBox boardCont PackNatural 0
61 --boxPackStart mainBox boardCont PackNatural 0
62 ------------------------------------------------------------------------------
64 layer <- reactiveValueRead layerRV
65 tempo <- reactiveValueRead tempoRV
66 (boardRV, pieceArrRV, phRV) <- initBoardRV guiBoard
67 reactiveValueOnCanRead playRV
68 (reactiveValueRead boardRV >>= reactiveValueWrite phRV . startHeads)
69 reactiveValueOnCanRead stopRV $ reactiveValueWrite phRV []
70 board <- reactiveValueRead boardRV
71 ph <- reactiveValueRead phRV
72 (inBoard, outBoard) <- yampaReactiveDual (board, layer, ph, tempo) boardSF
73 let tempoRV' = liftR2 (\bool t -> t * fromEnum (not bool)) pauseRV tempoRV
75 boardRV layerRV phRV tempoRV'
76 --let inRV = onTick clock inRV
78 reactiveValueOnCanRead outBoard $
79 reactiveValueRead (liftR (event mempty (,[]) <<< snd <<< splitE) outBoard) >>=
80 reactiveValueAppend boardQueue
81 -- This needs to be set last otherwise phRV is written to, so
82 -- inBoard is written to and the notes don't get played. There
83 -- supposedly is no guaranty of order but apparently there is…
84 fmap fst <^> outBoard >:> phRV
85 putStrLn "Board started."
87 forkIO $ jackSetup tempoRV chanRV boardQueue
89 pieceBox <- clickHandling pieceArrRV guiBoard =<< vBoxNew False 10
90 -- Piece characteristic
91 --pieceBox <- pieceButtons pieceArrRV guiBoard =<< vBoxNew False 10
92 ------------------------------------------------------------
94 boxPackStart settingsBox pieceBox PackNatural 10
95 onDestroy window mainQuit