Skip to content

Commit

Permalink
Simplifies subgraph signature
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Solomon committed Mar 16, 2022
1 parent f758642 commit 5d4edb2
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 101 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.3] - 2022-03-16

- Simplifies subgraph signature

## [0.7.2] - 2022-03-15

- Simplifies patched subgraph signature
Expand Down
9 changes: 6 additions & 3 deletions examples/patching/Patching.purs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,12 @@ createFrame atar =
{ microphone: Nothing
, mediaElement: Nothing
, subgraphs:
{ sg: fst (subgraph vec (\i _ -> subPiece0 i atar) (const $ const $ SGWorld false) {})
, sg2: fst (subgraph vec(\i _ -> subPiece1 i) (const $ const $ SGWorld false) {})
}
let
envs = V.fill $ const $ SGWorld false :: V.Vec D40 SGWorld
in
{ sg: fst (subgraph envs (flip subPiece0 atar) {})
, sg2: fst (subgraph envs (subPiece1) {})
}
, tumults: {}
} :*> ichange' (Proxy :: _ "gn") 1.0
:*> ichange' (Proxy :: _ "beep") { freq: 550.0, onOff: _on }
Expand Down
30 changes: 15 additions & 15 deletions examples/subgraph/Subgraph.purs
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,18 @@ piece :: Scene (BehavingScene Unit World ()) RunAudio RunEngine Frame0 Unit
piece = mempty # loopUsingScene \(BehavingScene env) _ ->
{ control: unit
, scene: speaker
{ gn: gain 1.0
{ sg: subgraph vec
(\i _ -> subPiece0 i env.world.atar)
(const $ const $ SGWorld env.time)
{}
, sg2: subgraph vec
(\i _ -> subPiece1 i)
(const $ const $ SGWorld env.time)
{ beep: sinOsc 440.0 }
}
}
let
envs = (V.fill $ const $ SGWorld env.time :: V.Vec D40 SGWorld)
in
{ gn: gain 1.0
{ sg: subgraph envs
(flip subPiece0 env.world.atar)
{}
, sg2: subgraph envs
(subPiece1)
{ beep: sinOsc 440.0 }
}
}
}

easingAlgorithm :: Cofree ((->) Int) Int
Expand All @@ -89,8 +90,7 @@ main =
body <- awaitBody
runUI component unit body

