diff --git a/client/src/Estuary/Languages/ExoLang.hs b/client/src/Estuary/Languages/ExoLang.hs index d97830ef..baf51e52 100644 --- a/client/src/Estuary/Languages/ExoLang.hs +++ b/client/src/Estuary/Languages/ExoLang.hs @@ -43,8 +43,8 @@ instance PToJSVal ExoLangClass where pToJSVal (ExoLangClass x) = x instance PFromJSVal ExoLangClass where pFromJSVal = ExoLangClass foreign import javascript safe - "$r = $2.exoLang($1);" - exoLangClass :: HTMLCanvasElement -> JSVal -> IO ExoLangClass + "$1.webAudioContext = $2; $r = $3.exoLang($1);" + exoLangClass :: HTMLCanvasElement -> MusicW.AudioContext -> JSVal -> IO ExoLangClass _loadExoLang :: HTMLCanvasElement -> Text -> IO ExoLangClass _loadExoLang canvas path = do @@ -54,7 +54,8 @@ _loadExoLang canvas path = do Left j -> throwIO (JSException j) Right j -> pure j putStrLn $ "loaded exolang from " ++ unpack path - elc <- exoLangClass canvas exoLangModule + webAudioContext <- MusicW.getGlobalAudioContext + elc <- exoLangClass canvas webAudioContext exoLangModule putStrLn $ " hasFunction define: " ++ show (hasFunction "define" elc) putStrLn $ " has deprecated function evaluate: " ++ show (hasFunction "evaluate" elc) putStrLn $ " hasFunction clear: " ++ show (hasFunction "clear" elc) diff --git a/client/src/Estuary/Render/RenderEnvironment.hs b/client/src/Estuary/Render/RenderEnvironment.hs index 59b6c823..e6cb4940 100644 --- a/client/src/Estuary/Render/RenderEnvironment.hs +++ b/client/src/Estuary/Render/RenderEnvironment.hs @@ -171,10 +171,6 @@ updateActiveRenderers rEnv = liftIO $ do writeIORef (activeRenderers rEnv) newActiveRenderers mapM_ (initializeRenderer rEnv) $ Map.difference newActiveRenderers prevActiveRenderers --- work in progress (above) --- the function above needs to change so that when a new renderer is added to activeRenderers it is 'initialized' (all setters called) --- initializeRenderer :: MonadIO m => RenderEnvironment -> Renderer -> m () - getActiveRenderers :: MonadIO m => RenderEnvironment -> m (Map.Map Text Renderer) getActiveRenderers rEnv = liftIO $ readIORef (activeRenderers rEnv) @@ -240,7 +236,6 @@ setNchnls rEnv x = liftIO $ do readIORef (activeRenderers rEnv) >>= mapM_ (flip Renderer.setNchnls $ x) --- TODO: this function needs to be called (for every new renderer that becomes active) -- a function to call setters with initial values when a new renderer becomes active initializeRenderer :: MonadIO m => RenderEnvironment -> Renderer -> m () initializeRenderer rEnv r = liftIO $ do