-
Notifications
You must be signed in to change notification settings - Fork 0
/
MusicBox.elm
47 lines (35 loc) · 977 Bytes
/
MusicBox.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
port module MusicBox exposing (..)
-- library functions
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
-- program
type alias Note =
{ tone : String
, duration : String
}
type Msg
= PlayMiddleCNote | PlayDNote
view model =
div [ class "container" ]
[
h1 [] [ text "Let's Play!" ],
button [ type_ "button", class "btn-warning", onClick PlayMiddleCNote ] [ text "Middle-C" ],
button [ type_ "button", class "btn", onClick PlayDNote ] [ text "Middle-D" ]
]
port play : Note -> Cmd msg
update msg model =
case msg of
PlayMiddleCNote ->
( model, play { tone = "C4", duration = "8n" } )
PlayDNote ->
(model, play { tone = "D3", duration = "8n"})
init =
( {}, Cmd.none )
main =
Html.program
{ init = init
, view = view
, update = update
, subscriptions = \_ -> Sub.none
}