type State
=
type State =
{ unsubscribe :: Effect Unit
, audioCtx :: Maybe AudioContext
, freqz :: Array String
Expand Down Expand Up @@ -142,8 +142,8 @@ handleAction = case _ of
unsubscribe <-
H.liftEffect
$ subscribe
(run (pure unit) (pure { atar }) { easingAlgorithm } (ffiAudio) piece)
(\(_ :: BehavingRun Unit ()) -> pure unit)
(run (pure unit) (pure { atar }) { easingAlgorithm } (ffiAudio) piece)
(\(_ :: BehavingRun Unit ()) -> pure unit)
H.modify_ _ { unsubscribe = unsubscribe, audioCtx = Just audioCtx }
StopAudio -> do
{ unsubscribe, audioCtx } <- H.get
Expand Down
7 changes: 3 additions & 4 deletions examples/tumult/Tumult.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Control.Comonad.Cofree (Cofree, mkCofree)
import Data.Foldable (for_)
import Data.Maybe (Maybe(..))
import Data.Typelevel.Num (D1)
import Data.Vec ((+>))
import Data.Vec (singleton, (+>))
import Data.Vec as V
import Effect (Effect)
import Effect.Aff.Class (class MonadAff)
Expand Down Expand Up @@ -78,9 +78,8 @@ piece = mempty # loopUsingScene \(BehavingScene env) _ ->
{ control: unit
, scene: speaker
{ gn: gain 1.0
{ sg2: subgraph vec
(\i _ -> subPiece1 i)
(const $ const $ SGWorld env.time)
{ sg2: subgraph (singleton $ SGWorld env.time)
(subPiece1)
{ beep: loopBuf env.world.shruti }
}
}
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.2",
"version": "0.7.3",
"description": "Web Audio Graphs as a Stream",
"scripts": {
"build": "spago build",
Expand Down
6 changes: 3 additions & 3 deletions src/WAGS/Change.purs
Original file line number Diff line number Diff line change
Expand Up @@ -1820,10 +1820,10 @@ instance changeSubgraph0 ::
, Pos n
, R.Cons ptr (NodeC (CTOR.TSubgraph n terminus inputs env) edges) ignore graph
) =>
Change' ptr (CTOR.Subgraph inputs (V.Vec n info) doesntMatterWillNotBeUsed (Int -> info -> env)) graph where
Change' ptr (CTOR.Subgraph inputs doesntMatterWillNotBeUsed (V.Vec n env)) graph where
change' ptr w = o
where
{ context: i, value: (CTOR.Subgraph vec _ env) } = unsafeUnWAG w
{ context: i, value: (CTOR.Subgraph _ env) } = unsafeUnWAG w

nn = reflectSymbol ptr

Expand All @@ -1832,7 +1832,7 @@ instance changeSubgraph0 ::
{ context:
i
{ instructions = i.instructions <>
[ setSubgraph { id: nn, controls: vec, envs: env } ]
[ setSubgraph { id: nn, envs: env } ]
}
, value: unit
}
Expand Down
12 changes: 6 additions & 6 deletions src/WAGS/Create.purs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ instance createStepRLNil :: CreateStepRL RL.Nil prefix map r inGraph inGraph whe
createStepRL _ _ _ r = r $> unit
instance createStepRLConsB ::
( IsSymbol key
, R.Cons key (Tuple (CTOR.Subgraph inputs subgraphGenerator subgraphMaker env) ignoreMe) ignore r
, R.Cons key (Tuple (CTOR.Subgraph inputs subgraphMaker env) ignoreMe) ignore r
, MakePrefixIfNeeded key prefix prefix'
, ConstructEdges prefix' map (Tuple (CTOR.Subgraph inputs subgraphGenerator subgraphMaker env) ignoreMe) newPrefix newMap (node /\ { | edges })
, ConstructEdges prefix' map (Tuple (CTOR.Subgraph inputs subgraphMaker env) ignoreMe) newPrefix newMap (node /\ { | edges })
, CoercePrefixToString prefix realPrefix
, Sym.Append realPrefix key newKey
, RL.RowToList edges edgesRL
Expand All @@ -63,7 +63,7 @@ instance createStepRLConsB ::
, CreateStepRL rest prefix map r graph1 graph2
, Create' newKey node graph2 graph3
) =>
CreateStepRL (RL.Cons key (Tuple (CTOR.Subgraph inputs subgraphGenerator subgraphMaker env) ignoreMe) rest) prefix map r graph0 graph3 where
CreateStepRL (RL.Cons key (Tuple (CTOR.Subgraph inputs subgraphMaker env) ignoreMe) rest) prefix map r graph0 graph3 where
createStepRL _ _ _ r = step3
where
rx = extract r
Expand Down Expand Up @@ -990,17 +990,17 @@ instance createSubgraph ::
, R.Lacks ptr graphi
, R.Cons ptr (NodeC (CTOR.TSubgraph n terminus inputs env) {}) graphi grapho
) =>
Create' ptr (CTOR.Subgraph inputs (V.Vec n info) (AsSubgraph terminus inputs info env) (Int -> info -> env)) graphi grapho where
Create' ptr (CTOR.Subgraph inputs (AsSubgraph terminus inputs env) (V.Vec n env)) graphi grapho where
create' ptr w = o
where
{ context: i, value: (CTOR.Subgraph vec asSub env) } = unsafeUnWAG w
{ context: i, value: (CTOR.Subgraph asSub env) } = unsafeUnWAG w
nn = reflectSymbol ptr
o =
unsafeWAG
{ context:
i
{ instructions = i.instructions <>
[ makeSubgraph { id: nn, terminus: Proxy :: _ terminus, controls: vec, envs: env, scenes: unAsSubGraph asSub } ]
[ makeSubgraph { id: nn, terminus: Proxy :: _ terminus, envs: env, scenes: unAsSubGraph asSub } ]
}
, value: unit
}
Expand Down
23 changes: 10 additions & 13 deletions src/WAGS/Create/Optionals.purs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,27 +1002,24 @@ type CStereoPanner a
-- | ```
-- | the validity of inputs with respect to r is validated higher upstream (at the scene construction level)
subgraph
:: forall n inputs info terminus env r
:: forall n inputs terminus env r
. Pos n
=> V.Vec n info
=> V.Vec n env
-> ( forall audio engine
. AudioInterpret audio engine
=> Int
-> info
-> SubScene terminus inputs env audio engine Frame0 Unit
)
-> (Int -> info -> env)
-> r
-> (CTOR.Subgraph inputs (V.Vec n info) (AsSubgraph terminus inputs info env) (Int -> info -> env)) /\ r
subgraph vec sg ev = Tuple (CTOR.Subgraph vec (AsSubgraph sg) ev)
-> (CTOR.Subgraph inputs (AsSubgraph terminus inputs env) (V.Vec n env)) /\ r
subgraph ev sg = Tuple (CTOR.Subgraph (AsSubgraph sg) ev)

subgraphSetter
:: forall n inputs info env
:: forall n inputs env
. Pos n
=> V.Vec n info
-> (Int -> info -> env)
-> (CTOR.Subgraph inputs (V.Vec n info) Unit (Int -> info -> env))
subgraphSetter vec ev = CTOR.Subgraph vec unit ev
=> V.Vec n env
-> (CTOR.Subgraph inputs Unit (V.Vec n env))
subgraphSetter vec = CTOR.Subgraph unit vec

subgraphSingleSetter
:: forall n env
Expand All @@ -1032,8 +1029,8 @@ subgraphSingleSetter
-> ChangeSubgraph n env
subgraphSingleSetter c ev = ChangeSubgraph (c /\ ev)

type CSubgraph (n :: Type) info terminus inputs env r
= (CTOR.Subgraph inputs (V.Vec n info) (AsSubgraph terminus inputs info env) (Int -> info -> env)) /\ r
type CSubgraph (n :: Type) terminus inputs env r
= (CTOR.Subgraph inputs (AsSubgraph terminus inputs env) (V.Vec n env) ) /\ r

------
data TriangleOsc
Expand Down
2 changes: 1 addition & 1 deletion src/WAGS/CreateT.purs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ instance createSubgraph ::
( R.Lacks ptr graphi
, R.Cons ptr (NodeC (CTOR.TSubgraph n terminus inputs env) {}) graphi grapho
) =>
CreateT' ptr (CTOR.Subgraph inputs (V.Vec n info) (AsSubgraph terminus inputs info env) (Int -> info -> env)) graphi grapho
CreateT' ptr (CTOR.Subgraph inputs (AsSubgraph terminus inputs env) (V.Vec n env)) graphi grapho

instance createTTriangleOsc ::
( R.Lacks ptr graphi
Expand Down
9 changes: 4 additions & 5 deletions src/WAGS/Graph/AudioUnit.purs
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,12 @@ instance typeToSymStereoPanner :: TypeToSym (StereoPanner pan) "StereoPanner"

-- | Term-level constructor for a subgraph
-- | - `inputs` - the inputs to the subgraph
-- | - `subgraphGenerator` - the generating vector for the subgraph
-- | - `subgraphMaker` - the scene that makes the subgraph
-- | - `enc` - the scene that makes the subgraph
data Subgraph (inputs :: Row Type) subgraphGenerator subgraphMaker env
= Subgraph subgraphGenerator subgraphMaker env
data Subgraph (inputs :: Row Type) subgraphMaker env
= Subgraph subgraphMaker env

instance typeToSymSubgraph :: TypeToSym (Subgraph inputs subgraphGenerator subgraphMaker env) "Subgraph"
instance typeToSymSubgraph :: TypeToSym (Subgraph inputs subgraphMaker env) "Subgraph"

-- | Term-level constructor for a triangle oscillator.
-- | - `onOff` - whether the generator is on or off.
Expand Down Expand Up @@ -721,7 +720,7 @@ instance semigroupTSubgraph :: Semigroup (TSubgraph arity terminus inputs env) w
instance monoidTSubgraph :: Monoid (TSubgraph arity terminus inputs env) where
mempty = TSubgraph

instance reifyTSubgraph :: ReifyAU (Subgraph a b c d) (TSubgraph w x y z) where
instance reifyTSubgraph :: ReifyAU (Subgraph a b c) (TSubgraph w x y z) where
reifyAU = const mempty

-- | Type-level constructor for a triangle oscillator.
Expand Down
18 changes: 7 additions & 11 deletions src/WAGS/Interpret.js
Original file line number Diff line number Diff line change
Expand Up @@ -750,23 +750,22 @@ exports.makeInput_ = function (ptr) {

exports.makeSubgraph_ = function (ptr) {
return function (terminalPtr) {
return function (vek) {
return function (envs) {
return function (sceneM) {
return function (envM) {
return function (funk) {
return function (state) {
return function () {
var children = [];
var scenes = [];
for (var i = 0; i < vek.length; i++) {
for (var i = 0; i < envs.length; i++) {
children[i] = {
context: state.context,
writeHead: state.writeHead,
units: {},
unqidfr: makeid(10),
parent: state,
};
scenes[i] = sceneM(i)(vek[i]);
scenes[i] = sceneM(i);
}
state.units[ptr] = {
outgoing: [],
Expand All @@ -779,7 +778,7 @@ exports.makeSubgraph_ = function (ptr) {
};
state.units[ptr].main.gain.value = 1.0;
for (var i = 0; i < scenes.length; i++) {
var applied = funk(envM(i)(vek[i]))(scenes[i]);
var applied = funk(envs[i])(scenes[i]);
for (var j = 0; j < applied.instructions.length; j++) {
// thunk
applied.instructions[j](children[i])();
Expand All @@ -796,7 +795,6 @@ exports.makeSubgraph_ = function (ptr) {
};
};
};
};
/**
*
* String
Expand Down Expand Up @@ -1148,17 +1146,16 @@ exports.setInput_ = function (ptr) {
};

exports.setSubgraph_ = function (ptr) {
return function (vek) {
return function (envM) {
return function (envs) {
return function (state) {
return function () {
for (var i = 0; i < vek.length; i++) {
for (var i = 0; i < envs.length; i++) {
state.units[ptr].children[i].writeHead = state.writeHead;
}
var scenes = state.units[ptr].scenes;
var children = state.units[ptr].children;
for (var i = 0; i < scenes.length; i++) {
var applied = state.units[ptr].funk(envM(i)(vek[i]))(scenes[i]);
var applied = state.units[ptr].funk(envs[i])(scenes[i]);
for (var j = 0; j < applied.instructions.length; j++) {
// thunk
applied.instructions[j](children[i])();
Expand All @@ -1169,7 +1166,6 @@ exports.setSubgraph_ = function (ptr) {
};
};
};
};

exports.setSingleSubgraph_ = function (ptr) {
return function (i) {
Expand Down
Loading

0 comments on commit 5d4edb2

Please sign in to comment.