@@ -5,7 +5,6 @@ import Prelude
5
5
import Control.Alt (alt , (<|>))
6
6
import Control.Monad.ST.Class (liftST )
7
7
import Control.Monad.ST.Internal as RRef
8
- import Control.Plus (empty )
9
8
import Data.Array ((..))
10
9
import Data.ArrayBuffer.Typed (toArray )
11
10
import Data.Foldable (for_ , intercalate , fold )
@@ -27,8 +26,8 @@ import Effect.Class (liftEffect)
27
26
import FRP.Behavior (sample_ )
28
27
import FRP.Event (Event , create , filterMap , hot , sampleOnRight , subscribe )
29
28
import FRP.Event.Animate (animationFrameEvent )
30
- import Ocarina.Clock (WriteHead , fot , writeHead )
31
- import Ocarina.Control (analyser , gain , loopBuf , speaker2 )
29
+ import Ocarina.Clock (WriteHead , fot , writeHead )
30
+ import Ocarina.Control (analyser_ , gain_ , loopBuf , speaker2 )
32
31
import Ocarina.Core (Audible , bangOn , opticN )
33
32
import Ocarina.Example.Utils (RaiseCancellation )
34
33
import Ocarina.Interpret (close , context , decodeAudioDataFromUri , effectfulAudioInterpret , getByteFrequencyData , makeFFIAudioSnapshot )
@@ -41,25 +40,25 @@ scene
41
40
-> AnalyserNodeCb
42
41
-> WriteHead Event
43
42
-> Audible D2 payload
44
- scene atar cb wh =
43
+ scene buffer cb wh =
45
44
let
46
45
tr = fot wh (mul pi)
47
46
in
48
- analyser { cb } empty
49
- [ gain 1.0 empty
50
- [ gain 0.3 empty
51
- [ loopBuf { buffer: atar , playbackRate: 1.0 }
47
+ analyser_ { cb }
48
+ [ gain_ 1.0
49
+ [ gain_ 0.3
50
+ [ loopBuf { buffer, playbackRate: 1.0 }
52
51
( bangOn <|>
53
52
playbackRate <<<
54
- ( over opticN (\rad -> 1.0 + 0.1 * sin rad) ) <$> tr
53
+ over opticN (\rad -> 1.0 + 0.1 * sin rad) <$> tr
55
54
)
56
55
]
57
- , gain 0.15 empty
58
- [ loopBuf { buffer: atar , playbackRate: 1.0 }
56
+ , gain_ 0.15
57
+ [ loopBuf { buffer, playbackRate: 1.0 }
59
58
( bangOn
60
59
<|>
61
60
playbackRate <<<
62
- ( over opticN (\rad -> 1.5 + 0.1 * sin (2.0 * rad) ))
61
+ over opticN (\rad -> 1.5 + 0.1 * sin (2.0 * rad))
63
62
<$> tr
64
63
<|>
65
64
loopStart <<< (\rad -> 0.1 + 0.1 * sin rad)
@@ -70,8 +69,7 @@ scene atar cb wh =
70
69
<<< view opticN <$> tr
71
70
)
72
71
]
73
- , gain 0.3 empty
74
- [ loopBuf { buffer: atar, playbackRate: 0.25 } bangOn ]
72
+ , gain_ 0.3 [ loopBuf { buffer, playbackRate: 0.25 } bangOn ]
75
73
]
76
74
]
77
75
@@ -83,16 +81,16 @@ data UIAction
83
81
type Init = BrowserAudioBuffer
84
82
85
83
initializeAtariSpeaks :: Aff Init
86
- initializeAtariSpeaks = do
87
- atar <- liftEffect context >>= flip decodeAudioDataFromUri
88
- " https://freesound.org/data/previews/100/100981_1234256-lq.mp3 "
89
- pure atar
84
+ initializeAtariSpeaks =
85
+ liftEffect context
86
+ >>= flip decodeAudioDataFromUri
87
+ " https://freesound.org/data/previews/100/100981_1234256-lq.mp3 "
90
88
91
89
atariSpeaks
92
90
:: BrowserAudioBuffer
93
91
-> RaiseCancellation
94
92
-> Nut
95
- atariSpeaks atar rc = bussed \push -> lcmap (alt (pure TurnOn )) \event ->
93
+ atariSpeaks atari rc = bussed \push -> lcmap (alt (pure TurnOn )) \event ->
96
94
DOM .div_
97
95
[ DOM .h1_ [ text_ " Atari speaks" ]
98
96
, DOM .button
@@ -109,7 +107,7 @@ atariSpeaks atar rc = bussed \push -> lcmap (alt (pure TurnOn)) \event ->
109
107
let wh = writeHead 0.04 ctx
110
108
let
111
109
audioE = speaker2
112
- [ scene atar
110
+ [ scene atari
113
111
( AnalyserNodeCb
114
112
( \a -> do
115
113
analyserE.push (Just a)
@@ -128,22 +126,10 @@ atariSpeaks atar rc = bussed \push -> lcmap (alt (pure TurnOn)) \event ->
128
126
( \(Tuple audio analyser) -> do
129
127
audio ffi2
130
128
for_ analyser \a -> do
131
- frequencyData <-
132
- getByteFrequencyData a
129
+ frequencyData <- getByteFrequencyData a
133
130
arr <- toArray frequencyData
134
- push $ AsciiMixer $
135
- intercalate " \n "
136
- ( map
137
- ( \ii ->
138
- fold
139
- ( ( 0 ..
140
- (toInt ii)
141
- ) $> " >"
142
- )
143
-
144
- )
145
- arr
146
- )
131
+ push $ AsciiMixer $ intercalate " \n " $
132
+ map (\ii -> fold ((0 .. toInt ii) $> " >" )) arr
147
133
)
148
134
let unsub = unsub' *> afe.unsubscribe
149
135
rc $ Just { unsub, ctx }
@@ -163,14 +149,14 @@ atariSpeaks atar rc = bussed \push -> lcmap (alt (pure TurnOn)) \event ->
163
149
)
164
150
]
165
151
[ text
166
- ( event # map case _ of
152
+ ( event <#> case _ of
167
153
TurnOn -> " Turn on"
168
154
_ -> " Turn off"
169
155
)
170
156
]
171
157
, DOM .p_
172
158
[ text
173
- ( event # map case _ of
159
+ ( event <#> case _ of
174
160
AsciiMixer s -> s
175
161
_ -> " "
176
162
)
@@ -179,5 +165,5 @@ atariSpeaks atar rc = bussed \push -> lcmap (alt (pure TurnOn)) \event ->
179
165
180
166
main :: Effect Unit
181
167
main = launchAff_ do
182
- atar <- initializeAtariSpeaks
183
- liftEffect $ runInBody (atariSpeaks atar (const $ pure unit))
168
+ atari <- initializeAtariSpeaks
169
+ liftEffect $ runInBody (atariSpeaks atari (const $ pure unit))
0 commit comments