Skip to content

Commit

Permalink
Chg (#12)
Browse files Browse the repository at this point in the history
* Revamps change mechanism

* Caches on/off

* Uses change in test

* Begins work on examples

* Begins work on examples

* Before slashing create

* Examples compile

* Sets flags for on/off

* Adds new files

* Adds new files

* Fixes example

* Updates change log

* Fixes test
  • Loading branch information
Mike Solomon authored Jun 6, 2021
1 parent 8a5775e commit bdaa704
Show file tree
Hide file tree
Showing 76 changed files with 3,648 additions and 2,869 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ 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.3.0] - 2021-06-06

### Added

- Simplifies `change` instructions. Now, instead of writing `{ sinOsc: sinOsc_ 440.0 }` it is possible to write `{ sinOsc: 440.0 }`.
- Speeds up rendering by avoiding unnecessary checks.

### Changed

- The `Optional` files are now split between `Create` and `Change`. This fixes many bugs where a default parameter in a `Create` accidentally modulated a value during a `Change`. Now, the `Change` default is `Nothing`, meaning nothing changes. Furthermore, the underscore syntax (`sinOsc_`) has been removed.

## [0.2.4] - 2021-06-05

### Added
Expand Down
11 changes: 6 additions & 5 deletions examples/atari-speaks/AtariSpeaks.purs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module WAGS.Example.AtariSpeaks where

import Prelude

import Control.Comonad.Cofree (Cofree, mkCofree)
import Control.Promise (toAffE)
import Data.Foldable (for_)
Expand All @@ -22,10 +23,10 @@ import WAGS.Change (ichange)
import WAGS.Control.Functions.Validated (iloop, (@!>))
import WAGS.Control.Types (Frame0, Scene)
import WAGS.Create (icreate)
import WAGS.Create.Optionals (CGain, CLoopBuf, CSpeaker, gain, loopBuf, speaker)
import WAGS.Graph.AudioUnit (TGain, TLoopBuf, TSpeaker)
import WAGS.Graph.Optionals (CGain, CLoopBuf, CSpeaker, gain, loopBuf, speaker)
import WAGS.Interpret (AudioContext, FFIAudio(..), close, context, decodeAudioDataFromUri, defaultFFIAudio, makeUnitCache)
import WAGS.Run (SceneI, run)
import WAGS.Run (RunAudio, SceneI, RunEngine, run)

vol = 1.4 :: Number

Expand Down Expand Up @@ -61,8 +62,8 @@ scene time =
{ loop1:
loopBuf
{ playbackRate: 1.5 + 0.1 * sin (2.0 * rad)
, start: 0.1 + 0.1 * sin rad
, end: 0.5 + 0.25 * sin (2.0 * rad)
, loopStart: 0.1 + 0.1 * sin rad
, loopEnd: 0.5 + 0.25 * sin (2.0 * rad)
}
"atar"
}
Expand All @@ -72,7 +73,7 @@ scene time =
}
}

piece :: Scene (SceneI Unit Unit) FFIAudio (Effect Unit) Frame0 Unit
piece :: Scene (SceneI Unit Unit) RunAudio RunEngine Frame0 Unit
piece = (_.time >>> scene >>> icreate) @!> iloop \{ time } _ -> ivoid $ ichange (scene time)

easingAlgorithm :: Cofree ((->) Int) Int
Expand Down
7 changes: 4 additions & 3 deletions examples/hello-world/HelloWorld.purs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module WAGS.Example.HelloWorld where

import Prelude

import Control.Comonad.Cofree (Cofree, mkCofree)
import Data.Functor.Indexed (ivoid)
import Data.Tuple.Nested (type (/\))
Expand All @@ -11,10 +12,10 @@ import WAGS.Change (ichange)
import WAGS.Control.Functions.Validated (iloop, (@!>))
import WAGS.Control.Types (Frame0, Scene)
import WAGS.Create (icreate)
import WAGS.Create.Optionals (CGain, CSpeaker, CSinOsc, gain, sinOsc, speaker)
import WAGS.Graph.AudioUnit (TGain, TSinOsc, TSpeaker)
import WAGS.Graph.Optionals (CGain, CSpeaker, CSinOsc, gain, sinOsc, speaker)
import WAGS.Interpret (FFIAudio(..), FFIAudio')
import WAGS.Run (SceneI, run)
import WAGS.Run (RunAudio, SceneI, RunEngine, run)

type SceneTemplate
= CSpeaker
Expand Down Expand Up @@ -48,7 +49,7 @@ scene time =
, gain3: gain 0.1 { sin3: sinOsc (530.0 + (19.0 * (5.0 * sin rad))) }
}

