packages feed

hosc-utils-0.14: hs/json-ws.hs

import Control.Monad {- base -}
import qualified Network.WebSockets as W {- websockets -}

import U

go :: WithT -> W.WebSockets W.Hybi00 ()
go withT = W.receiveData >>= proc_t withT

json_ws :: WithT -> W.Request -> W.WebSockets W.Hybi00 ()
json_ws withT rq = do
    W.acceptRequest rq
    forever (go withT)

main :: IO ()
main = do
  Opt t h w <- opt_arg
  W.runServer h w (json_ws t)

{-
json-ws.00

import Sound.SC3

let {kin = in' 1 KR
    ;o = sinOsc AR (kin 0) 0}
in audition (out 0 (pan2 o (kin 2) (kin 1)))

json-ws.02

let {kin = in' 1 KR
    ;f = kin 0 * 600 + 400
    ;a = kin 1 * 0.1}
in audition (out 0 (sinOsc AR f 0 * a))

json-ws.03

let {k0 = control KR "k0" 440
    ;k1 = control KR "k1" 0
    ;k2 = control KR "k2" 0.1
    ;k3 = control KR "k3" 0}
in audition (out k3 (sinOsc AR k0 k1 * k2))

withSC3 (send (n_set (-1) [("k0",660)]))
withSC3 (send (n_set (-1) [("k2",0.01)]))
-}