initJack :: IO [(String, [LispVal] -> IO LispVal)]
initJack = do
    -- In this function we fork twice.
    --
    -- The first fork is a real system fork to provide us with two seperate
    -- processes. This is needed because the Jack clients run unstable when it
    -- runs together with OpenGLs mainLoop.
    -- For now, both proccesses communicate with a pipe.
    -- TODO: Exit process when pipe is closed/broken
    (rfd, wfd) <- createPipe
    forkProcess $ capture wfd "Flowskell" ["input"]

    -- The following fork just creates a thread which will read from the pipe
    -- and store the result in an MVar.
    stvar <- newMVar 0.0
    forkIO $ forever $ do
        (str, cnt) <- fdRead rfd 10
        case str of
            "" -> return 0.0
            _  -> swapMVar stvar (decode $ head str)

    -- Finally, return a Scheme function to access the MVar
    return [("snd-level", getActivation stvar)]
initJack :: IO [(String, [LispVal] -> IO LispVal)]
initJack = do
    -- In this function we fork twice.
    --
    -- The first fork is a real system fork to provide us with two seperate
    -- processes. This is needed because the Jack clients run unstable when it
    -- runs together with OpenGLs mainLoop.
    -- For now, both proccesses communicate with a pipe.
    -- TODO: Exit process when pipe is closed/broken
    (rfd, wfd) <- createPipe
    forkProcess $ capture wfd "Flowskell" ["input"]

    -- The following fork just creates a thread which will read from the pipe
    -- and store the result in an MVar.
    stvar <- newMVar 0.0
    forkIO $ forever $ do
        (str, cnt) <- fdRead rfd 10
        case str of
            "" -> return 0.0
            _  -> swapMVar stvar (decode $ head str)

    -- Finally, return a Scheme function to access the MVar
    return [("snd-level", getActivation stvar)]
initJack = do
    -- In this function we fork twice.
    --
    -- The first fork is a real system fork to provide us with two seperate
    -- processes. This is needed because the Jack clients run unstable when it
    -- runs together with OpenGLs mainLoop.
    -- For now, both proccesses communicate with a pipe.
    -- TODO: Exit process when pipe is closed/broken
    (rfd, wfd) <- createPipe
    forkProcess $ capture wfd "Flowskell" ["input"]

    -- The following fork just creates a thread which will read from the pipe
    -- and store the result in an MVar.
    stvar <- newMVar 0.0
    forkIO $ forever $ do
        (str, cnt) <- fdRead rfd 10
        case str of
            "" -> return 0.0
            _  -> swapMVar stvar (decode $ head str)

    -- Finally, return a Scheme function to access the MVar
    return [("snd-level", getActivation stvar)]