piece :: Scene (SceneI Unit Unit) FFIAudio (Effect Unit) Frame0 Unit
piece :: Scene (SceneI Unit Unit) RunAudio RunEngine Frame0 Unit
piece = (_.time >>> scene >>> icreate) @!> iloop \{ time } _ -> ivoid $ ichange (scene time)

easingAlgorithm :: Cofree ((->) Int) Int
Expand Down
2 changes: 1 addition & 1 deletion examples/kitchen-sink/KitchenSink.purs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ handleAction = case _ of
unitCache <- H.liftEffect makeUnitCache
myWave <-
H.liftEffect
$ makePeriodicWave audioCtx (0.3 +> -0.1 +> empty) (-0.25 +> 0.05 +> empty)
$ makePeriodicWave audioCtx (0.0 +> -0.1 +> empty) (0.0 +> 0.05 +> empty)
wicked <- H.liftEffect $ makeFloatArray (makeDistortionCurve 400.0)
let
recorder =
Expand Down
2 changes: 1 addition & 1 deletion examples/kitchen-sink/KitchenSink/Piece.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import WAGS.Create (icreate)
import WAGS.Example.KitchenSink.TLP.LoopSig (LoopSig(..), SceneSig)
import WAGS.Example.KitchenSink.TLP.SinOsc (doSinOsc)
import WAGS.Example.KitchenSink.Types.SinOsc (ksSinOscCreate)
import WAGS.Graph.Optionals (gain, speaker)
import WAGS.Create.Optionals (gain, speaker)

piece :: SceneSig Frame0
piece =
Expand Down
14 changes: 5 additions & 9 deletions examples/kitchen-sink/KitchenSink/TLP/Allpass.purs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
module WAGS.Example.KitchenSink.TLP.Allpass where

import Prelude

import Control.Applicative.Indexed (ipure)
import Control.Monad.Indexed.Qualified as Ix
import Data.Either (Either(..))
import Data.Functor.Indexed (ivoid)
import Math ((%))
import Type.Proxy (Proxy(..))
import WAGS.Change (ichange)
Expand All @@ -20,14 +18,13 @@ import WAGS.Example.KitchenSink.Timing (timing, pieceTime)
import WAGS.Example.KitchenSink.Types.Allpass (AllpassGraph, deltaKsAllpass)
import WAGS.Example.KitchenSink.Types.Empty (cursorGain)
import WAGS.Example.KitchenSink.Types.Lowpass (ksLowpassCreate)
import WAGS.Graph.Optionals (lowpass_, playBuf_)
import WAGS.Patch (ipatch)

doAllpass :: forall proof. StepSig AllpassGraph proof
doAllpass =
ibranch \{ time } lsig ->
if time % pieceTime < timing.ksAllpass.end then
Right (ichange (deltaKsAllpass time) $> lsig)
Right (deltaKsAllpass time $> lsig)
else if lsig.iteration `mod` 2 == 0 then
Left
$ icont doLowpass Ix.do
Expand All @@ -46,9 +43,8 @@ doAllpass =
Left
$ icont doLowpass Ix.do
ipatch
ivoid
$ ichange
{ lowpass: lowpass_ { freq: 300.0 }
, buf: playBuf_ "my-buffer"
}
ichange
{ lowpass: 300.0
, buf: "my-buffer"
}
ipure lsig
4 changes: 1 addition & 3 deletions examples/kitchen-sink/KitchenSink/TLP/Bandpass.purs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
module WAGS.Example.KitchenSink.TLP.Bandpass where

import Prelude

import Control.Applicative.Indexed (ipure)
import Control.Monad.Indexed.Qualified as Ix
import Data.Either (Either(..))
import Math ((%))
import Type.Proxy (Proxy(..))
import WAGS.Change (ichange)
import WAGS.Connect (iconnect)
import WAGS.Control.Functions (ibranch, icont)
import WAGS.Create (icreate)
Expand All @@ -24,7 +22,7 @@ doBandpass :: forall proof. StepSig BandpassGraph proof
doBandpass =
ibranch \{ time } lsig ->
if time % pieceTime < timing.ksBandpass.end then
Right (ichange (deltaKsBandpass time) $> lsig)
Right (deltaKsBandpass time $> lsig)
else
Left
$ icont doNotch Ix.do
Expand Down
3 changes: 1 addition & 2 deletions examples/kitchen-sink/KitchenSink/TLP/Constant.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Control.Monad.Indexed.Qualified as Ix
import Data.Either (Either(..))
import Math ((%))
import Type.Proxy (Proxy(..))
import WAGS.Change (ichange)
import WAGS.Connect (iconnect)
import WAGS.Control.Functions (ibranch, icont)
import WAGS.Create (icreate)
Expand All @@ -24,7 +23,7 @@ doConstant :: forall proof. StepSig ConstantGraph proof
doConstant =
ibranch \{ time } lsig ->
if time % pieceTime < timing.ksConstant.end then
Right (ichange (deltaKsConstant time) $> lsig)
Right (deltaKsConstant time $> lsig)
else
Left
$ icont doDynamicsCompressor Ix.do
Expand Down
4 changes: 1 addition & 3 deletions examples/kitchen-sink/KitchenSink/TLP/Delay.purs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
module WAGS.Example.KitchenSink.TLP.Delay where

