Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASL2 #399

Merged
merged 40 commits into from
May 11, 2021
Merged

ASL2 #399

merged 40 commits into from
May 11, 2021

Conversation

trentgill
Copy link
Collaborator

@trentgill trentgill commented Apr 28, 2021

A Slope Language v2

ASL is rebuilt to execute in C, allowing for audiorate cycles - specifically oscillation up to nyquist freq (24kHz).

The API has some breaking changes, but is generally the same as V1.

-- globals (same as prior)
to(voltage, time, shape)
loop(...)
held(...)
lock(...)
times(n, ...)

-- globals. newly added
dyn{k=v}
mutable(n)
mutable{k=v}

-- notable ASL namespace functions
asl._if(predicate, ...)
asl._while(predicate, ...)

Asllib is also updated but functionality is unchanged (The code is dramatically simplified though).

n2v, negate and clamp are removed (as they can be replaced with native math operations, or asl constructs. This may break some rare scripts (notably n2v was used frequently in non-asl code. It can be replaced with a divide-by-12).

output[n].done event callback is no longer available
is_running = output[n].running query is no longer available


dyn, short for Dynamic, is useful for naming ASL arguments so that they can be updated by a script, without restarting the ASL.

-- create an lfo with a dynamic height, starting at 3V
output[1]( loop{ to( dyn{height=3}, 1)
               , to( 0, 1)
               }
)

output[1].dyn.height = 1 -- update height of LFO to 1V
-- note: this will take effect at the next repetition

Dynamic vars can be used anywhere in the ASL, either in a to() call, or as a predicate value (eg. asl._if).

Additionally, all asllib functions may take dyn values as variables. Eg:

-- an lfo whose speed can be changed at runtime
output[2]( lfo( dyn{speed=0.1} ) )

Mutable values are typically literal values that can have a mutation applied at each usage.

Stepping back, both dyn and mutable values can have arithmetic applied to them. This is written as if the wrapped values were simple literals, eg dyn{num=3} * 11 - 2. The result will be computed at runtime, such that as the dyn is updated, the result will change as well.

Available operations are + - * / % where % is floating point 'wrap' from zero to the 2nd operand. - may be used as unary negation, or subtraction.

Returning to mutable values, these values will be updated by any arithmetic operations at each usage of the value. This can be used for simple iterators (the times construct is implemented with a mutable), or more complex things like animated waveforms. There is much space to explore with this feature.

Mutable values may be named or anonymous. Anonymous are as discussed above, eg: asl._if( mutable(10)-1, ...). Named mutables add named access like Dynamic vars:

-- lfo where the frequency increases cyclically
output[3]( lfo( (mutable{time=1}-0.01) % 1 + 0.01 ) )

output[3].mutable.time = 0.2 -- jump to a faster FM

Notably, ASL can no longer call arbitrary lua functions. The only 'verb' function is to(), meaning the sole purpose of ASL is for controlling voltage slopes. This will break some older scripts, but I would suggest they'd be far more cleanly articulated as a clock routine. Unfortunately there's no way to provide this feature now that the runtime is entirely in C.

More commentary soon!

Fixes #301

@trentgill trentgill requested a review from tehn April 28, 2021 04:22
@tehn
Copy link
Member

tehn commented Apr 28, 2021

dang look at all of those commits!

dyn is fantastic, great design. looking forward to more documentation and examples generally.

(aha just found extra docs in casl.lua)

my feeling is that you should just merge this and we can/should test everything in parallel since THREE is basically a dev branch.

@trentgill trentgill merged commit 35495f2 into THREE May 11, 2021
@trentgill trentgill mentioned this pull request Jun 15, 2021
trentgill added a commit that referenced this pull request Jun 30, 2021
* can now update output[n].scale(_) with .scale = {note list}, so it can be dynamically set like a regular table (#373)

* fix bug where aliasing an ii address before use could stack overflow (#374)

* querying output voltage now returns the shaped & scaled voltage (real voltage at jack)

* add just intonation helpers: justvolts(), just12()
* support input scales: input[n].mode( 'scale', {...}, 'ji')
* support output scales: output[n].scale({...}, 'ji')

* Python based bootloader support and dfureset (#377)
* `make pydfu` to use python3 dfu bootloader
* `make dfureset` jumps to bootloader from make
* `make zip` now builds dfu file as well as binary
* add instructions for using pydfu instead of dfu-util

* Frequency detect mode for input[1] (#382)
* `input[1].mode('freq', interval)` reports frequency of a signal connected to input 1 (no support for input 2)
* `hztovolts(hz, <ref>)` helper fn converts an input hz equivalent voltage (uses default reference to match Just-Friends & W/Syn)

* print an error to usb host if event queue overflows (#391)

* clock.lua module added (#393)

* New calibrate.lua & underlying engine (#397)
Breaking:
* `cal` lua module refactored with new API
* calibration no longer auto-runs if no vals saved (ie new factory modules)
* `util/recalibrate.lua` demonstrates usage, and can be used for factory calibration (or at home)

* double userscript storage size to 16kB (#396)

* add jacktest.lua

* strip debug info from crow lua libs for dramatic ram reduction (#395)

* Sequins.lua library (#387)
* add sequins library

* ASL2 (#399) ASL2 library. Runtime operates in C for greatly optimized performance & sample accuracy

* introduce Caw_printf

* Public.lua library for sharing parameters (#394)
* after calling init() crow sends '^^ready()'
* add 'public.view' for enabling live monitoring of in & out voltages

* Oscillate asllib fn (#407)
* add 'oscillate' asllib fn

* add note about not using `note` in asllib. kept only to avoid the breaking change

* add quote library & remove quotes global (#412)

* support ii getters from teletype (#403)

Co-authored-by: brian crabtree <tehn@monome.org>
@trentgill trentgill deleted the Casl branch July 3, 2021 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants