Skip to content

Commit

Permalink
0.5.1.1 restored from-then-to ranges, and better guards for both from…
Browse files Browse the repository at this point in the history
…-then-to and from-to ranges
  • Loading branch information
dktr0 committed Jan 30, 2025
1 parent 160086e commit b1cc1a2
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 189 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ChangeLog

0.5.1.1:

-restored "from then to" ranges, e.g [0.0,0.1 .. 1.0] and established consistent limits for both from then to and from then ranges with respect to maximum resulting channels (currently 64)

0.5.1:

-added splay, pan, and panp (all work for both audio and visual outputs)
Expand Down
8 changes: 8 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ pan/panp [n] [graph] [graph] -- equal-power panning (cosine law) over n (an inte

splay [n] [graph] -- the channels of the provided graph are spread over n (an integer) output channels, using the same equal-power panning algorithm as pan/panp. also works with both audio and visual outputs.

## Ranges

Punctual has the following two notations for producing lists (one-dimensional matrices) of constant values, modeled on similar functionality found in Haskell and Purescript, but with some specific semantics adapted to the live coding situations in which Punctual is expected to be used.

[x ... y] -- x and y must both be constant integers. result is x and y and every integer in between them. if y < x then results will descend towards y. if the provided values would result in more than 64 results, they are limited to the first 64 results.

[a, b .. c] -- a, b, and c must be constant floating point numbers. result is a, then b, then every value between b and c proceeding by interval of (b-a), until and including c. To account for floating point rounding errors, if the second last value is less than half of (b-a) away from c, it is excluded. the final value in the result is always exactly c (no rounding error). If the provided values would result in more than 64 results, they are limited to the first 64 results.

## Punctual Graph Functions Specialised for Graphics

These functions are specialized for graphics. (While they are still "valid" in
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<div class="editorAndStatus">
<div class="editor">
<textarea class="editorArea" id="editorArea">
-- Punctual, an audiovisual live coding language, version 0.5.1
-- Punctual, an audiovisual live coding language, version 0.5.1.1
-- Press Shift-Enter to (re)evaluate/activate code
-- documentation @ /~https://github.com/dktr0/Punctual.git
-- help/discussion @ Estuary discord server
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": "punctual",
"version": "0.5.1",
"version": "0.5.1.1",
"description": "punctual",
"private": true,
"dependencies": {
Expand Down
340 changes: 170 additions & 170 deletions punctual.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ launch args = do
combinedProgramInfo <- new emptySignalInfo
webGLs <- new empty
audioZones <- new empty
log "punctual 0.5.1 initialization complete"
log "punctual 0.5.1.1 initialization complete"
pure { sharedResources, programs, previousPrograms, programInfos, previousProgramInfos, combinedProgramInfo, webGLs, audioZones }


Expand Down
22 changes: 11 additions & 11 deletions src/Number.purs
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ showNumber x
| otherwise = show x


fromThen :: forall f. Unfoldable1 f => Functor f => Int -> Int -> f Number
fromThen x y = toNumber <$> range x (_fromThenLimited x y)
fromTo :: forall f. Unfoldable1 f => Functor f => Int -> Int -> f Number
fromTo x y = toNumber <$> range x (_fromToLimited x y)

_fromThenLimited :: Int -> Int -> Int
_fromThenLimited x y
| y >= x = x + (min (y - x) 63)
| otherwise = x - (min (x - y) 63)
_fromToLimited :: Int -> Int -> Int
_fromToLimited x y
| y >= x = x + (min (y - x) (_fromToChannelLimit - 1))
| otherwise = x - (min (x - y) (_fromToChannelLimit -1))

_fromThenChannelLimit :: Int
_fromThenChannelLimit = 64
_fromToChannelLimit :: Int
_fromToChannelLimit = 64

fromThenTo :: forall f. Unfoldable1 f => Semigroup (f Number) => Number -> Number -> Number -> f Number
fromThenTo a b c
Expand All @@ -63,7 +63,7 @@ fromThenTo a b c
| b == c = singleton a <> singleton b
| (b > a) && (c < a) = singleton a
| (b < a) && (c > a) = singleton a
| _fromThenChannels a b c > (toNumber _fromThenChannelLimit) = fromThenTo a b (a+((b-a)*(toNumber _fromThenChannelLimit - 1.0)))
| _fromThenToChannels a b c > (toNumber _fromToChannelLimit) = fromThenTo a b (a+((b-a)*(toNumber _fromToChannelLimit - 1.0)))
-- in the generative case, the result is the starting value, the final value, and all values in between that are less than the final value
| otherwise = singleton a <> unfoldr1 (_fromThenToUnfolder c (b-a)) a <> singleton c

Expand All @@ -74,5 +74,5 @@ _fromThenToUnfolder finalValue delta prevValue = Tuple a maybeB
maybeB = if (a + delta) >= (finalValue - (delta * 0.5)) then Nothing else Just a

-- note: this is assumed to be correct only for the generative case
_fromThenChannels :: Number -> Number -> Number -> Number
_fromThenChannels a b c = ((c-a)/(b-a)) + 1.0
_fromThenToChannels :: Number -> Number -> Number -> Number
_fromThenToChannels a b c = ((c-a)/(b-a)) + 1.0
9 changes: 4 additions & 5 deletions src/Parser.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ module Parser where

import Prelude (bind, discard, pure, unit, ($), (<$>), (<<<), (<>), (>>=), max, show, Unit)
import Control.Monad (class Monad)
import Data.Int (toNumber)
import Data.Tuple (Tuple(..))
import Data.Either (Either(..))
import Data.Maybe (Maybe(..))
import Data.List (List(..), range, (:))
import Data.List (List(..),(:))
import Data.Traversable (traverse)
import Data.Map (empty)
import Control.Monad.Trans.Class (lift)
Expand Down Expand Up @@ -34,6 +33,7 @@ import Action (Action, setCrossFade, setOutput)
import Output (Output)
import Output as Output
import SharedResources (URL)
import Number (fromTo,fromThenTo)

parseProgram :: LibraryCache -> String -> DateTime -> Aff (Either ParseError Program)
parseProgram libCache txt eTime = do
Expand Down Expand Up @@ -134,9 +134,8 @@ parseExpression (Operation p op x y) = do
y' <- parseExpression y
z <- application f x'
application z y'
parseExpression (FromTo p x y) = pure $ ValueSignal p $ SignalList Combinatorial $ (Constant <<< toNumber) <$> range x y
parseExpression (FromThenTo p _ _ _) = throwError $ ParseError "FromThenTo not supported yet" p
-- TODO: implement FromThenTo
parseExpression (FromTo p x y) = pure $ ValueSignal p $ SignalList Combinatorial $ Constant <$> fromTo x y
parseExpression (FromThenTo p a b c) = pure $ ValueSignal p $ SignalList Combinatorial $ Constant <$> fromThenTo a b c
parseExpression (Lambda p xs e) = embedLambdas p xs e
parseExpression (IfThenElse p i t e) = do
i' <- parseExpression i >>= valueToSignal
Expand Down

0 comments on commit b1cc1a2

Please sign in to comment.