import Prelude

import Control.Applicative.Indexed (ipure)
import Control.Monad.Indexed.Qualified as Ix
import Data.Either (Either(..))
import Math ((%))
import Type.Proxy (Proxy(..))
import WAGS.Change (ichange)
import WAGS.Connect (iconnect)
import WAGS.Control.Functions (ibranch, icont)
import WAGS.Create (icreate)
Expand All @@ -24,7 +22,7 @@ doDelay :: forall proof. StepSig DelayGraph proof
doDelay =
ibranch \{ time } lsig ->
if time % pieceTime < timing.ksDelay.end then
Right (ichange (deltaKsDelay time) $> lsig)
Right (deltaKsDelay time $> lsig)
else
Left
$ icont doFeedback Ix.do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Control.Monad.Indexed.Qualified as Ix
import Data.Either (Either(..))
import Math ((%))
import Type.Proxy (Proxy(..))
import WAGS.Change (ichange)
import WAGS.Connect (iconnect)
import WAGS.Control.Functions (ibranch, icont)
import WAGS.Create (icreate)
Expand Down Expand Up @@ -36,4 +35,4 @@ doDynamicsCompressor =
iconnect { source: Proxy :: _ "sinOsc", dest: cursorGain }
ipure $ l { iteration = iteration + 1 }
else
Right (ichange (deltaKsDynamicsCompressor time) $> l)
Right (deltaKsDynamicsCompressor time $> l)
6 changes: 2 additions & 4 deletions examples/kitchen-sink/KitchenSink/TLP/Feedback.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Prelude
import Control.Applicative.Indexed (ipure)
import Control.Monad.Indexed.Qualified as Ix
import Data.Either (Either(..))
import Data.Functor.Indexed (ivoid)
import Math ((%))
import Type.Proxy (Proxy(..))
import WAGS.Change (ichange)
Expand All @@ -20,13 +19,12 @@ import WAGS.Example.KitchenSink.Timing (pieceTime, timing)
import WAGS.Example.KitchenSink.Types.Empty (cursorGain)
import WAGS.Example.KitchenSink.Types.Feedback (FeedbackGraph, deltaKsFeedback)
import WAGS.Example.KitchenSink.Types.LoopBuf (ksLoopBufCreate)
import WAGS.Graph.Optionals (gain_)

doFeedback :: forall proof. StepSig FeedbackGraph proof
doFeedback =
ibranch \{ time } lsig ->
if time % pieceTime < timing.ksFeedback.end then
Right (ichange (deltaKsFeedback time) $> lsig)
Right (deltaKsFeedback time $> lsig)
else
Left
$ icont doLoopBuf Ix.do
Expand All @@ -49,5 +47,5 @@ doFeedback =
idestroy cursorHighpass
icreate ksLoopBufCreate
iconnect { source: Proxy :: _ "loopBuf", dest: cursorGain }
ivoid $ ichange { mix: gain_ 1.0 }
ichange { mix: 1.0 }
ipure lsig
4 changes: 1 addition & 3 deletions examples/kitchen-sink/KitchenSink/TLP/Highpass.purs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
module WAGS.Example.KitchenSink.TLP.Highpass where

import Prelude

import Control.Applicative.Indexed (ipure)
import Control.Monad.Indexed.Qualified as Ix
import Data.Either (Either(..))
import Math ((%))
import Type.Proxy (Proxy(..))
import WAGS.Change (ichange)
import WAGS.Connect (iconnect)
import WAGS.Control.Functions (ibranch, icont)
import WAGS.Create (icreate)
Expand All @@ -24,7 +22,7 @@ doHighpass :: forall proof. StepSig HighpassGraph proof
doHighpass =
ibranch \{ time } lsig ->
if time % pieceTime < timing.ksHighpass.end then
Right (ichange (deltaKsHighpass time) $> lsig)
Right (deltaKsHighpass time $> lsig)
else
Left
$ icont doMicrophone Ix.do
Expand Down
4 changes: 1 addition & 3 deletions examples/kitchen-sink/KitchenSink/TLP/Highshelf.purs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
module WAGS.Example.KitchenSink.TLP.Highshelf where

import Prelude

