Skip to content

Commit

Permalink
exolang launch function gets WebAudioContext as a member of object it…
Browse files Browse the repository at this point in the history
… is passed
  • Loading branch information
dktr0 committed Nov 6, 2024
1 parent 081cebc commit f99b438
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
7 changes: 4 additions & 3 deletions client/src/Estuary/Languages/ExoLang.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions client/src/Estuary/Render/RenderEnvironment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f99b438

Please sign in to comment.