Skip to content

Commit

Permalink
Simplifies patched subgraph signature
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Solomon committed Mar 15, 2022
1 parent 5d54433 commit f758642
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 36 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.7.2] - 2022-03-15

- Simplifies patched subgraph signature

## [0.7.1] - 2022-03-15

- Adds updating for single subgraph
Expand Down
20 changes: 6 additions & 14 deletions examples/patching/Patching.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Data.Foldable (for_)
import Data.Identity (Identity(..))
import Data.Maybe (Maybe(..))
import Data.Newtype (unwrap)
import Data.Tuple (Tuple(..))
import Data.Tuple (Tuple(..), fst)
import Data.Tuple.Nested (type (/\))
import Data.Typelevel.Num (class Lt, class Pred, D0, D40, d39, pred)
import Data.Vec as V
Expand All @@ -31,11 +31,11 @@ import WAGS.Control.Functions.Graph (iloop, (@!>))
import WAGS.Control.Functions.Subgraph as SG
import WAGS.Control.Indexed (IxWAG)
import WAGS.Control.Types (Frame0, Scene, SubScene)
import WAGS.Create.Optionals (gain, input, playBuf, subgraphSingleSetter)
import WAGS.Create.Optionals (gain, input, playBuf, subgraph, subgraphSingleSetter)
import WAGS.Graph.AudioUnit (TGain, TSinOsc, TSpeaker, TSubgraph)
import WAGS.Graph.Parameter (_off, _on)
import WAGS.Interpret (class AudioInterpret, AsSubgraph(..), close, context, decodeAudioDataFromUri, makeFFIAudioSnapshot)
import WAGS.Patch (PatchedSubgraphInput(..), ipatch)
import WAGS.Interpret (class AudioInterpret, close, context, decodeAudioDataFromUri, makeFFIAudioSnapshot)
import WAGS.Patch (ipatch)
import WAGS.Run (RunAudio, RunEngine, TriggeredRun, TriggeredScene(..), runNoLoop)
import WAGS.WebAPI (AudioContext, BrowserAudioBuffer)

Expand Down Expand Up @@ -151,16 +151,8 @@ createFrame atar =
{ microphone: Nothing
, mediaElement: Nothing
, subgraphs:
{ sg: PatchedSubgraphInput
{ controls: vec
, scenes: AsSubgraph (\i _ -> subPiece0 i atar)
, envs: (const $ const $ SGWorld false)
}
, sg2: PatchedSubgraphInput
{ controls: vec
, scenes: AsSubgraph (\i _ -> subPiece1 i)
, envs: (const $ const $ SGWorld false)
}
{ sg: fst (subgraph vec (\i _ -> subPiece0 i atar) (const $ const $ SGWorld false) {})
, sg2: fst (subgraph vec(\i _ -> subPiece1 i) (const $ const $ SGWorld false) {})
}
, tumults: {}
} :*> ichange' (Proxy :: _ "gn") 1.0
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "purescript-wags",
"version": "0.7.1",
"version": "0.7.2",
"description": "Web Audio Graphs as a Stream",
"scripts": {
"build": "spago build",
Expand Down
27 changes: 6 additions & 21 deletions src/WAGS/Patch.purs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import WAGS.Control.Indexed (IxWAG(..))
import WAGS.Control.Types (WAG, unsafeUnWAG, unsafeWAG)
import WAGS.Graph.AudioUnit (TSubgraph, TTumult)
import WAGS.Graph.AudioUnit as AU
import WAGS.Graph.AudioUnit as CTOR
import WAGS.Graph.Graph (Graph)
import WAGS.Graph.Oversample (class IsOversample, reflectOversample)
import WAGS.Graph.Paramable (onOffIze, paramize)
Expand Down Expand Up @@ -757,41 +758,25 @@ class GetSubgraphsRL (g :: RowList Type) subgraphs | g -> subgraphs where
instance getSubgraphsRLNil :: GetSubgraphsRL RL.Nil subgraphs where
getSubgraphsRL _ _ = Object.empty

newtype PatchedSubgraphInput (n :: Type) terminus inputs env a = PatchedSubgraphInput
( { controls :: Vec n a
, envs :: Int -> a -> env
, scenes :: AsSubgraph terminus inputs a env
}
)

unPatchedSubgraph
:: forall n terminus inputs env a
. PatchedSubgraphInput n terminus inputs env a
-> { controls :: Vec n a
, envs :: Int -> a -> env
, scenes :: AsSubgraph terminus inputs a env
}
unPatchedSubgraph (PatchedSubgraphInput x) = x

instance getSubgraphsRLTumult ::
( IsSymbol id
, IsSymbol terminus
, Pos n
, Row.Cons id (PatchedSubgraphInput n terminus inputs env a) r' subgraphs
, Row.Cons id (CTOR.Subgraph inputs (Vec n info) (AsSubgraph terminus inputs info env) (Int -> info -> env)) r' subgraphs
, GetSubgraphsRL rest subgraphs
) =>
GetSubgraphsRL (RL.Cons id (TSubgraph n terminus inputs env /\ whatever) rest) subgraphs where
getSubgraphsRL _ t = Object.insert id
( AE
( let
unpatched = unPatchedSubgraph (get (Proxy :: _ id) t)
(CTOR.Subgraph vec asSub env) = get (Proxy :: _ id) t
in
makeSubgraph
{ id
, terminus: Proxy :: _ terminus
, controls: unpatched.controls
, envs: unpatched.envs
, scenes: unAsSubGraph unpatched.scenes
, controls: vec
, envs: env
, scenes: unAsSubGraph asSub
}
)
)
Expand Down

0 comments on commit f758642

Please sign in to comment.