import Control.Applicative.Indexed (ipure)
import Control.Monad.Indexed.Qualified as Ix
import Data.Either (Either(..))
import Math ((%))
import Type.Proxy (Proxy(..))
import WAGS.Change (ichange)
import WAGS.Connect (iconnect)
import WAGS.Control.Functions (ibranch, icont)
import WAGS.Create (icreate)
Expand All @@ -24,7 +22,7 @@ doHighshelf :: forall proof. StepSig HighshelfGraph proof
doHighshelf =
ibranch \{ time } lsig ->
if time % pieceTime < timing.ksHighshelf.end then
Right (ichange (deltaKsHighshelf time) $> lsig)
Right (deltaKsHighshelf time $> lsig)
else
Left
$ icont doLowshelf Ix.do
Expand Down
3 changes: 1 addition & 2 deletions examples/kitchen-sink/KitchenSink/TLP/LoopBuf.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Control.Monad.Indexed.Qualified as Ix
import Data.Either (Either(..))
import Math ((%))
import Type.Proxy (Proxy(..))
import WAGS.Change (ichange)
import WAGS.Connect (iconnect)
import WAGS.Control.Functions (ibranch, icont)
import WAGS.Create (icreate)
Expand All @@ -23,7 +22,7 @@ doLoopBuf :: forall proof. StepSig LoopBufGraph proof
doLoopBuf =
ibranch \{ time } lsig ->
if time % pieceTime < timing.ksLoopBuf.end then
Right (ichange (deltaKsLoopBuf time) $> lsig)
Right (deltaKsLoopBuf time $> lsig)
else
Left
$ icont doStereoPanner Ix.do
Expand Down
17 changes: 8 additions & 9 deletions examples/kitchen-sink/KitchenSink/TLP/LoopSig.purs
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
module WAGS.Example.KitchenSink.TLP.LoopSig where

import Prelude
import Effect (Effect)

import WAGS.Control.Indexed (IxWAG)
import WAGS.Control.Types (Frame, Scene, WAG)
import WAGS.Example.KitchenSink.Types.SinOsc (SinOscGraph)
import WAGS.Interpret (FFIAudio)
import WAGS.Run (SceneI)
import WAGS.Example.KitchenSink.Types.StartGraph (StartGraph)
import WAGS.Run (RunEngine, SceneI, RunAudio)

type Res
= String

type SceneSig :: forall k. k -> Type
type SceneSig proof
= Scene (SceneI Unit Unit) FFIAudio (Effect Unit) proof Res
= Scene (SceneI Unit Unit) RunAudio RunEngine proof Res

type FrameSig' step proof a
= Frame (SceneI Unit Unit) FFIAudio (Effect Unit) proof Res step a
= Frame (SceneI Unit Unit) RunAudio RunEngine proof Res step a

type FrameSig step proof
= FrameSig' step proof { loop :: LoopSig, iteration :: Int }

type WAGSig' step proof a
= WAG FFIAudio (Effect Unit) proof Res step a
= WAG RunAudio RunEngine proof Res step a

type WAGSig step proof
= WAGSig' step proof { loop :: LoopSig, iteration :: Int }

type IxWAGSig' stepA stepB proof a
= IxWAG FFIAudio (Effect Unit) proof Res stepA stepB a
= IxWAG RunAudio RunEngine proof Res stepA stepB a

type IxWAGSig stepA stepB proof
= IxWAGSig' stepA stepB proof { loop :: LoopSig, iteration :: Int }
Expand All @@ -38,4 +37,4 @@ type StepSig step proof
SceneSig proof

newtype LoopSig
= LoopSig (forall proof. StepSig SinOscGraph proof)
= LoopSig (forall proof. StepSig StartGraph proof)
4 changes: 1 addition & 3 deletions examples/kitchen-sink/KitchenSink/TLP/Lowpass.purs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
module WAGS.Example.KitchenSink.TLP.Lowpass where

import Prelude

import Control.Applicative.Indexed (ipure)
import Control.Monad.Indexed.Qualified as Ix
import Data.Either (Either(..))
import Math ((%))
import Type.Proxy (Proxy(..))
import WAGS.Change (ichange)
import WAGS.Connect (iconnect)
import WAGS.Control.Functions (ibranch, icont)
import WAGS.Create (icreate)
Expand All @@ -24,7 +22,7 @@ doLowpass :: forall proof. StepSig LowpassGraph proof
doLowpass =
ibranch \{ time } lsig ->
if time % pieceTime < timing.ksLowpass.end then
Right (ichange (deltaKsLowpass time) $> lsig)
Right (deltaKsLowpass time $> lsig)
else
Left
$ icont doHighshelf Ix.do
Expand Down
Loading

0 comments on commit bdaa704

Please sign in to comment.